forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Offline pages] Refactoring request_coordinator_unittest.cc to create…
… RC builder Extracting classes defined in the RC request_coordinator_unittest in order to include them in test_request_coordinator_factory. BUG= Review-Url: https://codereview.chromium.org/2523603004 Cr-Commit-Position: refs/heads/master@{#434391}
- Loading branch information
Showing
14 changed files
with
450 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
chrome/browser/android/offline_pages/test_request_coordinator_builder.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/android/offline_pages/test_request_coordinator_builder.h" | ||
|
||
#include <utility> | ||
|
||
#include "components/offline_pages/background/network_quality_provider_stub.h" | ||
#include "components/offline_pages/background/offliner_factory_stub.h" | ||
#include "components/offline_pages/background/offliner_policy.h" | ||
#include "components/offline_pages/background/request_coordinator.h" | ||
#include "components/offline_pages/background/request_queue.h" | ||
#include "components/offline_pages/background/request_queue_in_memory_store.h" | ||
#include "components/offline_pages/background/scheduler_stub.h" | ||
#include "content/public/browser/browser_context.h" | ||
|
||
namespace offline_pages { | ||
|
||
std::unique_ptr<KeyedService> BuildTestRequestCoordinator( | ||
content::BrowserContext* context) { | ||
// Use original policy. | ||
std::unique_ptr<OfflinerPolicy> policy(new OfflinerPolicy()); | ||
|
||
// Use the in-memory store. | ||
std::unique_ptr<RequestQueueInMemoryStore> store( | ||
new RequestQueueInMemoryStore()); | ||
// Use the regular test queue (should work). | ||
std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store))); | ||
|
||
// Initialize the rest with stubs. | ||
std::unique_ptr<OfflinerFactory> offliner_factory(new OfflinerFactoryStub()); | ||
std::unique_ptr<Scheduler> scheduler_stub(new SchedulerStub()); | ||
|
||
// NetworkQualityProviderStub should be set by the test on the context first. | ||
NetworkQualityProviderStub* network_quality_provider = | ||
NetworkQualityProviderStub::GetUserData(context); | ||
|
||
return std::unique_ptr<RequestCoordinator>(new RequestCoordinator( | ||
std::move(policy), std::move(offliner_factory), std::move(queue), | ||
std::move(scheduler_stub), network_quality_provider)); | ||
} | ||
|
||
} // namespace offline_pages |
26 changes: 26 additions & 0 deletions
26
chrome/browser/android/offline_pages/test_request_coordinator_builder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_TEST_REQUEST_COORDINATOR_BUILDER_H_ | ||
#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_TEST_REQUEST_COORDINATOR_BUILDER_H_ | ||
|
||
#include <memory> | ||
|
||
class KeyedService; | ||
|
||
namespace content { | ||
class BrowserContext; | ||
} | ||
|
||
namespace offline_pages { | ||
|
||
// Helper function to be used with | ||
// BrowserContextKeyedServiceFactory::SetTestingFactory() that returns a | ||
// RequestCoordinator object with mocked store. | ||
std::unique_ptr<KeyedService> BuildTestRequestCoordinator( | ||
content::BrowserContext* context); | ||
|
||
} // namespace offline_pages | ||
|
||
#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_TEST_REQUEST_COORDINATOR_BUILDER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
components/offline_pages/background/network_quality_provider_stub.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/offline_pages/background/network_quality_provider_stub.h" | ||
|
||
namespace offline_pages { | ||
|
||
const char kOfflineNQPKey[] = "OfflineNQP"; | ||
|
||
NetworkQualityProviderStub::NetworkQualityProviderStub() | ||
: connection_type_( | ||
net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G) {} | ||
|
||
NetworkQualityProviderStub::~NetworkQualityProviderStub() {} | ||
|
||
// static | ||
NetworkQualityProviderStub* NetworkQualityProviderStub::GetUserData( | ||
base::SupportsUserData* supports_user_data) { | ||
return static_cast<NetworkQualityProviderStub*>( | ||
supports_user_data->GetUserData(&kOfflineNQPKey)); | ||
} | ||
|
||
// static | ||
void NetworkQualityProviderStub::SetUserData( | ||
base::SupportsUserData* supports_user_data, | ||
NetworkQualityProviderStub* stub) { | ||
DCHECK(supports_user_data); | ||
DCHECK(stub); | ||
supports_user_data->SetUserData(&kOfflineNQPKey, stub); | ||
} | ||
|
||
void NetworkQualityProviderStub::AddEffectiveConnectionTypeObserver( | ||
net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) {} | ||
|
||
void NetworkQualityProviderStub::RemoveEffectiveConnectionTypeObserver( | ||
net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) {} | ||
|
||
net::EffectiveConnectionType | ||
NetworkQualityProviderStub::GetEffectiveConnectionType() const { | ||
return connection_type_; | ||
} | ||
} // namespace offline_pages |
48 changes: 48 additions & 0 deletions
48
components/offline_pages/background/network_quality_provider_stub.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_NETWORK_QUALITY_PROVIDER_STUB_H_ | ||
#define COMPONENTS_OFFLINE_PAGES_BACKGROUND_NETWORK_QUALITY_PROVIDER_STUB_H_ | ||
|
||
#include "base/supports_user_data.h" | ||
#include "net/nqe/effective_connection_type.h" | ||
#include "net/nqe/network_quality_estimator.h" | ||
|
||
namespace offline_pages { | ||
|
||
// Test class stubbing out the functionality of NQE::NetworkQualityProvider. | ||
// It is only used for test support. | ||
class NetworkQualityProviderStub | ||
: public net::NetworkQualityEstimator::NetworkQualityProvider, | ||
public base::SupportsUserData::Data { | ||
public: | ||
NetworkQualityProviderStub(); | ||
~NetworkQualityProviderStub() override; | ||
|
||
static NetworkQualityProviderStub* GetUserData( | ||
base::SupportsUserData* supports_user_data); | ||
static void SetUserData(base::SupportsUserData* supports_user_data, | ||
NetworkQualityProviderStub* stub); | ||
|
||
net::EffectiveConnectionType GetEffectiveConnectionType() const override; | ||
|
||
void AddEffectiveConnectionTypeObserver( | ||
net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) | ||
override; | ||
|
||
void RemoveEffectiveConnectionTypeObserver( | ||
net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) | ||
override; | ||
|
||
void SetEffectiveConnectionTypeForTest(net::EffectiveConnectionType type) { | ||
connection_type_ = type; | ||
} | ||
|
||
private: | ||
net::EffectiveConnectionType connection_type_; | ||
}; | ||
|
||
} // namespace offline_pages | ||
|
||
#endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_NETWORK_QUALITY_PROVIDER_STUB_H_ |
22 changes: 22 additions & 0 deletions
22
components/offline_pages/background/offliner_factory_stub.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/offline_pages/background/offliner_factory_stub.h" | ||
|
||
#include "components/offline_pages/background/offliner_stub.h" | ||
|
||
namespace offline_pages { | ||
|
||
OfflinerFactoryStub::OfflinerFactoryStub() : offliner_(nullptr) {} | ||
|
||
OfflinerFactoryStub::~OfflinerFactoryStub() {} | ||
|
||
Offliner* OfflinerFactoryStub::GetOffliner(const OfflinerPolicy* policy) { | ||
if (offliner_.get() == nullptr) { | ||
offliner_.reset(new OfflinerStub()); | ||
} | ||
return offliner_.get(); | ||
} | ||
|
||
} // namespace offline_pages |
31 changes: 31 additions & 0 deletions
31
components/offline_pages/background/offliner_factory_stub.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_FACTORY_STUB_H_ | ||
#define COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_FACTORY_STUB_H_ | ||
|
||
#include <memory> | ||
|
||
#include "components/offline_pages/background/offliner_factory.h" | ||
|
||
namespace offline_pages { | ||
|
||
class OfflinerStub; | ||
|
||
// Test class stubbing out the functionality of OfflinerFactory. | ||
// It is only used for test support. | ||
class OfflinerFactoryStub : public OfflinerFactory { | ||
public: | ||
OfflinerFactoryStub(); | ||
~OfflinerFactoryStub() override; | ||
|
||
Offliner* GetOffliner(const OfflinerPolicy* policy) override; | ||
|
||
private: | ||
std::unique_ptr<OfflinerStub> offliner_; | ||
}; | ||
|
||
} // namespace offline_pages | ||
|
||
#endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_FACTORY_STUB_H_ |
Oops, something went wrong.