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

Side by Side Diff: base/deferred_sequenced_task_runner_unittest.cc

Issue 12952005: Delay bookmarks load while the profile is loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address willchan's and jyasskin code reviews. Created 7 years, 8 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 | « base/deferred_sequenced_task_runner.cc ('k') | chrome/browser/bookmarks/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 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.
4
5 #include "base/deferred_sequenced_task_runner.h"
6
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/bind_helpers.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/message_loop.h"
12 #include "base/message_loop_proxy.h"
13 #include "base/threading/thread.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 class DeferredSequencedTaskRunnerTest : public testing::Test {
20 public :
Jeffrey Yasskin 2013/04/08 19:58:30 No space between "public" and ":".
msarda 2013/04/09 07:20:11 Done.
21 void ExecuteTask(int task_id) {
22 base::AutoLock lock(lock_);
23 executed_task_ids_.push_back(task_id);
24 }
25
26 protected:
27 DeferredSequencedTaskRunnerTest() : loop_(),
Jeffrey Yasskin 2013/04/08 19:58:30 I believe the style guide says to line up "loop_"
msarda 2013/04/09 07:20:11 Done.
28 runner_(
29 new base::DeferredSequencedTaskRunner(loop_.message_loop_proxy()) {
30 }
31
32 MessageLoop loop_;
33 scoped_refptr<base::DeferredSequencedTaskRunner> runner_;
34 mutable base::Lock lock_;
35 std::vector<int> executed_task_ids_;
36 };
37
38 TEST_F(DeferredSequencedTaskRunnerTest, Stopped) {
39 runner_->PostTask(FROM_HERE,
40 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
41 base::Unretained(this),
42 1));
43 loop_.RunUntilIdle();
44 EXPECT_TRUE(executed_task_ids_.empty()) << executed_task_ids_[0];
Jeffrey Yasskin 2013/04/08 19:58:30 You can use "EXPECT_THAT(executed_task_ids_, testi
msarda 2013/04/09 07:20:11 Done.
45 }
46
47 TEST_F(DeferredSequencedTaskRunnerTest, Start) {
48 runner_->Start();
49 runner_->PostTask(FROM_HERE,
50 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
51 base::Unretained(this),
52 1));
53 loop_.RunUntilIdle();
54 EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1));
55 }
56
57 TEST_F(DeferredSequencedTaskRunnerTest, StartWithMultipleElements) {
58 runner_->Start();
59 for (int i = 1; i < 5; ++i) {
60 runner_->PostTask(FROM_HERE,
61 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
62 base::Unretained(this),
63 i));
64 }
65 loop_.RunUntilIdle();
66 EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1, 2, 3, 4));
67 }
68
69 TEST_F(DeferredSequencedTaskRunnerTest, DeferredStart) {
70 runner_->PostTask(FROM_HERE,
71 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
72 base::Unretained(this),
73 1));
74 loop_.RunUntilIdle();
75 EXPECT_TRUE(executed_task_ids_.empty());
76
77 runner_->Start();
78 loop_.RunUntilIdle();
79 EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1));
80
81 runner_->PostTask(FROM_HERE,
82 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
83 base::Unretained(this),
84 2));
85 loop_.RunUntilIdle();
86 EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1, 2));
87 }
88
89 TEST_F(DeferredSequencedTaskRunnerTest, DeferredStartWithMultipleElements) {
90 for (int i = 1; i < 5; ++i) {
91 runner_->PostTask(FROM_HERE,
92 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
93 base::Unretained(this),
94 i));
95 }
96 loop_.RunUntilIdle();
97 EXPECT_TRUE(executed_task_ids_.empty());
98
99 runner_->Start();
100
101 for (int i = 5; i < 9; ++i) {
102 runner_->PostTask(FROM_HERE,
103 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
104 base::Unretained(this),
105 i));
106 }
107 loop_.RunUntilIdle();
108 EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1, 2,3, 4, 5, 6, 7, 8));
Jeffrey Yasskin 2013/04/08 19:58:30 Missing space between 2 and 3.
msarda 2013/04/09 07:20:11 Done.
109 }
110
111 TEST_F(DeferredSequencedTaskRunnerTest, DeferredStartWithMultipleThreads) {
112 {
113 base::Thread thread1("DeferredSequencedTaskRunnerTestThread1");
114 base::Thread thread2("DeferredSequencedTaskRunnerTestThread2");
115 thread1.Start();
116 thread2.Start();
117 for (int i = 0; i < 5; ++i) {
118 thread1.message_loop()->PostTask(FROM_HERE,
119 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
120 base::Unretained(this),
121 2 * i));
122 thread2.message_loop()->PostTask(FROM_HERE,
123 base::Bind(&DeferredSequencedTaskRunnerTest::ExecuteTask,
124 base::Unretained(this),
125 2 * i + 1));
126 if (i == 2)
127 runner_->Start();
Jeffrey Yasskin 2013/04/08 19:58:30 Post this to one of the threads too, or it's likel
msarda 2013/04/09 07:20:11 Done.
128 }
129 }
130
131 loop_.RunUntilIdle();
132 EXPECT_THAT(executed_task_ids_,
133 testing::WhenSorted(testing::ElementsAre(0, 1, 2,3, 4, 5, 6, 7, 8, 9)));
Jeffrey Yasskin 2013/04/08 19:58:30 Missing space between 2 and 3.
msarda 2013/04/09 07:20:11 Done.
134 }
135
136 } // namespace
OLDNEW
« no previous file with comments | « base/deferred_sequenced_task_runner.cc ('k') | chrome/browser/bookmarks/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698