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

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

Issue 2951413003: Add UMA for High Resolution Timer Usage (Closed)
Patch Set: Added suspend / resume logic Created 3 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
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/power_monitor/power_monitor.h" 11 #include "base/power_monitor/power_monitor.h"
12 #include "base/power_monitor/power_monitor_device_source.h" 12 #include "base/power_monitor/power_monitor_device_source.h"
13 #include "base/test/scoped_task_scheduler.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace base { 18 namespace base {
18 19
19 #if defined(OS_WIN) 20 #if defined(OS_WIN)
20 TEST(HiResTimerManagerTest, ToggleOnOff) { 21 TEST(HiResTimerManagerTest, ToggleOnOff) {
21 // The power monitor creates Window to receive power notifications from 22 // The power monitor creates Window to receive power notifications from
22 // Windows, which makes this test flaky if you run while the machine 23 // Windows, which makes this test flaky if you run while the machine
23 // goes in or out of AC power. 24 // goes in or out of AC power.
24 base::MessageLoop loop(base::MessageLoop::TYPE_UI); 25 base::MessageLoop loop(base::MessageLoop::TYPE_UI);
26 // Needed for HighResolutionTimerManager.
27 base::test::ScopedTaskScheduler task_scheduler(&loop);
gab 2017/06/28 16:39:33 ScopedTaskScheduler is deprecated. Please replace
stanisc 2017/06/28 22:28:35 Done.
25 std::unique_ptr<base::PowerMonitorSource> power_monitor_source( 28 std::unique_ptr<base::PowerMonitorSource> power_monitor_source(
26 new base::PowerMonitorDeviceSource()); 29 new base::PowerMonitorDeviceSource());
27 std::unique_ptr<base::PowerMonitor> power_monitor( 30 std::unique_ptr<base::PowerMonitor> power_monitor(
28 new base::PowerMonitor(std::move(power_monitor_source))); 31 new base::PowerMonitor(std::move(power_monitor_source)));
29 32
30 HighResolutionTimerManager manager; 33 HighResolutionTimerManager manager;
31 // Simulate a on-AC power event to get to a known initial state. 34 // Simulate a on-AC power event to get to a known initial state.
32 manager.OnPowerStateChange(false); 35 manager.OnPowerStateChange(false);
33 36
34 // Loop a few times to test power toggling. 37 // Loop a few times to test power toggling.
(...skipping 17 matching lines...) Expand all
52 EXPECT_TRUE(manager.hi_res_clock_available()); 55 EXPECT_TRUE(manager.hi_res_clock_available());
53 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse()); 56 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse());
54 57
55 // De-activate the high resolution timer. 58 // De-activate the high resolution timer.
56 base::Time::ActivateHighResolutionTimer(false); 59 base::Time::ActivateHighResolutionTimer(false);
57 } 60 }
58 } 61 }
59 #endif // defined(OS_WIN) 62 #endif // defined(OS_WIN)
60 63
61 } // namespace base 64 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698