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

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

Issue 1971033002: Call scheduler when we get a save page later request. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback per FGorski and DougArnett Created 4 years, 7 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 a589e08ba5d3e28d23b02d132849ef1ec8ac47a7..913be188bacad0f818da7125e3efc03849852f90 100644
--- a/components/offline_pages/background/request_coordinator_unittest.cc
+++ b/components/offline_pages/background/request_coordinator_unittest.cc
@@ -15,6 +15,7 @@
#include "components/offline_pages/background/request_queue.h"
#include "components/offline_pages/background/request_queue_in_memory_store.h"
#include "components/offline_pages/background/save_page_request.h"
+#include "components/offline_pages/background/scheduler.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace offline_pages {
@@ -25,6 +26,28 @@ const GURL kUrl("http://universe.com/everything");
const ClientId kClientId("bookmark", "42");
} // namespace
+class SchedulerStub : public Scheduler {
+ public:
+ SchedulerStub() : schedule_called_(false), unschedule_called_(false) {}
+
+ void Schedule(const TriggerCondition& trigger_condition) override {
+ schedule_called_ = true;
+ }
+
+ // Unschedules the currently scheduled task, if any.
+ void Unschedule() override {
+ unschedule_called_ = true;
+ }
+
+ bool schedule_called() const { return schedule_called_; }
+
+ bool unschedule_called() const { return unschedule_called_; }
+
+ private:
+ bool schedule_called_;
+ bool unschedule_called_;
+};
+
class RequestCoordinatorTest
: public testing::Test {
public:
@@ -35,7 +58,7 @@ class RequestCoordinatorTest
void PumpLoop();
- RequestCoordinator* getCoordinator() {
+ RequestCoordinator* coordinator() {
return coordinator_.get();
}
@@ -76,11 +99,12 @@ void RequestCoordinatorTest::SetUp() {
std::unique_ptr<RequestQueueInMemoryStore>
store(new RequestQueueInMemoryStore());
std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store)));
+ std::unique_ptr<Scheduler> scheduler_stub(new SchedulerStub());
coordinator_.reset(new RequestCoordinator(
- std::move(policy), std::move(factory), std::move(queue)));
+ std::move(policy), std::move(factory), std::move(queue),
+ std::move(scheduler_stub)));
}
-
void RequestCoordinatorTest::PumpLoop() {
task_runner_->RunUntilIdle();
}
@@ -97,14 +121,14 @@ TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) {
base::Bind(
&RequestCoordinatorTest::EmptyCallbackFunction,
base::Unretained(this));
- EXPECT_FALSE(getCoordinator()->StartProcessing(callback));
+ EXPECT_FALSE(coordinator()->StartProcessing(callback));
}
TEST_F(RequestCoordinatorTest, SavePageLater) {
- EXPECT_TRUE(getCoordinator()->SavePageLater(kUrl, kClientId));
+ EXPECT_TRUE(coordinator()->SavePageLater(kUrl, kClientId));
// Expect that a request got placed on the queue.
- getCoordinator()->GetQueue()->GetRequests(
+ coordinator()->GetQueue()->GetRequests(
base::Bind(&RequestCoordinatorTest::GetRequestsDone,
base::Unretained(this)));
@@ -116,7 +140,10 @@ TEST_F(RequestCoordinatorTest, SavePageLater) {
EXPECT_EQ(kUrl, last_requests()[0].url());
EXPECT_EQ(kClientId, last_requests()[0].client_id());
- // TODO(petewil): Expect that the scheduler got notified.
+ // Expect that the scheduler got notified.
+ SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>(
+ coordinator()->GetSchedulerForTesting());
+ EXPECT_TRUE(scheduler_stub->schedule_called());
}
} // 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