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

Side by Side Diff: base/timer/hi_res_timer_manager_unittest.cc

Issue 489793003: Fix logic on high Windows resolution timer and have (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lock fixes and utest Created 6 years, 3 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
« base/time/time_win.cc ('K') | « base/time/time_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/timer/hi_res_timer_manager.h" 5 #include "base/timer/hi_res_timer_manager.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/power_monitor/power_monitor.h" 9 #include "base/power_monitor/power_monitor.h"
10 #include "base/power_monitor/power_monitor_device_source.h" 10 #include "base/power_monitor/power_monitor_device_source.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 // http://crbug.com/114048 17 TEST(HiResTimerManagerTest, ToggleOnOff) {
18 TEST(HiResTimerManagerTest, DISABLED_ToggleOnOff) { 18 // The power monitor creates Window to receive power notifications from
jamesr 2014/08/26 19:47:40 "creates Window" -> "creates a Window"
19 base::MessageLoop loop; 19 // Windows, which makes this test flaky if you run while the machine
20 // goes in or out of AC power.
21 base::MessageLoop loop(base::MessageLoop::TYPE_UI);
20 scoped_ptr<base::PowerMonitorSource> power_monitor_source( 22 scoped_ptr<base::PowerMonitorSource> power_monitor_source(
21 new base::PowerMonitorDeviceSource()); 23 new base::PowerMonitorDeviceSource());
22 scoped_ptr<base::PowerMonitor> power_monitor( 24 scoped_ptr<base::PowerMonitor> power_monitor(
23 new base::PowerMonitor(power_monitor_source.Pass())); 25 new base::PowerMonitor(power_monitor_source.Pass()));
26
24 HighResolutionTimerManager manager; 27 HighResolutionTimerManager manager;
25 28 // Simulate a on-AC power event to get to a known initial state.
26 // At this point, we don't know if the high resolution timers are on or off, 29 manager.OnPowerStateChange(false);
27 // it depends on what system the tests are running on (for example, if this
28 // test is running on a laptop/battery, then the PowerMonitor would have
29 // already set the PowerState to battery power; but if we're running on a
30 // desktop, then the PowerState will be non-battery power). Simulate a power
31 // level change to get to a deterministic state.
32 manager.OnPowerStateChange(/* on_battery */ false);
33 30
34 // Loop a few times to test power toggling. 31 // Loop a few times to test power toggling.
35 for (int loop = 2; loop >= 0; --loop) { 32 for (int times = 0; times != 3; ++times) {
36 // The manager has the high resolution clock enabled now. 33 // The manager has the high resolution clock enabled now.
37 EXPECT_TRUE(manager.hi_res_clock_available()); 34 EXPECT_TRUE(manager.hi_res_clock_available());
38 // But the Time class has it off, because it hasn't been activated. 35 // But the Time class has it off, because it hasn't been activated.
39 EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse()); 36 EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse());
40 37
41 // Activate the high resolution timer. 38 // Activate the high resolution timer.
42 base::Time::ActivateHighResolutionTimer(true); 39 base::Time::ActivateHighResolutionTimer(true);
43 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse()); 40 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse());
44 41
45 // Simulate a on-battery power event. 42 // Simulate a on-battery power event.
46 manager.OnPowerStateChange(/* on_battery */ true); 43 manager.OnPowerStateChange(true);
47 EXPECT_FALSE(manager.hi_res_clock_available()); 44 EXPECT_FALSE(manager.hi_res_clock_available());
48 EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse()); 45 EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse());
49 46
50 // Simulate a off-battery power event. 47 // Back to on-AC power.
51 manager.OnPowerStateChange(/* on_battery */ false); 48 manager.OnPowerStateChange(false);
52 EXPECT_TRUE(manager.hi_res_clock_available()); 49 EXPECT_TRUE(manager.hi_res_clock_available());
53 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse()); 50 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse());
54 51
55 // De-activate the high resolution timer. 52 // De-activate the high resolution timer.
56 base::Time::ActivateHighResolutionTimer(false); 53 base::Time::ActivateHighResolutionTimer(false);
57 } 54 }
58 } 55 }
59 #endif // defined(OS_WIN) 56 #endif // defined(OS_WIN)
60 57
61 } // namespace base 58 } // namespace base
OLDNEW
« base/time/time_win.cc ('K') | « base/time/time_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698