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

Side by Side Diff: base/mac/libdispatch_task_runner_unittest.cc

Issue 2103333006: Remove calls to deprecated MessageLoop methods in base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/mac/libdispatch_task_runner.h" 5 #include "base/mac/libdispatch_task_runner.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/mac/bind_objc_block.h" 10 #include "base/mac/bind_objc_block.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h"
13 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 class LibDispatchTaskRunnerTest : public testing::Test { 18 class LibDispatchTaskRunnerTest : public testing::Test {
17 public: 19 public:
18 void SetUp() override { 20 void SetUp() override {
19 task_runner_ = new base::mac::LibDispatchTaskRunner( 21 task_runner_ = new base::mac::LibDispatchTaskRunner(
20 "org.chromium.LibDispatchTaskRunnerTest"); 22 "org.chromium.LibDispatchTaskRunnerTest");
21 } 23 }
22 24
23 // DispatchLastTask is used to run the main test thread's MessageLoop until 25 // DispatchLastTask is used to run the main test thread's MessageLoop until
24 // all non-delayed tasks are run on the LibDispatchTaskRunner. 26 // all non-delayed tasks are run on the LibDispatchTaskRunner.
25 void DispatchLastTask() { 27 void DispatchLastTask() {
26 dispatch_async(task_runner_->GetDispatchQueue(), ^{ 28 dispatch_async(task_runner_->GetDispatchQueue(), ^{
27 message_loop_.PostTask(FROM_HERE, 29 message_loop_.task_runner()->PostTask(
28 base::MessageLoop::QuitWhenIdleClosure()); 30 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
29 }); 31 });
30 message_loop_.Run(); 32 base::RunLoop().Run();
31 task_runner_->Shutdown(); 33 task_runner_->Shutdown();
32 } 34 }
33 35
34 // VerifyTaskOrder takes the expectations from TaskOrderMarkers and compares 36 // VerifyTaskOrder takes the expectations from TaskOrderMarkers and compares
35 // them against the recorded values. 37 // them against the recorded values.
36 void VerifyTaskOrder(const char* const expectations[], 38 void VerifyTaskOrder(const char* const expectations[],
37 size_t num_expectations) { 39 size_t num_expectations) {
38 size_t actual_size = task_order_.size(); 40 size_t actual_size = task_order_.size();
39 41
40 for (size_t i = 0; i < num_expectations; ++i) { 42 for (size_t i = 0; i < num_expectations; ++i) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 "END Second Task", 155 "END Second Task",
154 }; 156 };
155 VerifyTaskOrder(expectations, arraysize(expectations)); 157 VerifyTaskOrder(expectations, arraysize(expectations));
156 } 158 }
157 159
158 TEST_F(LibDispatchTaskRunnerTest, NonNestable) { 160 TEST_F(LibDispatchTaskRunnerTest, NonNestable) {
159 task_runner_->PostTask(FROM_HERE, base::BindBlock(^{ 161 task_runner_->PostTask(FROM_HERE, base::BindBlock(^{
160 TaskOrderMarker marker(this, "First"); 162 TaskOrderMarker marker(this, "First");
161 task_runner_->PostNonNestableTask(FROM_HERE, base::BindBlock(^{ 163 task_runner_->PostNonNestableTask(FROM_HERE, base::BindBlock(^{
162 TaskOrderMarker marker(this, "Second NonNestable"); 164 TaskOrderMarker marker(this, "Second NonNestable");
163 message_loop_.PostTask(FROM_HERE, 165 message_loop_.task_runner()->PostTask(
164 base::MessageLoop::QuitWhenIdleClosure()); 166 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
165 })); 167 }));
166 })); 168 }));
167 message_loop_.Run(); 169 base::RunLoop().Run();
168 task_runner_->Shutdown(); 170 task_runner_->Shutdown();
169 171
170 const char* const expectations[] = { 172 const char* const expectations[] = {
171 "BEGIN First", 173 "BEGIN First",
172 "END First", 174 "END First",
173 "BEGIN Second NonNestable", 175 "BEGIN Second NonNestable",
174 "END Second NonNestable" 176 "END Second NonNestable"
175 }; 177 };
176 VerifyTaskOrder(expectations, arraysize(expectations)); 178 VerifyTaskOrder(expectations, arraysize(expectations));
177 } 179 }
178 180
179 TEST_F(LibDispatchTaskRunnerTest, PostDelayed) { 181 TEST_F(LibDispatchTaskRunnerTest, PostDelayed) {
180 base::TimeTicks post_time; 182 base::TimeTicks post_time;
181 __block base::TimeTicks run_time; 183 __block base::TimeTicks run_time;
182 const base::TimeDelta delta = base::TimeDelta::FromMilliseconds(50); 184 const base::TimeDelta delta = base::TimeDelta::FromMilliseconds(50);
183 185
184 task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "First")); 186 task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "First"));
185 post_time = base::TimeTicks::Now(); 187 post_time = base::TimeTicks::Now();
186 task_runner_->PostDelayedTask(FROM_HERE, base::BindBlock(^{ 188 task_runner_->PostDelayedTask(FROM_HERE, base::BindBlock(^{
187 TaskOrderMarker marker(this, "Timed"); 189 TaskOrderMarker marker(this, "Timed");
188 run_time = base::TimeTicks::Now(); 190 run_time = base::TimeTicks::Now();
189 message_loop_.PostTask(FROM_HERE, 191 message_loop_.task_runner()->PostTask(
190 base::MessageLoop::QuitWhenIdleClosure()); 192 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
191 }), delta); 193 }), delta);
192 task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "Second")); 194 task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "Second"));
193 message_loop_.Run(); 195 base::RunLoop().Run();
194 task_runner_->Shutdown(); 196 task_runner_->Shutdown();
195 197
196 const char* const expectations[] = { 198 const char* const expectations[] = {
197 "BEGIN First", 199 "BEGIN First",
198 "END First", 200 "END First",
199 "BEGIN Second", 201 "BEGIN Second",
200 "END Second", 202 "END Second",
201 "BEGIN Timed", 203 "BEGIN Timed",
202 "END Timed", 204 "END Timed",
203 }; 205 };
(...skipping 14 matching lines...) Expand all
218 }))); 220 })));
219 221
220 const char* const expectations[] = { 222 const char* const expectations[] = {
221 "BEGIN First", 223 "BEGIN First",
222 "END First", 224 "END First",
223 "BEGIN Second", 225 "BEGIN Second",
224 "END Second" 226 "END Second"
225 }; 227 };
226 VerifyTaskOrder(expectations, arraysize(expectations)); 228 VerifyTaskOrder(expectations, arraysize(expectations));
227 } 229 }
OLDNEW
« no previous file with comments | « base/files/important_file_writer_unittest.cc ('k') | base/message_loop/message_loop_task_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698