OLD | NEW |
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 "base/message_loop/message_loop_test.h" | 5 #include "base/message_loop/message_loop_test.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 // Cause our Run function to take some time to execute. As a result we can | 85 // Cause our Run function to take some time to execute. As a result we can |
86 // count on subsequent RecordRunTimeFunc()s running at a future time, | 86 // count on subsequent RecordRunTimeFunc()s running at a future time, |
87 // without worry about the resolution of our system clock being an issue. | 87 // without worry about the resolution of our system clock being an issue. |
88 SlowFunc(TimeDelta::FromMilliseconds(10), quit_counter); | 88 SlowFunc(TimeDelta::FromMilliseconds(10), quit_counter); |
89 } | 89 } |
90 | 90 |
91 } // namespace | 91 } // namespace |
92 | 92 |
93 void RunTest_PostTask(MessagePumpFactory factory) { | 93 void RunTest_PostTask(MessagePumpFactory factory) { |
94 scoped_ptr<MessagePump> pump(factory()); | 94 std::unique_ptr<MessagePump> pump(factory()); |
95 MessageLoop loop(std::move(pump)); | 95 MessageLoop loop(std::move(pump)); |
96 // Add tests to message loop | 96 // Add tests to message loop |
97 scoped_refptr<Foo> foo(new Foo()); | 97 scoped_refptr<Foo> foo(new Foo()); |
98 std::string a("a"), b("b"), c("c"), d("d"); | 98 std::string a("a"), b("b"), c("c"), d("d"); |
99 MessageLoop::current()->PostTask(FROM_HERE, Bind( | 99 MessageLoop::current()->PostTask(FROM_HERE, Bind( |
100 &Foo::Test0, foo.get())); | 100 &Foo::Test0, foo.get())); |
101 MessageLoop::current()->PostTask(FROM_HERE, Bind( | 101 MessageLoop::current()->PostTask(FROM_HERE, Bind( |
102 &Foo::Test1ConstRef, foo.get(), a)); | 102 &Foo::Test1ConstRef, foo.get(), a)); |
103 MessageLoop::current()->PostTask(FROM_HERE, Bind( | 103 MessageLoop::current()->PostTask(FROM_HERE, Bind( |
104 &Foo::Test1Ptr, foo.get(), &b)); | 104 &Foo::Test1Ptr, foo.get(), &b)); |
105 MessageLoop::current()->PostTask(FROM_HERE, Bind( | 105 MessageLoop::current()->PostTask(FROM_HERE, Bind( |
106 &Foo::Test1Int, foo.get(), 100)); | 106 &Foo::Test1Int, foo.get(), 100)); |
107 MessageLoop::current()->PostTask(FROM_HERE, Bind( | 107 MessageLoop::current()->PostTask(FROM_HERE, Bind( |
108 &Foo::Test2Ptr, foo.get(), &a, &c)); | 108 &Foo::Test2Ptr, foo.get(), &a, &c)); |
109 MessageLoop::current()->PostTask(FROM_HERE, Bind( | 109 MessageLoop::current()->PostTask(FROM_HERE, Bind( |
110 &Foo::Test2Mixed, foo.get(), a, &d)); | 110 &Foo::Test2Mixed, foo.get(), a, &d)); |
111 // After all tests, post a message that will shut down the message loop | 111 // After all tests, post a message that will shut down the message loop |
112 MessageLoop::current()->PostTask( | 112 MessageLoop::current()->PostTask( |
113 FROM_HERE, | 113 FROM_HERE, |
114 Bind(&MessageLoop::QuitWhenIdle, Unretained(MessageLoop::current()))); | 114 Bind(&MessageLoop::QuitWhenIdle, Unretained(MessageLoop::current()))); |
115 | 115 |
116 // Now kick things off | 116 // Now kick things off |
117 MessageLoop::current()->Run(); | 117 MessageLoop::current()->Run(); |
118 | 118 |
119 EXPECT_EQ(foo->test_count(), 105); | 119 EXPECT_EQ(foo->test_count(), 105); |
120 EXPECT_EQ(foo->result(), "abacad"); | 120 EXPECT_EQ(foo->result(), "abacad"); |
121 } | 121 } |
122 | 122 |
123 void RunTest_PostDelayedTask_Basic(MessagePumpFactory factory) { | 123 void RunTest_PostDelayedTask_Basic(MessagePumpFactory factory) { |
124 scoped_ptr<MessagePump> pump(factory()); | 124 std::unique_ptr<MessagePump> pump(factory()); |
125 MessageLoop loop(std::move(pump)); | 125 MessageLoop loop(std::move(pump)); |
126 | 126 |
127 // Test that PostDelayedTask results in a delayed task. | 127 // Test that PostDelayedTask results in a delayed task. |
128 | 128 |
129 const TimeDelta kDelay = TimeDelta::FromMilliseconds(100); | 129 const TimeDelta kDelay = TimeDelta::FromMilliseconds(100); |
130 | 130 |
131 int num_tasks = 1; | 131 int num_tasks = 1; |
132 Time run_time; | 132 Time run_time; |
133 | 133 |
134 loop.PostDelayedTask( | 134 loop.PostDelayedTask( |
135 FROM_HERE, Bind(&RecordRunTimeFunc, &run_time, &num_tasks), | 135 FROM_HERE, Bind(&RecordRunTimeFunc, &run_time, &num_tasks), |
136 kDelay); | 136 kDelay); |
137 | 137 |
138 Time time_before_run = Time::Now(); | 138 Time time_before_run = Time::Now(); |
139 loop.Run(); | 139 loop.Run(); |
140 Time time_after_run = Time::Now(); | 140 Time time_after_run = Time::Now(); |
141 | 141 |
142 EXPECT_EQ(0, num_tasks); | 142 EXPECT_EQ(0, num_tasks); |
143 EXPECT_LT(kDelay, time_after_run - time_before_run); | 143 EXPECT_LT(kDelay, time_after_run - time_before_run); |
144 } | 144 } |
145 | 145 |
146 void RunTest_PostDelayedTask_InDelayOrder(MessagePumpFactory factory) { | 146 void RunTest_PostDelayedTask_InDelayOrder(MessagePumpFactory factory) { |
147 scoped_ptr<MessagePump> pump(factory()); | 147 std::unique_ptr<MessagePump> pump(factory()); |
148 MessageLoop loop(std::move(pump)); | 148 MessageLoop loop(std::move(pump)); |
149 | 149 |
150 // Test that two tasks with different delays run in the right order. | 150 // Test that two tasks with different delays run in the right order. |
151 int num_tasks = 2; | 151 int num_tasks = 2; |
152 Time run_time1, run_time2; | 152 Time run_time1, run_time2; |
153 | 153 |
154 loop.PostDelayedTask( | 154 loop.PostDelayedTask( |
155 FROM_HERE, | 155 FROM_HERE, |
156 Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), | 156 Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), |
157 TimeDelta::FromMilliseconds(200)); | 157 TimeDelta::FromMilliseconds(200)); |
158 // If we get a large pause in execution (due to a context switch) here, this | 158 // If we get a large pause in execution (due to a context switch) here, this |
159 // test could fail. | 159 // test could fail. |
160 loop.PostDelayedTask( | 160 loop.PostDelayedTask( |
161 FROM_HERE, | 161 FROM_HERE, |
162 Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), | 162 Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), |
163 TimeDelta::FromMilliseconds(10)); | 163 TimeDelta::FromMilliseconds(10)); |
164 | 164 |
165 loop.Run(); | 165 loop.Run(); |
166 EXPECT_EQ(0, num_tasks); | 166 EXPECT_EQ(0, num_tasks); |
167 | 167 |
168 EXPECT_TRUE(run_time2 < run_time1); | 168 EXPECT_TRUE(run_time2 < run_time1); |
169 } | 169 } |
170 | 170 |
171 void RunTest_PostDelayedTask_InPostOrder(MessagePumpFactory factory) { | 171 void RunTest_PostDelayedTask_InPostOrder(MessagePumpFactory factory) { |
172 scoped_ptr<MessagePump> pump(factory()); | 172 std::unique_ptr<MessagePump> pump(factory()); |
173 MessageLoop loop(std::move(pump)); | 173 MessageLoop loop(std::move(pump)); |
174 | 174 |
175 // Test that two tasks with the same delay run in the order in which they | 175 // Test that two tasks with the same delay run in the order in which they |
176 // were posted. | 176 // were posted. |
177 // | 177 // |
178 // NOTE: This is actually an approximate test since the API only takes a | 178 // NOTE: This is actually an approximate test since the API only takes a |
179 // "delay" parameter, so we are not exactly simulating two tasks that get | 179 // "delay" parameter, so we are not exactly simulating two tasks that get |
180 // posted at the exact same time. It would be nice if the API allowed us to | 180 // posted at the exact same time. It would be nice if the API allowed us to |
181 // specify the desired run time. | 181 // specify the desired run time. |
182 | 182 |
183 const TimeDelta kDelay = TimeDelta::FromMilliseconds(100); | 183 const TimeDelta kDelay = TimeDelta::FromMilliseconds(100); |
184 | 184 |
185 int num_tasks = 2; | 185 int num_tasks = 2; |
186 Time run_time1, run_time2; | 186 Time run_time1, run_time2; |
187 | 187 |
188 loop.PostDelayedTask( | 188 loop.PostDelayedTask( |
189 FROM_HERE, | 189 FROM_HERE, |
190 Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), kDelay); | 190 Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), kDelay); |
191 loop.PostDelayedTask( | 191 loop.PostDelayedTask( |
192 FROM_HERE, | 192 FROM_HERE, |
193 Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), kDelay); | 193 Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), kDelay); |
194 | 194 |
195 loop.Run(); | 195 loop.Run(); |
196 EXPECT_EQ(0, num_tasks); | 196 EXPECT_EQ(0, num_tasks); |
197 | 197 |
198 EXPECT_TRUE(run_time1 < run_time2); | 198 EXPECT_TRUE(run_time1 < run_time2); |
199 } | 199 } |
200 | 200 |
201 void RunTest_PostDelayedTask_InPostOrder_2(MessagePumpFactory factory) { | 201 void RunTest_PostDelayedTask_InPostOrder_2(MessagePumpFactory factory) { |
202 scoped_ptr<MessagePump> pump(factory()); | 202 std::unique_ptr<MessagePump> pump(factory()); |
203 MessageLoop loop(std::move(pump)); | 203 MessageLoop loop(std::move(pump)); |
204 | 204 |
205 // Test that a delayed task still runs after a normal tasks even if the | 205 // Test that a delayed task still runs after a normal tasks even if the |
206 // normal tasks take a long time to run. | 206 // normal tasks take a long time to run. |
207 | 207 |
208 const TimeDelta kPause = TimeDelta::FromMilliseconds(50); | 208 const TimeDelta kPause = TimeDelta::FromMilliseconds(50); |
209 | 209 |
210 int num_tasks = 2; | 210 int num_tasks = 2; |
211 Time run_time; | 211 Time run_time; |
212 | 212 |
213 loop.PostTask(FROM_HERE, Bind(&SlowFunc, kPause, &num_tasks)); | 213 loop.PostTask(FROM_HERE, Bind(&SlowFunc, kPause, &num_tasks)); |
214 loop.PostDelayedTask( | 214 loop.PostDelayedTask( |
215 FROM_HERE, | 215 FROM_HERE, |
216 Bind(&RecordRunTimeFunc, &run_time, &num_tasks), | 216 Bind(&RecordRunTimeFunc, &run_time, &num_tasks), |
217 TimeDelta::FromMilliseconds(10)); | 217 TimeDelta::FromMilliseconds(10)); |
218 | 218 |
219 Time time_before_run = Time::Now(); | 219 Time time_before_run = Time::Now(); |
220 loop.Run(); | 220 loop.Run(); |
221 Time time_after_run = Time::Now(); | 221 Time time_after_run = Time::Now(); |
222 | 222 |
223 EXPECT_EQ(0, num_tasks); | 223 EXPECT_EQ(0, num_tasks); |
224 | 224 |
225 EXPECT_LT(kPause, time_after_run - time_before_run); | 225 EXPECT_LT(kPause, time_after_run - time_before_run); |
226 } | 226 } |
227 | 227 |
228 void RunTest_PostDelayedTask_InPostOrder_3(MessagePumpFactory factory) { | 228 void RunTest_PostDelayedTask_InPostOrder_3(MessagePumpFactory factory) { |
229 scoped_ptr<MessagePump> pump(factory()); | 229 std::unique_ptr<MessagePump> pump(factory()); |
230 MessageLoop loop(std::move(pump)); | 230 MessageLoop loop(std::move(pump)); |
231 | 231 |
232 // Test that a delayed task still runs after a pile of normal tasks. The key | 232 // Test that a delayed task still runs after a pile of normal tasks. The key |
233 // difference between this test and the previous one is that here we return | 233 // difference between this test and the previous one is that here we return |
234 // the MessageLoop a lot so we give the MessageLoop plenty of opportunities | 234 // the MessageLoop a lot so we give the MessageLoop plenty of opportunities |
235 // to maybe run the delayed task. It should know not to do so until the | 235 // to maybe run the delayed task. It should know not to do so until the |
236 // delayed task's delay has passed. | 236 // delayed task's delay has passed. |
237 | 237 |
238 int num_tasks = 11; | 238 int num_tasks = 11; |
239 Time run_time1, run_time2; | 239 Time run_time1, run_time2; |
240 | 240 |
241 // Clutter the ML with tasks. | 241 // Clutter the ML with tasks. |
242 for (int i = 1; i < num_tasks; ++i) | 242 for (int i = 1; i < num_tasks; ++i) |
243 loop.PostTask(FROM_HERE, | 243 loop.PostTask(FROM_HERE, |
244 Bind(&RecordRunTimeFunc, &run_time1, &num_tasks)); | 244 Bind(&RecordRunTimeFunc, &run_time1, &num_tasks)); |
245 | 245 |
246 loop.PostDelayedTask( | 246 loop.PostDelayedTask( |
247 FROM_HERE, Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), | 247 FROM_HERE, Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), |
248 TimeDelta::FromMilliseconds(1)); | 248 TimeDelta::FromMilliseconds(1)); |
249 | 249 |
250 loop.Run(); | 250 loop.Run(); |
251 EXPECT_EQ(0, num_tasks); | 251 EXPECT_EQ(0, num_tasks); |
252 | 252 |
253 EXPECT_TRUE(run_time2 > run_time1); | 253 EXPECT_TRUE(run_time2 > run_time1); |
254 } | 254 } |
255 | 255 |
256 void RunTest_PostDelayedTask_SharedTimer(MessagePumpFactory factory) { | 256 void RunTest_PostDelayedTask_SharedTimer(MessagePumpFactory factory) { |
257 scoped_ptr<MessagePump> pump(factory()); | 257 std::unique_ptr<MessagePump> pump(factory()); |
258 MessageLoop loop(std::move(pump)); | 258 MessageLoop loop(std::move(pump)); |
259 | 259 |
260 // Test that the interval of the timer, used to run the next delayed task, is | 260 // Test that the interval of the timer, used to run the next delayed task, is |
261 // set to a value corresponding to when the next delayed task should run. | 261 // set to a value corresponding to when the next delayed task should run. |
262 | 262 |
263 // By setting num_tasks to 1, we ensure that the first task to run causes the | 263 // By setting num_tasks to 1, we ensure that the first task to run causes the |
264 // run loop to exit. | 264 // run loop to exit. |
265 int num_tasks = 1; | 265 int num_tasks = 1; |
266 Time run_time1, run_time2; | 266 Time run_time1, run_time2; |
267 | 267 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 314 } |
315 | 315 |
316 scoped_refptr<RecordDeletionProbe> post_on_delete_; | 316 scoped_refptr<RecordDeletionProbe> post_on_delete_; |
317 bool* was_deleted_; | 317 bool* was_deleted_; |
318 }; | 318 }; |
319 | 319 |
320 void RunTest_EnsureDeletion(MessagePumpFactory factory) { | 320 void RunTest_EnsureDeletion(MessagePumpFactory factory) { |
321 bool a_was_deleted = false; | 321 bool a_was_deleted = false; |
322 bool b_was_deleted = false; | 322 bool b_was_deleted = false; |
323 { | 323 { |
324 scoped_ptr<MessagePump> pump(factory()); | 324 std::unique_ptr<MessagePump> pump(factory()); |
325 MessageLoop loop(std::move(pump)); | 325 MessageLoop loop(std::move(pump)); |
326 loop.PostTask( | 326 loop.PostTask( |
327 FROM_HERE, Bind(&RecordDeletionProbe::Run, | 327 FROM_HERE, Bind(&RecordDeletionProbe::Run, |
328 new RecordDeletionProbe(NULL, &a_was_deleted))); | 328 new RecordDeletionProbe(NULL, &a_was_deleted))); |
329 // TODO(ajwong): Do we really need 1000ms here? | 329 // TODO(ajwong): Do we really need 1000ms here? |
330 loop.PostDelayedTask( | 330 loop.PostDelayedTask( |
331 FROM_HERE, Bind(&RecordDeletionProbe::Run, | 331 FROM_HERE, Bind(&RecordDeletionProbe::Run, |
332 new RecordDeletionProbe(NULL, &b_was_deleted)), | 332 new RecordDeletionProbe(NULL, &b_was_deleted)), |
333 TimeDelta::FromMilliseconds(1000)); | 333 TimeDelta::FromMilliseconds(1000)); |
334 } | 334 } |
335 EXPECT_TRUE(a_was_deleted); | 335 EXPECT_TRUE(a_was_deleted); |
336 EXPECT_TRUE(b_was_deleted); | 336 EXPECT_TRUE(b_was_deleted); |
337 } | 337 } |
338 | 338 |
339 void RunTest_EnsureDeletion_Chain(MessagePumpFactory factory) { | 339 void RunTest_EnsureDeletion_Chain(MessagePumpFactory factory) { |
340 bool a_was_deleted = false; | 340 bool a_was_deleted = false; |
341 bool b_was_deleted = false; | 341 bool b_was_deleted = false; |
342 bool c_was_deleted = false; | 342 bool c_was_deleted = false; |
343 { | 343 { |
344 scoped_ptr<MessagePump> pump(factory()); | 344 std::unique_ptr<MessagePump> pump(factory()); |
345 MessageLoop loop(std::move(pump)); | 345 MessageLoop loop(std::move(pump)); |
346 // The scoped_refptr for each of the below is held either by the chained | 346 // The scoped_refptr for each of the below is held either by the chained |
347 // RecordDeletionProbe, or the bound RecordDeletionProbe::Run() callback. | 347 // RecordDeletionProbe, or the bound RecordDeletionProbe::Run() callback. |
348 RecordDeletionProbe* a = new RecordDeletionProbe(NULL, &a_was_deleted); | 348 RecordDeletionProbe* a = new RecordDeletionProbe(NULL, &a_was_deleted); |
349 RecordDeletionProbe* b = new RecordDeletionProbe(a, &b_was_deleted); | 349 RecordDeletionProbe* b = new RecordDeletionProbe(a, &b_was_deleted); |
350 RecordDeletionProbe* c = new RecordDeletionProbe(b, &c_was_deleted); | 350 RecordDeletionProbe* c = new RecordDeletionProbe(b, &c_was_deleted); |
351 loop.PostTask(FROM_HERE, Bind(&RecordDeletionProbe::Run, c)); | 351 loop.PostTask(FROM_HERE, Bind(&RecordDeletionProbe::Run, c)); |
352 } | 352 } |
353 EXPECT_TRUE(a_was_deleted); | 353 EXPECT_TRUE(a_was_deleted); |
354 EXPECT_TRUE(b_was_deleted); | 354 EXPECT_TRUE(b_was_deleted); |
355 EXPECT_TRUE(c_was_deleted); | 355 EXPECT_TRUE(c_was_deleted); |
356 } | 356 } |
357 | 357 |
358 void NestingFunc(int* depth) { | 358 void NestingFunc(int* depth) { |
359 if (*depth > 0) { | 359 if (*depth > 0) { |
360 *depth -= 1; | 360 *depth -= 1; |
361 MessageLoop::current()->PostTask(FROM_HERE, | 361 MessageLoop::current()->PostTask(FROM_HERE, |
362 Bind(&NestingFunc, depth)); | 362 Bind(&NestingFunc, depth)); |
363 | 363 |
364 MessageLoop::current()->SetNestableTasksAllowed(true); | 364 MessageLoop::current()->SetNestableTasksAllowed(true); |
365 MessageLoop::current()->Run(); | 365 MessageLoop::current()->Run(); |
366 } | 366 } |
367 MessageLoop::current()->QuitWhenIdle(); | 367 MessageLoop::current()->QuitWhenIdle(); |
368 } | 368 } |
369 | 369 |
370 void RunTest_Nesting(MessagePumpFactory factory) { | 370 void RunTest_Nesting(MessagePumpFactory factory) { |
371 scoped_ptr<MessagePump> pump(factory()); | 371 std::unique_ptr<MessagePump> pump(factory()); |
372 MessageLoop loop(std::move(pump)); | 372 MessageLoop loop(std::move(pump)); |
373 | 373 |
374 int depth = 100; | 374 int depth = 100; |
375 MessageLoop::current()->PostTask(FROM_HERE, | 375 MessageLoop::current()->PostTask(FROM_HERE, |
376 Bind(&NestingFunc, &depth)); | 376 Bind(&NestingFunc, &depth)); |
377 MessageLoop::current()->Run(); | 377 MessageLoop::current()->Run(); |
378 EXPECT_EQ(depth, 0); | 378 EXPECT_EQ(depth, 0); |
379 } | 379 } |
380 | 380 |
381 enum TaskType { | 381 enum TaskType { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } | 469 } |
470 order->RecordEnd(RECURSIVE, cookie); | 470 order->RecordEnd(RECURSIVE, cookie); |
471 } | 471 } |
472 | 472 |
473 void QuitFunc(TaskList* order, int cookie) { | 473 void QuitFunc(TaskList* order, int cookie) { |
474 order->RecordStart(QUITMESSAGELOOP, cookie); | 474 order->RecordStart(QUITMESSAGELOOP, cookie); |
475 MessageLoop::current()->QuitWhenIdle(); | 475 MessageLoop::current()->QuitWhenIdle(); |
476 order->RecordEnd(QUITMESSAGELOOP, cookie); | 476 order->RecordEnd(QUITMESSAGELOOP, cookie); |
477 } | 477 } |
478 void RunTest_RecursiveDenial1(MessagePumpFactory factory) { | 478 void RunTest_RecursiveDenial1(MessagePumpFactory factory) { |
479 scoped_ptr<MessagePump> pump(factory()); | 479 std::unique_ptr<MessagePump> pump(factory()); |
480 MessageLoop loop(std::move(pump)); | 480 MessageLoop loop(std::move(pump)); |
481 | 481 |
482 EXPECT_TRUE(MessageLoop::current()->NestableTasksAllowed()); | 482 EXPECT_TRUE(MessageLoop::current()->NestableTasksAllowed()); |
483 TaskList order; | 483 TaskList order; |
484 MessageLoop::current()->PostTask( | 484 MessageLoop::current()->PostTask( |
485 FROM_HERE, | 485 FROM_HERE, |
486 Bind(&RecursiveFunc, &order, 1, 2, false)); | 486 Bind(&RecursiveFunc, &order, 1, 2, false)); |
487 MessageLoop::current()->PostTask( | 487 MessageLoop::current()->PostTask( |
488 FROM_HERE, | 488 FROM_HERE, |
489 Bind(&RecursiveFunc, &order, 2, 2, false)); | 489 Bind(&RecursiveFunc, &order, 2, 2, false)); |
(...skipping 26 matching lines...) Expand all Loading... |
516 RecursiveFunc(order, cookie, depth, is_reentrant); | 516 RecursiveFunc(order, cookie, depth, is_reentrant); |
517 PlatformThread::Sleep(TimeDelta::FromMilliseconds(10)); | 517 PlatformThread::Sleep(TimeDelta::FromMilliseconds(10)); |
518 } | 518 } |
519 | 519 |
520 void OrderedFunc(TaskList* order, int cookie) { | 520 void OrderedFunc(TaskList* order, int cookie) { |
521 order->RecordStart(ORDERED, cookie); | 521 order->RecordStart(ORDERED, cookie); |
522 order->RecordEnd(ORDERED, cookie); | 522 order->RecordEnd(ORDERED, cookie); |
523 } | 523 } |
524 | 524 |
525 void RunTest_RecursiveDenial3(MessagePumpFactory factory) { | 525 void RunTest_RecursiveDenial3(MessagePumpFactory factory) { |
526 scoped_ptr<MessagePump> pump(factory()); | 526 std::unique_ptr<MessagePump> pump(factory()); |
527 MessageLoop loop(std::move(pump)); | 527 MessageLoop loop(std::move(pump)); |
528 | 528 |
529 EXPECT_TRUE(MessageLoop::current()->NestableTasksAllowed()); | 529 EXPECT_TRUE(MessageLoop::current()->NestableTasksAllowed()); |
530 TaskList order; | 530 TaskList order; |
531 MessageLoop::current()->PostTask( | 531 MessageLoop::current()->PostTask( |
532 FROM_HERE, Bind(&RecursiveSlowFunc, &order, 1, 2, false)); | 532 FROM_HERE, Bind(&RecursiveSlowFunc, &order, 1, 2, false)); |
533 MessageLoop::current()->PostTask( | 533 MessageLoop::current()->PostTask( |
534 FROM_HERE, Bind(&RecursiveSlowFunc, &order, 2, 2, false)); | 534 FROM_HERE, Bind(&RecursiveSlowFunc, &order, 2, 2, false)); |
535 MessageLoop::current()->PostDelayedTask( | 535 MessageLoop::current()->PostDelayedTask( |
536 FROM_HERE, | 536 FROM_HERE, |
(...skipping 20 matching lines...) Expand all Loading... |
557 EXPECT_EQ(order.Get(9), TaskItem(RECURSIVE, 2, false)); | 557 EXPECT_EQ(order.Get(9), TaskItem(RECURSIVE, 2, false)); |
558 EXPECT_EQ(order.Get(10), TaskItem(QUITMESSAGELOOP, 4, true)); | 558 EXPECT_EQ(order.Get(10), TaskItem(QUITMESSAGELOOP, 4, true)); |
559 EXPECT_EQ(order.Get(11), TaskItem(QUITMESSAGELOOP, 4, false)); | 559 EXPECT_EQ(order.Get(11), TaskItem(QUITMESSAGELOOP, 4, false)); |
560 EXPECT_EQ(order.Get(12), TaskItem(RECURSIVE, 1, true)); | 560 EXPECT_EQ(order.Get(12), TaskItem(RECURSIVE, 1, true)); |
561 EXPECT_EQ(order.Get(13), TaskItem(RECURSIVE, 1, false)); | 561 EXPECT_EQ(order.Get(13), TaskItem(RECURSIVE, 1, false)); |
562 EXPECT_EQ(order.Get(14), TaskItem(RECURSIVE, 2, true)); | 562 EXPECT_EQ(order.Get(14), TaskItem(RECURSIVE, 2, true)); |
563 EXPECT_EQ(order.Get(15), TaskItem(RECURSIVE, 2, false)); | 563 EXPECT_EQ(order.Get(15), TaskItem(RECURSIVE, 2, false)); |
564 } | 564 } |
565 | 565 |
566 void RunTest_RecursiveSupport1(MessagePumpFactory factory) { | 566 void RunTest_RecursiveSupport1(MessagePumpFactory factory) { |
567 scoped_ptr<MessagePump> pump(factory()); | 567 std::unique_ptr<MessagePump> pump(factory()); |
568 MessageLoop loop(std::move(pump)); | 568 MessageLoop loop(std::move(pump)); |
569 | 569 |
570 TaskList order; | 570 TaskList order; |
571 MessageLoop::current()->PostTask( | 571 MessageLoop::current()->PostTask( |
572 FROM_HERE, Bind(&RecursiveFunc, &order, 1, 2, true)); | 572 FROM_HERE, Bind(&RecursiveFunc, &order, 1, 2, true)); |
573 MessageLoop::current()->PostTask( | 573 MessageLoop::current()->PostTask( |
574 FROM_HERE, Bind(&RecursiveFunc, &order, 2, 2, true)); | 574 FROM_HERE, Bind(&RecursiveFunc, &order, 2, 2, true)); |
575 MessageLoop::current()->PostTask( | 575 MessageLoop::current()->PostTask( |
576 FROM_HERE, Bind(&QuitFunc, &order, 3)); | 576 FROM_HERE, Bind(&QuitFunc, &order, 3)); |
577 | 577 |
(...skipping 12 matching lines...) Expand all Loading... |
590 EXPECT_EQ(order.Get(8), TaskItem(RECURSIVE, 2, true)); | 590 EXPECT_EQ(order.Get(8), TaskItem(RECURSIVE, 2, true)); |
591 EXPECT_EQ(order.Get(9), TaskItem(RECURSIVE, 2, false)); | 591 EXPECT_EQ(order.Get(9), TaskItem(RECURSIVE, 2, false)); |
592 EXPECT_EQ(order.Get(10), TaskItem(RECURSIVE, 1, true)); | 592 EXPECT_EQ(order.Get(10), TaskItem(RECURSIVE, 1, true)); |
593 EXPECT_EQ(order.Get(11), TaskItem(RECURSIVE, 1, false)); | 593 EXPECT_EQ(order.Get(11), TaskItem(RECURSIVE, 1, false)); |
594 EXPECT_EQ(order.Get(12), TaskItem(RECURSIVE, 2, true)); | 594 EXPECT_EQ(order.Get(12), TaskItem(RECURSIVE, 2, true)); |
595 EXPECT_EQ(order.Get(13), TaskItem(RECURSIVE, 2, false)); | 595 EXPECT_EQ(order.Get(13), TaskItem(RECURSIVE, 2, false)); |
596 } | 596 } |
597 | 597 |
598 // Tests that non nestable tasks run in FIFO if there are no nested loops. | 598 // Tests that non nestable tasks run in FIFO if there are no nested loops. |
599 void RunTest_NonNestableWithNoNesting(MessagePumpFactory factory) { | 599 void RunTest_NonNestableWithNoNesting(MessagePumpFactory factory) { |
600 scoped_ptr<MessagePump> pump(factory()); | 600 std::unique_ptr<MessagePump> pump(factory()); |
601 MessageLoop loop(std::move(pump)); | 601 MessageLoop loop(std::move(pump)); |
602 | 602 |
603 TaskList order; | 603 TaskList order; |
604 | 604 |
605 MessageLoop::current()->PostNonNestableTask( | 605 MessageLoop::current()->PostNonNestableTask( |
606 FROM_HERE, | 606 FROM_HERE, |
607 Bind(&OrderedFunc, &order, 1)); | 607 Bind(&OrderedFunc, &order, 1)); |
608 MessageLoop::current()->PostTask(FROM_HERE, | 608 MessageLoop::current()->PostTask(FROM_HERE, |
609 Bind(&OrderedFunc, &order, 2)); | 609 Bind(&OrderedFunc, &order, 2)); |
610 MessageLoop::current()->PostTask(FROM_HERE, | 610 MessageLoop::current()->PostTask(FROM_HERE, |
(...skipping 21 matching lines...) Expand all Loading... |
632 | 632 |
633 void SleepFunc(TaskList* order, int cookie, TimeDelta delay) { | 633 void SleepFunc(TaskList* order, int cookie, TimeDelta delay) { |
634 order->RecordStart(SLEEP, cookie); | 634 order->RecordStart(SLEEP, cookie); |
635 PlatformThread::Sleep(delay); | 635 PlatformThread::Sleep(delay); |
636 order->RecordEnd(SLEEP, cookie); | 636 order->RecordEnd(SLEEP, cookie); |
637 } | 637 } |
638 | 638 |
639 // Tests that non nestable tasks don't run when there's code in the call stack. | 639 // Tests that non nestable tasks don't run when there's code in the call stack. |
640 void RunTest_NonNestableInNestedLoop(MessagePumpFactory factory, | 640 void RunTest_NonNestableInNestedLoop(MessagePumpFactory factory, |
641 bool use_delayed) { | 641 bool use_delayed) { |
642 scoped_ptr<MessagePump> pump(factory()); | 642 std::unique_ptr<MessagePump> pump(factory()); |
643 MessageLoop loop(std::move(pump)); | 643 MessageLoop loop(std::move(pump)); |
644 | 644 |
645 TaskList order; | 645 TaskList order; |
646 | 646 |
647 MessageLoop::current()->PostTask( | 647 MessageLoop::current()->PostTask( |
648 FROM_HERE, | 648 FROM_HERE, |
649 Bind(&FuncThatPumps, &order, 1)); | 649 Bind(&FuncThatPumps, &order, 1)); |
650 if (use_delayed) { | 650 if (use_delayed) { |
651 MessageLoop::current()->PostNonNestableDelayedTask( | 651 MessageLoop::current()->PostNonNestableDelayedTask( |
652 FROM_HERE, | 652 FROM_HERE, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 run_loop->Run(); | 700 run_loop->Run(); |
701 } | 701 } |
702 order->RecordEnd(RUNS, cookie); | 702 order->RecordEnd(RUNS, cookie); |
703 } | 703 } |
704 | 704 |
705 void FuncThatQuitsNow() { | 705 void FuncThatQuitsNow() { |
706 MessageLoop::current()->QuitNow(); | 706 MessageLoop::current()->QuitNow(); |
707 } | 707 } |
708 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. | 708 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. |
709 void RunTest_QuitNow(MessagePumpFactory factory) { | 709 void RunTest_QuitNow(MessagePumpFactory factory) { |
710 scoped_ptr<MessagePump> pump(factory()); | 710 std::unique_ptr<MessagePump> pump(factory()); |
711 MessageLoop loop(std::move(pump)); | 711 MessageLoop loop(std::move(pump)); |
712 | 712 |
713 TaskList order; | 713 TaskList order; |
714 | 714 |
715 RunLoop run_loop; | 715 RunLoop run_loop; |
716 | 716 |
717 MessageLoop::current()->PostTask(FROM_HERE, | 717 MessageLoop::current()->PostTask(FROM_HERE, |
718 Bind(&FuncThatRuns, &order, 1, Unretained(&run_loop))); | 718 Bind(&FuncThatRuns, &order, 1, Unretained(&run_loop))); |
719 MessageLoop::current()->PostTask( | 719 MessageLoop::current()->PostTask( |
720 FROM_HERE, Bind(&OrderedFunc, &order, 2)); | 720 FROM_HERE, Bind(&OrderedFunc, &order, 2)); |
(...skipping 14 matching lines...) Expand all Loading... |
735 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, true)); | 735 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, true)); |
736 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, false)); | 736 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, false)); |
737 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); | 737 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); |
738 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 3, true)); | 738 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 3, true)); |
739 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 3, false)); | 739 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 3, false)); |
740 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); | 740 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); |
741 } | 741 } |
742 | 742 |
743 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. | 743 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. |
744 void RunTest_RunLoopQuitTop(MessagePumpFactory factory) { | 744 void RunTest_RunLoopQuitTop(MessagePumpFactory factory) { |
745 scoped_ptr<MessagePump> pump(factory()); | 745 std::unique_ptr<MessagePump> pump(factory()); |
746 MessageLoop loop(std::move(pump)); | 746 MessageLoop loop(std::move(pump)); |
747 | 747 |
748 TaskList order; | 748 TaskList order; |
749 | 749 |
750 RunLoop outer_run_loop; | 750 RunLoop outer_run_loop; |
751 RunLoop nested_run_loop; | 751 RunLoop nested_run_loop; |
752 | 752 |
753 MessageLoop::current()->PostTask(FROM_HERE, | 753 MessageLoop::current()->PostTask(FROM_HERE, |
754 Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); | 754 Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); |
755 MessageLoop::current()->PostTask( | 755 MessageLoop::current()->PostTask( |
756 FROM_HERE, outer_run_loop.QuitClosure()); | 756 FROM_HERE, outer_run_loop.QuitClosure()); |
757 MessageLoop::current()->PostTask( | 757 MessageLoop::current()->PostTask( |
758 FROM_HERE, Bind(&OrderedFunc, &order, 2)); | 758 FROM_HERE, Bind(&OrderedFunc, &order, 2)); |
759 MessageLoop::current()->PostTask( | 759 MessageLoop::current()->PostTask( |
760 FROM_HERE, nested_run_loop.QuitClosure()); | 760 FROM_HERE, nested_run_loop.QuitClosure()); |
761 | 761 |
762 outer_run_loop.Run(); | 762 outer_run_loop.Run(); |
763 | 763 |
764 ASSERT_EQ(4U, order.Size()); | 764 ASSERT_EQ(4U, order.Size()); |
765 int task_index = 0; | 765 int task_index = 0; |
766 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, true)); | 766 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, true)); |
767 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, true)); | 767 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, true)); |
768 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, false)); | 768 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, false)); |
769 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); | 769 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); |
770 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); | 770 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); |
771 } | 771 } |
772 | 772 |
773 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. | 773 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. |
774 void RunTest_RunLoopQuitNested(MessagePumpFactory factory) { | 774 void RunTest_RunLoopQuitNested(MessagePumpFactory factory) { |
775 scoped_ptr<MessagePump> pump(factory()); | 775 std::unique_ptr<MessagePump> pump(factory()); |
776 MessageLoop loop(std::move(pump)); | 776 MessageLoop loop(std::move(pump)); |
777 | 777 |
778 TaskList order; | 778 TaskList order; |
779 | 779 |
780 RunLoop outer_run_loop; | 780 RunLoop outer_run_loop; |
781 RunLoop nested_run_loop; | 781 RunLoop nested_run_loop; |
782 | 782 |
783 MessageLoop::current()->PostTask(FROM_HERE, | 783 MessageLoop::current()->PostTask(FROM_HERE, |
784 Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); | 784 Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); |
785 MessageLoop::current()->PostTask( | 785 MessageLoop::current()->PostTask( |
786 FROM_HERE, nested_run_loop.QuitClosure()); | 786 FROM_HERE, nested_run_loop.QuitClosure()); |
787 MessageLoop::current()->PostTask( | 787 MessageLoop::current()->PostTask( |
788 FROM_HERE, Bind(&OrderedFunc, &order, 2)); | 788 FROM_HERE, Bind(&OrderedFunc, &order, 2)); |
789 MessageLoop::current()->PostTask( | 789 MessageLoop::current()->PostTask( |
790 FROM_HERE, outer_run_loop.QuitClosure()); | 790 FROM_HERE, outer_run_loop.QuitClosure()); |
791 | 791 |
792 outer_run_loop.Run(); | 792 outer_run_loop.Run(); |
793 | 793 |
794 ASSERT_EQ(4U, order.Size()); | 794 ASSERT_EQ(4U, order.Size()); |
795 int task_index = 0; | 795 int task_index = 0; |
796 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, true)); | 796 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, true)); |
797 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); | 797 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); |
798 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, true)); | 798 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, true)); |
799 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, false)); | 799 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, false)); |
800 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); | 800 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); |
801 } | 801 } |
802 | 802 |
803 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. | 803 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. |
804 void RunTest_RunLoopQuitBogus(MessagePumpFactory factory) { | 804 void RunTest_RunLoopQuitBogus(MessagePumpFactory factory) { |
805 scoped_ptr<MessagePump> pump(factory()); | 805 std::unique_ptr<MessagePump> pump(factory()); |
806 MessageLoop loop(std::move(pump)); | 806 MessageLoop loop(std::move(pump)); |
807 | 807 |
808 TaskList order; | 808 TaskList order; |
809 | 809 |
810 RunLoop outer_run_loop; | 810 RunLoop outer_run_loop; |
811 RunLoop nested_run_loop; | 811 RunLoop nested_run_loop; |
812 RunLoop bogus_run_loop; | 812 RunLoop bogus_run_loop; |
813 | 813 |
814 MessageLoop::current()->PostTask(FROM_HERE, | 814 MessageLoop::current()->PostTask(FROM_HERE, |
815 Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); | 815 Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); |
(...skipping 12 matching lines...) Expand all Loading... |
828 int task_index = 0; | 828 int task_index = 0; |
829 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, true)); | 829 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, true)); |
830 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, true)); | 830 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, true)); |
831 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, false)); | 831 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 2, false)); |
832 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); | 832 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); |
833 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); | 833 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); |
834 } | 834 } |
835 | 835 |
836 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. | 836 // Tests RunLoopQuit only quits the corresponding MessageLoop::Run. |
837 void RunTest_RunLoopQuitDeep(MessagePumpFactory factory) { | 837 void RunTest_RunLoopQuitDeep(MessagePumpFactory factory) { |
838 scoped_ptr<MessagePump> pump(factory()); | 838 std::unique_ptr<MessagePump> pump(factory()); |
839 MessageLoop loop(std::move(pump)); | 839 MessageLoop loop(std::move(pump)); |
840 | 840 |
841 TaskList order; | 841 TaskList order; |
842 | 842 |
843 RunLoop outer_run_loop; | 843 RunLoop outer_run_loop; |
844 RunLoop nested_loop1; | 844 RunLoop nested_loop1; |
845 RunLoop nested_loop2; | 845 RunLoop nested_loop2; |
846 RunLoop nested_loop3; | 846 RunLoop nested_loop3; |
847 RunLoop nested_loop4; | 847 RunLoop nested_loop4; |
848 | 848 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 9, false)); | 897 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 9, false)); |
898 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 4, false)); | 898 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 4, false)); |
899 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 3, false)); | 899 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 3, false)); |
900 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 2, false)); | 900 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 2, false)); |
901 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); | 901 EXPECT_EQ(order.Get(task_index++), TaskItem(RUNS, 1, false)); |
902 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); | 902 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); |
903 } | 903 } |
904 | 904 |
905 // Tests RunLoopQuit works before RunWithID. | 905 // Tests RunLoopQuit works before RunWithID. |
906 void RunTest_RunLoopQuitOrderBefore(MessagePumpFactory factory) { | 906 void RunTest_RunLoopQuitOrderBefore(MessagePumpFactory factory) { |
907 scoped_ptr<MessagePump> pump(factory()); | 907 std::unique_ptr<MessagePump> pump(factory()); |
908 MessageLoop loop(std::move(pump)); | 908 MessageLoop loop(std::move(pump)); |
909 | 909 |
910 TaskList order; | 910 TaskList order; |
911 | 911 |
912 RunLoop run_loop; | 912 RunLoop run_loop; |
913 | 913 |
914 run_loop.Quit(); | 914 run_loop.Quit(); |
915 | 915 |
916 MessageLoop::current()->PostTask( | 916 MessageLoop::current()->PostTask( |
917 FROM_HERE, Bind(&OrderedFunc, &order, 1)); // never runs | 917 FROM_HERE, Bind(&OrderedFunc, &order, 1)); // never runs |
918 MessageLoop::current()->PostTask( | 918 MessageLoop::current()->PostTask( |
919 FROM_HERE, Bind(&FuncThatQuitsNow)); // never runs | 919 FROM_HERE, Bind(&FuncThatQuitsNow)); // never runs |
920 | 920 |
921 run_loop.Run(); | 921 run_loop.Run(); |
922 | 922 |
923 ASSERT_EQ(0U, order.Size()); | 923 ASSERT_EQ(0U, order.Size()); |
924 } | 924 } |
925 | 925 |
926 // Tests RunLoopQuit works during RunWithID. | 926 // Tests RunLoopQuit works during RunWithID. |
927 void RunTest_RunLoopQuitOrderDuring(MessagePumpFactory factory) { | 927 void RunTest_RunLoopQuitOrderDuring(MessagePumpFactory factory) { |
928 scoped_ptr<MessagePump> pump(factory()); | 928 std::unique_ptr<MessagePump> pump(factory()); |
929 MessageLoop loop(std::move(pump)); | 929 MessageLoop loop(std::move(pump)); |
930 | 930 |
931 TaskList order; | 931 TaskList order; |
932 | 932 |
933 RunLoop run_loop; | 933 RunLoop run_loop; |
934 | 934 |
935 MessageLoop::current()->PostTask( | 935 MessageLoop::current()->PostTask( |
936 FROM_HERE, Bind(&OrderedFunc, &order, 1)); | 936 FROM_HERE, Bind(&OrderedFunc, &order, 1)); |
937 MessageLoop::current()->PostTask( | 937 MessageLoop::current()->PostTask( |
938 FROM_HERE, run_loop.QuitClosure()); | 938 FROM_HERE, run_loop.QuitClosure()); |
939 MessageLoop::current()->PostTask( | 939 MessageLoop::current()->PostTask( |
940 FROM_HERE, Bind(&OrderedFunc, &order, 2)); // never runs | 940 FROM_HERE, Bind(&OrderedFunc, &order, 2)); // never runs |
941 MessageLoop::current()->PostTask( | 941 MessageLoop::current()->PostTask( |
942 FROM_HERE, Bind(&FuncThatQuitsNow)); // never runs | 942 FROM_HERE, Bind(&FuncThatQuitsNow)); // never runs |
943 | 943 |
944 run_loop.Run(); | 944 run_loop.Run(); |
945 | 945 |
946 ASSERT_EQ(2U, order.Size()); | 946 ASSERT_EQ(2U, order.Size()); |
947 int task_index = 0; | 947 int task_index = 0; |
948 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 1, true)); | 948 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 1, true)); |
949 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 1, false)); | 949 EXPECT_EQ(order.Get(task_index++), TaskItem(ORDERED, 1, false)); |
950 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); | 950 EXPECT_EQ(static_cast<size_t>(task_index), order.Size()); |
951 } | 951 } |
952 | 952 |
953 // Tests RunLoopQuit works after RunWithID. | 953 // Tests RunLoopQuit works after RunWithID. |
954 void RunTest_RunLoopQuitOrderAfter(MessagePumpFactory factory) { | 954 void RunTest_RunLoopQuitOrderAfter(MessagePumpFactory factory) { |
955 scoped_ptr<MessagePump> pump(factory()); | 955 std::unique_ptr<MessagePump> pump(factory()); |
956 MessageLoop loop(std::move(pump)); | 956 MessageLoop loop(std::move(pump)); |
957 | 957 |
958 TaskList order; | 958 TaskList order; |
959 | 959 |
960 RunLoop run_loop; | 960 RunLoop run_loop; |
961 | 961 |
962 MessageLoop::current()->PostTask(FROM_HERE, | 962 MessageLoop::current()->PostTask(FROM_HERE, |
963 Bind(&FuncThatRuns, &order, 1, Unretained(&run_loop))); | 963 Bind(&FuncThatRuns, &order, 1, Unretained(&run_loop))); |
964 MessageLoop::current()->PostTask( | 964 MessageLoop::current()->PostTask( |
965 FROM_HERE, Bind(&OrderedFunc, &order, 2)); | 965 FROM_HERE, Bind(&OrderedFunc, &order, 2)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 // There was a bug in the MessagePumpGLib where posting tasks recursively | 1003 // There was a bug in the MessagePumpGLib where posting tasks recursively |
1004 // caused the message loop to hang, due to the buffer of the internal pipe | 1004 // caused the message loop to hang, due to the buffer of the internal pipe |
1005 // becoming full. Test all MessageLoop types to ensure this issue does not | 1005 // becoming full. Test all MessageLoop types to ensure this issue does not |
1006 // exist in other MessagePumps. | 1006 // exist in other MessagePumps. |
1007 // | 1007 // |
1008 // On Linux, the pipe buffer size is 64KiB by default. The bug caused one | 1008 // On Linux, the pipe buffer size is 64KiB by default. The bug caused one |
1009 // byte accumulated in the pipe per two posts, so we should repeat 128K | 1009 // byte accumulated in the pipe per two posts, so we should repeat 128K |
1010 // times to reproduce the bug. | 1010 // times to reproduce the bug. |
1011 void RunTest_RecursivePosts(MessagePumpFactory factory) { | 1011 void RunTest_RecursivePosts(MessagePumpFactory factory) { |
1012 const int kNumTimes = 1 << 17; | 1012 const int kNumTimes = 1 << 17; |
1013 scoped_ptr<MessagePump> pump(factory()); | 1013 std::unique_ptr<MessagePump> pump(factory()); |
1014 MessageLoop loop(std::move(pump)); | 1014 MessageLoop loop(std::move(pump)); |
1015 loop.PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumTimes)); | 1015 loop.PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumTimes)); |
1016 loop.Run(); | 1016 loop.Run(); |
1017 } | 1017 } |
1018 | 1018 |
1019 } // namespace test | 1019 } // namespace test |
1020 } // namespace base | 1020 } // namespace base |
OLD | NEW |