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"
8 #include "testing/gtest/include/gtest/gtest.h"
12 class GCMDelayedTaskControllerTest
: public testing::Test
{
14 GCMDelayedTaskControllerTest();
15 ~GCMDelayedTaskControllerTest() override
;
19 GCMDelayedTaskController
* controller() { return controller_
.get(); }
21 int number_of_triggered_tasks() const { return number_of_triggered_tasks_
; }
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());