OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "testing/gtest/include/gtest/gtest.h" | |
6 | |
7 #include "app/hi_res_timer_manager.h" | |
8 #include "app/system_monitor.h" | |
9 #include "base/time.h" | |
10 | |
11 #if defined(OS_WIN) | |
12 TEST(HiResTimerManagerTest, ToggleOnOff) { | |
13 MessageLoop loop; | |
14 scoped_ptr<SystemMonitor> system_monitor(new SystemMonitor()); | |
15 HighResolutionTimerManager manager; | |
16 | |
17 // At this point, we don't know if the high resolution timers are on or off, | |
18 // it depends on what system the tests are running on (for example, if this | |
19 // test is running on a laptop/battery, then the SystemMonitor would have | |
20 // already set the PowerState to battery power; but if we're running on a | |
21 // desktop, then the PowerState will be non-battery power). Simulate a power | |
22 // level change to get to a deterministic state. | |
23 manager.OnPowerStateChange(/* on_battery */ false); | |
24 | |
25 // Loop a few times to test power toggling. | |
26 for (int loop = 2; loop >= 0; --loop) { | |
27 // The manager has the high resolution clock enabled now. | |
28 EXPECT_TRUE(manager.using_hi_res_clock()); | |
29 // But the Time class has it off, because it hasn't been activated. | |
30 EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse()); | |
31 | |
32 // Activate the high resolution timer. | |
33 base::Time::ActivateHighResolutionTimer(true); | |
34 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse()); | |
35 | |
36 // Simulate a on-battery power event. | |
37 manager.OnPowerStateChange(/* on_battery */ true); | |
38 EXPECT_FALSE(manager.using_hi_res_clock()); | |
39 EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse()); | |
40 | |
41 // Simulate a off-battery power event. | |
42 manager.OnPowerStateChange(/* on_battery */ false); | |
43 EXPECT_TRUE(manager.using_hi_res_clock()); | |
44 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse()); | |
45 | |
46 // De-activate the high resolution timer. | |
47 base::Time::ActivateHighResolutionTimer(false); | |
48 } | |
49 } | |
50 #endif // defined(OS_WIN) | |
51 | |
OLD | NEW |