summaryrefslogtreecommitdiffstats
path: root/base/system_monitor_unittest.cc
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-03 15:01:12 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-03 15:01:12 +0000
commit52a261f59b20e89f8c5936bce642362f8e367b57 (patch)
treefcc7b3c100caaf43848cd9a241beafc883f93b7d /base/system_monitor_unittest.cc
parent7d926f9072ac496db6df715cc6a6bd5d3f9bd011 (diff)
downloadchromium_src-52a261f59b20e89f8c5936bce642362f8e367b57.zip
chromium_src-52a261f59b20e89f8c5936bce642362f8e367b57.tar.gz
chromium_src-52a261f59b20e89f8c5936bce642362f8e367b57.tar.bz2
NO CODE CHANGE (except one global std::wstring changed to const wchar_t* const per style compliance).
Preliminary work to enforce new PRESUBMIT.py rules: - <=80 cols - no trailing whitespaces - svn:eol-style=LF git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10791 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor_unittest.cc')
-rw-r--r--base/system_monitor_unittest.cc158
1 files changed, 79 insertions, 79 deletions
diff --git a/base/system_monitor_unittest.cc b/base/system_monitor_unittest.cc
index 786a94d..7fe3d8f 100644
--- a/base/system_monitor_unittest.cc
+++ b/base/system_monitor_unittest.cc
@@ -1,79 +1,79 @@
-// Copyright (c) 2008 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(base::SystemMonitor*) { power_state_changes_++; };
- void OnSuspend(base::SystemMonitor*) { suspends_++; };
- void OnResume(base::SystemMonitor*) { 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* monitor = base::SystemMonitor::Get();
- PowerTest test[kObservers];
- for (int index = 0; index < kObservers; ++index)
- 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++) {
- monitor->ProcessPowerMessage(base::SystemMonitor::POWER_STATE_EVENT);
- EXPECT_EQ(test[0].power_state_changes(), 0);
- }
-
- // Sending resume when not suspended should have no effect.
- monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 0);
-
- // Pretend we suspended.
- monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].suspends(), 1);
-
- // Send a second suspend notification. This should be suppressed.
- monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].suspends(), 1);
-
- // Pretend we were awakened.
- monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 1);
-
- // Send a duplicate resume notification. This should be suppressed.
- monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 1);
-}
-
+// Copyright (c) 2008 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(base::SystemMonitor*) { power_state_changes_++; };
+ void OnSuspend(base::SystemMonitor*) { suspends_++; };
+ void OnResume(base::SystemMonitor*) { 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* monitor = base::SystemMonitor::Get();
+ PowerTest test[kObservers];
+ for (int index = 0; index < kObservers; ++index)
+ 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++) {
+ monitor->ProcessPowerMessage(base::SystemMonitor::POWER_STATE_EVENT);
+ EXPECT_EQ(test[0].power_state_changes(), 0);
+ }
+
+ // Sending resume when not suspended should have no effect.
+ monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
+ loop.RunAllPending();
+ EXPECT_EQ(test[0].resumes(), 0);
+
+ // Pretend we suspended.
+ monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT);
+ loop.RunAllPending();
+ EXPECT_EQ(test[0].suspends(), 1);
+
+ // Send a second suspend notification. This should be suppressed.
+ monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT);
+ loop.RunAllPending();
+ EXPECT_EQ(test[0].suspends(), 1);
+
+ // Pretend we were awakened.
+ monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
+ loop.RunAllPending();
+ EXPECT_EQ(test[0].resumes(), 1);
+
+ // Send a duplicate resume notification. This should be suppressed.
+ monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT);
+ loop.RunAllPending();
+ EXPECT_EQ(test[0].resumes(), 1);
+}
+