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

Side by Side Diff: chrome/browser/chromeos/login/screen_locker_browsertest.cc

Issue 8664014: chromeos: move screen lock handling to power manager client (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebased Created 9 years 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 | « chrome/browser/chromeos/login/screen_locker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "chrome/browser/automation/ui_controls.h" 8 #include "chrome/browser/automation/ui_controls.h"
9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" 9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
10 #include "chrome/browser/chromeos/cros/mock_screen_lock_library.h" 10 #include "chrome/browser/chromeos/dbus/mock_power_manager_client.h"
11 #include "chrome/browser/chromeos/login/mock_authenticator.h" 11 #include "chrome/browser/chromeos/login/mock_authenticator.h"
12 #include "chrome/browser/chromeos/login/screen_locker.h" 12 #include "chrome/browser/chromeos/login/screen_locker.h"
13 #include "chrome/browser/chromeos/login/screen_locker_tester.h" 13 #include "chrome/browser/chromeos/login/screen_locker_tester.h"
14 #include "chrome/browser/chromeos/login/user_manager.h" 14 #include "chrome/browser/chromeos/login/user_manager.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/views/browser_dialogs.h" 18 #include "chrome/browser/ui/views/browser_dialogs.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 MessageLoop::current()->Quit(); 90 MessageLoop::current()->Quit();
91 return false; 91 return false;
92 } 92 }
93 93
94 } // namespace 94 } // namespace
95 95
96 namespace chromeos { 96 namespace chromeos {
97 97
98 class ScreenLockerTest : public CrosInProcessBrowserTest { 98 class ScreenLockerTest : public CrosInProcessBrowserTest {
99 public: 99 public:
100 ScreenLockerTest() : mock_screen_lock_library_(NULL) { 100 ScreenLockerTest() {
101 } 101 }
102 102
103 protected: 103 protected:
104 MockScreenLockLibrary *mock_screen_lock_library_; 104 MockPowerManagerClient mock_power_manager_client_;
105 105
106 // Test the no password mode with different unlock scheme given by 106 // Test the no password mode with different unlock scheme given by
107 // |unlock| function. 107 // |unlock| function.
108 void TestNoPassword(void (unlock)(views::Widget*)) { 108 void TestNoPassword(void (unlock)(views::Widget*)) {
109 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockRequested()) 109 EXPECT_CALL(mock_power_manager_client_, NotifyScreenUnlockRequested())
110 .Times(1) 110 .Times(1)
111 .RetiresOnSaturation(); 111 .RetiresOnSaturation();
112 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) 112 EXPECT_CALL(mock_power_manager_client_, NotifyScreenLockCompleted())
113 .Times(1) 113 .Times(1)
114 .RetiresOnSaturation(); 114 .RetiresOnSaturation();
115 UserManager::Get()->GuestUserLoggedIn(); 115 UserManager::Get()->GuestUserLoggedIn();
116 ScreenLocker::Show(); 116 ScreenLocker::Show();
117 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 117 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
118 tester->EmulateWindowManagerReady(); 118 tester->EmulateWindowManagerReady();
119 ui_test_utils::WindowedNotificationObserver lock_state_observer( 119 ui_test_utils::WindowedNotificationObserver lock_state_observer(
120 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 120 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
121 content::NotificationService::AllSources()); 121 content::NotificationService::AllSources());
122 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) 122 if (!chromeos::ScreenLocker::GetTester()->IsLocked())
(...skipping 21 matching lines...) Expand all
144 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 144 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
145 content::NotificationService::AllSources()); 145 content::NotificationService::AllSources());
146 if (!tester->IsLocked()) 146 if (!tester->IsLocked())
147 lock_state_observer.Wait(); 147 lock_state_observer.Wait();
148 EXPECT_TRUE(tester->IsLocked()); 148 EXPECT_TRUE(tester->IsLocked());
149 } 149 }
150 150
151 private: 151 private:
152 virtual void SetUpInProcessBrowserTestFixture() { 152 virtual void SetUpInProcessBrowserTestFixture() {
153 cros_mock_->InitStatusAreaMocks(); 153 cros_mock_->InitStatusAreaMocks();
154 cros_mock_->InitMockScreenLockLibrary(); 154 EXPECT_CALL(mock_power_manager_client_, AddObserver(testing::_))
155 mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library();
156 EXPECT_CALL(*mock_screen_lock_library_, AddObserver(testing::_))
157 .Times(1) 155 .Times(1)
158 .RetiresOnSaturation(); 156 .RetiresOnSaturation();
159 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockCompleted()) 157 EXPECT_CALL(mock_power_manager_client_, NotifyScreenUnlockCompleted())
160 .Times(1) 158 .Times(1)
161 .RetiresOnSaturation(); 159 .RetiresOnSaturation();
162 // Expectations for the status are on the screen lock window. 160 // Expectations for the status are on the screen lock window.
163 cros_mock_->SetStatusAreaMocksExpectations(); 161 cros_mock_->SetStatusAreaMocksExpectations();
164 // Expectations for the status area on the browser window. 162 // Expectations for the status area on the browser window.
165 cros_mock_->SetStatusAreaMocksExpectations(); 163 cros_mock_->SetStatusAreaMocksExpectations();
166 } 164 }
167 165
168 virtual void SetUpCommandLine(CommandLine* command_line) { 166 virtual void SetUpCommandLine(CommandLine* command_line) {
169 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 167 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
170 command_line->AppendSwitch(switches::kNoFirstRun); 168 command_line->AppendSwitch(switches::kNoFirstRun);
171 } 169 }
172 170
173 DISALLOW_COPY_AND_ASSIGN(ScreenLockerTest); 171 DISALLOW_COPY_AND_ASSIGN(ScreenLockerTest);
174 }; 172 };
175 173
176 // Temporarily disabling all screen locker tests while investigating the 174 // Temporarily disabling all screen locker tests while investigating the
177 // issue crbug.com/78764. 175 // issue crbug.com/78764.
178 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestBasic) { 176 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestBasic) {
179 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockRequested()) 177 EXPECT_CALL(mock_power_manager_client_, NotifyScreenUnlockRequested())
180 .Times(1) 178 .Times(1)
181 .RetiresOnSaturation(); 179 .RetiresOnSaturation();
182 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) 180 EXPECT_CALL(mock_power_manager_client_, NotifyScreenLockCompleted())
183 .Times(1) 181 .Times(1)
184 .RetiresOnSaturation(); 182 .RetiresOnSaturation();
185 UserManager::Get()->UserLoggedIn("user"); 183 UserManager::Get()->UserLoggedIn("user");
186 ScreenLocker::Show(); 184 ScreenLocker::Show();
187 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 185 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
188 tester->EmulateWindowManagerReady(); 186 tester->EmulateWindowManagerReady();
189 ui_test_utils::WindowedNotificationObserver lock_state_observer( 187 ui_test_utils::WindowedNotificationObserver lock_state_observer(
190 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 188 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
191 content::NotificationService::AllSources()); 189 content::NotificationService::AllSources());
192 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) 190 if (!chromeos::ScreenLocker::GetTester()->IsLocked())
(...skipping 17 matching lines...) Expand all
210 EXPECT_TRUE(tester->IsLocked()); 208 EXPECT_TRUE(tester->IsLocked());
211 209
212 // Emulate LockScreen request from PowerManager (via SessionManager). 210 // Emulate LockScreen request from PowerManager (via SessionManager).
213 // TODO(oshima): Find out better way to handle this in mock. 211 // TODO(oshima): Find out better way to handle this in mock.
214 ScreenLocker::Hide(); 212 ScreenLocker::Hide();
215 ui_test_utils::RunAllPendingInMessageLoop(); 213 ui_test_utils::RunAllPendingInMessageLoop();
216 EXPECT_FALSE(tester->IsLocked()); 214 EXPECT_FALSE(tester->IsLocked());
217 } 215 }
218 216
219 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestFullscreenExit) { 217 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestFullscreenExit) {
220 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockRequested()) 218 EXPECT_CALL(mock_power_manager_client_, NotifyScreenUnlockRequested())
221 .Times(1) 219 .Times(1)
222 .RetiresOnSaturation(); 220 .RetiresOnSaturation();
223 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) 221 EXPECT_CALL(mock_power_manager_client_, NotifyScreenLockCompleted())
224 .Times(1) 222 .Times(1)
225 .RetiresOnSaturation(); 223 .RetiresOnSaturation();
226 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 224 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
227 { 225 {
228 Waiter waiter(browser()); 226 Waiter waiter(browser());
229 browser()->ToggleFullscreenMode(false); 227 browser()->ToggleFullscreenMode(false);
230 waiter.Wait(false /* not locked */, true /* full screen */); 228 waiter.Wait(false /* not locked */, true /* full screen */);
231 EXPECT_TRUE(browser()->window()->IsFullscreen()); 229 EXPECT_TRUE(browser()->window()->IsFullscreen());
232 EXPECT_FALSE(tester->IsLocked()); 230 EXPECT_FALSE(tester->IsLocked());
233 } 231 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 void KeyPress(views::Widget* widget) { 267 void KeyPress(views::Widget* widget) {
270 ui_controls::SendKeyPress(GTK_WINDOW(widget->GetNativeView()), 268 ui_controls::SendKeyPress(GTK_WINDOW(widget->GetNativeView()),
271 ui::VKEY_SPACE, false, false, false, false); 269 ui::VKEY_SPACE, false, false, false, false);
272 } 270 }
273 271
274 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestNoPasswordWithKeyPress) { 272 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestNoPasswordWithKeyPress) {
275 TestNoPassword(KeyPress); 273 TestNoPassword(KeyPress);
276 } 274 }
277 275
278 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestShowTwice) { 276 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestShowTwice) {
279 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) 277 EXPECT_CALL(mock_power_manager_client_, NotifyScreenLockCompleted())
280 .Times(2) 278 .Times(2)
281 .RetiresOnSaturation(); 279 .RetiresOnSaturation();
282 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 280 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
283 LockScreenWithUser(tester.get(), "user"); 281 LockScreenWithUser(tester.get(), "user");
284 282
285 // Ensure there's a profile or this test crashes. 283 // Ensure there's a profile or this test crashes.
286 ProfileManager::GetDefaultProfile(); 284 ProfileManager::GetDefaultProfile();
287 285
288 // Calling Show again simply send LockCompleted signal. 286 // Calling Show again simply send LockCompleted signal.
289 ScreenLocker::Show(); 287 ScreenLocker::Show();
290 EXPECT_TRUE(tester->IsLocked()); 288 EXPECT_TRUE(tester->IsLocked());
291 289
292 // Close the locker to match expectations. 290 // Close the locker to match expectations.
293 ScreenLocker::Hide(); 291 ScreenLocker::Hide();
294 ui_test_utils::RunAllPendingInMessageLoop(); 292 ui_test_utils::RunAllPendingInMessageLoop();
295 EXPECT_FALSE(tester->IsLocked()); 293 EXPECT_FALSE(tester->IsLocked());
296 } 294 }
297 295
298 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestEscape) { 296 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestEscape) {
299 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) 297 EXPECT_CALL(mock_power_manager_client_, NotifyScreenLockCompleted())
300 .Times(1) 298 .Times(1)
301 .RetiresOnSaturation(); 299 .RetiresOnSaturation();
302 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 300 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
303 LockScreenWithUser(tester.get(), "user"); 301 LockScreenWithUser(tester.get(), "user");
304 302
305 // Ensure there's a profile or this test crashes. 303 // Ensure there's a profile or this test crashes.
306 ProfileManager::GetDefaultProfile(); 304 ProfileManager::GetDefaultProfile();
307 305
308 tester->SetPassword("password"); 306 tester->SetPassword("password");
309 EXPECT_EQ("password", tester->GetPassword()); 307 EXPECT_EQ("password", tester->GetPassword());
310 // Escape clears the password. 308 // Escape clears the password.
311 ui_controls::SendKeyPress(GTK_WINDOW(tester->GetWidget()->GetNativeView()), 309 ui_controls::SendKeyPress(GTK_WINDOW(tester->GetWidget()->GetNativeView()),
312 ui::VKEY_ESCAPE, false, false, false, false); 310 ui::VKEY_ESCAPE, false, false, false, false);
313 ui_test_utils::RunAllPendingInMessageLoop(); 311 ui_test_utils::RunAllPendingInMessageLoop();
314 EXPECT_EQ("", tester->GetPassword()); 312 EXPECT_EQ("", tester->GetPassword());
315 313
316 // Close the locker to match expectations. 314 // Close the locker to match expectations.
317 ScreenLocker::Hide(); 315 ScreenLocker::Hide();
318 ui_test_utils::RunAllPendingInMessageLoop(); 316 ui_test_utils::RunAllPendingInMessageLoop();
319 EXPECT_FALSE(tester->IsLocked()); 317 EXPECT_FALSE(tester->IsLocked());
320 } 318 }
321 319
322 } // namespace chromeos 320 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/screen_locker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698