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/test/test_session_state_delegate.h" | |
10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
11 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
13 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
14 #include "chromeos/dbus/power_manager_client.h" | 13 #include "chromeos/dbus/power_manager_client.h" |
15 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
16 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
17 #include "ui/compositor/compositor.h" | 16 #include "ui/compositor/compositor.h" |
18 | 17 |
19 namespace ash { | 18 namespace ash { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest); | 50 DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest); |
52 }; | 51 }; |
53 | 52 |
54 TEST_F(PowerEventObserverTest, LockBeforeSuspend) { | 53 TEST_F(PowerEventObserverTest, LockBeforeSuspend) { |
55 chromeos::PowerManagerClient* client = | 54 chromeos::PowerManagerClient* client = |
56 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | 55 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
57 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); | 56 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); |
58 | 57 |
59 // Check that the observer requests a suspend-readiness callback when it hears | 58 // Check that the observer requests a suspend-readiness callback when it hears |
60 // that the system is about to suspend. | 59 // that the system is about to suspend. |
61 test::TestSessionStateDelegate::SetCanLockScreen(true); | 60 SetCanLockScreen(true); |
62 SetShouldLockScreenAutomatically(true); | 61 SetShouldLockScreenAutomatically(true); |
63 observer_->SuspendImminent(); | 62 observer_->SuspendImminent(); |
64 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); | 63 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); |
65 | 64 |
66 // It should run the callback when it hears that the screen is locked and the | 65 // It should run the callback when it hears that the screen is locked and the |
67 // lock screen animations have completed. | 66 // lock screen animations have completed. |
68 observer_->ScreenIsLocked(); | 67 observer_->ScreenIsLocked(); |
69 observer_->OnLockAnimationsComplete(); | 68 observer_->OnLockAnimationsComplete(); |
70 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); | 69 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); |
71 | 70 |
(...skipping 17 matching lines...) Expand all Loading... |
89 // Tests that all the Compositors are marked invisible before a suspend | 88 // Tests that all the Compositors are marked invisible before a suspend |
90 // request when the screen is not supposed to be locked before a suspend. | 89 // request when the screen is not supposed to be locked before a suspend. |
91 EXPECT_EQ(1, GetNumVisibleCompositors()); | 90 EXPECT_EQ(1, GetNumVisibleCompositors()); |
92 | 91 |
93 observer_->SuspendImminent(); | 92 observer_->SuspendImminent(); |
94 EXPECT_EQ(0, GetNumVisibleCompositors()); | 93 EXPECT_EQ(0, GetNumVisibleCompositors()); |
95 observer_->SuspendDone(base::TimeDelta()); | 94 observer_->SuspendDone(base::TimeDelta()); |
96 | 95 |
97 // Tests that all the Compositors are marked invisible _after_ the screen lock | 96 // Tests that all the Compositors are marked invisible _after_ the screen lock |
98 // animations have completed. | 97 // animations have completed. |
99 test::TestSessionStateDelegate::SetCanLockScreen(true); | 98 SetCanLockScreen(true); |
100 SetShouldLockScreenAutomatically(true); | 99 SetShouldLockScreenAutomatically(true); |
101 | 100 |
102 observer_->SuspendImminent(); | 101 observer_->SuspendImminent(); |
103 EXPECT_EQ(1, GetNumVisibleCompositors()); | 102 EXPECT_EQ(1, GetNumVisibleCompositors()); |
104 | 103 |
105 observer_->ScreenIsLocked(); | 104 observer_->ScreenIsLocked(); |
106 EXPECT_EQ(1, GetNumVisibleCompositors()); | 105 EXPECT_EQ(1, GetNumVisibleCompositors()); |
107 | 106 |
108 observer_->OnLockAnimationsComplete(); | 107 observer_->OnLockAnimationsComplete(); |
109 EXPECT_EQ(0, GetNumVisibleCompositors()); | 108 EXPECT_EQ(0, GetNumVisibleCompositors()); |
110 | 109 |
111 observer_->SuspendDone(base::TimeDelta()); | 110 observer_->SuspendDone(base::TimeDelta()); |
112 EXPECT_EQ(1, GetNumVisibleCompositors()); | 111 EXPECT_EQ(1, GetNumVisibleCompositors()); |
113 } | 112 } |
114 | 113 |
115 TEST_F(PowerEventObserverTest, CanceledSuspend) { | 114 TEST_F(PowerEventObserverTest, CanceledSuspend) { |
116 // Tests that the Compositors are not marked invisible if a suspend is | 115 // Tests that the Compositors are not marked invisible if a suspend is |
117 // canceled or the system resumes before the lock screen is ready. | 116 // canceled or the system resumes before the lock screen is ready. |
118 test::TestSessionStateDelegate::SetCanLockScreen(true); | 117 SetCanLockScreen(true); |
119 SetShouldLockScreenAutomatically(true); | 118 SetShouldLockScreenAutomatically(true); |
120 observer_->SuspendImminent(); | 119 observer_->SuspendImminent(); |
121 EXPECT_EQ(1, GetNumVisibleCompositors()); | 120 EXPECT_EQ(1, GetNumVisibleCompositors()); |
122 | 121 |
123 observer_->SuspendDone(base::TimeDelta()); | 122 observer_->SuspendDone(base::TimeDelta()); |
124 observer_->ScreenIsLocked(); | 123 observer_->ScreenIsLocked(); |
125 observer_->OnLockAnimationsComplete(); | 124 observer_->OnLockAnimationsComplete(); |
126 EXPECT_EQ(1, GetNumVisibleCompositors()); | 125 EXPECT_EQ(1, GetNumVisibleCompositors()); |
127 } | 126 } |
128 | 127 |
129 TEST_F(PowerEventObserverTest, DelayResuspendForLockAnimations) { | 128 TEST_F(PowerEventObserverTest, DelayResuspendForLockAnimations) { |
130 // Tests that the following order of events is handled correctly: | 129 // Tests that the following order of events is handled correctly: |
131 // | 130 // |
132 // - A suspend request is started. | 131 // - A suspend request is started. |
133 // - The screen is locked. | 132 // - The screen is locked. |
134 // - The suspend request is canceled. | 133 // - The suspend request is canceled. |
135 // - Another suspend request is started. | 134 // - Another suspend request is started. |
136 // - The screen lock animations complete. | 135 // - The screen lock animations complete. |
137 // | 136 // |
138 // In this case, the observer should block the second suspend request until | 137 // In this case, the observer should block the second suspend request until |
139 // the animations have completed. | 138 // the animations have completed. |
140 test::TestSessionStateDelegate::SetCanLockScreen(true); | 139 SetCanLockScreen(true); |
141 SetShouldLockScreenAutomatically(true); | 140 SetShouldLockScreenAutomatically(true); |
142 | 141 |
143 chromeos::PowerManagerClient* client = | 142 chromeos::PowerManagerClient* client = |
144 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | 143 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
145 observer_->SuspendImminent(); | 144 observer_->SuspendImminent(); |
146 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); | 145 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); |
147 | 146 |
148 observer_->ScreenIsLocked(); | 147 observer_->ScreenIsLocked(); |
149 observer_->SuspendDone(base::TimeDelta()); | 148 observer_->SuspendDone(base::TimeDelta()); |
150 observer_->SuspendImminent(); | 149 observer_->SuspendImminent(); |
151 | 150 |
152 // The expected number of suspend readiness callbacks is 2 because the | 151 // The expected number of suspend readiness callbacks is 2 because the |
153 // observer has not run the callback that it got from the first suspend | 152 // observer has not run the callback that it got from the first suspend |
154 // request. The real PowerManagerClient would reset its internal counter in | 153 // request. The real PowerManagerClient would reset its internal counter in |
155 // this situation but the stub client is not that smart. | 154 // this situation but the stub client is not that smart. |
156 EXPECT_EQ(2, client->GetNumPendingSuspendReadinessCallbacks()); | 155 EXPECT_EQ(2, client->GetNumPendingSuspendReadinessCallbacks()); |
157 | 156 |
158 observer_->OnLockAnimationsComplete(); | 157 observer_->OnLockAnimationsComplete(); |
159 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); | 158 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); |
160 EXPECT_EQ(0, GetNumVisibleCompositors()); | 159 EXPECT_EQ(0, GetNumVisibleCompositors()); |
161 } | 160 } |
162 | 161 |
163 } // namespace ash | 162 } // namespace ash |
OLD | NEW |