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

Unified Diff: app/system_monitor_unittest.cc

Issue 6361002: Move SystemMonitor to src/chrome/common.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | « app/system_monitor_posix.cc ('k') | app/system_monitor_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/system_monitor_unittest.cc
===================================================================
--- app/system_monitor_unittest.cc (revision 71446)
+++ app/system_monitor_unittest.cc (working copy)
@@ -1,87 +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 "app/system_monitor.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class PowerTest : public 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();
-
- SystemMonitor system_monitor;
- 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(SystemMonitor::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);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 0);
-
- // Pretend we suspended.
- system_monitor.ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].suspends(), 1);
-
- // Send a second suspend notification. This should be suppressed.
- system_monitor.ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].suspends(), 1);
-
- // Pretend we were awakened.
- system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 1);
-
- // Send a duplicate resume notification. This should be suppressed.
- system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
- loop.RunAllPending();
- EXPECT_EQ(test[0].resumes(), 1);
-}
« no previous file with comments | « app/system_monitor_posix.cc ('k') | app/system_monitor_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698