summaryrefslogtreecommitdiffstats
path: root/base/system_monitor_unittest.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-26 19:48:34 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-26 19:48:34 +0000
commit097ae5a93a863b604fd6dbd939bed0c2be1afed2 (patch)
tree61177362b1c1bd2d1b2438acc50ccb2c061b176e /base/system_monitor_unittest.cc
parent902c971382790170852fe5b5d22d1b79adb31056 (diff)
downloadchromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.zip
chromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.tar.gz
chromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.tar.bz2
Make SystemMonitor not a Singleton and move it out of base
SystemMonitor makes an assumption that through its lifetime a MessageLoop exists and stays the same. It is difficult and error-prone to satisfy that when it is a Singleton. It has caused problems in the past. Additionally, extract HighResoltionTimerManager out of time_win.cc, eliminating yet another Singleton. TEST=none BUG=none Review URL: http://codereview.chromium.org/431008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor_unittest.cc')
-rw-r--r--base/system_monitor_unittest.cc86
1 files changed, 0 insertions, 86 deletions
diff --git a/base/system_monitor_unittest.cc b/base/system_monitor_unittest.cc
deleted file mode 100644
index 7ba3a6b..0000000
--- a/base/system_monitor_unittest.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (c) 2009 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.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class PowerTest : public base::SystemMonitor::PowerObserver {
- public:
- PowerTest()
- : battery_(false),
- power_state_changes_(0),
- suspends_(0),
- resumes_(0) {};
-
- // PowerObserver callbacks.
- void OnPowerStateChange(bool on_battery_power) {
- power_state_changes_++;
- }
-
- void OnSuspend() {
- suspends_++;
- }
-
- void OnResume() {
- resumes_++;
- }
-
- // Test status counts.
- bool battery() { return battery_; }
- int power_state_changes() { return power_state_changes_; }
- int suspends() { return suspends_; }
- int resumes() { return resumes_; }
-
- private:
- bool battery_; // Do we currently think we're on battery power.
- int power_state_changes_; // Count of OnPowerStateChange notifications.
- int suspends_; // Count of OnSuspend notifications.
- int resumes_; // Count of OnResume notifications.
-};
-
-TEST(SystemMonitor, PowerNotifications) {
- const int kObservers = 5;
-
- // Initialize a message loop for this to run on.
- MessageLoop loop;
- // Initialize time() since it registers as a SystemMonitor observer.
- base::Time now = base::Time::Now();
-
- base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
- PowerTest test[kObservers];
- for (int index = 0; index < kObservers; ++index)
- system_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(base::SystemMonitor::POWER_STATE_EVENT);
- EXPECT_EQ(test[0].power_state_changes(), 0);
- }
-
- // Sending resume when not suspended should have no effect.
- system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 0);
-
- // Pretend we suspended.
- system_monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].suspends(), 1);
-
- // Send a second suspend notification. This should be suppressed.
- system_monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].suspends(), 1);
-
- // Pretend we were awakened.
- system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 1);
-
- // Send a duplicate resume notification. This should be suppressed.
- system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 1);
-}