Fix unit test for system monitor.
Not sure how I missed this! Review URL: http://codereview.chromium.org/9250 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4457 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -33,6 +33,12 @@ class PowerTest : public base::SystemMonitor::PowerObserver {
|
||||
|
||||
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)
|
||||
@ -47,22 +53,27 @@ TEST(SystemMonitor, PowerNotifications) {
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user