OLD | NEW |
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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/prefs/scoped_user_pref_update.h" |
14 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 18 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
17 #include "chrome/browser/chromeos/login/help_app_launcher.h" | 19 #include "chrome/browser/chromeos/login/help_app_launcher.h" |
18 #include "chrome/browser/chromeos/login/helper.h" | 20 #include "chrome/browser/chromeos/login/helper.h" |
19 #include "chrome/browser/chromeos/login/mock_login_utils.h" | |
20 #include "chrome/browser/chromeos/login/screens/mock_base_screen_delegate.h" | 21 #include "chrome/browser/chromeos/login/screens/mock_base_screen_delegate.h" |
| 22 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 23 #include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" |
21 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_scre
en.h" | 24 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_scre
en.h" |
22 #include "chrome/browser/chromeos/login/ui/mock_login_display.h" | 25 #include "chrome/browser/chromeos/login/ui/mock_login_display.h" |
23 #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h" | 26 #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h" |
24 #include "chrome/browser/chromeos/login/user_flow.h" | |
25 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | |
26 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | |
27 #include "chrome/browser/chromeos/login/wizard_controller.h" | 27 #include "chrome/browser/chromeos/login/wizard_controller.h" |
28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
29 #include "chrome/browser/chromeos/policy/device_local_account.h" | 29 #include "chrome/browser/chromeos/policy/device_local_account.h" |
30 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 30 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
31 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 31 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
32 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 32 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
33 #include "chrome/browser/chromeos/settings/cros_settings.h" | 33 #include "chrome/browser/chromeos/settings/cros_settings.h" |
34 #include "chrome/browser/ui/webui/chromeos/login/supervised_user_creation_screen
_handler.h" | 34 #include "chrome/browser/ui/webui/chromeos/login/supervised_user_creation_screen
_handler.h" |
35 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
36 #include "chrome/test/base/testing_browser_process.h" | 36 #include "chrome/test/base/testing_browser_process.h" |
37 #include "chrome/test/base/testing_profile.h" | |
38 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
39 #include "chromeos/dbus/fake_session_manager_client.h" | 38 #include "chromeos/dbus/fake_session_manager_client.h" |
40 #include "chromeos/login/auth/authenticator.h" | |
41 #include "chromeos/login/auth/key.h" | 39 #include "chromeos/login/auth/key.h" |
42 #include "chromeos/login/auth/mock_authenticator.h" | |
43 #include "chromeos/login/auth/mock_url_fetchers.h" | 40 #include "chromeos/login/auth/mock_url_fetchers.h" |
44 #include "chromeos/login/auth/user_context.h" | 41 #include "chromeos/login/auth/user_context.h" |
45 #include "chromeos/login/user_names.h" | 42 #include "chromeos/login/user_names.h" |
46 #include "chromeos/settings/cros_settings_names.h" | 43 #include "chromeos/settings/cros_settings_names.h" |
47 #include "chromeos/settings/cros_settings_provider.h" | 44 #include "chromeos/settings/cros_settings_provider.h" |
48 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 45 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
49 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 46 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
50 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 47 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
51 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" | 48 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
52 #include "components/policy/core/common/cloud/policy_builder.h" | 49 #include "components/policy/core/common/cloud/policy_builder.h" |
(...skipping 15 matching lines...) Expand all Loading... |
68 using ::testing::WithArg; | 65 using ::testing::WithArg; |
69 using ::testing::_; | 66 using ::testing::_; |
70 | 67 |
71 namespace em = enterprise_management; | 68 namespace em = enterprise_management; |
72 | 69 |
73 namespace chromeos { | 70 namespace chromeos { |
74 | 71 |
75 namespace { | 72 namespace { |
76 | 73 |
77 const char kUsername[] = "test_user@gmail.com"; | 74 const char kUsername[] = "test_user@gmail.com"; |
78 const char kNewUsername[] = "test_new_user@gmail.com"; | |
79 const char kSupervisedUserID[] = "supervised_user@locally-managed.localhost"; | 75 const char kSupervisedUserID[] = "supervised_user@locally-managed.localhost"; |
80 const char kPassword[] = "test_password"; | 76 const char kPassword[] = "test_password"; |
81 | 77 |
82 const char kPublicSessionAccountId[] = "public_session_user@localhost"; | 78 const char kPublicSessionAccountId[] = "public_session_user@localhost"; |
83 const int kAutoLoginNoDelay = 0; | 79 const int kAutoLoginNoDelay = 0; |
84 const int kAutoLoginShortDelay = 1; | 80 const int kAutoLoginShortDelay = 1; |
85 const int kAutoLoginLongDelay = 10000; | 81 const int kAutoLoginLongDelay = 10000; |
86 | 82 |
87 ACTION_P(CreateAuthenticator, user_context) { | |
88 return new MockAuthenticator(arg0, user_context); | |
89 } | |
90 | |
91 void DeleteUserFlow(UserFlow* user_flow) { | |
92 delete user_flow; | |
93 } | |
94 | |
95 // Wait for cros settings to become permanently untrusted and run |callback|. | 83 // Wait for cros settings to become permanently untrusted and run |callback|. |
96 void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure& callback) { | 84 void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure& callback) { |
97 while (true) { | 85 while (true) { |
98 const CrosSettingsProvider::TrustedStatus status = | 86 const CrosSettingsProvider::TrustedStatus status = |
99 CrosSettings::Get()->PrepareTrustedValues(base::Bind( | 87 CrosSettings::Get()->PrepareTrustedValues(base::Bind( |
100 &WaitForPermanentlyUntrustedStatusAndRun, | 88 &WaitForPermanentlyUntrustedStatusAndRun, |
101 callback)); | 89 callback)); |
102 switch (status) { | 90 switch (status) { |
103 case CrosSettingsProvider::PERMANENTLY_UNTRUSTED: | 91 case CrosSettingsProvider::PERMANENTLY_UNTRUSTED: |
104 callback.Run(); | 92 callback.Run(); |
105 return; | 93 return; |
106 case CrosSettingsProvider::TEMPORARILY_UNTRUSTED: | 94 case CrosSettingsProvider::TEMPORARILY_UNTRUSTED: |
107 return; | 95 return; |
108 case CrosSettingsProvider::TRUSTED: | 96 case CrosSettingsProvider::TRUSTED: |
109 content::RunAllPendingInMessageLoop(); | 97 content::RunAllPendingInMessageLoop(); |
110 break; | 98 break; |
111 } | 99 } |
112 } | 100 } |
113 } | 101 } |
114 | 102 |
115 } // namespace | 103 } // namespace |
116 | 104 |
117 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { | 105 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { |
118 protected: | 106 protected: |
119 ExistingUserControllerTest() | 107 ExistingUserControllerTest() : mock_login_display_(NULL) {} |
120 : mock_login_display_(NULL), mock_user_manager_(NULL) {} | |
121 | 108 |
122 ExistingUserController* existing_user_controller() { | 109 ExistingUserController* existing_user_controller() { |
123 return ExistingUserController::current_controller(); | 110 return ExistingUserController::current_controller(); |
124 } | 111 } |
125 | 112 |
126 const ExistingUserController* existing_user_controller() const { | 113 const ExistingUserController* existing_user_controller() const { |
127 return ExistingUserController::current_controller(); | 114 return ExistingUserController::current_controller(); |
128 } | 115 } |
129 | 116 |
130 void SetUpInProcessBrowserTestFixture() override { | 117 void SetUpInProcessBrowserTestFixture() override { |
131 SetUpSessionManager(); | 118 SetUpSessionManager(); |
132 | 119 |
133 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); | 120 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); |
134 | 121 |
135 mock_login_utils_ = new MockLoginUtils(); | |
136 LoginUtils::Set(mock_login_utils_); | |
137 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) | |
138 .Times(1); | |
139 | |
140 mock_login_display_host_.reset(new MockLoginDisplayHost()); | 122 mock_login_display_host_.reset(new MockLoginDisplayHost()); |
141 mock_login_display_ = new MockLoginDisplay(); | 123 mock_login_display_ = new MockLoginDisplay(); |
142 SetUpLoginDisplay(); | 124 SetUpLoginDisplay(); |
143 } | 125 } |
144 | 126 |
145 virtual void SetUpSessionManager() { | 127 virtual void SetUpSessionManager() { |
146 } | 128 } |
147 | 129 |
148 virtual void SetUpLoginDisplay() { | 130 virtual void SetUpLoginDisplay() { |
149 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | 131 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
150 .Times(1) | 132 .Times(1) |
151 .WillOnce(Return(mock_login_display_)); | 133 .WillOnce(Return(mock_login_display_)); |
152 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 134 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
153 .Times(1) | 135 .Times(1) |
154 .WillOnce(ReturnNull()); | 136 .WillOnce(ReturnNull()); |
155 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) | 137 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
156 .Times(1); | 138 .Times(1); |
157 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) | 139 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) |
158 .Times(1); | 140 .Times(1); |
159 } | 141 } |
160 | 142 |
161 void SetUpCommandLine(base::CommandLine* command_line) override { | 143 void SetUpCommandLine(base::CommandLine* command_line) override { |
162 command_line->AppendSwitch(switches::kLoginManager); | 144 command_line->AppendSwitch(switches::kLoginManager); |
163 } | 145 command_line->AppendSwitch(switches::kForceLoginManagerInTests); |
164 | |
165 virtual void SetUpUserManager() { | |
166 // Replace the UserManager singleton with a mock. | |
167 mock_user_manager_ = new MockUserManager; | |
168 user_manager_enabler_.reset( | |
169 new ScopedUserManagerEnabler(mock_user_manager_)); | |
170 EXPECT_CALL(*mock_user_manager_, IsKnownUser(kUsername)) | |
171 .Times(AnyNumber()) | |
172 .WillRepeatedly(Return(true)); | |
173 EXPECT_CALL(*mock_user_manager_, IsKnownUser(kNewUsername)) | |
174 .Times(AnyNumber()) | |
175 .WillRepeatedly(Return(false)); | |
176 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) | |
177 .Times(AnyNumber()) | |
178 .WillRepeatedly(Return(false)); | |
179 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsGuest()) | |
180 .Times(AnyNumber()) | |
181 .WillRepeatedly(Return(false)); | |
182 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsPublicAccount()) | |
183 .Times(AnyNumber()) | |
184 .WillRepeatedly(Return(false)); | |
185 EXPECT_CALL(*mock_user_manager_, IsSessionStarted()) | |
186 .Times(AnyNumber()) | |
187 .WillRepeatedly(Return(false)); | |
188 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) | |
189 .Times(AnyNumber()) | |
190 .WillRepeatedly(Return(false)); | |
191 EXPECT_CALL(*mock_user_manager_, Shutdown()) | |
192 .Times(1); | |
193 EXPECT_CALL(*mock_user_manager_, FindUser(_)) | |
194 .Times(AnyNumber()) | |
195 .WillRepeatedly(ReturnNull()); | |
196 } | 146 } |
197 | 147 |
198 void SetUpOnMainThread() override { | 148 void SetUpOnMainThread() override { |
199 testing_profile_.reset(new TestingProfile()); | |
200 SetUpUserManager(); | |
201 existing_user_controller_.reset( | 149 existing_user_controller_.reset( |
202 new ExistingUserController(mock_login_display_host_.get())); | 150 new ExistingUserController(mock_login_display_host_.get())); |
203 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); | 151 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); |
204 existing_user_controller_->Init(user_manager::UserList()); | 152 existing_user_controller_->Init(user_manager::UserList()); |
205 profile_prepared_cb_ = | |
206 base::Bind(&ExistingUserController::OnProfilePrepared, | |
207 base::Unretained(existing_user_controller()), | |
208 testing_profile_.get(), | |
209 false); | |
210 } | 153 } |
211 | 154 |
212 void TearDownOnMainThread() override { | 155 void TearDownOnMainThread() override { |
213 // ExistingUserController must be deleted before the thread is cleaned up: | 156 // ExistingUserController must be deleted before the thread is cleaned up: |
214 // If there is an outstanding login attempt when ExistingUserController is | 157 // If there is an outstanding login attempt when ExistingUserController is |
215 // deleted, its LoginPerformer instance will be deleted, which in turn | 158 // deleted, its LoginPerformer instance will be deleted, which in turn |
216 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must | 159 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must |
217 // be deleted on the UI thread. | 160 // be deleted on the UI thread. |
218 existing_user_controller_.reset(); | 161 existing_user_controller_.reset(); |
219 DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread(); | 162 DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread(); |
220 testing_profile_.reset(NULL); | 163 |
221 user_manager_enabler_.reset(); | 164 // Test case may be configured with the real user manager but empty user |
| 165 // list initially. So network OOBE screen is initialized. |
| 166 // Need to reset it manually so that we don't end up with CrosSettings |
| 167 // observer that wasn't removed. |
| 168 WizardController* controller = WizardController::default_controller(); |
| 169 if (controller && controller->current_screen()) |
| 170 controller->current_screen()->Hide(); |
222 } | 171 } |
223 | 172 |
224 void ExpectLoginFailure() { | 173 void ExpectLoginFailure() { |
225 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 174 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
226 .Times(1); | 175 .Times(1); |
227 EXPECT_CALL(*mock_login_display_, | 176 EXPECT_CALL(*mock_login_display_, |
228 ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST, | 177 ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST, |
229 1, | 178 1, |
230 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT)) | 179 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT)) |
231 .Times(1); | 180 .Times(1); |
232 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 181 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
233 .Times(1); | 182 .Times(1); |
234 } | 183 } |
235 | 184 |
| 185 void RegisterUser(const std::string& user_id) { |
| 186 ListPrefUpdate users_pref(g_browser_process->local_state(), |
| 187 "LoggedInUsers"); |
| 188 users_pref->AppendIfNotPresent(new base::StringValue(user_id)); |
| 189 } |
| 190 |
236 // ExistingUserController private member accessors. | 191 // ExistingUserController private member accessors. |
237 base::OneShotTimer<ExistingUserController>* auto_login_timer() { | 192 base::OneShotTimer<ExistingUserController>* auto_login_timer() { |
238 return existing_user_controller()->auto_login_timer_.get(); | 193 return existing_user_controller()->auto_login_timer_.get(); |
239 } | 194 } |
240 | 195 |
241 const std::string& auto_login_username() const { | 196 const std::string& auto_login_username() const { |
242 return existing_user_controller()->public_session_auto_login_username_; | 197 return existing_user_controller()->public_session_auto_login_username_; |
243 } | 198 } |
244 | 199 |
245 int auto_login_delay() const { | 200 int auto_login_delay() const { |
246 return existing_user_controller()->public_session_auto_login_delay_; | 201 return existing_user_controller()->public_session_auto_login_delay_; |
247 } | 202 } |
248 | 203 |
249 bool is_login_in_progress() const { | 204 bool is_login_in_progress() const { |
250 return existing_user_controller()->is_login_in_progress_; | 205 return existing_user_controller()->is_login_in_progress_; |
251 } | 206 } |
252 | 207 |
253 scoped_ptr<ExistingUserController> existing_user_controller_; | 208 scoped_ptr<ExistingUserController> existing_user_controller_; |
254 | 209 |
255 // |mock_login_display_| is owned by the ExistingUserController, which calls | 210 // |mock_login_display_| is owned by the ExistingUserController, which calls |
256 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. | 211 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. |
257 MockLoginDisplay* mock_login_display_; | 212 MockLoginDisplay* mock_login_display_; |
258 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; | 213 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; |
259 | 214 |
260 // Owned by LoginUtilsWrapper. | |
261 MockLoginUtils* mock_login_utils_; | |
262 | |
263 MockUserManager* mock_user_manager_; // Not owned. | |
264 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | |
265 | |
266 scoped_ptr<TestingProfile> testing_profile_; | |
267 | |
268 // Mock URLFetcher. | 215 // Mock URLFetcher. |
269 MockURLFetcherFactory<SuccessFetcher> factory_; | 216 MockURLFetcherFactory<SuccessFetcher> factory_; |
270 | 217 |
271 base::Callback<void(void)> profile_prepared_cb_; | |
272 | |
273 private: | 218 private: |
274 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); | 219 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); |
275 }; | 220 }; |
276 | 221 |
| 222 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, PRE_ExistingUserLogin) { |
| 223 RegisterUser(kUsername); |
| 224 } |
| 225 |
277 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { | 226 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { |
278 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 227 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
279 .Times(2); | 228 .Times(2); |
280 UserContext user_context(kUsername); | 229 UserContext user_context(kUsername); |
281 user_context.SetKey(Key(kPassword)); | 230 user_context.SetKey(Key(kPassword)); |
282 user_context.SetUserIDHash(kUsername); | 231 user_context.SetUserIDHash(kUsername); |
283 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 232 test::UserSessionManagerTestApi session_manager_test_api( |
284 .Times(1) | 233 UserSessionManager::GetInstance()); |
285 .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); | 234 session_manager_test_api.InjectStubUserContext(user_context); |
286 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _)) | |
287 .Times(1) | |
288 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | |
289 &base::Callback<void(void)>::Run)); | |
290 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 235 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
291 .Times(1); | 236 .Times(1); |
292 EXPECT_CALL(*mock_login_display_host_, | 237 EXPECT_CALL(*mock_login_display_host_, |
293 StartWizard(WizardController::kTermsOfServiceScreenName)) | 238 StartWizard(WizardController::kTermsOfServiceScreenName)) |
294 .Times(0); | 239 .Times(0); |
295 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) | 240 |
296 .Times(AnyNumber()) | 241 content::WindowedNotificationObserver profile_prepared_observer( |
297 .WillRepeatedly(Return(false)); | 242 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 243 content::NotificationService::AllSources()); |
298 existing_user_controller()->Login(user_context, SigninSpecifics()); | 244 existing_user_controller()->Login(user_context, SigninSpecifics()); |
| 245 |
| 246 profile_prepared_observer.Wait(); |
299 content::RunAllPendingInMessageLoop(); | 247 content::RunAllPendingInMessageLoop(); |
300 } | 248 } |
301 | 249 |
302 // Verifies that when the cros settings are untrusted, no new session can be | 250 // Verifies that when the cros settings are untrusted, no new session can be |
303 // started. | 251 // started. |
304 class ExistingUserControllerUntrustedTest : public ExistingUserControllerTest { | 252 class ExistingUserControllerUntrustedTest : public ExistingUserControllerTest { |
305 public: | 253 public: |
306 ExistingUserControllerUntrustedTest(); | 254 ExistingUserControllerUntrustedTest(); |
307 | 255 |
308 void SetUpInProcessBrowserTestFixture() override; | 256 void SetUpInProcessBrowserTestFixture() override; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 existing_user_controller()->Login(user_context, SigninSpecifics()); | 302 existing_user_controller()->Login(user_context, SigninSpecifics()); |
355 } | 303 } |
356 | 304 |
357 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, | 305 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, |
358 SupervisedUserCreationForbidden) { | 306 SupervisedUserCreationForbidden) { |
359 MockBaseScreenDelegate mock_base_screen_delegate; | 307 MockBaseScreenDelegate mock_base_screen_delegate; |
360 SupervisedUserCreationScreenHandler supervised_user_creation_screen_handler; | 308 SupervisedUserCreationScreenHandler supervised_user_creation_screen_handler; |
361 SupervisedUserCreationScreen supervised_user_creation_screen( | 309 SupervisedUserCreationScreen supervised_user_creation_screen( |
362 &mock_base_screen_delegate, &supervised_user_creation_screen_handler); | 310 &mock_base_screen_delegate, &supervised_user_creation_screen_handler); |
363 | 311 |
364 EXPECT_CALL(*mock_user_manager_, SetUserFlow(kUsername, _)) | |
365 .Times(1) | |
366 .WillOnce(WithArg<1>(Invoke(DeleteUserFlow))); | |
367 supervised_user_creation_screen.AuthenticateManager(kUsername, kPassword); | 312 supervised_user_creation_screen.AuthenticateManager(kUsername, kPassword); |
368 } | 313 } |
369 | 314 |
370 MATCHER_P(HasDetails, expected, "") { | 315 MATCHER_P(HasDetails, expected, "") { |
371 return expected == *content::Details<const std::string>(arg).ptr(); | 316 return expected == *content::Details<const std::string>(arg).ptr(); |
372 } | 317 } |
373 | 318 |
374 class ExistingUserControllerPublicSessionTest | 319 class ExistingUserControllerPublicSessionTest |
375 : public ExistingUserControllerTest { | 320 : public ExistingUserControllerTest { |
376 protected: | 321 protected: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 .WillOnce(Return(mock_login_display_)); | 392 .WillOnce(Return(mock_login_display_)); |
448 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 393 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
449 .Times(AnyNumber()) | 394 .Times(AnyNumber()) |
450 .WillRepeatedly(ReturnNull()); | 395 .WillRepeatedly(ReturnNull()); |
451 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) | 396 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
452 .Times(AnyNumber()); | 397 .Times(AnyNumber()); |
453 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) | 398 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) |
454 .Times(AnyNumber()); | 399 .Times(AnyNumber()); |
455 } | 400 } |
456 | 401 |
457 void SetUpUserManager() override {} | 402 void TearDownOnMainThread() override { |
| 403 ExistingUserControllerTest::TearDownOnMainThread(); |
| 404 |
| 405 // Test case may be configured with the real user manager but empty user |
| 406 // list initially. So network OOBE screen is initialized. |
| 407 // Need to reset it manually so that we don't end up with CrosSettings |
| 408 // observer that wasn't removed. |
| 409 WizardController* controller = WizardController::default_controller(); |
| 410 if (controller && controller->current_screen()) |
| 411 controller->current_screen()->Hide(); |
| 412 } |
458 | 413 |
459 void ExpectSuccessfulLogin(const UserContext& user_context) { | 414 void ExpectSuccessfulLogin(const UserContext& user_context) { |
460 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 415 test::UserSessionManagerTestApi session_manager_test_api( |
461 .Times(AnyNumber()); | 416 UserSessionManager::GetInstance()); |
462 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 417 session_manager_test_api.InjectStubUserContext(user_context); |
463 .Times(1) | |
464 .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); | |
465 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _)) | |
466 .Times(1) | |
467 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | |
468 &base::Callback<void(void)>::Run)); | |
469 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | |
470 .Times(1); | |
471 EXPECT_CALL(*mock_login_display_host_, | 418 EXPECT_CALL(*mock_login_display_host_, |
472 StartWizard(WizardController::kTermsOfServiceScreenName)) | 419 StartWizard(WizardController::kTermsOfServiceScreenName)) |
473 .Times(0); | 420 .Times(0); |
| 421 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)).Times(AnyNumber()); |
| 422 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)).Times(AnyNumber()); |
474 } | 423 } |
475 | 424 |
476 void SetAutoLoginPolicy(const std::string& username, int delay) { | 425 void SetAutoLoginPolicy(const std::string& username, int delay) { |
477 // Wait until ExistingUserController has finished auto-login | 426 // Wait until ExistingUserController has finished auto-login |
478 // configuration by observing the same settings that trigger | 427 // configuration by observing the same settings that trigger |
479 // ConfigurePublicSessionAutoLogin. | 428 // ConfigurePublicSessionAutoLogin. |
480 | 429 |
481 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 430 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
482 | 431 |
483 // If both settings have changed we need to wait for both to | 432 // If both settings have changed we need to wait for both to |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 525 } |
577 | 526 |
578 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 527 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
579 AutoLoginShortDelay) { | 528 AutoLoginShortDelay) { |
580 // Set up mocks to check login success. | 529 // Set up mocks to check login success. |
581 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, | 530 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, |
582 public_session_user_id_); | 531 public_session_user_id_); |
583 user_context.SetUserIDHash(user_context.GetUserID()); | 532 user_context.SetUserIDHash(user_context.GetUserID()); |
584 ExpectSuccessfulLogin(user_context); | 533 ExpectSuccessfulLogin(user_context); |
585 existing_user_controller()->OnSigninScreenReady(); | 534 existing_user_controller()->OnSigninScreenReady(); |
| 535 |
| 536 content::WindowedNotificationObserver profile_prepared_observer( |
| 537 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 538 content::NotificationService::AllSources()); |
| 539 |
586 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay); | 540 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay); |
587 ASSERT_TRUE(auto_login_timer()); | 541 ASSERT_TRUE(auto_login_timer()); |
588 // Don't assert that timer is running: with the short delay sometimes | 542 // Don't assert that timer is running: with the short delay sometimes |
589 // the trigger happens before the assert. We've already tested that | 543 // the trigger happens before the assert. We've already tested that |
590 // the timer starts when it should. | 544 // the timer starts when it should. |
591 | 545 |
592 // Wait for the timer to fire. | 546 // Wait for the timer to fire. |
593 base::RunLoop runner; | 547 base::RunLoop runner; |
594 base::OneShotTimer<base::RunLoop> timer; | 548 base::OneShotTimer<base::RunLoop> timer; |
595 timer.Start(FROM_HERE, | 549 timer.Start(FROM_HERE, |
596 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), | 550 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), |
597 runner.QuitClosure()); | 551 runner.QuitClosure()); |
598 runner.Run(); | 552 runner.Run(); |
599 | 553 |
| 554 profile_prepared_observer.Wait(); |
| 555 |
600 // Wait for login tasks to complete. | 556 // Wait for login tasks to complete. |
601 content::RunAllPendingInMessageLoop(); | 557 content::RunAllPendingInMessageLoop(); |
602 } | 558 } |
603 | 559 |
604 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 560 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
605 LoginStopsAutoLogin) { | 561 LoginStopsAutoLogin) { |
606 // Set up mocks to check login success. | 562 // Set up mocks to check login success. |
607 UserContext user_context(kUsername); | 563 UserContext user_context(kUsername); |
608 user_context.SetKey(Key(kPassword)); | 564 user_context.SetKey(Key(kPassword)); |
609 user_context.SetUserIDHash(user_context.GetUserID()); | 565 user_context.SetUserIDHash(user_context.GetUserID()); |
610 ExpectSuccessfulLogin(user_context); | 566 ExpectSuccessfulLogin(user_context); |
611 | 567 |
612 existing_user_controller()->OnSigninScreenReady(); | 568 existing_user_controller()->OnSigninScreenReady(); |
613 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 569 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
614 EXPECT_TRUE(auto_login_timer()); | 570 EXPECT_TRUE(auto_login_timer()); |
615 | 571 |
| 572 content::WindowedNotificationObserver profile_prepared_observer( |
| 573 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 574 content::NotificationService::AllSources()); |
| 575 |
616 // Log in and check that it stopped the timer. | 576 // Log in and check that it stopped the timer. |
617 existing_user_controller()->Login(user_context, SigninSpecifics()); | 577 existing_user_controller()->Login(user_context, SigninSpecifics()); |
618 EXPECT_TRUE(is_login_in_progress()); | 578 EXPECT_TRUE(is_login_in_progress()); |
619 ASSERT_TRUE(auto_login_timer()); | 579 ASSERT_TRUE(auto_login_timer()); |
620 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 580 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
621 | 581 |
| 582 profile_prepared_observer.Wait(); |
| 583 |
622 // Wait for login tasks to complete. | 584 // Wait for login tasks to complete. |
623 content::RunAllPendingInMessageLoop(); | 585 content::RunAllPendingInMessageLoop(); |
624 | 586 |
625 // Timer should still be stopped after login completes. | 587 // Timer should still be stopped after login completes. |
626 ASSERT_TRUE(auto_login_timer()); | 588 ASSERT_TRUE(auto_login_timer()); |
627 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 589 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
628 } | 590 } |
629 | 591 |
630 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 592 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
631 GuestModeLoginStopsAutoLogin) { | 593 GuestModeLoginStopsAutoLogin) { |
632 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 594 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
633 .Times(2); | 595 .Times(2); |
634 UserContext user_context(kUsername); | 596 UserContext user_context(kUsername); |
635 user_context.SetKey(Key(kPassword)); | 597 user_context.SetKey(Key(kPassword)); |
636 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 598 test::UserSessionManagerTestApi session_manager_test_api( |
637 .Times(1) | 599 UserSessionManager::GetInstance()); |
638 .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); | 600 session_manager_test_api.InjectStubUserContext(user_context); |
639 | 601 |
640 existing_user_controller()->OnSigninScreenReady(); | 602 existing_user_controller()->OnSigninScreenReady(); |
641 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 603 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
642 EXPECT_TRUE(auto_login_timer()); | 604 EXPECT_TRUE(auto_login_timer()); |
643 | 605 |
644 // Login and check that it stopped the timer. | 606 // Login and check that it stopped the timer. |
645 existing_user_controller()->Login(UserContext(user_manager::USER_TYPE_GUEST, | 607 existing_user_controller()->Login(UserContext(user_manager::USER_TYPE_GUEST, |
646 std::string()), | 608 std::string()), |
647 SigninSpecifics()); | 609 SigninSpecifics()); |
648 EXPECT_TRUE(is_login_in_progress()); | 610 EXPECT_TRUE(is_login_in_progress()); |
(...skipping 15 matching lines...) Expand all Loading... |
664 user_context.SetKey(Key(kPassword)); | 626 user_context.SetKey(Key(kPassword)); |
665 user_context.SetUserIDHash(user_context.GetUserID()); | 627 user_context.SetUserIDHash(user_context.GetUserID()); |
666 ExpectSuccessfulLogin(user_context); | 628 ExpectSuccessfulLogin(user_context); |
667 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) | 629 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) |
668 .Times(1); | 630 .Times(1); |
669 | 631 |
670 existing_user_controller()->OnSigninScreenReady(); | 632 existing_user_controller()->OnSigninScreenReady(); |
671 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 633 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
672 EXPECT_TRUE(auto_login_timer()); | 634 EXPECT_TRUE(auto_login_timer()); |
673 | 635 |
| 636 content::WindowedNotificationObserver profile_prepared_observer( |
| 637 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 638 content::NotificationService::AllSources()); |
| 639 |
674 // Check that login completes and stops the timer. | 640 // Check that login completes and stops the timer. |
675 existing_user_controller()->CompleteLogin(user_context); | 641 existing_user_controller()->CompleteLogin(user_context); |
676 ASSERT_TRUE(auto_login_timer()); | 642 ASSERT_TRUE(auto_login_timer()); |
677 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 643 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
678 | 644 |
| 645 profile_prepared_observer.Wait(); |
| 646 |
679 // Wait for login tasks to complete. | 647 // Wait for login tasks to complete. |
680 content::RunAllPendingInMessageLoop(); | 648 content::RunAllPendingInMessageLoop(); |
681 | 649 |
682 // Timer should still be stopped after login completes. | 650 // Timer should still be stopped after login completes. |
683 ASSERT_TRUE(auto_login_timer()); | 651 ASSERT_TRUE(auto_login_timer()); |
684 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 652 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
685 } | 653 } |
686 | 654 |
687 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 655 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
688 PublicSessionLoginStopsAutoLogin) { | 656 PublicSessionLoginStopsAutoLogin) { |
689 // Set up mocks to check login success. | 657 // Set up mocks to check login success. |
690 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, | 658 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, |
691 public_session_user_id_); | 659 public_session_user_id_); |
692 user_context.SetUserIDHash(user_context.GetUserID()); | 660 user_context.SetUserIDHash(user_context.GetUserID()); |
693 ExpectSuccessfulLogin(user_context); | 661 ExpectSuccessfulLogin(user_context); |
694 existing_user_controller()->OnSigninScreenReady(); | 662 existing_user_controller()->OnSigninScreenReady(); |
695 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 663 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
696 EXPECT_TRUE(auto_login_timer()); | 664 EXPECT_TRUE(auto_login_timer()); |
697 | 665 |
| 666 content::WindowedNotificationObserver profile_prepared_observer( |
| 667 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 668 content::NotificationService::AllSources()); |
| 669 |
698 // Login and check that it stopped the timer. | 670 // Login and check that it stopped the timer. |
699 existing_user_controller()->Login( | 671 existing_user_controller()->Login( |
700 UserContext(user_manager::USER_TYPE_PUBLIC_ACCOUNT, | 672 UserContext(user_manager::USER_TYPE_PUBLIC_ACCOUNT, |
701 public_session_user_id_), | 673 public_session_user_id_), |
702 SigninSpecifics()); | 674 SigninSpecifics()); |
703 | 675 |
704 EXPECT_TRUE(is_login_in_progress()); | 676 EXPECT_TRUE(is_login_in_progress()); |
705 ASSERT_TRUE(auto_login_timer()); | 677 ASSERT_TRUE(auto_login_timer()); |
706 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 678 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
707 | 679 |
| 680 profile_prepared_observer.Wait(); |
| 681 |
708 // Wait for login tasks to complete. | 682 // Wait for login tasks to complete. |
709 content::RunAllPendingInMessageLoop(); | 683 content::RunAllPendingInMessageLoop(); |
710 | 684 |
711 // Timer should still be stopped after login completes. | 685 // Timer should still be stopped after login completes. |
712 ASSERT_TRUE(auto_login_timer()); | 686 ASSERT_TRUE(auto_login_timer()); |
713 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 687 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
714 } | 688 } |
715 | 689 |
716 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 690 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
717 LoginForbiddenWhenUntrusted) { | 691 LoginForbiddenWhenUntrusted) { |
(...skipping 28 matching lines...) Expand all Loading... |
746 // First run propagates public accounts and stores them in Local State. | 720 // First run propagates public accounts and stores them in Local State. |
747 } | 721 } |
748 | 722 |
749 // See http://crbug.com/393704; flaky. | 723 // See http://crbug.com/393704; flaky. |
750 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 724 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
751 DISABLED_TestLoadingPublicUsersFromLocalState) { | 725 DISABLED_TestLoadingPublicUsersFromLocalState) { |
752 // Second run loads list of public accounts from Local State. | 726 // Second run loads list of public accounts from Local State. |
753 } | 727 } |
754 | 728 |
755 } // namespace chromeos | 729 } // namespace chromeos |
OLD | NEW |