This source file includes following definitions.
- SetUp
- TearDown
- TEST_F
#include "ash/system/chromeos/power/power_event_observer.h"
#include "ash/test/ash_test_base.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
namespace ash {
class PowerEventObserverTest : public test::AshTestBase {
public:
PowerEventObserverTest() {}
virtual ~PowerEventObserverTest() {}
virtual void SetUp() OVERRIDE {
test::AshTestBase::SetUp();
observer_.reset(new PowerEventObserver());
}
virtual void TearDown() OVERRIDE {
observer_.reset();
test::AshTestBase::TearDown();
}
protected:
scoped_ptr<PowerEventObserver> observer_;
private:
DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest);
};
TEST_F(PowerEventObserverTest, LockBeforeSuspend) {
chromeos::PowerManagerClient* client =
chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
SetCanLockScreen(true);
SetShouldLockScreenBeforeSuspending(true);
observer_->SuspendImminent();
EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks());
observer_->ScreenIsLocked();
RunAllPendingInMessageLoop();
EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
observer_->SystemResumed(base::TimeDelta());
observer_->ScreenIsUnlocked();
observer_->ScreenIsLocked();
observer_->SuspendImminent();
EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
observer_->SystemResumed(base::TimeDelta());
SetShouldLockScreenBeforeSuspending(false);
observer_->SuspendImminent();
EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
}
}