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

Unified Diff: extensions/common/one_shot_event_unittest.cc

Issue 14757022: Add a non-blocking "OneShotEvent" class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace ExtensionServiceReady() with passing &ready_ into the ExtensionService constructor Created 7 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 | « extensions/common/one_shot_event.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/common/one_shot_event_unittest.cc
diff --git a/extensions/common/one_shot_event_unittest.cc b/extensions/common/one_shot_event_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..81a27e2f181091f29efa8b7a8208433d6b21173f
--- /dev/null
+++ b/extensions/common/one_shot_event_unittest.cc
@@ -0,0 +1,78 @@
+// Copyright 2013 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 "extensions/common/one_shot_event.h"
+
+#include "base/bind.h"
+#include "base/run_loop.h"
+#include "base/test/test_simple_task_runner.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+namespace {
+
+void Increment(int* i) { ++*i; }
not at google - send to devlin 2013/05/16 22:26:11 There are a couple more scenarios it would be nice
Jeffrey Yasskin 2013/05/16 22:45:51 Done.
+
+TEST(OneShotEventTest, RecordsSignal) {
+ OneShotEvent event;
+ EXPECT_FALSE(event.is_signaled());
+ event.Signal();
+ EXPECT_TRUE(event.is_signaled());
+}
+
+TEST(OneShotEventTest, CallsQueue) {
+ OneShotEvent event;
+ scoped_refptr<base::TestSimpleTaskRunner> runner(
+ new base::TestSimpleTaskRunner);
+ int i = 0;
+ event.Post(FROM_HERE, base::Bind(&Increment, &i), runner);
+ event.Post(FROM_HERE, base::Bind(&Increment, &i), runner);
+ EXPECT_EQ(0U, runner->GetPendingTasks().size());
+ event.Signal();
+ ASSERT_EQ(2U, runner->GetPendingTasks().size());
+ EXPECT_NE(runner->GetPendingTasks()[0].location.line_number(),
+ runner->GetPendingTasks()[1].location.line_number())
+ << "Make sure FROM_HERE is propagated.";
+ EXPECT_EQ(0, i);
+ runner->RunPendingTasks();
+ EXPECT_EQ(2, i);
+}
+
+TEST(OneShotEventTest, CallsAfterSignalDontRunInline) {
+ OneShotEvent event;
+ scoped_refptr<base::TestSimpleTaskRunner> runner(
+ new base::TestSimpleTaskRunner);
+ int i = 0;
+
+ event.Signal();
+ event.Post(FROM_HERE, base::Bind(&Increment, &i), runner);
+ EXPECT_EQ(1U, runner->GetPendingTasks().size());
+ EXPECT_EQ(0, i);
+ runner->RunPendingTasks();
+ EXPECT_EQ(1, i);
+}
+
+TEST(OneShotEventTest, PostDefaultsToCurrentMessageLoop) {
+ OneShotEvent event;
+ scoped_refptr<base::TestSimpleTaskRunner> runner(
+ new base::TestSimpleTaskRunner);
+ MessageLoop loop;
+ int runner_i = 0;
+ int loop_i = 0;
+
+ event.Post(FROM_HERE, base::Bind(&Increment, &runner_i), runner);
+ event.Post(FROM_HERE, base::Bind(&Increment, &loop_i));
+ event.Signal();
+ EXPECT_EQ(1U, runner->GetPendingTasks().size());
+ EXPECT_EQ(0, runner_i);
+ runner->RunPendingTasks();
+ EXPECT_EQ(1, runner_i);
+ EXPECT_EQ(0, loop_i);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, loop_i);
+}
+
+} // namespace
+} // namespace extensions
« no previous file with comments | « extensions/common/one_shot_event.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698