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

Side by Side Diff: content/common/hi_res_timer_manager_unittest.cc

Issue 6904117: Reland old fix that was reverted without my knowledge. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 "base/memory/scoped_ptr.h"
8 #include "base/time.h"
9 #include "content/common/hi_res_timer_manager.h"
10 #include "ui/base/system_monitor/system_monitor.h"
11
12 #if defined(OS_WIN)
13 TEST(HiResTimerManagerTest, ToggleOnOff) {
14 MessageLoop loop;
15 scoped_ptr<ui::SystemMonitor> system_monitor(new ui::SystemMonitor());
16 HighResolutionTimerManager manager;
17
18 // At this point, we don't know if the high resolution timers are on or off,
19 // it depends on what system the tests are running on (for example, if this
20 // test is running on a laptop/battery, then the SystemMonitor would have
21 // already set the PowerState to battery power; but if we're running on a
22 // desktop, then the PowerState will be non-battery power). Simulate a power
23 // level change to get to a deterministic state.
24 manager.OnPowerStateChange(/* on_battery */ false);
jar (doing other things) 2011/05/01 17:42:34 Rather than using a boolean, it would be much more
Mike Belshe 2011/05/01 21:58:00 Well, if I'm going to change the API and all calle
jar (doing other things) 2011/05/04 16:08:26 Yeah... a name change like that would be an equall
25
26 // Loop a few times to test power toggling.
27 for (int loop = 2; loop >= 0; --loop) {
28 // The manager has the high resolution clock enabled now.
29 EXPECT_TRUE(manager.hi_res_clock_available());
30 // But the Time class has it off, because it hasn't been activated.
31 EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse());
32
33 // Activate the high resolution timer.
34 base::Time::ActivateHighResolutionTimer(true);
35 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse());
36
37 // Simulate a on-battery power event.
38 manager.OnPowerStateChange(/* on_battery */ true);
39 EXPECT_FALSE(manager.hi_res_clock_available());
40 EXPECT_FALSE(base::Time::IsHighResolutionTimerInUse());
41
42 // Simulate a off-battery power event.
43 manager.OnPowerStateChange(/* on_battery */ false);
44 EXPECT_TRUE(manager.hi_res_clock_available());
45 EXPECT_TRUE(base::Time::IsHighResolutionTimerInUse());
46
47 // De-activate the high resolution timer.
48 base::Time::ActivateHighResolutionTimer(false);
49 }
50 }
51 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698