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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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) 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_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/ui_test_utils.h" 20 #include "chrome/test/ui_test_utils.h"
21 #include "content/common/content_notification_types.h"
21 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
22 #include "content/common/notification_type.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 26
27 namespace { 27 namespace {
28 28
29 // An object that wait for lock state and fullscreen state. 29 // An object that wait for lock state and fullscreen state.
30 class Waiter : public NotificationObserver { 30 class Waiter : public NotificationObserver {
31 public: 31 public:
32 explicit Waiter(Browser* browser) 32 explicit Waiter(Browser* browser)
33 : browser_(browser), 33 : browser_(browser),
34 running_(false) { 34 running_(false) {
35 registrar_.Add(this, 35 registrar_.Add(this,
36 NotificationType::SCREEN_LOCK_STATE_CHANGED, 36 chrome::SCREEN_LOCK_STATE_CHANGED,
37 NotificationService::AllSources()); 37 NotificationService::AllSources());
38 handler_id_ = g_signal_connect( 38 handler_id_ = g_signal_connect(
39 G_OBJECT(browser_->window()->GetNativeHandle()), 39 G_OBJECT(browser_->window()->GetNativeHandle()),
40 "window-state-event", 40 "window-state-event",
41 G_CALLBACK(OnWindowStateEventThunk), 41 G_CALLBACK(OnWindowStateEventThunk),
42 this); 42 this);
43 } 43 }
44 44
45 ~Waiter() { 45 ~Waiter() {
46 g_signal_handler_disconnect( 46 g_signal_handler_disconnect(
47 G_OBJECT(browser_->window()->GetNativeHandle()), 47 G_OBJECT(browser_->window()->GetNativeHandle()),
48 handler_id_); 48 handler_id_);
49 } 49 }
50 50
51 virtual void Observe(NotificationType type, 51 virtual void Observe(int type,
52 const NotificationSource& source, 52 const NotificationSource& source,
53 const NotificationDetails& details) { 53 const NotificationDetails& details) {
54 DCHECK(type == NotificationType::SCREEN_LOCK_STATE_CHANGED); 54 DCHECK(type == chrome::SCREEN_LOCK_STATE_CHANGED);
55 if (running_) 55 if (running_)
56 MessageLoop::current()->Quit(); 56 MessageLoop::current()->Quit();
57 } 57 }
58 58
59 // Wait until the two conditions are met. 59 // Wait until the two conditions are met.
60 void Wait(bool locker_state, bool fullscreen) { 60 void Wait(bool locker_state, bool fullscreen) {
61 running_ = true; 61 running_ = true;
62 scoped_ptr<chromeos::test::ScreenLockerTester> 62 scoped_ptr<chromeos::test::ScreenLockerTester>
63 tester(chromeos::ScreenLocker::GetTester()); 63 tester(chromeos::ScreenLocker::GetTester());
64 while (tester->IsLocked() != locker_state || 64 while (tester->IsLocked() != locker_state ||
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 .RetiresOnSaturation(); 110 .RetiresOnSaturation();
111 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) 111 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted())
112 .Times(1) 112 .Times(1)
113 .RetiresOnSaturation(); 113 .RetiresOnSaturation();
114 UserManager::Get()->OffTheRecordUserLoggedIn(); 114 UserManager::Get()->OffTheRecordUserLoggedIn();
115 ScreenLocker::Show(); 115 ScreenLocker::Show();
116 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 116 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
117 tester->EmulateWindowManagerReady(); 117 tester->EmulateWindowManagerReady();
118 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) 118 if (!chromeos::ScreenLocker::GetTester()->IsLocked())
119 ui_test_utils::WaitForNotification( 119 ui_test_utils::WaitForNotification(
120 NotificationType::SCREEN_LOCK_STATE_CHANGED); 120 chrome::SCREEN_LOCK_STATE_CHANGED);
121 EXPECT_TRUE(tester->IsLocked()); 121 EXPECT_TRUE(tester->IsLocked());
122 tester->InjectMockAuthenticator("", ""); 122 tester->InjectMockAuthenticator("", "");
123 123
124 unlock(tester->GetWidget()); 124 unlock(tester->GetWidget());
125 125
126 ui_test_utils::RunAllPendingInMessageLoop(); 126 ui_test_utils::RunAllPendingInMessageLoop();
127 EXPECT_TRUE(tester->IsLocked()); 127 EXPECT_TRUE(tester->IsLocked());
128 128
129 // Emulate LockScreen request from PowerManager (via SessionManager). 129 // Emulate LockScreen request from PowerManager (via SessionManager).
130 ScreenLocker::Hide(); 130 ScreenLocker::Hide();
131 ui_test_utils::RunAllPendingInMessageLoop(); 131 ui_test_utils::RunAllPendingInMessageLoop();
132 EXPECT_FALSE(tester->IsLocked()); 132 EXPECT_FALSE(tester->IsLocked());
133 } 133 }
134 134
135 void LockScreenWithUser(test::ScreenLockerTester* tester, 135 void LockScreenWithUser(test::ScreenLockerTester* tester,
136 const std::string& user) { 136 const std::string& user) {
137 UserManager::Get()->UserLoggedIn(user); 137 UserManager::Get()->UserLoggedIn(user);
138 ScreenLocker::Show(); 138 ScreenLocker::Show();
139 tester->EmulateWindowManagerReady(); 139 tester->EmulateWindowManagerReady();
140 if (!tester->IsLocked()) { 140 if (!tester->IsLocked()) {
141 ui_test_utils::WaitForNotification( 141 ui_test_utils::WaitForNotification(
142 NotificationType::SCREEN_LOCK_STATE_CHANGED); 142 chrome::SCREEN_LOCK_STATE_CHANGED);
143 } 143 }
144 EXPECT_TRUE(tester->IsLocked()); 144 EXPECT_TRUE(tester->IsLocked());
145 } 145 }
146 146
147 private: 147 private:
148 virtual void SetUpInProcessBrowserTestFixture() { 148 virtual void SetUpInProcessBrowserTestFixture() {
149 cros_mock_->InitStatusAreaMocks(); 149 cros_mock_->InitStatusAreaMocks();
150 cros_mock_->InitMockScreenLockLibrary(); 150 cros_mock_->InitMockScreenLockLibrary();
151 mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library(); 151 mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library();
152 EXPECT_CALL(*mock_screen_lock_library_, AddObserver(testing::_)) 152 EXPECT_CALL(*mock_screen_lock_library_, AddObserver(testing::_))
(...skipping 24 matching lines...) Expand all
177 .RetiresOnSaturation(); 177 .RetiresOnSaturation();
178 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted()) 178 EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenLockCompleted())
179 .Times(1) 179 .Times(1)
180 .RetiresOnSaturation(); 180 .RetiresOnSaturation();
181 UserManager::Get()->UserLoggedIn("user"); 181 UserManager::Get()->UserLoggedIn("user");
182 ScreenLocker::Show(); 182 ScreenLocker::Show();
183 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester()); 183 scoped_ptr<test::ScreenLockerTester> tester(ScreenLocker::GetTester());
184 tester->EmulateWindowManagerReady(); 184 tester->EmulateWindowManagerReady();
185 if (!chromeos::ScreenLocker::GetTester()->IsLocked()) 185 if (!chromeos::ScreenLocker::GetTester()->IsLocked())
186 ui_test_utils::WaitForNotification( 186 ui_test_utils::WaitForNotification(
187 NotificationType::SCREEN_LOCK_STATE_CHANGED); 187 chrome::SCREEN_LOCK_STATE_CHANGED);
188 188
189 // Test to make sure that the widget is actually appearing and is of 189 // Test to make sure that the widget is actually appearing and is of
190 // reasonable size, preventing a regression of 190 // reasonable size, preventing a regression of
191 // http://code.google.com/p/chromium-os/issues/detail?id=5987 191 // http://code.google.com/p/chromium-os/issues/detail?id=5987
192 gfx::Rect lock_bounds = tester->GetChildWidget()->GetWindowScreenBounds(); 192 gfx::Rect lock_bounds = tester->GetChildWidget()->GetWindowScreenBounds();
193 EXPECT_GT(lock_bounds.width(), 10); 193 EXPECT_GT(lock_bounds.width(), 10);
194 EXPECT_GT(lock_bounds.height(), 10); 194 EXPECT_GT(lock_bounds.height(), 10);
195 195
196 tester->InjectMockAuthenticator("user", "pass"); 196 tester->InjectMockAuthenticator("user", "pass");
197 EXPECT_TRUE(tester->IsLocked()); 197 EXPECT_TRUE(tester->IsLocked());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ui_test_utils::RunAllPendingInMessageLoop(); 307 ui_test_utils::RunAllPendingInMessageLoop();
308 EXPECT_EQ("", tester->GetPassword()); 308 EXPECT_EQ("", tester->GetPassword());
309 309
310 // Close the locker to match expectations. 310 // Close the locker to match expectations.
311 ScreenLocker::Hide(); 311 ScreenLocker::Hide();
312 ui_test_utils::RunAllPendingInMessageLoop(); 312 ui_test_utils::RunAllPendingInMessageLoop();
313 EXPECT_FALSE(tester->IsLocked()); 313 EXPECT_FALSE(tester->IsLocked());
314 } 314 }
315 315
316 } // namespace chromeos 316 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698