Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: components/offline_pages/background/request_coordinator_unittest.cc

Issue 2269173003: Adjust scheduling for non-user requested items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: FGorski CR feedback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/background/request_coordinator_unittest.cc
diff --git a/components/offline_pages/background/request_coordinator_unittest.cc b/components/offline_pages/background/request_coordinator_unittest.cc
index 25c6311e1034c0437c628875ebec7a272b1969b7..61ea62fd0bdac36373e5cb1f3b6348941ab0745a 100644
--- a/components/offline_pages/background/request_coordinator_unittest.cc
+++ b/components/offline_pages/background/request_coordinator_unittest.cc
@@ -239,6 +239,12 @@ class RequestCoordinatorTest
coordinator()->SetNetworkConditionsForTest(connection);
}
+ void ScheduleForTest() { coordinator_->ScheduleAsNeeded(); }
+
+ void CallRequestNotPicked(bool non_user_requested_tasks_remaining) {
+ coordinator_->RequestNotPicked(non_user_requested_tasks_remaining);
+ }
+
void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) {
coordinator_->SetOfflinerTimeoutForTest(timeout);
}
@@ -391,7 +397,7 @@ TEST_F(RequestCoordinatorTest, SavePageLater) {
coordinator()->scheduler());
EXPECT_TRUE(scheduler_stub->schedule_called());
EXPECT_EQ(coordinator()
- ->GetTriggerConditionsForUserRequest()
+ ->GetTriggerConditions(last_requests()[0].user_requested())
.minimum_battery_percentage,
scheduler_stub->conditions()->minimum_battery_percentage);
@@ -582,6 +588,70 @@ TEST_F(RequestCoordinatorTest, OfflinerDonePrerenderingCancel) {
EXPECT_EQ(0L, found_request.completed_attempt_count());
}
+// If one item completes, and there are no more user requeted items left,
+// we should make a scheduler entry for a non-user requested item.
+TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) {
+ // Call start processing just to set up a scheduler callback.
+ DeviceConditions device_conditions(false, 75,
+ net::NetworkChangeNotifier::CONNECTION_3G);
+ base::Callback<void(bool)> callback = base::Bind(
+ &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
+ coordinator()->StartProcessing(device_conditions, callback);
+
+ // Call RequestNotPicked, and make sure we pick schedule a task for non user
+ // requested conditions.
+ CallRequestNotPicked(true);
+ PumpLoop();
+
+ // The scheduler should have been called to schedule the non-user requested
+ // task.
+ SchedulerStub* scheduler_stub =
+ reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
+ EXPECT_TRUE(scheduler_stub->schedule_called());
+ EXPECT_TRUE(scheduler_stub->unschedule_called());
+ const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions();
+ EXPECT_EQ(conditions->require_power_connected,
+ coordinator()->policy()->PowerRequired(!kUserRequested));
+ EXPECT_EQ(
+ conditions->minimum_battery_percentage,
+ coordinator()->policy()->BatteryPercentageRequired(!kUserRequested));
+ EXPECT_EQ(conditions->require_unmetered_network,
+ coordinator()->policy()->UnmeteredNetworkRequired(!kUserRequested));
+}
+
+TEST_F(RequestCoordinatorTest, SchedulerGetsLeastRestrictiveConditions) {
+ // Put two requests on the queue - The first is user requested, and
+ // the second is not user requested.
+ offline_pages::SavePageRequest request1(kRequestId1, kUrl1, kClientId1,
+ base::Time::Now(), kUserRequested);
+ coordinator()->queue()->AddRequest(
+ request1, base::Bind(&RequestCoordinatorTest::AddRequestDone,
+ base::Unretained(this)));
+ offline_pages::SavePageRequest request2(kRequestId2, kUrl2, kClientId2,
+ base::Time::Now(), !kUserRequested);
+ coordinator()->queue()->AddRequest(
+ request2, base::Bind(&RequestCoordinatorTest::AddRequestDone,
+ base::Unretained(this)));
+ PumpLoop();
+
+ // Trigger the scheduler to schedule for the least restrictive condition.
+ ScheduleForTest();
+ PumpLoop();
+
+ // Expect that the scheduler got notified, and it is at user_requested
+ // priority.
+ SchedulerStub* scheduler_stub =
+ reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
+ const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions();
+ EXPECT_TRUE(scheduler_stub->schedule_called());
+ EXPECT_EQ(conditions->require_power_connected,
+ coordinator()->policy()->PowerRequired(kUserRequested));
+ EXPECT_EQ(conditions->minimum_battery_percentage,
+ coordinator()->policy()->BatteryPercentageRequired(kUserRequested));
+ EXPECT_EQ(conditions->require_unmetered_network,
+ coordinator()->policy()->UnmeteredNetworkRequired(kUserRequested));
+}
+
// This tests a StopProcessing call before we have actually started the
// prerenderer.
TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | components/offline_pages/background/request_picker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698