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

Unified 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: nits and leaky singleton Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/time/time_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/timer/hi_res_timer_manager_unittest.cc
diff --git a/base/timer/hi_res_timer_manager_unittest.cc b/base/timer/hi_res_timer_manager_unittest.cc
index ce10e3786d70e295710da4cd05aaa4317e103f6a..5475a91446bdef369b8d2974cbb17b48f170499e 100644
--- a/base/timer/hi_res_timer_manager_unittest.cc
+++ b/base/timer/hi_res_timer_manager_unittest.cc
@@ -14,25 +14,22 @@
namespace base {
#if defined(OS_WIN)
-// http://crbug.com/114048
-TEST(HiResTimerManagerTest, DISABLED_ToggleOnOff) {
- base::MessageLoop loop;
+TEST(HiResTimerManagerTest, ToggleOnOff) {
+ // The power monitor creates Window to receive power notifications from
+ // Windows, which makes this test flaky if you run while the machine
+ // goes in or out of AC power.
+ base::MessageLoop loop(base::MessageLoop::TYPE_UI);
scoped_ptr<base::PowerMonitorSource> power_monitor_source(
new base::PowerMonitorDeviceSource());
scoped_ptr<base::PowerMonitor> power_monitor(
new base::PowerMonitor(power_monitor_source.Pass()));
- HighResolutionTimerManager manager;
- // At this point, we don't know if the high resolution timers are on or off,
- // it depends on what system the tests are running on (for example, if this
- // test is running on a laptop/battery, then the PowerMonitor would have
- // already set the PowerState to battery power; but if we're running on a
- // desktop, then the PowerState will be non-battery power). Simulate a power
- // level change to get to a deterministic state.
- manager.OnPowerStateChange(/* on_battery */ false);
+ HighResolutionTimerManager manager;
+ // Simulate a on-AC power event to get to a known initial state.
+ manager.OnPowerStateChange(false);
// Loop a few times to test power toggling.
- for (int loop = 2; loop >= 0; --loop) {
+ for (int times = 0; times != 3; ++times) {
// The manager has the high resolution clock enabled now.
EXPECT_TRUE(manager.hi_res_clock_available());
// But the Time class has it off, because it hasn't been activated.
@@ -43,12 +40,12 @@ TEST(HiResTimerManagerTest, DISABLED_ToggleOnOff) {
EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse());
// Simulate a on-battery power event.
- manager.OnPowerStateChange(/* on_battery */ true);
+ manager.OnPowerStateChange(true);
EXPECT_FALSE(manager.hi_res_clock_available());
EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse());
- // Simulate a off-battery power event.
- manager.OnPowerStateChange(/* on_battery */ false);
+ // Back to on-AC power.
+ manager.OnPowerStateChange(false);
EXPECT_TRUE(manager.hi_res_clock_available());
EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse());
« no previous file with comments | « base/time/time_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698