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

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: more cleanup 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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 } 717 }
718 718
719 TEST(MessageLoopTest, IOHandler) { 719 TEST(MessageLoopTest, IOHandler) {
720 RunTest_IOHandler(); 720 RunTest_IOHandler();
721 } 721 }
722 722
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) {
darin (slow to review) 2014/07/18 04:07:59 it'd be good to test that a MessageLoop with pendi
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 // Check that a slow task does not triggering the high resolution logic.
741 // Post a slow task and verify high resolution timers
742 // are still enabled.
743 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), 741 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1),
744 kSlowTimer); 742 kSlowTimer);
743 EXPECT_FALSE(loop.HasHighResolutionTasks());
745 loop.Run(); 744 loop.Run();
746 EXPECT_TRUE(loop.IsHighResolutionTimerEnabledForTesting()); 745 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 } 746 }
758 747
759 #endif // defined(OS_WIN) 748 #endif // defined(OS_WIN)
760 749
761 #if defined(OS_POSIX) && !defined(OS_NACL) 750 #if defined(OS_POSIX) && !defined(OS_NACL)
762 751
763 namespace { 752 namespace {
764 753
765 class QuitDelegate : public MessageLoopForIO::Watcher { 754 class QuitDelegate : public MessageLoopForIO::Watcher {
766 public: 755 public:
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 1004
1016 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); 1005 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1));
1017 1006
1018 loop.Run(); 1007 loop.Run();
1019 1008
1020 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); 1009 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance));
1021 } 1010 }
1022 #endif // defined(OS_WIN) 1011 #endif // defined(OS_WIN)
1023 1012
1024 } // namespace base 1013 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698