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

Unified Diff: base/power_monitor/power_monitor_unittest.cc

Issue 10959020: SystemMonitor refactoring: move power state monitor into a separate class called PowerMonitor (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use holder class for lazy initialization on Android Created 7 years, 9 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/power_monitor/power_monitor_posix.cc ('k') | base/power_monitor/power_monitor_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/power_monitor/power_monitor_unittest.cc
diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/power_monitor/power_monitor_unittest.cc
similarity index 46%
copy from base/system_monitor/system_monitor_unittest.cc
copy to base/power_monitor/power_monitor_unittest.cc
index 43f1dd68fb3792fa620d2491a9427ba54d4176a8..af3ed419ef9842933b8b048aef339e13e6411b45 100644
--- a/base/system_monitor/system_monitor_unittest.cc
+++ b/base/power_monitor/power_monitor_unittest.cc
@@ -1,20 +1,15 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/message_loop.h"
-#include "base/run_loop.h"
-#include "base/test/mock_devices_changed_observer.h"
-#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
-namespace {
-
-class PowerTest : public SystemMonitor::PowerObserver {
+class PowerTest : public PowerObserver {
public:
PowerTest()
: power_state_changes_(0),
@@ -46,85 +41,66 @@ class PowerTest : public SystemMonitor::PowerObserver {
int resumes_; // Count of OnResume notifications.
};
-class SystemMonitorTest : public testing::Test {
+class PowerMonitorTest : public testing::Test {
protected:
- SystemMonitorTest() {
+ PowerMonitorTest() {
#if defined(OS_MACOSX)
- // This needs to happen before SystemMonitor's ctor.
- SystemMonitor::AllocateSystemIOPorts();
+ // This needs to happen before PowerMonitor's ctor.
+ PowerMonitor::AllocateSystemIOPorts();
#endif
- system_monitor_.reset(new SystemMonitor);
+ power_monitor_.reset(new PowerMonitor);
+ }
+
+ void ProcessPowerEvent(PowerMonitor::PowerEvent event_id) {
+ power_monitor_->ProcessPowerEvent(event_id);
}
- virtual ~SystemMonitorTest() {}
+
+ virtual ~PowerMonitorTest() {}
MessageLoop message_loop_;
- scoped_ptr<SystemMonitor> system_monitor_;
+ scoped_ptr<PowerMonitor> power_monitor_;
- DISALLOW_COPY_AND_ASSIGN(SystemMonitorTest);
+ DISALLOW_COPY_AND_ASSIGN(PowerMonitorTest);
};
-TEST_F(SystemMonitorTest, PowerNotifications) {
+TEST_F(PowerMonitorTest, PowerNotifications) {
const int kObservers = 5;
PowerTest test[kObservers];
for (int index = 0; index < kObservers; ++index)
- system_monitor_->AddPowerObserver(&test[index]);
+ power_monitor_->AddObserver(&test[index]);
// Send a bunch of power changes. Since the battery power hasn't
// actually changed, we shouldn't get notifications.
for (int index = 0; index < 5; index++) {
- system_monitor_->ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
+ ProcessPowerEvent(PowerMonitor::POWER_STATE_EVENT);
EXPECT_EQ(test[0].power_state_changes(), 0);
}
// Sending resume when not suspended should have no effect.
- system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
- RunLoop().RunUntilIdle();
+ ProcessPowerEvent(PowerMonitor::RESUME_EVENT);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(test[0].resumes(), 0);
// Pretend we suspended.
- system_monitor_->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
- RunLoop().RunUntilIdle();
+ ProcessPowerEvent(PowerMonitor::SUSPEND_EVENT);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(test[0].suspends(), 1);
// Send a second suspend notification. This should be suppressed.
- system_monitor_->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
- RunLoop().RunUntilIdle();
+ ProcessPowerEvent(PowerMonitor::SUSPEND_EVENT);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(test[0].suspends(), 1);
// Pretend we were awakened.
- system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
- RunLoop().RunUntilIdle();
+ ProcessPowerEvent(PowerMonitor::RESUME_EVENT);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(test[0].resumes(), 1);
// Send a duplicate resume notification. This should be suppressed.
- system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
- RunLoop().RunUntilIdle();
+ ProcessPowerEvent(PowerMonitor::RESUME_EVENT);
+ message_loop_.RunUntilIdle();
EXPECT_EQ(test[0].resumes(), 1);
}
-TEST_F(SystemMonitorTest, DeviceChangeNotifications) {
- const int kObservers = 5;
-
- testing::Sequence mock_sequencer[kObservers];
- MockDevicesChangedObserver observers[kObservers];
- for (int index = 0; index < kObservers; ++index) {
- system_monitor_->AddDevicesChangedObserver(&observers[index]);
-
- EXPECT_CALL(observers[index],
- OnDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN))
- .Times(3)
- .InSequence(mock_sequencer[index]);
- }
-
- system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
- RunLoop().RunUntilIdle();
-
- system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
- system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
- RunLoop().RunUntilIdle();
-}
-
-} // namespace
-
} // namespace base
« no previous file with comments | « base/power_monitor/power_monitor_posix.cc ('k') | base/power_monitor/power_monitor_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698