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

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

Issue 10825085: Move RunAllPendingInMessageLoop from ui_test_utils.h to test_utils.h, so that it can be reused by c… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/cros/cros_in_process_browser_test.h" 8 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
9 #include "chrome/browser/chromeos/cros/mock_network_library.h" 9 #include "chrome/browser/chromeos/cros/mock_network_library.h"
10 #include "chrome/browser/chromeos/login/mock_authenticator.h" 10 #include "chrome/browser/chromeos/login/mock_authenticator.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Wait until the two conditions are met. 57 // Wait until the two conditions are met.
58 void Wait(bool locker_state, bool fullscreen) { 58 void Wait(bool locker_state, bool fullscreen) {
59 running_ = true; 59 running_ = true;
60 scoped_ptr<chromeos::test::ScreenLockerTester> 60 scoped_ptr<chromeos::test::ScreenLockerTester>
61 tester(chromeos::ScreenLocker::GetTester()); 61 tester(chromeos::ScreenLocker::GetTester());
62 while (tester->IsLocked() != locker_state || 62 while (tester->IsLocked() != locker_state ||
63 browser_->window()->IsFullscreen() != fullscreen) { 63 browser_->window()->IsFullscreen() != fullscreen) {
64 content::RunMessageLoop(); 64 content::RunMessageLoop();
65 } 65 }
66 // Make sure all pending tasks are executed. 66 // Make sure all pending tasks are executed.
67 ui_test_utils::RunAllPendingInMessageLoop(); 67 content::RunAllPendingInMessageLoop();
68 running_ = false; 68 running_ = false;
69 } 69 }
70 70
71 private: 71 private:
72 Browser* browser_; 72 Browser* browser_;
73 content::NotificationRegistrar registrar_; 73 content::NotificationRegistrar registrar_;
74 74
75 // Are we currently running the message loop? 75 // Are we currently running the message loop?
76 bool running_; 76 bool running_;
77 77
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // Test to make sure that the widget is actually appearing and is of 148 // Test to make sure that the widget is actually appearing and is of
149 // reasonable size, preventing a regression of 149 // reasonable size, preventing a regression of
150 // http://code.google.com/p/chromium-os/issues/detail?id=5987 150 // http://code.google.com/p/chromium-os/issues/detail?id=5987
151 gfx::Rect lock_bounds = tester->GetChildWidget()->GetWindowBoundsInScreen(); 151 gfx::Rect lock_bounds = tester->GetChildWidget()->GetWindowBoundsInScreen();
152 EXPECT_GT(lock_bounds.width(), 10); 152 EXPECT_GT(lock_bounds.width(), 10);
153 EXPECT_GT(lock_bounds.height(), 10); 153 EXPECT_GT(lock_bounds.height(), 10);
154 154
155 tester->InjectMockAuthenticator(UserManager::kStubUser, "pass"); 155 tester->InjectMockAuthenticator(UserManager::kStubUser, "pass");
156 EXPECT_TRUE(tester->IsLocked()); 156 EXPECT_TRUE(tester->IsLocked());
157 tester->EnterPassword("fail"); 157 tester->EnterPassword("fail");
158 ui_test_utils::RunAllPendingInMessageLoop(); 158 content::RunAllPendingInMessageLoop();
159 EXPECT_TRUE(tester->IsLocked()); 159 EXPECT_TRUE(tester->IsLocked());
160 tester->EnterPassword("pass"); 160 tester->EnterPassword("pass");
161 ui_test_utils::RunAllPendingInMessageLoop(); 161 content::RunAllPendingInMessageLoop();
162 // Successful authentication simply send a unlock request to PowerManager. 162 // Successful authentication simply send a unlock request to PowerManager.
163 EXPECT_TRUE(tester->IsLocked()); 163 EXPECT_TRUE(tester->IsLocked());
164 164
165 // Emulate LockScreen request from SessionManager. 165 // Emulate LockScreen request from SessionManager.
166 // TODO(oshima): Find out better way to handle this in mock. 166 // TODO(oshima): Find out better way to handle this in mock.
167 ScreenLocker::Hide(); 167 ScreenLocker::Hide();
168 ui_test_utils::RunAllPendingInMessageLoop(); 168 content::RunAllPendingInMessageLoop();
169 EXPECT_FALSE(tester->IsLocked()); 169 EXPECT_FALSE(tester->IsLocked());
170 } 170 }
171 171
172 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestFullscreenExit) { 172 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestFullscreenExit) {
173 EXPECT_CALL(*mock_power_manager_client_, NotifyScreenLockCompleted()) 173 EXPECT_CALL(*mock_power_manager_client_, NotifyScreenLockCompleted())
174 .Times(1) 174 .Times(1)
175 .RetiresOnSaturation(); 175 .RetiresOnSaturation();
176 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 176 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
177 { 177 {
178 Waiter waiter(browser()); 178 Waiter waiter(browser());
179 browser()->fullscreen_controller()->ToggleFullscreenMode(); 179 browser()->fullscreen_controller()->ToggleFullscreenMode();
180 waiter.Wait(false /* not locked */, true /* full screen */); 180 waiter.Wait(false /* not locked */, true /* full screen */);
181 EXPECT_TRUE(browser()->window()->IsFullscreen()); 181 EXPECT_TRUE(browser()->window()->IsFullscreen());
182 EXPECT_FALSE(tester->IsLocked()); 182 EXPECT_FALSE(tester->IsLocked());
183 } 183 }
184 { 184 {
185 Waiter waiter(browser()); 185 Waiter waiter(browser());
186 ScreenLocker::Show(); 186 ScreenLocker::Show();
187 tester->EmulateWindowManagerReady(); 187 tester->EmulateWindowManagerReady();
188 waiter.Wait(true /* locked */, false /* full screen */); 188 waiter.Wait(true /* locked */, false /* full screen */);
189 EXPECT_FALSE(browser()->window()->IsFullscreen()); 189 EXPECT_FALSE(browser()->window()->IsFullscreen());
190 EXPECT_TRUE(tester->IsLocked()); 190 EXPECT_TRUE(tester->IsLocked());
191 } 191 }
192 tester->InjectMockAuthenticator(UserManager::kStubUser, "pass"); 192 tester->InjectMockAuthenticator(UserManager::kStubUser, "pass");
193 tester->EnterPassword("pass"); 193 tester->EnterPassword("pass");
194 ui_test_utils::RunAllPendingInMessageLoop(); 194 content::RunAllPendingInMessageLoop();
195 ScreenLocker::Hide(); 195 ScreenLocker::Hide();
196 ui_test_utils::RunAllPendingInMessageLoop(); 196 content::RunAllPendingInMessageLoop();
197 EXPECT_FALSE(tester->IsLocked()); 197 EXPECT_FALSE(tester->IsLocked());
198 } 198 }
199 199
200 void SimulateKeyPress(views::Widget* widget, ui::KeyboardCode key_code) { 200 void SimulateKeyPress(views::Widget* widget, ui::KeyboardCode key_code) {
201 ui_controls::SendKeyPress(widget->GetNativeWindow(), 201 ui_controls::SendKeyPress(widget->GetNativeWindow(),
202 key_code, false, false, false, false); 202 key_code, false, false, false, false);
203 } 203 }
204 204
205 void UnlockKeyPress(views::Widget* widget) { 205 void UnlockKeyPress(views::Widget* widget) {
206 SimulateKeyPress(widget, ui::VKEY_SPACE); 206 SimulateKeyPress(widget, ui::VKEY_SPACE);
207 } 207 }
208 208
209 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestShowTwice) { 209 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestShowTwice) {
210 EXPECT_CALL(*mock_power_manager_client_, NotifyScreenLockCompleted()) 210 EXPECT_CALL(*mock_power_manager_client_, NotifyScreenLockCompleted())
211 .Times(2) 211 .Times(2)
212 .RetiresOnSaturation(); 212 .RetiresOnSaturation();
213 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 213 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
214 LockScreen(tester.get()); 214 LockScreen(tester.get());
215 215
216 // Ensure there's a profile or this test crashes. 216 // Ensure there's a profile or this test crashes.
217 ProfileManager::GetDefaultProfile(); 217 ProfileManager::GetDefaultProfile();
218 218
219 // Calling Show again simply send LockCompleted signal. 219 // Calling Show again simply send LockCompleted signal.
220 ScreenLocker::Show(); 220 ScreenLocker::Show();
221 EXPECT_TRUE(tester->IsLocked()); 221 EXPECT_TRUE(tester->IsLocked());
222 222
223 // Close the locker to match expectations. 223 // Close the locker to match expectations.
224 ScreenLocker::Hide(); 224 ScreenLocker::Hide();
225 ui_test_utils::RunAllPendingInMessageLoop(); 225 content::RunAllPendingInMessageLoop();
226 EXPECT_FALSE(tester->IsLocked()); 226 EXPECT_FALSE(tester->IsLocked());
227 } 227 }
228 228
229 // TODO(flackr): Find out why the RenderView isn't getting the escape press 229 // TODO(flackr): Find out why the RenderView isn't getting the escape press
230 // and re-enable this test (currently this test is flaky). 230 // and re-enable this test (currently this test is flaky).
231 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestEscape) { 231 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestEscape) {
232 EXPECT_CALL(*mock_power_manager_client_, NotifyScreenLockCompleted()) 232 EXPECT_CALL(*mock_power_manager_client_, NotifyScreenLockCompleted())
233 .Times(1) 233 .Times(1)
234 .RetiresOnSaturation(); 234 .RetiresOnSaturation();
235 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 235 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
236 LockScreen(tester.get()); 236 LockScreen(tester.get());
237 237
238 // Ensure there's a profile or this test crashes. 238 // Ensure there's a profile or this test crashes.
239 ProfileManager::GetDefaultProfile(); 239 ProfileManager::GetDefaultProfile();
240 240
241 tester->SetPassword("password"); 241 tester->SetPassword("password");
242 EXPECT_EQ("password", tester->GetPassword()); 242 EXPECT_EQ("password", tester->GetPassword());
243 // Escape clears the password. 243 // Escape clears the password.
244 SimulateKeyPress(tester->GetWidget(), ui::VKEY_ESCAPE); 244 SimulateKeyPress(tester->GetWidget(), ui::VKEY_ESCAPE);
245 ui_test_utils::RunAllPendingInMessageLoop(); 245 content::RunAllPendingInMessageLoop();
246 EXPECT_EQ("", tester->GetPassword()); 246 EXPECT_EQ("", tester->GetPassword());
247 247
248 // Close the locker to match expectations. 248 // Close the locker to match expectations.
249 ScreenLocker::Hide(); 249 ScreenLocker::Hide();
250 ui_test_utils::RunAllPendingInMessageLoop(); 250 content::RunAllPendingInMessageLoop();
251 EXPECT_FALSE(tester->IsLocked()); 251 EXPECT_FALSE(tester->IsLocked());
252 } 252 }
253 253
254 } // namespace chromeos 254 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698