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

Side by Side Diff: app/hi_res_timer_manager_unittest.cc

Issue 3848002: Fix regression where high resolution timers could be activated even under... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: nonono - fix thread safety problem, simplify! Created 10 years, 2 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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());
jar (doing other things) 2010/10/20 00:37:19 nit: Suggest rename: hi_res_clock_allowable
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698