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

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

Issue 2446453002: Refactor ShouldLockScreenBeforeSuspending to ShouldLockScreenAutomatically (Closed)
Patch Set: comment Created 4 years, 1 month 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/system/chromeos/power/power_event_observer.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/common/test/test_session_state_delegate.h" 9 #include "ash/common/test/test_session_state_delegate.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 }; 52 };
53 53
54 TEST_F(PowerEventObserverTest, LockBeforeSuspend) { 54 TEST_F(PowerEventObserverTest, LockBeforeSuspend) {
55 chromeos::PowerManagerClient* client = 55 chromeos::PowerManagerClient* client =
56 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); 56 chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
57 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); 57 ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
58 58
59 // 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
60 // that the system is about to suspend. 60 // that the system is about to suspend.
61 test::TestSessionStateDelegate::SetCanLockScreen(true); 61 test::TestSessionStateDelegate::SetCanLockScreen(true);
62 SetShouldLockScreenBeforeSuspending(true); 62 SetShouldLockScreenAutomatically(true);
63 observer_->SuspendImminent(); 63 observer_->SuspendImminent();
64 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); 64 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks());
65 65
66 // 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
67 // lock screen animations have completed. 67 // lock screen animations have completed.
68 observer_->ScreenIsLocked(); 68 observer_->ScreenIsLocked();
69 observer_->OnLockAnimationsComplete(); 69 observer_->OnLockAnimationsComplete();
70 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); 70 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
71 71
72 // If the system is already locked, no callback should be requested. 72 // If the system is already locked, no callback should be requested.
73 observer_->SuspendDone(base::TimeDelta()); 73 observer_->SuspendDone(base::TimeDelta());
74 observer_->ScreenIsUnlocked(); 74 observer_->ScreenIsUnlocked();
75 observer_->ScreenIsLocked(); 75 observer_->ScreenIsLocked();
76 observer_->OnLockAnimationsComplete(); 76 observer_->OnLockAnimationsComplete();
77 observer_->SuspendImminent(); 77 observer_->SuspendImminent();
78 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); 78 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
79 79
80 // It also shouldn't request a callback if it isn't instructed to lock the 80 // It also shouldn't request a callback if it isn't instructed to lock the
81 // screen. 81 // screen.
82 observer_->SuspendDone(base::TimeDelta()); 82 observer_->SuspendDone(base::TimeDelta());
83 SetShouldLockScreenBeforeSuspending(false); 83 SetShouldLockScreenAutomatically(false);
84 observer_->SuspendImminent(); 84 observer_->SuspendImminent();
85 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); 85 EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
86 } 86 }
87 87
88 TEST_F(PowerEventObserverTest, SetInvisibleBeforeSuspend) { 88 TEST_F(PowerEventObserverTest, SetInvisibleBeforeSuspend) {
89 // Tests that all the Compositors are marked invisible before a suspend 89 // 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. 90 // request when the screen is not supposed to be locked before a suspend.
91 EXPECT_EQ(1, GetNumVisibleCompositors()); 91 EXPECT_EQ(1, GetNumVisibleCompositors());
92 92
93 observer_->SuspendImminent(); 93 observer_->SuspendImminent();
94 EXPECT_EQ(0, GetNumVisibleCompositors()); 94 EXPECT_EQ(0, GetNumVisibleCompositors());
95 observer_->SuspendDone(base::TimeDelta()); 95 observer_->SuspendDone(base::TimeDelta());
96 96
97 // 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
98 // animations have completed. 98 // animations have completed.
99 test::TestSessionStateDelegate::SetCanLockScreen(true); 99 test::TestSessionStateDelegate::SetCanLockScreen(true);
100 SetShouldLockScreenBeforeSuspending(true); 100 SetShouldLockScreenAutomatically(true);
101 101
102 observer_->SuspendImminent(); 102 observer_->SuspendImminent();
103 EXPECT_EQ(1, GetNumVisibleCompositors()); 103 EXPECT_EQ(1, GetNumVisibleCompositors());
104 104
105 observer_->ScreenIsLocked(); 105 observer_->ScreenIsLocked();
106 EXPECT_EQ(1, GetNumVisibleCompositors()); 106 EXPECT_EQ(1, GetNumVisibleCompositors());
107 107
108 observer_->OnLockAnimationsComplete(); 108 observer_->OnLockAnimationsComplete();
109 EXPECT_EQ(0, GetNumVisibleCompositors()); 109 EXPECT_EQ(0, GetNumVisibleCompositors());
110 110
111 observer_->SuspendDone(base::TimeDelta()); 111 observer_->SuspendDone(base::TimeDelta());
112 EXPECT_EQ(1, GetNumVisibleCompositors()); 112 EXPECT_EQ(1, GetNumVisibleCompositors());
113 } 113 }
114 114
115 TEST_F(PowerEventObserverTest, CanceledSuspend) { 115 TEST_F(PowerEventObserverTest, CanceledSuspend) {
116 // 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
117 // canceled or the system resumes before the lock screen is ready. 117 // canceled or the system resumes before the lock screen is ready.
118 test::TestSessionStateDelegate::SetCanLockScreen(true); 118 test::TestSessionStateDelegate::SetCanLockScreen(true);
119 SetShouldLockScreenBeforeSuspending(true); 119 SetShouldLockScreenAutomatically(true);
120 observer_->SuspendImminent(); 120 observer_->SuspendImminent();
121 EXPECT_EQ(1, GetNumVisibleCompositors()); 121 EXPECT_EQ(1, GetNumVisibleCompositors());
122 122
123 observer_->SuspendDone(base::TimeDelta()); 123 observer_->SuspendDone(base::TimeDelta());
124 observer_->ScreenIsLocked(); 124 observer_->ScreenIsLocked();
125 observer_->OnLockAnimationsComplete(); 125 observer_->OnLockAnimationsComplete();
126 EXPECT_EQ(1, GetNumVisibleCompositors()); 126 EXPECT_EQ(1, GetNumVisibleCompositors());
127 } 127 }
128 128
129 TEST_F(PowerEventObserverTest, DelayResuspendForLockAnimations) { 129 TEST_F(PowerEventObserverTest, DelayResuspendForLockAnimations) {
130 // Tests that the following order of events is handled correctly: 130 // Tests that the following order of events is handled correctly:
131 // 131 //
132 // - A suspend request is started. 132 // - A suspend request is started.
133 // - The screen is locked. 133 // - The screen is locked.
134 // - The suspend request is canceled. 134 // - The suspend request is canceled.
135 // - Another suspend request is started. 135 // - Another suspend request is started.
136 // - The screen lock animations complete. 136 // - The screen lock animations complete.
137 // 137 //
138 // 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
139 // the animations have completed. 139 // the animations have completed.
140 test::TestSessionStateDelegate::SetCanLockScreen(true); 140 test::TestSessionStateDelegate::SetCanLockScreen(true);
141 SetShouldLockScreenBeforeSuspending(true); 141 SetShouldLockScreenAutomatically(true);
142 142
143 chromeos::PowerManagerClient* client = 143 chromeos::PowerManagerClient* client =
144 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); 144 chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
145 observer_->SuspendImminent(); 145 observer_->SuspendImminent();
146 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); 146 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks());
147 147
148 observer_->ScreenIsLocked(); 148 observer_->ScreenIsLocked();
149 observer_->SuspendDone(base::TimeDelta()); 149 observer_->SuspendDone(base::TimeDelta());
150 observer_->SuspendImminent(); 150 observer_->SuspendImminent();
151 151
152 // The expected number of suspend readiness callbacks is 2 because the 152 // 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 153 // observer has not run the callback that it got from the first suspend
154 // request. The real PowerManagerClient would reset its internal counter in 154 // request. The real PowerManagerClient would reset its internal counter in
155 // this situation but the stub client is not that smart. 155 // this situation but the stub client is not that smart.
156 EXPECT_EQ(2, client->GetNumPendingSuspendReadinessCallbacks()); 156 EXPECT_EQ(2, client->GetNumPendingSuspendReadinessCallbacks());
157 157
158 observer_->OnLockAnimationsComplete(); 158 observer_->OnLockAnimationsComplete();
159 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); 159 EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks());
160 EXPECT_EQ(0, GetNumVisibleCompositors()); 160 EXPECT_EQ(0, GetNumVisibleCompositors());
161 } 161 }
162 162
163 } // namespace ash 163 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/power/power_event_observer.cc ('k') | ash/test/ash_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698