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

Side by Side Diff: base/power_monitor/power_monitor_unittest.cc

Issue 226263008: Revert of Attempting to resolve a race condition with PowerMonitor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
« no previous file with comments | « base/power_monitor/power_monitor_source.cc ('k') | base/timer/hi_res_timer_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/power_monitor/power_monitor.h" 5 #include "base/power_monitor/power_monitor.h"
6 #include "base/test/power_monitor_test_base.h" 6 #include "base/test/power_monitor_test_base.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 class PowerMonitorTest : public testing::Test { 11 class PowerMonitorTest : public testing::Test {
12 protected: 12 protected:
13 PowerMonitorTest() { 13 PowerMonitorTest() {
14 power_monitor_source_ = new PowerMonitorTestSource(); 14 power_monitor_source_ = new PowerMonitorTestSource();
15 PowerMonitor::Initialize( 15 power_monitor_.reset(new PowerMonitor(
16 scoped_ptr<PowerMonitorSource>(power_monitor_source_)); 16 scoped_ptr<PowerMonitorSource>(power_monitor_source_)));
17 } 17 }
18 virtual ~PowerMonitorTest() { 18 virtual ~PowerMonitorTest() {};
19 PowerMonitor::ShutdownForTesting();
20 };
21 19
22 PowerMonitorTestSource* source() { return power_monitor_source_; } 20 PowerMonitorTestSource* source() { return power_monitor_source_; }
21 PowerMonitor* monitor() { return power_monitor_.get(); }
23 22
24 private: 23 private:
25 PowerMonitorTestSource* power_monitor_source_; 24 PowerMonitorTestSource* power_monitor_source_;
25 scoped_ptr<PowerMonitor> power_monitor_;
26 26
27 DISALLOW_COPY_AND_ASSIGN(PowerMonitorTest); 27 DISALLOW_COPY_AND_ASSIGN(PowerMonitorTest);
28 }; 28 };
29 29
30 // PowerMonitorSource is tightly coupled with the PowerMonitor, so this test 30 // PowerMonitorSource is tightly coupled with the PowerMonitor, so this test
31 // Will cover both classes 31 // Will cover both classes
32 TEST_F(PowerMonitorTest, PowerNotifications) { 32 TEST_F(PowerMonitorTest, PowerNotifications) {
33 const int kObservers = 5; 33 const int kObservers = 5;
34 34
35 PowerMonitorTestObserver observers[kObservers]; 35 PowerMonitorTestObserver observers[kObservers];
36 for (int index = 0; index < kObservers; ++index) 36 for (int index = 0; index < kObservers; ++index)
37 PowerMonitor::AddObserver(&observers[index]); 37 monitor()->AddObserver(&observers[index]);
38 38
39 // Sending resume when not suspended should have no effect. 39 // Sending resume when not suspended should have no effect.
40 source()->GenerateResumeEvent(); 40 source()->GenerateResumeEvent();
41 EXPECT_EQ(observers[0].resumes(), 0); 41 EXPECT_EQ(observers[0].resumes(), 0);
42 42
43 // Pretend we suspended. 43 // Pretend we suspended.
44 source()->GenerateSuspendEvent(); 44 source()->GenerateSuspendEvent();
45 // Ensure all observers were notified of the event 45 // Ensure all observers were notified of the event
46 for (int index = 0; index < kObservers; ++index) 46 for (int index = 0; index < kObservers; ++index)
47 EXPECT_EQ(observers[index].suspends(), 1); 47 EXPECT_EQ(observers[index].suspends(), 1);
(...skipping 23 matching lines...) Expand all
71 source()->GeneratePowerStateEvent(false); 71 source()->GeneratePowerStateEvent(false);
72 EXPECT_EQ(observers[0].power_state_changes(), 2); 72 EXPECT_EQ(observers[0].power_state_changes(), 2);
73 EXPECT_EQ(observers[0].last_power_state(), false); 73 EXPECT_EQ(observers[0].last_power_state(), false);
74 74
75 // Repeated indications the device is off battery power should be suppressed. 75 // Repeated indications the device is off battery power should be suppressed.
76 source()->GeneratePowerStateEvent(false); 76 source()->GeneratePowerStateEvent(false);
77 EXPECT_EQ(observers[0].power_state_changes(), 2); 77 EXPECT_EQ(observers[0].power_state_changes(), 2);
78 } 78 }
79 79
80 } // namespace base 80 } // namespace base
OLDNEW
« no previous file with comments | « base/power_monitor/power_monitor_source.cc ('k') | base/timer/hi_res_timer_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698