OLD | NEW |
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 <utility> |
| 8 |
7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
9 #include "base/power_monitor/power_monitor.h" | 11 #include "base/power_monitor/power_monitor.h" |
10 #include "base/power_monitor/power_monitor_device_source.h" | 12 #include "base/power_monitor/power_monitor_device_source.h" |
11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 namespace base { | 16 namespace base { |
15 | 17 |
16 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
17 TEST(HiResTimerManagerTest, ToggleOnOff) { | 19 TEST(HiResTimerManagerTest, ToggleOnOff) { |
18 // The power monitor creates Window to receive power notifications from | 20 // The power monitor creates Window to receive power notifications from |
19 // Windows, which makes this test flaky if you run while the machine | 21 // Windows, which makes this test flaky if you run while the machine |
20 // goes in or out of AC power. | 22 // goes in or out of AC power. |
21 base::MessageLoop loop(base::MessageLoop::TYPE_UI); | 23 base::MessageLoop loop(base::MessageLoop::TYPE_UI); |
22 scoped_ptr<base::PowerMonitorSource> power_monitor_source( | 24 scoped_ptr<base::PowerMonitorSource> power_monitor_source( |
23 new base::PowerMonitorDeviceSource()); | 25 new base::PowerMonitorDeviceSource()); |
24 scoped_ptr<base::PowerMonitor> power_monitor( | 26 scoped_ptr<base::PowerMonitor> power_monitor( |
25 new base::PowerMonitor(power_monitor_source.Pass())); | 27 new base::PowerMonitor(std::move(power_monitor_source))); |
26 | 28 |
27 HighResolutionTimerManager manager; | 29 HighResolutionTimerManager manager; |
28 // Simulate a on-AC power event to get to a known initial state. | 30 // Simulate a on-AC power event to get to a known initial state. |
29 manager.OnPowerStateChange(false); | 31 manager.OnPowerStateChange(false); |
30 | 32 |
31 // Loop a few times to test power toggling. | 33 // Loop a few times to test power toggling. |
32 for (int times = 0; times != 3; ++times) { | 34 for (int times = 0; times != 3; ++times) { |
33 // The manager has the high resolution clock enabled now. | 35 // The manager has the high resolution clock enabled now. |
34 EXPECT_TRUE(manager.hi_res_clock_available()); | 36 EXPECT_TRUE(manager.hi_res_clock_available()); |
35 // But the Time class has it off, because it hasn't been activated. | 37 // But the Time class has it off, because it hasn't been activated. |
(...skipping 13 matching lines...) Expand all Loading... |
49 EXPECT_TRUE(manager.hi_res_clock_available()); | 51 EXPECT_TRUE(manager.hi_res_clock_available()); |
50 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse()); | 52 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse()); |
51 | 53 |
52 // De-activate the high resolution timer. | 54 // De-activate the high resolution timer. |
53 base::Time::ActivateHighResolutionTimer(false); | 55 base::Time::ActivateHighResolutionTimer(false); |
54 } | 56 } |
55 } | 57 } |
56 #endif // defined(OS_WIN) | 58 #endif // defined(OS_WIN) |
57 | 59 |
58 } // namespace base | 60 } // namespace base |
OLD | NEW |