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

Side by Side Diff: base/message_loop/message_loop_unittest.cc

Issue 395913006: High resolution timer fix for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: real fixes for review Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <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/logging.h" 10 #include "base/logging.h"
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 TEST(MessageLoopTest, WaitForIO) { 723 TEST(MessageLoopTest, WaitForIO) {
724 RunTest_WaitForIO(); 724 RunTest_WaitForIO();
725 } 725 }
726 726
727 TEST(MessageLoopTest, HighResolutionTimer) { 727 TEST(MessageLoopTest, HighResolutionTimer) {
728 MessageLoop loop; 728 MessageLoop loop;
729 729
730 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5); 730 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5);
731 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100); 731 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100);
732 732
733 EXPECT_FALSE(loop.IsHighResolutionTimerEnabledForTesting()); 733 EXPECT_FALSE(loop.HasHighResolutionTasks());
734
735 // Post a fast task to enable the high resolution timers. 734 // Post a fast task to enable the high resolution timers.
736 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), 735 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1),
737 kFastTimer); 736 kFastTimer);
737 EXPECT_TRUE(loop.HasHighResolutionTasks());
738 loop.Run(); 738 loop.Run();
739 EXPECT_TRUE(loop.IsHighResolutionTimerEnabledForTesting()); 739 EXPECT_FALSE(loop.HasHighResolutionTasks());
740 740 EXPECT_FALSE(Time::IsHighResolutionTimerInUse());
741 // Post a slow task and verify high resolution timers 741 // Check that a slow task does not trigger the high resolution logic.
742 // are still enabled.
743 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), 742 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1),
744 kSlowTimer); 743 kSlowTimer);
744 EXPECT_FALSE(loop.HasHighResolutionTasks());
745 loop.Run(); 745 loop.Run();
746 EXPECT_TRUE(loop.IsHighResolutionTimerEnabledForTesting()); 746 EXPECT_FALSE(loop.HasHighResolutionTasks());
747
748 // Wait for a while so that high-resolution mode elapses.
749 PlatformThread::Sleep(TimeDelta::FromMilliseconds(
750 MessageLoop::kHighResolutionTimerModeLeaseTimeMs));
751
752 // Post a slow task to disable the high resolution timers.
753 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1),
754 kSlowTimer);
755 loop.Run();
756 EXPECT_FALSE(loop.IsHighResolutionTimerEnabledForTesting());
757 } 747 }
758 748
759 #endif // defined(OS_WIN) 749 #endif // defined(OS_WIN)
760 750
761 #if defined(OS_POSIX) && !defined(OS_NACL) 751 #if defined(OS_POSIX) && !defined(OS_NACL)
762 752
763 namespace { 753 namespace {
764 754
765 class QuitDelegate : public MessageLoopForIO::Watcher { 755 class QuitDelegate : public MessageLoopForIO::Watcher {
766 public: 756 public:
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 1005
1016 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); 1006 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1));
1017 1007
1018 loop.Run(); 1008 loop.Run();
1019 1009
1020 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); 1010 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance));
1021 } 1011 }
1022 #endif // defined(OS_WIN) 1012 #endif // defined(OS_WIN)
1023 1013
1024 } // namespace base 1014 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698