| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // Now kick things off with the SEH block active. | 169 // Now kick things off with the SEH block active. |
| 170 MessageLoop::current()->set_exception_restoration(true); | 170 MessageLoop::current()->set_exception_restoration(true); |
| 171 MessageLoop::current()->Run(); | 171 MessageLoop::current()->Run(); |
| 172 MessageLoop::current()->set_exception_restoration(false); | 172 MessageLoop::current()->set_exception_restoration(false); |
| 173 | 173 |
| 174 EXPECT_EQ(foo->test_count(), 105); | 174 EXPECT_EQ(foo->test_count(), 105); |
| 175 EXPECT_EQ(foo->result(), "abacad"); | 175 EXPECT_EQ(foo->result(), "abacad"); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // This function runs slowly to simulate a large amount of work being done. | 178 // This function runs slowly to simulate a large amount of work being done. |
| 179 static void SlowFunc(int pause_ms, int* quit_counter) { | 179 static void SlowFunc(TimeDelta pause, int* quit_counter) { |
| 180 PlatformThread::Sleep(pause_ms); | 180 PlatformThread::Sleep(pause); |
| 181 if (--(*quit_counter) == 0) | 181 if (--(*quit_counter) == 0) |
| 182 MessageLoop::current()->Quit(); | 182 MessageLoop::current()->Quit(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // This function records the time when Run was called in a Time object, which is | 185 // This function records the time when Run was called in a Time object, which is |
| 186 // useful for building a variety of MessageLoop tests. | 186 // useful for building a variety of MessageLoop tests. |
| 187 static void RecordRunTimeFunc(Time* run_time, int* quit_counter) { | 187 static void RecordRunTimeFunc(Time* run_time, int* quit_counter) { |
| 188 *run_time = Time::Now(); | 188 *run_time = Time::Now(); |
| 189 | 189 |
| 190 // Cause our Run function to take some time to execute. As a result we can | 190 // Cause our Run function to take some time to execute. As a result we can |
| 191 // count on subsequent RecordRunTimeFunc()s running at a future time, | 191 // count on subsequent RecordRunTimeFunc()s running at a future time, |
| 192 // without worry about the resolution of our system clock being an issue. | 192 // without worry about the resolution of our system clock being an issue. |
| 193 SlowFunc(10, quit_counter); | 193 SlowFunc(TimeDelta::FromMilliseconds(10), quit_counter); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void RunTest_PostDelayedTask_Basic(MessageLoop::Type message_loop_type) { | 196 void RunTest_PostDelayedTask_Basic(MessageLoop::Type message_loop_type) { |
| 197 MessageLoop loop(message_loop_type); | 197 MessageLoop loop(message_loop_type); |
| 198 | 198 |
| 199 // Test that PostDelayedTask results in a delayed task. | 199 // Test that PostDelayedTask results in a delayed task. |
| 200 | 200 |
| 201 const int kDelayMS = 100; | 201 const int kDelayMS = 100; |
| 202 | 202 |
| 203 int num_tasks = 1; | 203 int num_tasks = 1; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 EXPECT_TRUE(run_time1 < run_time2); | 266 EXPECT_TRUE(run_time1 < run_time2); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void RunTest_PostDelayedTask_InPostOrder_2( | 269 void RunTest_PostDelayedTask_InPostOrder_2( |
| 270 MessageLoop::Type message_loop_type) { | 270 MessageLoop::Type message_loop_type) { |
| 271 MessageLoop loop(message_loop_type); | 271 MessageLoop loop(message_loop_type); |
| 272 | 272 |
| 273 // Test that a delayed task still runs after a normal tasks even if the | 273 // Test that a delayed task still runs after a normal tasks even if the |
| 274 // normal tasks take a long time to run. | 274 // normal tasks take a long time to run. |
| 275 | 275 |
| 276 const int kPauseMS = 50; | 276 const TimeDelta kPause = TimeDelta::FromMilliseconds(50); |
| 277 | 277 |
| 278 int num_tasks = 2; | 278 int num_tasks = 2; |
| 279 Time run_time; | 279 Time run_time; |
| 280 | 280 |
| 281 loop.PostTask(FROM_HERE, base::Bind(&SlowFunc, kPauseMS, &num_tasks)); | 281 loop.PostTask(FROM_HERE, base::Bind(&SlowFunc, kPause, &num_tasks)); |
| 282 loop.PostDelayedTask( | 282 loop.PostDelayedTask( |
| 283 FROM_HERE, base::Bind(&RecordRunTimeFunc, &run_time, &num_tasks), 10); | 283 FROM_HERE, base::Bind(&RecordRunTimeFunc, &run_time, &num_tasks), 10); |
| 284 | 284 |
| 285 Time time_before_run = Time::Now(); | 285 Time time_before_run = Time::Now(); |
| 286 loop.Run(); | 286 loop.Run(); |
| 287 Time time_after_run = Time::Now(); | 287 Time time_after_run = Time::Now(); |
| 288 | 288 |
| 289 EXPECT_EQ(0, num_tasks); | 289 EXPECT_EQ(0, num_tasks); |
| 290 | 290 |
| 291 EXPECT_LT(kPauseMS, (time_after_run - time_before_run).InMilliseconds()); | 291 EXPECT_LT(kPause, time_after_run - time_before_run); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void RunTest_PostDelayedTask_InPostOrder_3( | 294 void RunTest_PostDelayedTask_InPostOrder_3( |
| 295 MessageLoop::Type message_loop_type) { | 295 MessageLoop::Type message_loop_type) { |
| 296 MessageLoop loop(message_loop_type); | 296 MessageLoop loop(message_loop_type); |
| 297 | 297 |
| 298 // Test that a delayed task still runs after a pile of normal tasks. The key | 298 // Test that a delayed task still runs after a pile of normal tasks. The key |
| 299 // difference between this test and the previous one is that here we return | 299 // difference between this test and the previous one is that here we return |
| 300 // the MessageLoop a lot so we give the MessageLoop plenty of opportunities | 300 // the MessageLoop a lot so we give the MessageLoop plenty of opportunities |
| 301 // to maybe run the delayed task. It should know not to do so until the | 301 // to maybe run the delayed task. It should know not to do so until the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 loop.Run(); | 342 loop.Run(); |
| 343 EXPECT_EQ(0, num_tasks); | 343 EXPECT_EQ(0, num_tasks); |
| 344 | 344 |
| 345 // Ensure that we ran in far less time than the slower timer. | 345 // Ensure that we ran in far less time than the slower timer. |
| 346 TimeDelta total_time = Time::Now() - start_time; | 346 TimeDelta total_time = Time::Now() - start_time; |
| 347 EXPECT_GT(5000, total_time.InMilliseconds()); | 347 EXPECT_GT(5000, total_time.InMilliseconds()); |
| 348 | 348 |
| 349 // In case both timers somehow run at nearly the same time, sleep a little | 349 // In case both timers somehow run at nearly the same time, sleep a little |
| 350 // and then run all pending to force them both to have run. This is just | 350 // and then run all pending to force them both to have run. This is just |
| 351 // encouraging flakiness if there is any. | 351 // encouraging flakiness if there is any. |
| 352 PlatformThread::Sleep(100); | 352 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); |
| 353 loop.RunAllPending(); | 353 loop.RunAllPending(); |
| 354 | 354 |
| 355 EXPECT_TRUE(run_time1.is_null()); | 355 EXPECT_TRUE(run_time1.is_null()); |
| 356 EXPECT_FALSE(run_time2.is_null()); | 356 EXPECT_FALSE(run_time2.is_null()); |
| 357 } | 357 } |
| 358 | 358 |
| 359 #if defined(OS_WIN) | 359 #if defined(OS_WIN) |
| 360 | 360 |
| 361 void SubPumpFunc() { | 361 void SubPumpFunc() { |
| 362 MessageLoop::current()->SetNestableTasksAllowed(true); | 362 MessageLoop::current()->SetNestableTasksAllowed(true); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 loop.Run(); | 395 loop.Run(); |
| 396 EXPECT_EQ(1, num_tasks); | 396 EXPECT_EQ(1, num_tasks); |
| 397 | 397 |
| 398 // Ensure that we ran in far less time than the slower timer. | 398 // Ensure that we ran in far less time than the slower timer. |
| 399 TimeDelta total_time = Time::Now() - start_time; | 399 TimeDelta total_time = Time::Now() - start_time; |
| 400 EXPECT_GT(5000, total_time.InMilliseconds()); | 400 EXPECT_GT(5000, total_time.InMilliseconds()); |
| 401 | 401 |
| 402 // In case both timers somehow run at nearly the same time, sleep a little | 402 // In case both timers somehow run at nearly the same time, sleep a little |
| 403 // and then run all pending to force them both to have run. This is just | 403 // and then run all pending to force them both to have run. This is just |
| 404 // encouraging flakiness if there is any. | 404 // encouraging flakiness if there is any. |
| 405 PlatformThread::Sleep(100); | 405 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); |
| 406 loop.RunAllPending(); | 406 loop.RunAllPending(); |
| 407 | 407 |
| 408 EXPECT_TRUE(run_time.is_null()); | 408 EXPECT_TRUE(run_time.is_null()); |
| 409 } | 409 } |
| 410 | 410 |
| 411 #endif // defined(OS_WIN) | 411 #endif // defined(OS_WIN) |
| 412 | 412 |
| 413 // This is used to inject a test point for recording the destructor calls for | 413 // This is used to inject a test point for recording the destructor calls for |
| 414 // Closure objects send to MessageLoop::PostTask(). It is awkward usage since we | 414 // Closure objects send to MessageLoop::PostTask(). It is awkward usage since we |
| 415 // are trying to hook the actual destruction, which is not a common operation. | 415 // are trying to hook the actual destruction, which is not a common operation. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // If the right SEH filter is installed, it will fix the error. | 490 // If the right SEH filter is installed, it will fix the error. |
| 491 class Crasher : public base::RefCounted<Crasher> { | 491 class Crasher : public base::RefCounted<Crasher> { |
| 492 public: | 492 public: |
| 493 // Ctor. If trash_SEH_handler is true, the task will override the unhandled | 493 // Ctor. If trash_SEH_handler is true, the task will override the unhandled |
| 494 // exception handler with one sure to crash this test. | 494 // exception handler with one sure to crash this test. |
| 495 explicit Crasher(bool trash_SEH_handler) | 495 explicit Crasher(bool trash_SEH_handler) |
| 496 : trash_SEH_handler_(trash_SEH_handler) { | 496 : trash_SEH_handler_(trash_SEH_handler) { |
| 497 } | 497 } |
| 498 | 498 |
| 499 void Run() { | 499 void Run() { |
| 500 PlatformThread::Sleep(1); | 500 PlatformThread::Sleep(TimeDelta::FromMilliseconds(1)); |
| 501 if (trash_SEH_handler_) | 501 if (trash_SEH_handler_) |
| 502 ::SetUnhandledExceptionFilter(&BadExceptionHandler); | 502 ::SetUnhandledExceptionFilter(&BadExceptionHandler); |
| 503 // Generate a SEH fault. We do it in asm to make sure we know how to undo | 503 // Generate a SEH fault. We do it in asm to make sure we know how to undo |
| 504 // the damage. | 504 // the damage. |
| 505 | 505 |
| 506 #if defined(_M_IX86) | 506 #if defined(_M_IX86) |
| 507 | 507 |
| 508 __asm { | 508 __asm { |
| 509 mov eax, dword ptr [Crasher::bad_array_] | 509 mov eax, dword ptr [Crasher::bad_array_] |
| 510 mov byte ptr [eax], 66 | 510 mov byte ptr [eax], 66 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 MessageLoop::current()->PostTask( | 729 MessageLoop::current()->PostTask( |
| 730 FROM_HERE, | 730 FROM_HERE, |
| 731 base::Bind(&RecursiveFunc, order, cookie, depth - 1, is_reentrant)); | 731 base::Bind(&RecursiveFunc, order, cookie, depth - 1, is_reentrant)); |
| 732 } | 732 } |
| 733 order->RecordEnd(RECURSIVE, cookie); | 733 order->RecordEnd(RECURSIVE, cookie); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void RecursiveSlowFunc(TaskList* order, int cookie, int depth, | 736 void RecursiveSlowFunc(TaskList* order, int cookie, int depth, |
| 737 bool is_reentrant) { | 737 bool is_reentrant) { |
| 738 RecursiveFunc(order, cookie, depth, is_reentrant); | 738 RecursiveFunc(order, cookie, depth, is_reentrant); |
| 739 PlatformThread::Sleep(10); // milliseconds | 739 PlatformThread::Sleep(TimeDelta::FromMilliseconds(10)); |
| 740 } | 740 } |
| 741 | 741 |
| 742 void QuitFunc(TaskList* order, int cookie) { | 742 void QuitFunc(TaskList* order, int cookie) { |
| 743 order->RecordStart(QUITMESSAGELOOP, cookie); | 743 order->RecordStart(QUITMESSAGELOOP, cookie); |
| 744 MessageLoop::current()->Quit(); | 744 MessageLoop::current()->Quit(); |
| 745 order->RecordEnd(QUITMESSAGELOOP, cookie); | 745 order->RecordEnd(QUITMESSAGELOOP, cookie); |
| 746 } | 746 } |
| 747 | 747 |
| 748 void SleepFunc(TaskList* order, int cookie, int ms) { | 748 void SleepFunc(TaskList* order, int cookie, TimeDelta delay) { |
| 749 order->RecordStart(SLEEP, cookie); | 749 order->RecordStart(SLEEP, cookie); |
| 750 PlatformThread::Sleep(ms); | 750 PlatformThread::Sleep(delay); |
| 751 order->RecordEnd(SLEEP, cookie); | 751 order->RecordEnd(SLEEP, cookie); |
| 752 } | 752 } |
| 753 | 753 |
| 754 #if defined(OS_WIN) | 754 #if defined(OS_WIN) |
| 755 void RecursiveFuncWin(MessageLoop* target, | 755 void RecursiveFuncWin(MessageLoop* target, |
| 756 HANDLE event, | 756 HANDLE event, |
| 757 bool expect_window, | 757 bool expect_window, |
| 758 TaskList* order, | 758 TaskList* order, |
| 759 bool is_reentrant) { | 759 bool is_reentrant) { |
| 760 target->PostTask(FROM_HERE, | 760 target->PostTask(FROM_HERE, |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 FROM_HERE, | 1049 FROM_HERE, |
| 1050 base::Bind(&OrderedFunc, &order, 2), | 1050 base::Bind(&OrderedFunc, &order, 2), |
| 1051 1); | 1051 1); |
| 1052 } else { | 1052 } else { |
| 1053 MessageLoop::current()->PostNonNestableTask( | 1053 MessageLoop::current()->PostNonNestableTask( |
| 1054 FROM_HERE, | 1054 FROM_HERE, |
| 1055 base::Bind(&OrderedFunc, &order, 2)); | 1055 base::Bind(&OrderedFunc, &order, 2)); |
| 1056 } | 1056 } |
| 1057 MessageLoop::current()->PostTask(FROM_HERE, | 1057 MessageLoop::current()->PostTask(FROM_HERE, |
| 1058 base::Bind(&OrderedFunc, &order, 3)); | 1058 base::Bind(&OrderedFunc, &order, 3)); |
| 1059 MessageLoop::current()->PostTask(FROM_HERE, | 1059 MessageLoop::current()->PostTask( |
| 1060 base::Bind(&SleepFunc, &order, 4, 50)); | 1060 FROM_HERE, |
| 1061 base::Bind(&SleepFunc, &order, 4, TimeDelta::FromMilliseconds(50))); |
| 1061 MessageLoop::current()->PostTask(FROM_HERE, | 1062 MessageLoop::current()->PostTask(FROM_HERE, |
| 1062 base::Bind(&OrderedFunc, &order, 5)); | 1063 base::Bind(&OrderedFunc, &order, 5)); |
| 1063 if (use_delayed) { | 1064 if (use_delayed) { |
| 1064 MessageLoop::current()->PostNonNestableDelayedTask( | 1065 MessageLoop::current()->PostNonNestableDelayedTask( |
| 1065 FROM_HERE, | 1066 FROM_HERE, |
| 1066 base::Bind(&QuitFunc, &order, 6), | 1067 base::Bind(&QuitFunc, &order, 6), |
| 1067 2); | 1068 2); |
| 1068 } else { | 1069 } else { |
| 1069 MessageLoop::current()->PostNonNestableTask( | 1070 MessageLoop::current()->PostNonNestableTask( |
| 1070 FROM_HERE, | 1071 FROM_HERE, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 Thread::Options options; | 1214 Thread::Options options; |
| 1214 options.message_loop_type = MessageLoop::TYPE_IO; | 1215 options.message_loop_type = MessageLoop::TYPE_IO; |
| 1215 ASSERT_TRUE(thread.StartWithOptions(options)); | 1216 ASSERT_TRUE(thread.StartWithOptions(options)); |
| 1216 | 1217 |
| 1217 MessageLoop* thread_loop = thread.message_loop(); | 1218 MessageLoop* thread_loop = thread.message_loop(); |
| 1218 ASSERT_TRUE(NULL != thread_loop); | 1219 ASSERT_TRUE(NULL != thread_loop); |
| 1219 | 1220 |
| 1220 TestIOHandler handler(kPipeName, callback_called, false); | 1221 TestIOHandler handler(kPipeName, callback_called, false); |
| 1221 thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, | 1222 thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, |
| 1222 base::Unretained(&handler))); | 1223 base::Unretained(&handler))); |
| 1223 Sleep(100); // Make sure the thread runs and sleeps for lack of work. | 1224 // Make sure the thread runs and sleeps for lack of work. |
| 1225 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 1224 | 1226 |
| 1225 const char buffer[] = "Hello there!"; | 1227 const char buffer[] = "Hello there!"; |
| 1226 DWORD written; | 1228 DWORD written; |
| 1227 EXPECT_TRUE(WriteFile(server, buffer, sizeof(buffer), &written, NULL)); | 1229 EXPECT_TRUE(WriteFile(server, buffer, sizeof(buffer), &written, NULL)); |
| 1228 | 1230 |
| 1229 DWORD result = WaitForSingleObject(callback_called, 1000); | 1231 DWORD result = WaitForSingleObject(callback_called, 1000); |
| 1230 EXPECT_EQ(WAIT_OBJECT_0, result); | 1232 EXPECT_EQ(WAIT_OBJECT_0, result); |
| 1231 | 1233 |
| 1232 thread.Stop(); | 1234 thread.Stop(); |
| 1233 } | 1235 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1255 ASSERT_TRUE(thread.StartWithOptions(options)); | 1257 ASSERT_TRUE(thread.StartWithOptions(options)); |
| 1256 | 1258 |
| 1257 MessageLoop* thread_loop = thread.message_loop(); | 1259 MessageLoop* thread_loop = thread.message_loop(); |
| 1258 ASSERT_TRUE(NULL != thread_loop); | 1260 ASSERT_TRUE(NULL != thread_loop); |
| 1259 | 1261 |
| 1260 TestIOHandler handler1(kPipeName1, callback1_called, false); | 1262 TestIOHandler handler1(kPipeName1, callback1_called, false); |
| 1261 TestIOHandler handler2(kPipeName2, callback2_called, true); | 1263 TestIOHandler handler2(kPipeName2, callback2_called, true); |
| 1262 thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, | 1264 thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, |
| 1263 base::Unretained(&handler1))); | 1265 base::Unretained(&handler1))); |
| 1264 // TODO(ajwong): Do we really need such long Sleeps in ths function? | 1266 // TODO(ajwong): Do we really need such long Sleeps in ths function? |
| 1265 Sleep(100); // Make sure the thread runs and sleeps for lack of work. | 1267 // Make sure the thread runs and sleeps for lack of work. |
| 1268 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(100); |
| 1269 base::PlatformThread::Sleep(delay); |
| 1266 thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, | 1270 thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, |
| 1267 base::Unretained(&handler2))); | 1271 base::Unretained(&handler2))); |
| 1268 Sleep(100); | 1272 base::PlatformThread::Sleep(delay); |
| 1269 | 1273 |
| 1270 // At this time handler1 is waiting to be called, and the thread is waiting | 1274 // At this time handler1 is waiting to be called, and the thread is waiting |
| 1271 // on the Init method of handler2, filtering only handler2 callbacks. | 1275 // on the Init method of handler2, filtering only handler2 callbacks. |
| 1272 | 1276 |
| 1273 const char buffer[] = "Hello there!"; | 1277 const char buffer[] = "Hello there!"; |
| 1274 DWORD written; | 1278 DWORD written; |
| 1275 EXPECT_TRUE(WriteFile(server1, buffer, sizeof(buffer), &written, NULL)); | 1279 EXPECT_TRUE(WriteFile(server1, buffer, sizeof(buffer), &written, NULL)); |
| 1276 Sleep(200); | 1280 base::PlatformThread::Sleep(2 * delay); |
| 1277 EXPECT_EQ(WAIT_TIMEOUT, WaitForSingleObject(callback1_called, 0)) << | 1281 EXPECT_EQ(WAIT_TIMEOUT, WaitForSingleObject(callback1_called, 0)) << |
| 1278 "handler1 has not been called"; | 1282 "handler1 has not been called"; |
| 1279 | 1283 |
| 1280 EXPECT_TRUE(WriteFile(server2, buffer, sizeof(buffer), &written, NULL)); | 1284 EXPECT_TRUE(WriteFile(server2, buffer, sizeof(buffer), &written, NULL)); |
| 1281 | 1285 |
| 1282 HANDLE objects[2] = { callback1_called.Get(), callback2_called.Get() }; | 1286 HANDLE objects[2] = { callback1_called.Get(), callback2_called.Get() }; |
| 1283 DWORD result = WaitForMultipleObjects(2, objects, TRUE, 1000); | 1287 DWORD result = WaitForMultipleObjects(2, objects, TRUE, 1000); |
| 1284 EXPECT_EQ(WAIT_OBJECT_0, result); | 1288 EXPECT_EQ(WAIT_OBJECT_0, result); |
| 1285 | 1289 |
| 1286 thread.Stop(); | 1290 thread.Stop(); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 EXPECT_TRUE(loop.high_resolution_timers_enabled()); | 1539 EXPECT_TRUE(loop.high_resolution_timers_enabled()); |
| 1536 | 1540 |
| 1537 // Post a slow task and verify high resolution timers | 1541 // Post a slow task and verify high resolution timers |
| 1538 // are still enabled. | 1542 // are still enabled. |
| 1539 loop.PostDelayedTask(FROM_HERE, base::Bind(&PostNTasksThenQuit, 1), | 1543 loop.PostDelayedTask(FROM_HERE, base::Bind(&PostNTasksThenQuit, 1), |
| 1540 kSlowTimerMs); | 1544 kSlowTimerMs); |
| 1541 loop.Run(); | 1545 loop.Run(); |
| 1542 EXPECT_TRUE(loop.high_resolution_timers_enabled()); | 1546 EXPECT_TRUE(loop.high_resolution_timers_enabled()); |
| 1543 | 1547 |
| 1544 // Wait for a while so that high-resolution mode elapses. | 1548 // Wait for a while so that high-resolution mode elapses. |
| 1545 Sleep(MessageLoop::kHighResolutionTimerModeLeaseTimeMs); | 1549 base::PlatformThread::Sleep(TimeDelta::FromMilliseconds( |
| 1550 MessageLoop::kHighResolutionTimerModeLeaseTimeMs)); |
| 1546 | 1551 |
| 1547 // Post a slow task to disable the high resolution timers. | 1552 // Post a slow task to disable the high resolution timers. |
| 1548 loop.PostDelayedTask(FROM_HERE, base::Bind(&PostNTasksThenQuit, 1), | 1553 loop.PostDelayedTask(FROM_HERE, base::Bind(&PostNTasksThenQuit, 1), |
| 1549 kSlowTimerMs); | 1554 kSlowTimerMs); |
| 1550 loop.Run(); | 1555 loop.Run(); |
| 1551 EXPECT_FALSE(loop.high_resolution_timers_enabled()); | 1556 EXPECT_FALSE(loop.high_resolution_timers_enabled()); |
| 1552 } | 1557 } |
| 1553 | 1558 |
| 1554 #endif // defined(OS_WIN) | 1559 #endif // defined(OS_WIN) |
| 1555 | 1560 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1688 base::Bind(&DestructionObserverProbe::Run, | 1693 base::Bind(&DestructionObserverProbe::Run, |
| 1689 new DestructionObserverProbe(&task_destroyed, | 1694 new DestructionObserverProbe(&task_destroyed, |
| 1690 &destruction_observer_called)), | 1695 &destruction_observer_called)), |
| 1691 kDelayMS); | 1696 kDelayMS); |
| 1692 delete loop; | 1697 delete loop; |
| 1693 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); | 1698 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); |
| 1694 // The task should have been destroyed when we deleted the loop. | 1699 // The task should have been destroyed when we deleted the loop. |
| 1695 EXPECT_TRUE(task_destroyed); | 1700 EXPECT_TRUE(task_destroyed); |
| 1696 EXPECT_TRUE(destruction_observer_called); | 1701 EXPECT_TRUE(destruction_observer_called); |
| 1697 } | 1702 } |
| OLD | NEW |