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

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

Issue 2317893002: [Offline Pages] Close race condition of multiple StartProcessing callers. (Closed)
Patch Set: Pete feedback - clear starting flag in deadbeat timeout case 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 61ea62fd0bdac36373e5cb1f3b6348941ab0745a..689c00d3d4591b187807eb6a65aa9b0e15d319d1 100644
--- a/components/offline_pages/background/request_coordinator_unittest.cc
+++ b/components/offline_pages/background/request_coordinator_unittest.cc
@@ -190,6 +190,8 @@ class RequestCoordinatorTest
return coordinator_->is_busy();
}
+ bool is_starting() { return coordinator_->is_starting(); }
+
// Empty callback function.
void EmptyCallbackFunction(bool result) {
}
@@ -597,12 +599,15 @@ TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) {
base::Callback<void(bool)> callback = base::Bind(
&RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
coordinator()->StartProcessing(device_conditions, callback);
+ EXPECT_TRUE(is_starting());
// Call RequestNotPicked, and make sure we pick schedule a task for non user
// requested conditions.
CallRequestNotPicked(true);
PumpLoop();
+ EXPECT_FALSE(is_starting());
+
// The scheduler should have been called to schedule the non-user requested
// task.
SchedulerStub* scheduler_stub =
@@ -671,6 +676,7 @@ TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
&RequestCoordinatorTest::EmptyCallbackFunction,
base::Unretained(this));
EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
+ EXPECT_TRUE(is_starting());
// Now, quick, before it can do much (we haven't called PumpLoop), cancel it.
coordinator()->StopProcessing();
@@ -678,6 +684,8 @@ TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
// Let the async callbacks in the request coordinator run.
PumpLoop();
+ EXPECT_FALSE(is_starting());
+
// OfflinerDoneCallback will not end up getting called with status SAVED,
// since we cancelled the event before it called offliner_->LoadAndSave().
EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED,
@@ -708,12 +716,14 @@ TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingLater) {
&RequestCoordinatorTest::EmptyCallbackFunction,
base::Unretained(this));
EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
+ EXPECT_TRUE(is_starting());
// Let all the async parts of the start processing pipeline run to completion.
PumpLoop();
// Coordinator should now be busy.
EXPECT_TRUE(is_busy());
+ EXPECT_FALSE(is_starting());
// Now we cancel it while the prerenderer is busy.
coordinator()->StopProcessing();
@@ -808,6 +818,7 @@ TEST_F(RequestCoordinatorTest, WatchdogTimeout) {
WaitForCallback();
PumpLoop();
+ EXPECT_FALSE(is_starting());
EXPECT_TRUE(OfflinerWasCanceled());
EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED,
last_offlining_status());

Powered by Google App Engine
This is Rietveld 408576698