| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/login/lock/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "ash/wm/window_state.h" | 9 #include "ash/wm/window_state.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/chromeos/login/lock/screen_locker_tester.h" | 14 #include "chrome/browser/chromeos/login/lock/screen_locker_tester.h" |
| 14 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 15 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 19 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 const content::NotificationDetails& details) override { | 63 const content::NotificationDetails& details) override { |
| 63 DCHECK(type == chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED || | 64 DCHECK(type == chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED || |
| 64 type == chrome::NOTIFICATION_FULLSCREEN_CHANGED); | 65 type == chrome::NOTIFICATION_FULLSCREEN_CHANGED); |
| 65 if (running_) | 66 if (running_) |
| 66 base::MessageLoop::current()->QuitWhenIdle(); | 67 base::MessageLoop::current()->QuitWhenIdle(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 // Wait until the two conditions are met. | 70 // Wait until the two conditions are met. |
| 70 void Wait(bool locker_state, bool fullscreen) { | 71 void Wait(bool locker_state, bool fullscreen) { |
| 71 running_ = true; | 72 running_ = true; |
| 72 scoped_ptr<chromeos::test::ScreenLockerTester> | 73 std::unique_ptr<chromeos::test::ScreenLockerTester> tester( |
| 73 tester(chromeos::ScreenLocker::GetTester()); | 74 chromeos::ScreenLocker::GetTester()); |
| 74 while (tester->IsLocked() != locker_state || | 75 while (tester->IsLocked() != locker_state || |
| 75 browser_->window()->IsFullscreen() != fullscreen) { | 76 browser_->window()->IsFullscreen() != fullscreen) { |
| 76 content::RunMessageLoop(); | 77 content::RunMessageLoop(); |
| 77 } | 78 } |
| 78 // Make sure all pending tasks are executed. | 79 // Make sure all pending tasks are executed. |
| 79 content::RunAllPendingInMessageLoop(); | 80 content::RunAllPendingInMessageLoop(); |
| 80 running_ = false; | 81 running_ = false; |
| 81 } | 82 } |
| 82 | 83 |
| 83 private: | 84 private: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // Verifies if LockScreenDismissed() was called once. | 117 // Verifies if LockScreenDismissed() was called once. |
| 117 bool VerifyLockScreenDismissed() { | 118 bool VerifyLockScreenDismissed() { |
| 118 return 1 == fake_session_manager_client_-> | 119 return 1 == fake_session_manager_client_-> |
| 119 notify_lock_screen_dismissed_call_count(); | 120 notify_lock_screen_dismissed_call_count(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 private: | 123 private: |
| 123 void SetUpInProcessBrowserTestFixture() override { | 124 void SetUpInProcessBrowserTestFixture() override { |
| 124 fake_session_manager_client_ = new FakeSessionManagerClient; | 125 fake_session_manager_client_ = new FakeSessionManagerClient; |
| 125 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 126 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 126 scoped_ptr<SessionManagerClient>(fake_session_manager_client_)); | 127 std::unique_ptr<SessionManagerClient>(fake_session_manager_client_)); |
| 127 | 128 |
| 128 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 129 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 129 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 130 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| 130 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 131 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void SetUpCommandLine(base::CommandLine* command_line) override { | 134 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 134 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 135 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
| 135 } | 136 } |
| 136 | 137 |
| 137 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; | 138 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; |
| 138 | 139 |
| 139 DISALLOW_COPY_AND_ASSIGN(ScreenLockerTest); | 140 DISALLOW_COPY_AND_ASSIGN(ScreenLockerTest); |
| 140 }; | 141 }; |
| 141 | 142 |
| 142 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestBasic) { | 143 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestBasic) { |
| 143 ScreenLocker::Show(); | 144 ScreenLocker::Show(); |
| 144 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); | 145 std::unique_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); |
| 145 tester->EmulateWindowManagerReady(); | 146 tester->EmulateWindowManagerReady(); |
| 146 content::WindowedNotificationObserver lock_state_observer( | 147 content::WindowedNotificationObserver lock_state_observer( |
| 147 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 148 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 148 content::NotificationService::AllSources()); | 149 content::NotificationService::AllSources()); |
| 149 if (!tester->IsLocked()) | 150 if (!tester->IsLocked()) |
| 150 lock_state_observer.Wait(); | 151 lock_state_observer.Wait(); |
| 151 | 152 |
| 152 // Test to make sure that the widget is actually appearing and is of | 153 // Test to make sure that the widget is actually appearing and is of |
| 153 // reasonable size, preventing a regression of | 154 // reasonable size, preventing a regression of |
| 154 // http://code.google.com/p/chromium-os/issues/detail?id=5987 | 155 // http://code.google.com/p/chromium-os/issues/detail?id=5987 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 182 content::RunAllPendingInMessageLoop(); | 183 content::RunAllPendingInMessageLoop(); |
| 183 ScreenLocker::HandleLockScreenRequest(); | 184 ScreenLocker::HandleLockScreenRequest(); |
| 184 } | 185 } |
| 185 | 186 |
| 186 // Test how locking the screen affects an active fullscreen window. | 187 // Test how locking the screen affects an active fullscreen window. |
| 187 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestFullscreenExit) { | 188 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestFullscreenExit) { |
| 188 // 1) If the active browser window is in fullscreen and the fullscreen window | 189 // 1) If the active browser window is in fullscreen and the fullscreen window |
| 189 // does not have all the pixels (e.g. the shelf is auto hidden instead of | 190 // does not have all the pixels (e.g. the shelf is auto hidden instead of |
| 190 // hidden), locking the screen should not exit fullscreen. The shelf is | 191 // hidden), locking the screen should not exit fullscreen. The shelf is |
| 191 // auto hidden when in immersive fullscreen. | 192 // auto hidden when in immersive fullscreen. |
| 192 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); | 193 std::unique_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); |
| 193 BrowserWindow* browser_window = browser()->window(); | 194 BrowserWindow* browser_window = browser()->window(); |
| 194 ash::wm::WindowState* window_state = ash::wm::GetWindowState( | 195 ash::wm::WindowState* window_state = ash::wm::GetWindowState( |
| 195 browser_window->GetNativeWindow()); | 196 browser_window->GetNativeWindow()); |
| 196 { | 197 { |
| 197 Waiter waiter(browser()); | 198 Waiter waiter(browser()); |
| 198 browser() | 199 browser() |
| 199 ->exclusive_access_manager() | 200 ->exclusive_access_manager() |
| 200 ->fullscreen_controller() | 201 ->fullscreen_controller() |
| 201 ->ToggleBrowserFullscreenMode(); | 202 ->ToggleBrowserFullscreenMode(); |
| 202 waiter.Wait(false /* not locked */, true /* full screen */); | 203 waiter.Wait(false /* not locked */, true /* full screen */); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 void SimulateKeyPress(views::Widget* widget, ui::KeyboardCode key_code) { | 270 void SimulateKeyPress(views::Widget* widget, ui::KeyboardCode key_code) { |
| 270 ui_controls::SendKeyPress(widget->GetNativeWindow(), | 271 ui_controls::SendKeyPress(widget->GetNativeWindow(), |
| 271 key_code, false, false, false, false); | 272 key_code, false, false, false, false); |
| 272 } | 273 } |
| 273 | 274 |
| 274 void UnlockKeyPress(views::Widget* widget) { | 275 void UnlockKeyPress(views::Widget* widget) { |
| 275 SimulateKeyPress(widget, ui::VKEY_SPACE); | 276 SimulateKeyPress(widget, ui::VKEY_SPACE); |
| 276 } | 277 } |
| 277 | 278 |
| 278 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestShowTwice) { | 279 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestShowTwice) { |
| 279 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); | 280 std::unique_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); |
| 280 LockScreen(tester.get()); | 281 LockScreen(tester.get()); |
| 281 | 282 |
| 282 // Calling Show again simply send LockCompleted signal. | 283 // Calling Show again simply send LockCompleted signal. |
| 283 ScreenLocker::Show(); | 284 ScreenLocker::Show(); |
| 284 EXPECT_TRUE(tester->IsLocked()); | 285 EXPECT_TRUE(tester->IsLocked()); |
| 285 EXPECT_EQ( | 286 EXPECT_EQ( |
| 286 2, | 287 2, |
| 287 fake_session_manager_client_->notify_lock_screen_shown_call_count()); | 288 fake_session_manager_client_->notify_lock_screen_shown_call_count()); |
| 288 | 289 |
| 289 | 290 |
| 290 // Close the locker to match expectations. | 291 // Close the locker to match expectations. |
| 291 ScreenLocker::Hide(); | 292 ScreenLocker::Hide(); |
| 292 content::RunAllPendingInMessageLoop(); | 293 content::RunAllPendingInMessageLoop(); |
| 293 EXPECT_FALSE(tester->IsLocked()); | 294 EXPECT_FALSE(tester->IsLocked()); |
| 294 EXPECT_TRUE(VerifyLockScreenDismissed()); | 295 EXPECT_TRUE(VerifyLockScreenDismissed()); |
| 295 } | 296 } |
| 296 | 297 |
| 297 // TODO(flackr): Find out why the RenderView isn't getting the escape press | 298 // TODO(flackr): Find out why the RenderView isn't getting the escape press |
| 298 // and re-enable this test (currently this test is flaky). | 299 // and re-enable this test (currently this test is flaky). |
| 299 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestEscape) { | 300 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestEscape) { |
| 300 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); | 301 std::unique_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); |
| 301 LockScreen(tester.get()); | 302 LockScreen(tester.get()); |
| 302 | 303 |
| 303 EXPECT_EQ( | 304 EXPECT_EQ( |
| 304 1, | 305 1, |
| 305 fake_session_manager_client_->notify_lock_screen_shown_call_count()); | 306 fake_session_manager_client_->notify_lock_screen_shown_call_count()); |
| 306 | 307 |
| 307 tester->SetPassword("password"); | 308 tester->SetPassword("password"); |
| 308 EXPECT_EQ("password", tester->GetPassword()); | 309 EXPECT_EQ("password", tester->GetPassword()); |
| 309 // Escape clears the password. | 310 // Escape clears the password. |
| 310 SimulateKeyPress(tester->GetWidget(), ui::VKEY_ESCAPE); | 311 SimulateKeyPress(tester->GetWidget(), ui::VKEY_ESCAPE); |
| 311 content::RunAllPendingInMessageLoop(); | 312 content::RunAllPendingInMessageLoop(); |
| 312 EXPECT_EQ("", tester->GetPassword()); | 313 EXPECT_EQ("", tester->GetPassword()); |
| 313 | 314 |
| 314 // Close the locker to match expectations. | 315 // Close the locker to match expectations. |
| 315 ScreenLocker::Hide(); | 316 ScreenLocker::Hide(); |
| 316 content::RunAllPendingInMessageLoop(); | 317 content::RunAllPendingInMessageLoop(); |
| 317 EXPECT_FALSE(tester->IsLocked()); | 318 EXPECT_FALSE(tester->IsLocked()); |
| 318 EXPECT_TRUE(VerifyLockScreenDismissed()); | 319 EXPECT_TRUE(VerifyLockScreenDismissed()); |
| 319 } | 320 } |
| 320 | 321 |
| 321 } // namespace chromeos | 322 } // namespace chromeos |
| OLD | NEW |