Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / system / chromeos / power / power_event_observer_unittest.cc
blob30cd2e993ce48d5b8d00f5bd739245c8a4c5c9ae
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/system/chromeos/power/power_event_observer.h"
7 #include "ash/test/ash_test_base.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/power_manager_client.h"
13 namespace ash {
15 class PowerEventObserverTest : public test::AshTestBase {
16 public:
17 PowerEventObserverTest() {}
18 virtual ~PowerEventObserverTest() {}
20 // test::AshTestBase::SetUp() overrides:
21 virtual void SetUp() OVERRIDE {
22 test::AshTestBase::SetUp();
23 observer_.reset(new PowerEventObserver());
26 virtual void TearDown() OVERRIDE {
27 observer_.reset();
28 test::AshTestBase::TearDown();
31 protected:
32 scoped_ptr<PowerEventObserver> observer_;
34 private:
35 DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest);
38 TEST_F(PowerEventObserverTest, LockBeforeSuspend) {
39 chromeos::PowerManagerClient* client =
40 chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
41 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
43 // Check that the observer requests a suspend-readiness callback when it hears
44 // that the system is about to suspend.
45 SetCanLockScreen(true);
46 SetShouldLockScreenBeforeSuspending(true);
47 observer_->SuspendImminent();
48 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks());
50 // It should run the callback when it hears that the screen is locked.
51 observer_->ScreenIsLocked();
52 RunAllPendingInMessageLoop();
53 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
55 // If the system is already locked, no callback should be requested.
56 observer_->SuspendDone(base::TimeDelta());
57 observer_->ScreenIsUnlocked();
58 observer_->ScreenIsLocked();
59 observer_->SuspendImminent();
60 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
62 // It also shouldn't request a callback if it isn't instructed to lock the
63 // screen.
64 observer_->SuspendDone(base::TimeDelta());
65 SetShouldLockScreenBeforeSuspending(false);
66 observer_->SuspendImminent();
67 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
70 } // namespace ash