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

Side by Side Diff: extensions/common/one_shot_event_unittest.cc

Issue 2331423002: Replace TestSimpleTaskRunner::GetPendingTasks with TakePendingTasks (Closed)
Patch Set: split test Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « device/bluetooth/test/bluetooth_test_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/one_shot_event.h" 5 #include "extensions/common/one_shot_event.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace extensions { 13 namespace extensions {
14 14
15 namespace { 15 namespace {
16 16
17 void Increment(int* i) { ++*i; } 17 void Increment(int* i) { ++*i; }
18 18
19 TEST(OneShotEventTest, RecordsSignal) { 19 TEST(OneShotEventTest, RecordsSignal) {
20 OneShotEvent event; 20 OneShotEvent event;
21 EXPECT_FALSE(event.is_signaled()); 21 EXPECT_FALSE(event.is_signaled());
22 event.Signal(); 22 event.Signal();
23 EXPECT_TRUE(event.is_signaled()); 23 EXPECT_TRUE(event.is_signaled());
24 } 24 }
25 25
26 TEST(OneShotEventTest, CallsQueueAsDistinctTask) {
27 OneShotEvent event;
28 scoped_refptr<base::TestSimpleTaskRunner> runner(
29 new base::TestSimpleTaskRunner);
30 int i = 0;
31 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner);
32 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner);
33 EXPECT_EQ(0U, runner->NumPendingTasks());
34 event.Signal();
35
36 auto pending_tasks = runner->TakePendingTasks();
37 ASSERT_EQ(2U, pending_tasks.size());
38 EXPECT_NE(pending_tasks[0].location.line_number(),
39 pending_tasks[1].location.line_number())
40 << "Make sure FROM_HERE is propagated.";
41 }
42
26 TEST(OneShotEventTest, CallsQueue) { 43 TEST(OneShotEventTest, CallsQueue) {
27 OneShotEvent event; 44 OneShotEvent event;
28 scoped_refptr<base::TestSimpleTaskRunner> runner( 45 scoped_refptr<base::TestSimpleTaskRunner> runner(
29 new base::TestSimpleTaskRunner); 46 new base::TestSimpleTaskRunner);
30 int i = 0; 47 int i = 0;
31 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); 48 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner);
32 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); 49 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner);
33 EXPECT_EQ(0U, runner->NumPendingTasks()); 50 EXPECT_EQ(0U, runner->NumPendingTasks());
34 event.Signal(); 51 event.Signal();
35 ASSERT_EQ(2U, runner->NumPendingTasks()); 52 ASSERT_EQ(2U, runner->NumPendingTasks());
36 EXPECT_NE(runner->GetPendingTasks()[0].location.line_number(), 53
37 runner->GetPendingTasks()[1].location.line_number())
38 << "Make sure FROM_HERE is propagated.";
39 EXPECT_EQ(0, i); 54 EXPECT_EQ(0, i);
40 runner->RunPendingTasks(); 55 runner->RunPendingTasks();
41 EXPECT_EQ(2, i); 56 EXPECT_EQ(2, i);
42 } 57 }
43 58
44 TEST(OneShotEventTest, CallsAfterSignalDontRunInline) { 59 TEST(OneShotEventTest, CallsAfterSignalDontRunInline) {
45 OneShotEvent event; 60 OneShotEvent event;
46 scoped_refptr<base::TestSimpleTaskRunner> runner( 61 scoped_refptr<base::TestSimpleTaskRunner> runner(
47 new base::TestSimpleTaskRunner); 62 new base::TestSimpleTaskRunner);
48 int i = 0; 63 int i = 0;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 EXPECT_EQ(1U, runner->NumPendingTasks()); 118 EXPECT_EQ(1U, runner->NumPendingTasks());
104 EXPECT_EQ(0, i); 119 EXPECT_EQ(0, i);
105 runner->RunPendingTasks(); 120 runner->RunPendingTasks();
106 // Increment has run. 121 // Increment has run.
107 EXPECT_EQ(0U, runner->NumPendingTasks()); 122 EXPECT_EQ(0U, runner->NumPendingTasks());
108 EXPECT_EQ(1, i); 123 EXPECT_EQ(1, i);
109 } 124 }
110 125
111 } // namespace 126 } // namespace
112 } // namespace extensions 127 } // namespace extensions
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698