Roll ANGLE cc54ab3..c5b2ba5
[chromium-blink-merge.git] / components / gcm_driver / gcm_delayed_task_controller_unittest.cc
blob28f5d6e072a9d7cf2c214dade6fc817f4e3f0611
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/gcm_driver/gcm_delayed_task_controller.h"
7 #include "base/bind.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace gcm {
12 class GCMDelayedTaskControllerTest : public testing::Test {
13 public:
14 GCMDelayedTaskControllerTest();
15 ~GCMDelayedTaskControllerTest() override;
17 void TestTask();
19 GCMDelayedTaskController* controller() { return controller_.get(); }
21 int number_of_triggered_tasks() const { return number_of_triggered_tasks_; }
23 private:
24 scoped_ptr<GCMDelayedTaskController> controller_;
25 int number_of_triggered_tasks_;
28 GCMDelayedTaskControllerTest::GCMDelayedTaskControllerTest()
29 : controller_(new GCMDelayedTaskController), number_of_triggered_tasks_(0) {
32 GCMDelayedTaskControllerTest::~GCMDelayedTaskControllerTest() {
35 void GCMDelayedTaskControllerTest::TestTask() {
36 ++number_of_triggered_tasks_;
39 // Tests that a newly created controller forced tasks to be delayed, while
40 // calling SetReady allows tasks to execute.
41 TEST_F(GCMDelayedTaskControllerTest, SetReadyWithNoTasks) {
42 EXPECT_FALSE(controller()->CanRunTaskWithoutDelay());
43 EXPECT_EQ(0, number_of_triggered_tasks());
45 controller()->SetReady();
46 EXPECT_TRUE(controller()->CanRunTaskWithoutDelay());
47 EXPECT_EQ(0, number_of_triggered_tasks());
50 // Tests that tasks are triggered when controlles is set to ready.
51 TEST_F(GCMDelayedTaskControllerTest, PendingTasksTriggeredWhenSetReady) {
52 controller()->AddTask(base::Bind(&GCMDelayedTaskControllerTest::TestTask,
53 base::Unretained(this)));
54 controller()->AddTask(base::Bind(&GCMDelayedTaskControllerTest::TestTask,
55 base::Unretained(this)));
57 controller()->SetReady();
58 EXPECT_EQ(2, number_of_triggered_tasks());
61 } // namespace gcm