OLD | NEW |
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/cros/mock_screen_lock_library.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" |
21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
22 #include "content/common/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "views/controls/textfield/textfield.h" | 25 #include "views/controls/textfield/textfield.h" |
26 #include "views/widget/native_widget_gtk.h" | 26 #include "views/widget/native_widget_gtk.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // An object that wait for lock state and fullscreen state. | 30 // An object that wait for lock state and fullscreen state. |
31 class Waiter : public content::NotificationObserver { | 31 class Waiter : public content::NotificationObserver { |
32 public: | 32 public: |
33 explicit Waiter(Browser* browser) | 33 explicit Waiter(Browser* browser) |
34 : browser_(browser), | 34 : browser_(browser), |
35 running_(false) { | 35 running_(false) { |
36 registrar_.Add(this, | 36 registrar_.Add(this, |
37 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 37 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
38 NotificationService::AllSources()); | 38 content::NotificationService::AllSources()); |
39 handler_id_ = g_signal_connect( | 39 handler_id_ = g_signal_connect( |
40 G_OBJECT(browser_->window()->GetNativeHandle()), | 40 G_OBJECT(browser_->window()->GetNativeHandle()), |
41 "window-state-event", | 41 "window-state-event", |
42 G_CALLBACK(OnWindowStateEventThunk), | 42 G_CALLBACK(OnWindowStateEventThunk), |
43 this); | 43 this); |
44 } | 44 } |
45 | 45 |
46 ~Waiter() { | 46 ~Waiter() { |
47 g_signal_handler_disconnect( | 47 g_signal_handler_disconnect( |
48 G_OBJECT(browser_->window()->GetNativeHandle()), | 48 G_OBJECT(browser_->window()->GetNativeHandle()), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 .RetiresOnSaturation(); | 111 .RetiresOnSaturation(); |
112 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) | 112 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) |
113 .Times(1) | 113 .Times(1) |
114 .RetiresOnSaturation(); | 114 .RetiresOnSaturation(); |
115 UserManager::Get()->OffTheRecordUserLoggedIn(); | 115 UserManager::Get()->OffTheRecordUserLoggedIn(); |
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 NotificationService::AllSources()); | 121 content::NotificationService::AllSources()); |
122 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) | 122 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) |
123 lock_state_observer.Wait(); | 123 lock_state_observer.Wait(); |
124 EXPECT_TRUE(tester->IsLocked()); | 124 EXPECT_TRUE(tester->IsLocked()); |
125 tester->InjectMockAuthenticator("", ""); | 125 tester->InjectMockAuthenticator("", ""); |
126 | 126 |
127 unlock(tester->GetWidget()); | 127 unlock(tester->GetWidget()); |
128 | 128 |
129 ui_test_utils::RunAllPendingInMessageLoop(); | 129 ui_test_utils::RunAllPendingInMessageLoop(); |
130 EXPECT_TRUE(tester->IsLocked()); | 130 EXPECT_TRUE(tester->IsLocked()); |
131 | 131 |
132 // Emulate LockScreen request from PowerManager (via SessionManager). | 132 // Emulate LockScreen request from PowerManager (via SessionManager). |
133 ScreenLocker::Hide(); | 133 ScreenLocker::Hide(); |
134 ui_test_utils::RunAllPendingInMessageLoop(); | 134 ui_test_utils::RunAllPendingInMessageLoop(); |
135 EXPECT_FALSE(tester->IsLocked()); | 135 EXPECT_FALSE(tester->IsLocked()); |
136 } | 136 } |
137 | 137 |
138 void LockScreenWithUser(test::ScreenLockerTester* tester, | 138 void LockScreenWithUser(test::ScreenLockerTester* tester, |
139 const std::string& user) { | 139 const std::string& user) { |
140 UserManager::Get()->UserLoggedIn(user); | 140 UserManager::Get()->UserLoggedIn(user); |
141 ScreenLocker::Show(); | 141 ScreenLocker::Show(); |
142 tester->EmulateWindowManagerReady(); | 142 tester->EmulateWindowManagerReady(); |
143 ui_test_utils::WindowedNotificationObserver lock_state_observer( | 143 ui_test_utils::WindowedNotificationObserver lock_state_observer( |
144 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 144 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
145 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 cros_mock_->InitMockScreenLockLibrary(); |
155 mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library(); | 155 mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library(); |
(...skipping 25 matching lines...) Expand all Loading... |
181 .RetiresOnSaturation(); | 181 .RetiresOnSaturation(); |
182 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) | 182 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) |
183 .Times(1) | 183 .Times(1) |
184 .RetiresOnSaturation(); | 184 .RetiresOnSaturation(); |
185 UserManager::Get()->UserLoggedIn("user"); | 185 UserManager::Get()->UserLoggedIn("user"); |
186 ScreenLocker::Show(); | 186 ScreenLocker::Show(); |
187 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); | 187 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); |
188 tester->EmulateWindowManagerReady(); | 188 tester->EmulateWindowManagerReady(); |
189 ui_test_utils::WindowedNotificationObserver lock_state_observer( | 189 ui_test_utils::WindowedNotificationObserver lock_state_observer( |
190 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 190 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
191 NotificationService::AllSources()); | 191 content::NotificationService::AllSources()); |
192 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) | 192 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) |
193 lock_state_observer.Wait(); | 193 lock_state_observer.Wait(); |
194 | 194 |
195 // Test to make sure that the widget is actually appearing and is of | 195 // Test to make sure that the widget is actually appearing and is of |
196 // reasonable size, preventing a regression of | 196 // reasonable size, preventing a regression of |
197 // http://code.google.com/p/chromium-os/issues/detail?id=5987 | 197 // http://code.google.com/p/chromium-os/issues/detail?id=5987 |
198 gfx::Rect lock_bounds = tester->GetChildWidget()->GetWindowScreenBounds(); | 198 gfx::Rect lock_bounds = tester->GetChildWidget()->GetWindowScreenBounds(); |
199 EXPECT_GT(lock_bounds.width(), 10); | 199 EXPECT_GT(lock_bounds.width(), 10); |
200 EXPECT_GT(lock_bounds.height(), 10); | 200 EXPECT_GT(lock_bounds.height(), 10); |
201 | 201 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 ui_test_utils::RunAllPendingInMessageLoop(); | 313 ui_test_utils::RunAllPendingInMessageLoop(); |
314 EXPECT_EQ("", tester->GetPassword()); | 314 EXPECT_EQ("", tester->GetPassword()); |
315 | 315 |
316 // Close the locker to match expectations. | 316 // Close the locker to match expectations. |
317 ScreenLocker::Hide(); | 317 ScreenLocker::Hide(); |
318 ui_test_utils::RunAllPendingInMessageLoop(); | 318 ui_test_utils::RunAllPendingInMessageLoop(); |
319 EXPECT_FALSE(tester->IsLocked()); | 319 EXPECT_FALSE(tester->IsLocked()); |
320 } | 320 } |
321 | 321 |
322 } // namespace chromeos | 322 } // namespace chromeos |
OLD | NEW |