OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "chrome/browser/automation/ui_controls.h" | 8 #include "chrome/browser/automation/ui_controls.h" |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "views/controls/textfield/textfield.h" | 26 #include "views/controls/textfield/textfield.h" |
27 #include "views/window/window_gtk.h" | 27 #include "views/window/window_gtk.h" |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // An object that wait for lock state and fullscreen state. | 31 // An object that wait for lock state and fullscreen state. |
32 class Waiter : public NotificationObserver { | 32 class Waiter : public NotificationObserver { |
33 public: | 33 public: |
34 explicit Waiter(Browser* browser) | 34 explicit Waiter(Browser* browser) |
35 : browser_(browser) { | 35 : browser_(browser), |
| 36 running_(false) { |
36 registrar_.Add(this, | 37 registrar_.Add(this, |
37 NotificationType::SCREEN_LOCK_STATE_CHANGED, | 38 NotificationType::SCREEN_LOCK_STATE_CHANGED, |
38 NotificationService::AllSources()); | 39 NotificationService::AllSources()); |
39 handler_id_ = g_signal_connect( | 40 handler_id_ = g_signal_connect( |
40 G_OBJECT(browser_->window()->GetNativeHandle()), | 41 G_OBJECT(browser_->window()->GetNativeHandle()), |
41 "window-state-event", | 42 "window-state-event", |
42 G_CALLBACK(OnWindowStateEventThunk), | 43 G_CALLBACK(OnWindowStateEventThunk), |
43 this); | 44 this); |
44 } | 45 } |
45 | 46 |
46 ~Waiter() { | 47 ~Waiter() { |
47 g_signal_handler_disconnect( | 48 g_signal_handler_disconnect( |
48 G_OBJECT(browser_->window()->GetNativeHandle()), | 49 G_OBJECT(browser_->window()->GetNativeHandle()), |
49 handler_id_); | 50 handler_id_); |
50 } | 51 } |
51 | 52 |
52 virtual void Observe(NotificationType type, | 53 virtual void Observe(NotificationType type, |
53 const NotificationSource& source, | 54 const NotificationSource& source, |
54 const NotificationDetails& details) { | 55 const NotificationDetails& details) { |
55 DCHECK(type == NotificationType::SCREEN_LOCK_STATE_CHANGED); | 56 DCHECK(type == NotificationType::SCREEN_LOCK_STATE_CHANGED); |
56 MessageLoop::current()->Quit(); | 57 if (running_) |
| 58 MessageLoop::current()->Quit(); |
57 } | 59 } |
58 | 60 |
59 // Wait until the two conditions are met. | 61 // Wait until the two conditions are met. |
60 void Wait(bool locker_state, bool fullscreen) { | 62 void Wait(bool locker_state, bool fullscreen) { |
| 63 running_ = true; |
61 scoped_ptr<chromeos::test::ScreenLockerTester> | 64 scoped_ptr<chromeos::test::ScreenLockerTester> |
62 tester(chromeos::ScreenLocker::GetTester()); | 65 tester(chromeos::ScreenLocker::GetTester()); |
63 while (tester->IsLocked() != locker_state || | 66 while (tester->IsLocked() != locker_state || |
64 browser_->window()->IsFullscreen() != fullscreen) { | 67 browser_->window()->IsFullscreen() != fullscreen) { |
65 ui_test_utils::RunMessageLoop(); | 68 ui_test_utils::RunMessageLoop(); |
66 } | 69 } |
67 // Make sure all pending tasks are executed. | 70 // Make sure all pending tasks are executed. |
68 ui_test_utils::RunAllPendingInMessageLoop(); | 71 ui_test_utils::RunAllPendingInMessageLoop(); |
| 72 running_ = false; |
69 } | 73 } |
70 | 74 |
71 CHROMEGTK_CALLBACK_1(Waiter, gboolean, OnWindowStateEvent, | 75 CHROMEGTK_CALLBACK_1(Waiter, gboolean, OnWindowStateEvent, |
72 GdkEventWindowState*); | 76 GdkEventWindowState*); |
73 | 77 |
74 private: | 78 private: |
75 Browser* browser_; | 79 Browser* browser_; |
76 gulong handler_id_; | 80 gulong handler_id_; |
77 NotificationRegistrar registrar_; | 81 NotificationRegistrar registrar_; |
78 | 82 |
| 83 // Are we currently running the message loop? |
| 84 bool running_; |
| 85 |
79 DISALLOW_COPY_AND_ASSIGN(Waiter); | 86 DISALLOW_COPY_AND_ASSIGN(Waiter); |
80 }; | 87 }; |
81 | 88 |
82 gboolean Waiter::OnWindowStateEvent(GtkWidget* widget, | 89 gboolean Waiter::OnWindowStateEvent(GtkWidget* widget, |
83 GdkEventWindowState* event) { | 90 GdkEventWindowState* event) { |
84 MessageLoop::current()->Quit(); | 91 MessageLoop::current()->Quit(); |
85 return false; | 92 return false; |
86 } | 93 } |
87 | 94 |
88 } // namespace | 95 } // namespace |
(...skipping 16 matching lines...) Expand all Loading... |
105 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockRequested()) | 112 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockRequested()) |
106 .Times(1) | 113 .Times(1) |
107 .RetiresOnSaturation(); | 114 .RetiresOnSaturation(); |
108 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) | 115 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) |
109 .Times(1) | 116 .Times(1) |
110 .RetiresOnSaturation(); | 117 .RetiresOnSaturation(); |
111 UserManager::Get()->OffTheRecordUserLoggedIn(); | 118 UserManager::Get()->OffTheRecordUserLoggedIn(); |
112 ScreenLocker::Show(); | 119 ScreenLocker::Show(); |
113 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); | 120 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); |
114 tester->EmulateWindowManagerReady(); | 121 tester->EmulateWindowManagerReady(); |
115 ui_test_utils::WaitForNotification( | 122 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) |
116 NotificationType::SCREEN_LOCK_STATE_CHANGED); | 123 ui_test_utils::WaitForNotification( |
| 124 NotificationType::SCREEN_LOCK_STATE_CHANGED); |
117 EXPECT_TRUE(tester->IsLocked()); | 125 EXPECT_TRUE(tester->IsLocked()); |
118 tester->InjectMockAuthenticator("", ""); | 126 tester->InjectMockAuthenticator("", ""); |
119 | 127 |
120 unlock(tester->GetWidget()); | 128 unlock(tester->GetWidget()); |
121 | 129 |
122 ui_test_utils::RunAllPendingInMessageLoop(); | 130 ui_test_utils::RunAllPendingInMessageLoop(); |
123 EXPECT_TRUE(tester->IsLocked()); | 131 EXPECT_TRUE(tester->IsLocked()); |
124 | 132 |
125 // Emulate LockScreen request from PowerManager (via SessionManager). | 133 // Emulate LockScreen request from PowerManager (via SessionManager). |
126 ScreenLocker::Hide(); | 134 ScreenLocker::Hide(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockRequested()) | 170 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockRequested()) |
163 .Times(1) | 171 .Times(1) |
164 .RetiresOnSaturation(); | 172 .RetiresOnSaturation(); |
165 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) | 173 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) |
166 .Times(1) | 174 .Times(1) |
167 .RetiresOnSaturation(); | 175 .RetiresOnSaturation(); |
168 UserManager::Get()->UserLoggedIn("user"); | 176 UserManager::Get()->UserLoggedIn("user"); |
169 ScreenLocker::Show(); | 177 ScreenLocker::Show(); |
170 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); | 178 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); |
171 tester->EmulateWindowManagerReady(); | 179 tester->EmulateWindowManagerReady(); |
172 ui_test_utils::WaitForNotification( | 180 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) |
173 NotificationType::SCREEN_LOCK_STATE_CHANGED); | 181 ui_test_utils::WaitForNotification( |
| 182 NotificationType::SCREEN_LOCK_STATE_CHANGED); |
174 | 183 |
175 // Test to make sure that the widget is actually appearing and is of | 184 // Test to make sure that the widget is actually appearing and is of |
176 // reasonable size, preventing a regression of | 185 // reasonable size, preventing a regression of |
177 // http://code.google.com/p/chromium-os/issues/detail?id=5987 | 186 // http://code.google.com/p/chromium-os/issues/detail?id=5987 |
178 gfx::Rect lock_bounds; | 187 gfx::Rect lock_bounds; |
179 tester->GetChildWidget()->GetBounds(&lock_bounds, true); | 188 tester->GetChildWidget()->GetBounds(&lock_bounds, true); |
180 EXPECT_GT(lock_bounds.width(), 10); | 189 EXPECT_GT(lock_bounds.width(), 10); |
181 EXPECT_GT(lock_bounds.height(), 10); | 190 EXPECT_GT(lock_bounds.height(), 10); |
182 | 191 |
183 tester->InjectMockAuthenticator("user", "pass"); | 192 tester->InjectMockAuthenticator("user", "pass"); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 265 |
257 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestShowTwice) { | 266 IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestShowTwice) { |
258 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) | 267 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) |
259 .Times(2) | 268 .Times(2) |
260 .RetiresOnSaturation(); | 269 .RetiresOnSaturation(); |
261 | 270 |
262 UserManager::Get()->UserLoggedIn("user"); | 271 UserManager::Get()->UserLoggedIn("user"); |
263 ScreenLocker::Show(); | 272 ScreenLocker::Show(); |
264 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); | 273 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); |
265 tester->EmulateWindowManagerReady(); | 274 tester->EmulateWindowManagerReady(); |
266 ui_test_utils::WaitForNotification( | 275 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) |
267 NotificationType::SCREEN_LOCK_STATE_CHANGED); | 276 ui_test_utils::WaitForNotification( |
| 277 NotificationType::SCREEN_LOCK_STATE_CHANGED); |
268 EXPECT_TRUE(tester->IsLocked()); | 278 EXPECT_TRUE(tester->IsLocked()); |
269 | 279 |
270 // Calling Show again simply send LockCompleted signal. | 280 // Calling Show again simply send LockCompleted signal. |
271 ScreenLocker::Show(); | 281 ScreenLocker::Show(); |
272 EXPECT_TRUE(tester->IsLocked()); | 282 EXPECT_TRUE(tester->IsLocked()); |
273 | 283 |
274 // Close the locker to match expectations. | 284 // Close the locker to match expectations. |
275 ScreenLocker::Hide(); | 285 ScreenLocker::Hide(); |
276 ui_test_utils::RunAllPendingInMessageLoop(); | 286 ui_test_utils::RunAllPendingInMessageLoop(); |
277 EXPECT_FALSE(tester->IsLocked()); | 287 EXPECT_FALSE(tester->IsLocked()); |
278 } | 288 } |
279 | 289 |
280 } // namespace chromeos | 290 } // namespace chromeos |
OLD | NEW |