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