diff options
author | tedvessenes@gmail.com <tedvessenes@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-31 22:53:51 +0000 |
---|---|---|
committer | tedvessenes@gmail.com <tedvessenes@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-31 22:53:51 +0000 |
commit | a1b75b94f61d90054e3b432e8be3c897383450bd (patch) | |
tree | 22a388ee703fe9aa05aab3cb850e0012c3b501f8 /base/message_loop_unittest.cc | |
parent | d117d35a46d16907c89b92e5ed03d40690fb8f81 (diff) | |
download | chromium_src-a1b75b94f61d90054e3b432e8be3c897383450bd.zip chromium_src-a1b75b94f61d90054e3b432e8be3c897383450bd.tar.gz chromium_src-a1b75b94f61d90054e3b432e8be3c897383450bd.tar.bz2 |
Change code in base (primarily unit tests) to use Sleep(TimeDelta).
BUG=108171
TEST=
Review URL: http://codereview.chromium.org/9055001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop_unittest.cc')
-rw-r--r-- | base/message_loop_unittest.cc | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/base/message_loop_unittest.cc b/base/message_loop_unittest.cc index 7eb4f4a..01a57c8 100644 --- a/base/message_loop_unittest.cc +++ b/base/message_loop_unittest.cc @@ -176,8 +176,8 @@ void RunTest_PostTask_SEH(MessageLoop::Type message_loop_type) { } // This function runs slowly to simulate a large amount of work being done. -static void SlowFunc(int pause_ms, int* quit_counter) { - PlatformThread::Sleep(pause_ms); +static void SlowFunc(TimeDelta pause, int* quit_counter) { + PlatformThread::Sleep(pause); if (--(*quit_counter) == 0) MessageLoop::current()->Quit(); } @@ -190,7 +190,7 @@ static void RecordRunTimeFunc(Time* run_time, int* quit_counter) { // Cause our Run function to take some time to execute. As a result we can // count on subsequent RecordRunTimeFunc()s running at a future time, // without worry about the resolution of our system clock being an issue. - SlowFunc(10, quit_counter); + SlowFunc(TimeDelta::FromMilliseconds(10), quit_counter); } void RunTest_PostDelayedTask_Basic(MessageLoop::Type message_loop_type) { @@ -273,12 +273,12 @@ void RunTest_PostDelayedTask_InPostOrder_2( // Test that a delayed task still runs after a normal tasks even if the // normal tasks take a long time to run. - const int kPauseMS = 50; + const TimeDelta kPause = TimeDelta::FromMilliseconds(50); int num_tasks = 2; Time run_time; - loop.PostTask(FROM_HERE, base::Bind(&SlowFunc, kPauseMS, &num_tasks)); + loop.PostTask(FROM_HERE, base::Bind(&SlowFunc, kPause, &num_tasks)); loop.PostDelayedTask( FROM_HERE, base::Bind(&RecordRunTimeFunc, &run_time, &num_tasks), 10); @@ -288,7 +288,7 @@ void RunTest_PostDelayedTask_InPostOrder_2( EXPECT_EQ(0, num_tasks); - EXPECT_LT(kPauseMS, (time_after_run - time_before_run).InMilliseconds()); + EXPECT_LT(kPause, time_after_run - time_before_run); } void RunTest_PostDelayedTask_InPostOrder_3( @@ -349,7 +349,7 @@ void RunTest_PostDelayedTask_SharedTimer( // In case both timers somehow run at nearly the same time, sleep a little // and then run all pending to force them both to have run. This is just // encouraging flakiness if there is any. - PlatformThread::Sleep(100); + PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); loop.RunAllPending(); EXPECT_TRUE(run_time1.is_null()); @@ -402,7 +402,7 @@ void RunTest_PostDelayedTask_SharedTimer_SubPump() { // In case both timers somehow run at nearly the same time, sleep a little // and then run all pending to force them both to have run. This is just // encouraging flakiness if there is any. - PlatformThread::Sleep(100); + PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); loop.RunAllPending(); EXPECT_TRUE(run_time.is_null()); @@ -497,7 +497,7 @@ class Crasher : public base::RefCounted<Crasher> { } void Run() { - PlatformThread::Sleep(1); + PlatformThread::Sleep(TimeDelta::FromMilliseconds(1)); if (trash_SEH_handler_) ::SetUnhandledExceptionFilter(&BadExceptionHandler); // Generate a SEH fault. We do it in asm to make sure we know how to undo @@ -736,7 +736,7 @@ void RecursiveFunc(TaskList* order, int cookie, int depth, void RecursiveSlowFunc(TaskList* order, int cookie, int depth, bool is_reentrant) { RecursiveFunc(order, cookie, depth, is_reentrant); - PlatformThread::Sleep(10); // milliseconds + PlatformThread::Sleep(TimeDelta::FromMilliseconds(10)); } void QuitFunc(TaskList* order, int cookie) { @@ -745,9 +745,9 @@ void QuitFunc(TaskList* order, int cookie) { order->RecordEnd(QUITMESSAGELOOP, cookie); } -void SleepFunc(TaskList* order, int cookie, int ms) { +void SleepFunc(TaskList* order, int cookie, TimeDelta delay) { order->RecordStart(SLEEP, cookie); - PlatformThread::Sleep(ms); + PlatformThread::Sleep(delay); order->RecordEnd(SLEEP, cookie); } @@ -1056,8 +1056,9 @@ void RunTest_NonNestableInNestedLoop(MessageLoop::Type message_loop_type, } MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&OrderedFunc, &order, 3)); - MessageLoop::current()->PostTask(FROM_HERE, - base::Bind(&SleepFunc, &order, 4, 50)); + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&SleepFunc, &order, 4, TimeDelta::FromMilliseconds(50))); MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&OrderedFunc, &order, 5)); if (use_delayed) { @@ -1220,7 +1221,8 @@ void RunTest_IOHandler() { TestIOHandler handler(kPipeName, callback_called, false); thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, base::Unretained(&handler))); - Sleep(100); // Make sure the thread runs and sleeps for lack of work. + // Make sure the thread runs and sleeps for lack of work. + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); const char buffer[] = "Hello there!"; DWORD written; @@ -1262,10 +1264,12 @@ void RunTest_WaitForIO() { thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, base::Unretained(&handler1))); // TODO(ajwong): Do we really need such long Sleeps in ths function? - Sleep(100); // Make sure the thread runs and sleeps for lack of work. + // Make sure the thread runs and sleeps for lack of work. + base::TimeDelta delay = base::TimeDelta::FromMilliseconds(100); + base::PlatformThread::Sleep(delay); thread_loop->PostTask(FROM_HERE, base::Bind(&TestIOHandler::Init, base::Unretained(&handler2))); - Sleep(100); + base::PlatformThread::Sleep(delay); // At this time handler1 is waiting to be called, and the thread is waiting // on the Init method of handler2, filtering only handler2 callbacks. @@ -1273,7 +1277,7 @@ void RunTest_WaitForIO() { const char buffer[] = "Hello there!"; DWORD written; EXPECT_TRUE(WriteFile(server1, buffer, sizeof(buffer), &written, NULL)); - Sleep(200); + base::PlatformThread::Sleep(2 * delay); EXPECT_EQ(WAIT_TIMEOUT, WaitForSingleObject(callback1_called, 0)) << "handler1 has not been called"; @@ -1542,7 +1546,8 @@ TEST(MessageLoopTest, HighResolutionTimer) { EXPECT_TRUE(loop.high_resolution_timers_enabled()); // Wait for a while so that high-resolution mode elapses. - Sleep(MessageLoop::kHighResolutionTimerModeLeaseTimeMs); + base::PlatformThread::Sleep(TimeDelta::FromMilliseconds( + MessageLoop::kHighResolutionTimerModeLeaseTimeMs)); // Post a slow task to disable the high resolution timers. loop.PostDelayedTask(FROM_HERE, base::Bind(&PostNTasksThenQuit, 1), |