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

Unified Diff: components/gcm_driver/gcm_delayed_task_controller_unittest.cc

Issue 551163002: [GCM] Extracting Delayed Task Controller from GCMDesktopDriver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Solving compilation issue Created 6 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
« no previous file with comments | « components/gcm_driver/gcm_delayed_task_controller.cc ('k') | components/gcm_driver/gcm_driver_desktop.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/gcm_driver/gcm_delayed_task_controller_unittest.cc
diff --git a/components/gcm_driver/gcm_delayed_task_controller_unittest.cc b/components/gcm_driver/gcm_delayed_task_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf224928e3aa83b416dc9aaf0f51fe14447617ec
--- /dev/null
+++ b/components/gcm_driver/gcm_delayed_task_controller_unittest.cc
@@ -0,0 +1,63 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/gcm_driver/gcm_delayed_task_controller.h"
+
+#include "base/bind.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace gcm {
+
+class GCMDelayedTaskControllerTest : public testing::Test {
+ public:
+ GCMDelayedTaskControllerTest();
+ virtual ~GCMDelayedTaskControllerTest();
+
+ void TestTask();
+
+ GCMDelayedTaskController* controller() { return controller_.get(); }
+
+ int number_of_triggered_tasks() const { return number_of_triggered_tasks_; }
+
+ private:
+ scoped_ptr<GCMDelayedTaskController> controller_;
+ int number_of_triggered_tasks_;
+};
+
+GCMDelayedTaskControllerTest::GCMDelayedTaskControllerTest()
+ : controller_(new GCMDelayedTaskController), number_of_triggered_tasks_(0) {
+}
+
+GCMDelayedTaskControllerTest::~GCMDelayedTaskControllerTest() {
+}
+
+void GCMDelayedTaskControllerTest::TestTask() {
+ ++number_of_triggered_tasks_;
+}
+
+// Tests that a newly created controller forced tasks to be delayed.
+TEST_F(GCMDelayedTaskControllerTest, CannotRunTaskWithoutDelayWhenNew) {
+ EXPECT_FALSE(controller()->CanRunTaskWithoutDelay());
+ EXPECT_EQ(0, number_of_triggered_tasks());
+}
+
+// Tests that tasks can be run after controller is set to ready.
+TEST_F(GCMDelayedTaskControllerTest, CanRunTaskWithoutDelayWhenSetReady) {
+ controller()->SetReady();
+ EXPECT_TRUE(controller()->CanRunTaskWithoutDelay());
+ EXPECT_EQ(0, number_of_triggered_tasks());
+}
+
+// Tests that tasks are triggered when controlles is set to ready.
+TEST_F(GCMDelayedTaskControllerTest, PendingTasksTriggeredWhenSetReady) {
jianli 2014/09/09 19:53:18 I think we can combine all these 3 tests into one
fgorski 2014/09/09 23:11:43 Done. I went down to 2, because I didn't want to c
+ controller()->AddTask(base::Bind(&GCMDelayedTaskControllerTest::TestTask,
+ base::Unretained(this)));
+ controller()->AddTask(base::Bind(&GCMDelayedTaskControllerTest::TestTask,
+ base::Unretained(this)));
+
+ controller()->SetReady();
+ EXPECT_EQ(2, number_of_triggered_tasks());
+}
+
+} // namespace gcm
« no previous file with comments | « components/gcm_driver/gcm_delayed_task_controller.cc ('k') | components/gcm_driver/gcm_driver_desktop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698