| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/chromeos/power/power_event_observer.h" | 5 #include "ash/system/chromeos/power/power_event_observer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/dbus_thread_manager_ash.h" |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | 13 // #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/power_manager_client.h" | 14 #include "chromeos/dbus/power_manager_client.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/compositor/compositor.h" | 17 #include "ui/compositor/compositor.h" |
| 17 | 18 |
| 18 namespace ash { | 19 namespace ash { |
| 19 | 20 |
| 20 class PowerEventObserverTest : public test::AshTestBase { | 21 class PowerEventObserverTest : public test::AshTestBase { |
| 21 public: | 22 public: |
| 22 PowerEventObserverTest() {} | 23 PowerEventObserverTest() {} |
| (...skipping 22 matching lines...) Expand all Loading... |
| 45 } | 46 } |
| 46 | 47 |
| 47 std::unique_ptr<PowerEventObserver> observer_; | 48 std::unique_ptr<PowerEventObserver> observer_; |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest); | 51 DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest); |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 TEST_F(PowerEventObserverTest, LockBeforeSuspend) { | 54 TEST_F(PowerEventObserverTest, LockBeforeSuspend) { |
| 54 chromeos::PowerManagerClient* client = | 55 chromeos::PowerManagerClient* client = |
| 55 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | 56 DBusThreadManagerAsh::Get()->GetPowerManagerClient(); |
| 56 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); | 57 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); |
| 57 | 58 |
| 58 // Check that the observer requests a suspend-readiness callback when it hears | 59 // Check that the observer requests a suspend-readiness callback when it hears |
| 59 // that the system is about to suspend. | 60 // that the system is about to suspend. |
| 60 SetCanLockScreen(true); | 61 SetCanLockScreen(true); |
| 61 SetShouldLockScreenBeforeSuspending(true); | 62 SetShouldLockScreenBeforeSuspending(true); |
| 62 observer_->SuspendImminent(); | 63 observer_->SuspendImminent(); |
| 63 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); | 64 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); |
| 64 | 65 |
| 65 // It should run the callback when it hears that the screen is locked and the | 66 // It should run the callback when it hears that the screen is locked and the |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // - The suspend request is canceled. | 134 // - The suspend request is canceled. |
| 134 // - Another suspend request is started. | 135 // - Another suspend request is started. |
| 135 // - The screen lock animations complete. | 136 // - The screen lock animations complete. |
| 136 // | 137 // |
| 137 // In this case, the observer should block the second suspend request until | 138 // In this case, the observer should block the second suspend request until |
| 138 // the animations have completed. | 139 // the animations have completed. |
| 139 SetCanLockScreen(true); | 140 SetCanLockScreen(true); |
| 140 SetShouldLockScreenBeforeSuspending(true); | 141 SetShouldLockScreenBeforeSuspending(true); |
| 141 | 142 |
| 142 chromeos::PowerManagerClient* client = | 143 chromeos::PowerManagerClient* client = |
| 143 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | 144 DBusThreadManagerAsh::Get()->GetPowerManagerClient(); |
| 144 observer_->SuspendImminent(); | 145 observer_->SuspendImminent(); |
| 145 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); | 146 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); |
| 146 | 147 |
| 147 observer_->ScreenIsLocked(); | 148 observer_->ScreenIsLocked(); |
| 148 observer_->SuspendDone(base::TimeDelta()); | 149 observer_->SuspendDone(base::TimeDelta()); |
| 149 observer_->SuspendImminent(); | 150 observer_->SuspendImminent(); |
| 150 | 151 |
| 151 // The expected number of suspend readiness callbacks is 2 because the | 152 // The expected number of suspend readiness callbacks is 2 because the |
| 152 // observer has not run the callback that it got from the first suspend | 153 // observer has not run the callback that it got from the first suspend |
| 153 // request. The real PowerManagerClient would reset its internal counter in | 154 // request. The real PowerManagerClient would reset its internal counter in |
| 154 // this situation but the stub client is not that smart. | 155 // this situation but the stub client is not that smart. |
| 155 EXPECT_EQ(2, client->GetNumPendingSuspendReadinessCallbacks()); | 156 EXPECT_EQ(2, client->GetNumPendingSuspendReadinessCallbacks()); |
| 156 | 157 |
| 157 observer_->OnLockAnimationsComplete(); | 158 observer_->OnLockAnimationsComplete(); |
| 158 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); | 159 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); |
| 159 EXPECT_EQ(0, GetNumVisibleCompositors()); | 160 EXPECT_EQ(0, GetNumVisibleCompositors()); |
| 160 } | 161 } |
| 161 | 162 |
| 162 } // namespace ash | 163 } // namespace ash |
| OLD | NEW |