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

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

Issue 2064793003: Remove old requests from queue, start new requests if any, add test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test Created 4 years, 6 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
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 96cb37e855a90015526b253e7ce774cd37b4a56c..7e0ba5f1fe7b54c28e8577b73f1670cb4d200cf9 100644
--- a/components/offline_pages/background/request_coordinator_unittest.cc
+++ b/components/offline_pages/background/request_coordinator_unittest.cc
@@ -27,6 +27,7 @@ namespace {
// put test constants here
const GURL kUrl("http://universe.com/everything");
const ClientId kClientId("bookmark", "42");
+const int kRequestId(1);
} // namespace
class SchedulerStub : public Scheduler {
@@ -94,10 +95,17 @@ class RequestCoordinatorTest
void EmptyCallbackFunction(bool result) {
}
+ // Callback for Add requests
+ void AddRequestDone(RequestQueue::AddRequestResult result,
+ const SavePageRequest& request);
+
// Callback for getting requests.
void GetRequestsDone(RequestQueue::GetRequestsResult result,
const std::vector<SavePageRequest>& requests);
+ void SendOfflinerDoneCallback(const SavePageRequest& request,
+ Offliner::RequestStatus status);
+
RequestQueue::GetRequestsResult last_get_requests_result() const {
return last_get_requests_result_;
}
@@ -144,12 +152,24 @@ void RequestCoordinatorTest::GetRequestsDone(
last_requests_ = requests;
}
+
+void RequestCoordinatorTest::AddRequestDone(
+ RequestQueue::AddRequestResult result,
+ const SavePageRequest& request) {}
+
+void RequestCoordinatorTest::SendOfflinerDoneCallback(
+ const SavePageRequest& request, Offliner::RequestStatus status) {
+ // Using the fact that the test class is a friend, call to the callback
+ coordinator_->OfflinerDoneCallback(request, status);
+}
+
+
TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) {
base::Callback<void(bool)> callback =
base::Bind(
&RequestCoordinatorTest::EmptyCallbackFunction,
base::Unretained(this));
- EXPECT_FALSE(coordinator()->StartProcessing(callback));
+ EXPECT_TRUE(coordinator()->StartProcessing(callback));
}
TEST_F(RequestCoordinatorTest, SavePageLater) {
@@ -174,4 +194,39 @@ TEST_F(RequestCoordinatorTest, SavePageLater) {
EXPECT_TRUE(scheduler_stub->schedule_called());
}
+TEST_F(RequestCoordinatorTest, OfflinerDone) {
+
+ // Add a request to the queue, wait for callbacks to finish.
+ offline_pages::SavePageRequest request(
+ kRequestId, kUrl, kClientId, base::Time::Now());
+ coordinator()->queue()->AddRequest(
+ request,
+ base::Bind(&RequestCoordinatorTest::AddRequestDone,
+ base::Unretained(this)));
+ PumpLoop();
+
+ // We need to give a callback to the request.
+ base::Callback<void(bool)> callback =
+ base::Bind(
+ &RequestCoordinatorTest::EmptyCallbackFunction,
+ base::Unretained(this));
+ coordinator()->SetProcessingCallbackForTest(callback);
+
+ // Call the OfflinerDoneCallback to simulate the page being completed, wait
+ // for callbacks.
+ SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED);
+ PumpLoop();
+
+ // Verify the request gets removed from the queue, and wait for callbacks.
+ coordinator()->queue()->GetRequests(
+ base::Bind(&RequestCoordinatorTest::GetRequestsDone,
+ base::Unretained(this)));
+ PumpLoop();
+
+ // We should not find any requests in the queue anymore.
+ // RequestPicker should *not* have tried to start an additional job,
+ // because the request queue is empty now.
+ EXPECT_EQ(0UL, last_requests().size());
+}
+
} // namespace offline_pages
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698