Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: ash/system/chromeos/power/power_event_observer_unittest.cc

Issue 2391153002: Converts most of WorkspaceLayoutManager tests to use common code (Closed)
Patch Set: merge Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/mus/test/wm_test_base.cc ('k') | ash/test/ash_test_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/test_session_state_delegate.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 {
(...skipping 29 matching lines...) Expand all
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 chromeos::DBusThreadManager::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 test::TestSessionStateDelegate::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
66 // lock screen animations have completed. 67 // lock screen animations have completed.
67 observer_->ScreenIsLocked(); 68 observer_->ScreenIsLocked();
68 observer_->OnLockAnimationsComplete(); 69 observer_->OnLockAnimationsComplete();
69 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); 70 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
70 71
(...skipping 17 matching lines...) Expand all
88 // Tests that all the Compositors are marked invisible before a suspend 89 // Tests that all the Compositors are marked invisible before a suspend
89 // request when the screen is not supposed to be locked before a suspend. 90 // request when the screen is not supposed to be locked before a suspend.
90 EXPECT_EQ(1, GetNumVisibleCompositors()); 91 EXPECT_EQ(1, GetNumVisibleCompositors());
91 92
92 observer_->SuspendImminent(); 93 observer_->SuspendImminent();
93 EXPECT_EQ(0, GetNumVisibleCompositors()); 94 EXPECT_EQ(0, GetNumVisibleCompositors());
94 observer_->SuspendDone(base::TimeDelta()); 95 observer_->SuspendDone(base::TimeDelta());
95 96
96 // Tests that all the Compositors are marked invisible _after_ the screen lock 97 // Tests that all the Compositors are marked invisible _after_ the screen lock
97 // animations have completed. 98 // animations have completed.
98 SetCanLockScreen(true); 99 test::TestSessionStateDelegate::SetCanLockScreen(true);
99 SetShouldLockScreenBeforeSuspending(true); 100 SetShouldLockScreenBeforeSuspending(true);
100 101
101 observer_->SuspendImminent(); 102 observer_->SuspendImminent();
102 EXPECT_EQ(1, GetNumVisibleCompositors()); 103 EXPECT_EQ(1, GetNumVisibleCompositors());
103 104
104 observer_->ScreenIsLocked(); 105 observer_->ScreenIsLocked();
105 EXPECT_EQ(1, GetNumVisibleCompositors()); 106 EXPECT_EQ(1, GetNumVisibleCompositors());
106 107
107 observer_->OnLockAnimationsComplete(); 108 observer_->OnLockAnimationsComplete();
108 EXPECT_EQ(0, GetNumVisibleCompositors()); 109 EXPECT_EQ(0, GetNumVisibleCompositors());
109 110
110 observer_->SuspendDone(base::TimeDelta()); 111 observer_->SuspendDone(base::TimeDelta());
111 EXPECT_EQ(1, GetNumVisibleCompositors()); 112 EXPECT_EQ(1, GetNumVisibleCompositors());
112 } 113 }
113 114
114 TEST_F(PowerEventObserverTest, CanceledSuspend) { 115 TEST_F(PowerEventObserverTest, CanceledSuspend) {
115 // Tests that the Compositors are not marked invisible if a suspend is 116 // Tests that the Compositors are not marked invisible if a suspend is
116 // canceled or the system resumes before the lock screen is ready. 117 // canceled or the system resumes before the lock screen is ready.
117 SetCanLockScreen(true); 118 test::TestSessionStateDelegate::SetCanLockScreen(true);
118 SetShouldLockScreenBeforeSuspending(true); 119 SetShouldLockScreenBeforeSuspending(true);
119 observer_->SuspendImminent(); 120 observer_->SuspendImminent();
120 EXPECT_EQ(1, GetNumVisibleCompositors()); 121 EXPECT_EQ(1, GetNumVisibleCompositors());
121 122
122 observer_->SuspendDone(base::TimeDelta()); 123 observer_->SuspendDone(base::TimeDelta());
123 observer_->ScreenIsLocked(); 124 observer_->ScreenIsLocked();
124 observer_->OnLockAnimationsComplete(); 125 observer_->OnLockAnimationsComplete();
125 EXPECT_EQ(1, GetNumVisibleCompositors()); 126 EXPECT_EQ(1, GetNumVisibleCompositors());
126 } 127 }
127 128
128 TEST_F(PowerEventObserverTest, DelayResuspendForLockAnimations) { 129 TEST_F(PowerEventObserverTest, DelayResuspendForLockAnimations) {
129 // Tests that the following order of events is handled correctly: 130 // Tests that the following order of events is handled correctly:
130 // 131 //
131 // - A suspend request is started. 132 // - A suspend request is started.
132 // - The screen is locked. 133 // - The screen is locked.
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 test::TestSessionStateDelegate::SetCanLockScreen(true);
140 SetShouldLockScreenBeforeSuspending(true); 141 SetShouldLockScreenBeforeSuspending(true);
141 142
142 chromeos::PowerManagerClient* client = 143 chromeos::PowerManagerClient* client =
143 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); 144 chromeos::DBusThreadManager::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
OLDNEW
« no previous file with comments | « ash/mus/test/wm_test_base.cc ('k') | ash/test/ash_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698