Chromium Code Reviews| 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 "ash/shell.h" | |
| 7 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/power_manager_client.h" | 12 #include "chromeos/dbus/power_manager_client.h" |
| 13 #include "ui/aura/window.h" | |
| 14 #include "ui/aura/window_tree_host.h" | |
| 15 #include "ui/compositor/compositor.h" | |
| 12 | 16 |
| 13 namespace ash { | 17 namespace ash { |
| 14 | 18 |
| 15 class PowerEventObserverTest : public test::AshTestBase { | 19 class PowerEventObserverTest : public test::AshTestBase { |
| 16 public: | 20 public: |
| 17 PowerEventObserverTest() {} | 21 PowerEventObserverTest() {} |
| 18 ~PowerEventObserverTest() override {} | 22 ~PowerEventObserverTest() override {} |
| 19 | 23 |
| 20 // test::AshTestBase::SetUp() overrides: | 24 // test::AshTestBase::SetUp() overrides: |
| 21 void SetUp() override { | 25 void SetUp() override { |
| 22 test::AshTestBase::SetUp(); | 26 test::AshTestBase::SetUp(); |
| 23 observer_.reset(new PowerEventObserver()); | 27 observer_.reset(new PowerEventObserver()); |
| 24 } | 28 } |
| 25 | 29 |
| 26 void TearDown() override { | 30 void TearDown() override { |
| 27 observer_.reset(); | 31 observer_.reset(); |
| 28 test::AshTestBase::TearDown(); | 32 test::AshTestBase::TearDown(); |
| 29 } | 33 } |
| 30 | 34 |
| 31 protected: | 35 protected: |
| 36 void ExpectCompositorVisibility(bool expected) { | |
|
Daniel Erat
2015/02/11 14:11:43
to get more-meaningful failure messages, how about
Chirantan Ekbote
2015/02/18 02:47:13
Done.
| |
| 37 for (const auto& window : Shell::GetAllRootWindows()) { | |
|
Daniel Erat
2015/02/11 14:11:42
nit: omit curly brackets
| |
| 38 EXPECT_EQ(expected, window->GetHost()->compositor()->IsVisible()); | |
| 39 } | |
| 40 } | |
| 41 | |
| 32 scoped_ptr<PowerEventObserver> observer_; | 42 scoped_ptr<PowerEventObserver> observer_; |
| 33 | 43 |
| 34 private: | 44 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest); | 45 DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest); |
| 36 }; | 46 }; |
| 37 | 47 |
| 38 TEST_F(PowerEventObserverTest, LockBeforeSuspend) { | 48 TEST_F(PowerEventObserverTest, LockBeforeSuspend) { |
| 39 chromeos::PowerManagerClient* client = | 49 chromeos::PowerManagerClient* client = |
| 40 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | 50 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
| 41 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); | 51 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 60 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); | 70 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); |
| 61 | 71 |
| 62 // It also shouldn't request a callback if it isn't instructed to lock the | 72 // It also shouldn't request a callback if it isn't instructed to lock the |
| 63 // screen. | 73 // screen. |
| 64 observer_->SuspendDone(base::TimeDelta()); | 74 observer_->SuspendDone(base::TimeDelta()); |
| 65 SetShouldLockScreenBeforeSuspending(false); | 75 SetShouldLockScreenBeforeSuspending(false); |
| 66 observer_->SuspendImminent(); | 76 observer_->SuspendImminent(); |
| 67 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); | 77 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); |
| 68 } | 78 } |
| 69 | 79 |
| 80 TEST_F(PowerEventObserverTest, SetInvisibleBeforeSuspend) { | |
| 81 // Tests that all the LayerTreeHosts are marked invisible before a suspend | |
| 82 // request when the screen is not supposed to be locked before a suspend. | |
| 83 ExpectCompositorVisibility(true); | |
| 84 | |
| 85 observer_->SuspendImminent(); | |
| 86 ExpectCompositorVisibility(false); | |
| 87 observer_->SuspendDone(base::TimeDelta()); | |
| 88 | |
| 89 // Tests that all the LayerTreeHosts are marked invisible _after_ the screen | |
| 90 // is locked for a suspend request. | |
| 91 SetCanLockScreen(true); | |
| 92 SetShouldLockScreenBeforeSuspending(true); | |
| 93 | |
| 94 observer_->SuspendImminent(); | |
| 95 ExpectCompositorVisibility(true); | |
| 96 | |
| 97 observer_->ScreenIsLocked(); | |
| 98 ExpectCompositorVisibility(false); | |
| 99 | |
| 100 observer_->SuspendDone(base::TimeDelta()); | |
| 101 ExpectCompositorVisibility(true); | |
| 102 } | |
| 103 | |
| 104 TEST_F(PowerEventObserverTest, CanceledSuspend) { | |
| 105 // Tests that the LayerTreeHosts are not marked invisible if a suspend is | |
| 106 // canceled before the lock screen is ready. | |
|
Daniel Erat
2015/02/11 14:11:43
nit: s/canceled/canceled or resumed/
Chirantan Ekbote
2015/02/18 02:47:13
Done.
| |
| 107 SetCanLockScreen(true); | |
| 108 SetShouldLockScreenBeforeSuspending(true); | |
| 109 observer_->SuspendImminent(); | |
| 110 ExpectCompositorVisibility(true); | |
| 111 | |
| 112 observer_->SuspendDone(base::TimeDelta()); | |
| 113 observer_->ScreenIsLocked(); | |
| 114 ExpectCompositorVisibility(true); | |
| 115 } | |
| 116 | |
| 70 } // namespace ash | 117 } // namespace ash |
| OLD | NEW |