| Index: components/offline_pages/core/background/request_coordinator_unittest.cc
|
| diff --git a/components/offline_pages/core/background/request_coordinator_unittest.cc b/components/offline_pages/core/background/request_coordinator_unittest.cc
|
| index a880978473392ff8d74d374e705abacc21adbd21..6f606be8331684ecf05a42798e0d7e0eedf44b15 100644
|
| --- a/components/offline_pages/core/background/request_coordinator_unittest.cc
|
| +++ b/components/offline_pages/core/background/request_coordinator_unittest.cc
|
| @@ -127,7 +127,7 @@ class RequestCoordinatorTest : public testing::Test {
|
| void WaitingCallbackFunction(bool result) { waiter_.Signal(); }
|
|
|
| net::NetworkChangeNotifier::ConnectionType GetConnectionType() {
|
| - return coordinator()->GetConnectionType();
|
| + return coordinator()->current_conditions_->GetNetConnectionType();
|
| }
|
|
|
| // Callback for Add requests.
|
| @@ -168,24 +168,23 @@ class RequestCoordinatorTest : public testing::Test {
|
| offliner_->enable_callback(enable);
|
| }
|
|
|
| - void SetNetworkConditionsForTest(
|
| - net::NetworkChangeNotifier::ConnectionType connection) {
|
| - coordinator()->SetNetworkConditionsForTest(connection);
|
| - }
|
| -
|
| void SetEffectiveConnectionTypeForTest(net::EffectiveConnectionType type) {
|
| network_quality_estimator_->SetEffectiveConnectionTypeForTest(type);
|
| }
|
|
|
| void SetNetworkConnected(bool connected) {
|
| if (connected) {
|
| - SetNetworkConditionsForTest(
|
| - net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
|
| + DeviceConditions device_conditions(
|
| + !kPowerRequired, kBatteryPercentageHigh,
|
| + net::NetworkChangeNotifier::CONNECTION_3G);
|
| + SetDeviceConditionsForTest(device_conditions);
|
| SetEffectiveConnectionTypeForTest(
|
| net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G);
|
| } else {
|
| - SetNetworkConditionsForTest(
|
| - net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE);
|
| + DeviceConditions device_conditions(
|
| + !kPowerRequired, kBatteryPercentageHigh,
|
| + net::NetworkChangeNotifier::CONNECTION_NONE);
|
| + SetDeviceConditionsForTest(device_conditions);
|
| SetEffectiveConnectionTypeForTest(
|
| net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
|
| }
|
| @@ -227,6 +226,10 @@ class RequestCoordinatorTest : public testing::Test {
|
| coordinator_->SetDeviceConditionsForTest(device_conditions);
|
| }
|
|
|
| + DeviceConditions* GetDeviceConditions() {
|
| + return coordinator()->current_conditions_.get();
|
| + }
|
| +
|
| void WaitForCallback() { waiter_.Wait(); }
|
|
|
| void AdvanceClockBy(base::TimeDelta delta) {
|
| @@ -443,8 +446,7 @@ TEST_F(RequestCoordinatorTest, StartScheduledProcessingWithRequestInProgress) {
|
| }
|
|
|
| TEST_F(RequestCoordinatorTest, StartImmediateProcessingWithNoRequests) {
|
| - EXPECT_TRUE(coordinator()->StartImmediateProcessing(device_conditions(),
|
| - processing_callback()));
|
| + EXPECT_TRUE(coordinator()->StartImmediateProcessing(processing_callback()));
|
| PumpLoop();
|
|
|
| EXPECT_TRUE(processing_callback_called());
|
| @@ -457,8 +459,7 @@ TEST_F(RequestCoordinatorTest, StartImmediateProcessingOnSvelte) {
|
| // Set as low-end device to verfiy immediate processing will not start.
|
| SetIsLowEndDeviceForTest(true);
|
|
|
| - EXPECT_FALSE(coordinator()->StartImmediateProcessing(device_conditions(),
|
| - processing_callback()));
|
| + EXPECT_FALSE(coordinator()->StartImmediateProcessing(processing_callback()));
|
| histograms().ExpectBucketCount("OfflinePages.Background.ImmediateStartStatus",
|
| 5 /* NOT_STARTED_ON_SVELTE */, 1);
|
| }
|
| @@ -467,8 +468,8 @@ TEST_F(RequestCoordinatorTest, StartImmediateProcessingWhenDisconnected) {
|
| DeviceConditions disconnected_conditions(
|
| !kPowerRequired, kBatteryPercentageHigh,
|
| net::NetworkChangeNotifier::CONNECTION_NONE);
|
| - EXPECT_FALSE(coordinator()->StartImmediateProcessing(disconnected_conditions,
|
| - processing_callback()));
|
| + SetDeviceConditionsForTest(disconnected_conditions);
|
| + EXPECT_FALSE(coordinator()->StartImmediateProcessing(processing_callback()));
|
| histograms().ExpectBucketCount("OfflinePages.Background.ImmediateStartStatus",
|
| 3 /* NO_CONNECTION */, 1);
|
| }
|
| @@ -484,8 +485,7 @@ TEST_F(RequestCoordinatorTest, StartImmediateProcessingWithRequestInProgress) {
|
| EnableOfflinerCallback(false);
|
|
|
| // Sending the request to the offliner should make it busy.
|
| - EXPECT_TRUE(coordinator()->StartImmediateProcessing(device_conditions(),
|
| - processing_callback()));
|
| + EXPECT_TRUE(coordinator()->StartImmediateProcessing(processing_callback()));
|
| PumpLoop();
|
|
|
| EXPECT_TRUE(is_busy());
|
| @@ -493,8 +493,7 @@ TEST_F(RequestCoordinatorTest, StartImmediateProcessingWithRequestInProgress) {
|
| EXPECT_FALSE(processing_callback_called());
|
|
|
| // Now trying to start processing should return false since already busy.
|
| - EXPECT_FALSE(coordinator()->StartImmediateProcessing(device_conditions(),
|
| - processing_callback()));
|
| + EXPECT_FALSE(coordinator()->StartImmediateProcessing(processing_callback()));
|
|
|
| histograms().ExpectBucketCount("OfflinePages.Background.ImmediateStartStatus",
|
| 1 /* BUSY */, 1);
|
| @@ -531,7 +530,7 @@ TEST_F(RequestCoordinatorTest, SavePageLater) {
|
| EXPECT_EQ(coordinator()
|
| ->GetTriggerConditions(last_requests()[0]->user_requested())
|
| .minimum_battery_percentage,
|
| - scheduler_stub->conditions()->minimum_battery_percentage);
|
| + scheduler_stub->trigger_conditions()->minimum_battery_percentage);
|
|
|
| // Check that the observer got the notification that a page is available
|
| EXPECT_TRUE(observer().added_called());
|
| @@ -583,7 +582,7 @@ TEST_F(RequestCoordinatorTest, SavePageLaterFailed) {
|
| EXPECT_EQ(coordinator()
|
| ->GetTriggerConditions(last_requests()[0]->user_requested())
|
| .minimum_battery_percentage,
|
| - scheduler_stub->conditions()->minimum_battery_percentage);
|
| + scheduler_stub->trigger_conditions()->minimum_battery_percentage);
|
|
|
| // Check that the observer got the notification that a page is available
|
| EXPECT_TRUE(observer().added_called());
|
| @@ -846,7 +845,8 @@ TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) {
|
| reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
|
| EXPECT_TRUE(scheduler_stub->schedule_called());
|
| EXPECT_TRUE(scheduler_stub->unschedule_called());
|
| - const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions();
|
| + const Scheduler::TriggerConditions* conditions =
|
| + scheduler_stub->trigger_conditions();
|
| EXPECT_EQ(conditions->require_power_connected,
|
| coordinator()->policy()->PowerRequired(!kUserRequested));
|
| EXPECT_EQ(
|
| @@ -875,7 +875,8 @@ TEST_F(RequestCoordinatorTest, SchedulerGetsLeastRestrictiveConditions) {
|
| // priority.
|
| SchedulerStub* scheduler_stub =
|
| reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
|
| - const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions();
|
| + const Scheduler::TriggerConditions* conditions =
|
| + scheduler_stub->trigger_conditions();
|
| EXPECT_TRUE(scheduler_stub->schedule_called());
|
| EXPECT_EQ(conditions->require_power_connected,
|
| coordinator()->policy()->PowerRequired(kUserRequested));
|
| @@ -1366,8 +1367,9 @@ TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) {
|
| TEST_F(RequestCoordinatorTest,
|
| SavePageDoesStartProcessingWhenPoorlyConnected) {
|
| // Set specific network type for 2G with poor effective connection.
|
| - SetNetworkConditionsForTest(
|
| - net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G);
|
| + DeviceConditions device_conditions(!kPowerRequired, kBatteryPercentageHigh,
|
| + net::NetworkChangeNotifier::CONNECTION_2G);
|
| + SetDeviceConditionsForTest(device_conditions);
|
| SetEffectiveConnectionTypeForTest(
|
| net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
|
|
|
|
|