This source file includes following definitions.
- source
- monitor
- TEST_F
#include "base/power_monitor/power_monitor.h"
#include "base/test/power_monitor_test_base.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
class PowerMonitorTest : public testing::Test {
protected:
PowerMonitorTest() {
power_monitor_source_ = new PowerMonitorTestSource();
power_monitor_.reset(new PowerMonitor(
scoped_ptr<PowerMonitorSource>(power_monitor_source_)));
}
virtual ~PowerMonitorTest() {};
PowerMonitorTestSource* source() { return power_monitor_source_; }
PowerMonitor* monitor() { return power_monitor_.get(); }
private:
PowerMonitorTestSource* power_monitor_source_;
scoped_ptr<PowerMonitor> power_monitor_;
DISALLOW_COPY_AND_ASSIGN(PowerMonitorTest);
};
TEST_F(PowerMonitorTest, PowerNotifications) {
const int kObservers = 5;
PowerMonitorTestObserver observers[kObservers];
for (int index = 0; index < kObservers; ++index)
monitor()->AddObserver(&observers[index]);
source()->GenerateResumeEvent();
EXPECT_EQ(observers[0].resumes(), 0);
source()->GenerateSuspendEvent();
for (int index = 0; index < kObservers; ++index)
EXPECT_EQ(observers[index].suspends(), 1);
source()->GenerateSuspendEvent();
EXPECT_EQ(observers[0].suspends(), 1);
source()->GenerateResumeEvent();
EXPECT_EQ(observers[0].resumes(), 1);
source()->GenerateResumeEvent();
EXPECT_EQ(observers[0].resumes(), 1);
source()->GeneratePowerStateEvent(true);
EXPECT_EQ(observers[0].power_state_changes(), 1);
EXPECT_EQ(observers[0].last_power_state(), true);
source()->GeneratePowerStateEvent(true);
EXPECT_EQ(observers[0].power_state_changes(), 1);
source()->GeneratePowerStateEvent(false);
EXPECT_EQ(observers[0].power_state_changes(), 2);
EXPECT_EQ(observers[0].last_power_state(), false);
source()->GeneratePowerStateEvent(false);
EXPECT_EQ(observers[0].power_state_changes(), 2);
}
}