This source file includes following definitions.
- resumes_
- Send
- power_state_changes
- suspends
- resumes
- source
- monitor
- TEST_F
#include "base/test/power_monitor_test_base.h"
#include "content/browser/power_monitor_message_broadcaster.h"
#include "content/common/power_monitor_messages.h"
#include "ipc/ipc_sender.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
class PowerMonitorMessageSender : public IPC::Sender {
public:
PowerMonitorMessageSender()
: power_state_changes_(0),
suspends_(0),
resumes_(0) {
}
virtual ~PowerMonitorMessageSender() {}
virtual bool Send(IPC::Message* msg) OVERRIDE {
switch (msg->type()) {
case PowerMonitorMsg_Suspend::ID:
suspends_++;
break;
case PowerMonitorMsg_Resume::ID:
resumes_++;
break;
case PowerMonitorMsg_PowerStateChange::ID:
power_state_changes_++;
break;
}
delete msg;
return true;
};
int power_state_changes() { return power_state_changes_; }
int suspends() { return suspends_; }
int resumes() { return resumes_; }
private:
int power_state_changes_;
int suspends_;
int resumes_;
};
class PowerMonitorMessageBroadcasterTest : public testing::Test {
protected:
PowerMonitorMessageBroadcasterTest() {
power_monitor_source_ = new base::PowerMonitorTestSource();
power_monitor_.reset(new base::PowerMonitor(
scoped_ptr<base::PowerMonitorSource>(power_monitor_source_)));
}
virtual ~PowerMonitorMessageBroadcasterTest() {};
base::PowerMonitorTestSource* source() { return power_monitor_source_; }
base::PowerMonitor* monitor() { return power_monitor_.get(); }
private:
base::PowerMonitorTestSource* power_monitor_source_;
scoped_ptr<base::PowerMonitor> power_monitor_;
DISALLOW_COPY_AND_ASSIGN(PowerMonitorMessageBroadcasterTest);
};
TEST_F(PowerMonitorMessageBroadcasterTest, PowerMessageBroadcast) {
PowerMonitorMessageSender sender;
PowerMonitorMessageBroadcaster broadcaster(&sender);
source()->GenerateResumeEvent();
EXPECT_EQ(sender.resumes(), 0);
source()->GenerateSuspendEvent();
EXPECT_EQ(sender.suspends(), 1);
source()->GenerateSuspendEvent();
EXPECT_EQ(sender.suspends(), 1);
source()->GenerateResumeEvent();
EXPECT_EQ(sender.resumes(), 1);
source()->GenerateResumeEvent();
EXPECT_EQ(sender.resumes(), 1);
source()->GeneratePowerStateEvent(true);
EXPECT_EQ(sender.power_state_changes(), 1);
source()->GeneratePowerStateEvent(true);
EXPECT_EQ(sender.power_state_changes(), 1);
source()->GeneratePowerStateEvent(false);
EXPECT_EQ(sender.power_state_changes(), 2);
source()->GeneratePowerStateEvent(false);
EXPECT_EQ(sender.power_state_changes(), 2);
}
}