Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / existing_user_controller_browsertest.cc
blobb2dada94192b9f41297d2505ba0ae7cc349098ad
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
3 // found in the LICENSE file.
5 #include <vector>
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/run_loop.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/login/authenticator.h"
16 #include "chrome/browser/chromeos/login/existing_user_controller.h"
17 #include "chrome/browser/chromeos/login/helper.h"
18 #include "chrome/browser/chromeos/login/mock_authenticator.h"
19 #include "chrome/browser/chromeos/login/mock_login_display.h"
20 #include "chrome/browser/chromeos/login/mock_login_display_host.h"
21 #include "chrome/browser/chromeos/login/mock_login_utils.h"
22 #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
23 #include "chrome/browser/chromeos/login/mock_user_manager.h"
24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #include "chrome/browser/chromeos/login/wizard_controller.h"
26 #include "chrome/browser/chromeos/policy/device_local_account.h"
27 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
28 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
29 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
30 #include "chrome/browser/chromeos/settings/cros_settings.h"
31 #include "chrome/browser/policy/browser_policy_connector.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/test/base/testing_browser_process.h"
34 #include "chrome/test/base/testing_profile.h"
35 #include "chrome/test/base/ui_test_utils.h"
36 #include "chromeos/chromeos_switches.h"
37 #include "chromeos/dbus/fake_session_manager_client.h"
38 #include "chromeos/settings/cros_settings_names.h"
39 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
40 #include "components/policy/core/common/cloud/cloud_policy_core.h"
41 #include "components/policy/core/common/cloud/cloud_policy_store.h"
42 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
43 #include "components/policy/core/common/cloud/policy_builder.h"
44 #include "content/public/test/mock_notification_observer.h"
45 #include "content/public/test/test_utils.h"
46 #include "google_apis/gaia/mock_url_fetcher_factory.h"
47 #include "grit/generated_resources.h"
48 #include "testing/gmock/include/gmock/gmock.h"
49 #include "testing/gtest/include/gtest/gtest.h"
50 #include "ui/base/l10n/l10n_util.h"
52 using ::testing::AnyNumber;
53 using ::testing::Invoke;
54 using ::testing::InvokeWithoutArgs;
55 using ::testing::Return;
56 using ::testing::ReturnNull;
57 using ::testing::Sequence;
58 using ::testing::WithArg;
59 using ::testing::_;
61 namespace em = enterprise_management;
63 namespace chromeos {
65 namespace {
67 const char kUsername[] = "test_user@gmail.com";
68 const char kNewUsername[] = "test_new_user@gmail.com";
69 const char kPassword[] = "test_password";
71 const char kPublicSessionAccountId[] = "public_session_user@localhost";
72 const int kAutoLoginNoDelay = 0;
73 const int kAutoLoginShortDelay = 1;
74 const int kAutoLoginLongDelay = 10000;
77 ACTION_P2(CreateAuthenticator, username, password) {
78 return new MockAuthenticator(arg0, username, password);
81 } // namespace
83 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest,
84 public testing::WithParamInterface<bool> {
85 protected:
86 ExistingUserControllerTest()
87 : mock_login_display_(NULL), mock_user_manager_(NULL) {}
89 ExistingUserController* existing_user_controller() {
90 return ExistingUserController::current_controller();
93 const ExistingUserController* existing_user_controller() const {
94 return ExistingUserController::current_controller();
97 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
98 SetUpSessionManager();
100 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
102 mock_login_utils_ = new MockLoginUtils();
103 LoginUtils::Set(mock_login_utils_);
104 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_))
105 .Times(1);
107 mock_login_display_host_.reset(new MockLoginDisplayHost());
108 mock_login_display_ = new MockLoginDisplay();
109 SetUpLoginDisplay();
112 virtual void SetUpSessionManager() {
115 virtual void SetUpLoginDisplay() {
116 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
117 .Times(1)
118 .WillOnce(Return(mock_login_display_));
119 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
120 .Times(1)
121 .WillOnce(ReturnNull());
122 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
123 .Times(1);
124 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true))
125 .Times(1);
128 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
129 command_line->AppendSwitch(switches::kLoginManager);
130 if (GetParam())
131 command_line->AppendSwitch(::switches::kMultiProfiles);
134 virtual void SetUpUserManager() {
135 // Replace the UserManager singleton with a mock.
136 mock_user_manager_ = new MockUserManager;
137 user_manager_enabler_.reset(
138 new ScopedUserManagerEnabler(mock_user_manager_));
139 EXPECT_CALL(*mock_user_manager_, IsKnownUser(kUsername))
140 .Times(AnyNumber())
141 .WillRepeatedly(Return(true));
142 EXPECT_CALL(*mock_user_manager_, IsKnownUser(kNewUsername))
143 .Times(AnyNumber())
144 .WillRepeatedly(Return(false));
145 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
146 .Times(AnyNumber())
147 .WillRepeatedly(Return(false));
148 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsGuest())
149 .Times(AnyNumber())
150 .WillRepeatedly(Return(false));
151 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsDemoUser())
152 .Times(AnyNumber())
153 .WillRepeatedly(Return(false));
154 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsPublicAccount())
155 .Times(AnyNumber())
156 .WillRepeatedly(Return(false));
157 EXPECT_CALL(*mock_user_manager_, IsSessionStarted())
158 .Times(AnyNumber())
159 .WillRepeatedly(Return(false));
160 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
161 .Times(AnyNumber())
162 .WillRepeatedly(Return(false));
163 EXPECT_CALL(*mock_user_manager_, Shutdown())
164 .Times(1);
165 EXPECT_CALL(*mock_user_manager_, GetProfileByUser(_))
166 .Times(AnyNumber())
167 .WillRepeatedly(Return(testing_profile_.get()));
170 virtual void SetUpOnMainThread() OVERRIDE {
171 testing_profile_.reset(new TestingProfile());
172 SetUpUserManager();
173 existing_user_controller_.reset(
174 new ExistingUserController(mock_login_display_host_.get()));
175 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get());
176 existing_user_controller_->Init(UserList());
177 profile_prepared_cb_ =
178 base::Bind(&ExistingUserController::OnProfilePrepared,
179 base::Unretained(existing_user_controller()),
180 testing_profile_.get());
183 virtual void CleanUpOnMainThread() OVERRIDE {
184 // ExistingUserController must be deleted before the thread is cleaned up:
185 // If there is an outstanding login attempt when ExistingUserController is
186 // deleted, its LoginPerformer instance will be deleted, which in turn
187 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
188 // be deleted on the UI thread.
189 existing_user_controller_.reset();
190 DevicePolicyCrosBrowserTest::InProcessBrowserTest::CleanUpOnMainThread();
191 testing_profile_.reset(NULL);
192 user_manager_enabler_.reset();
195 // ExistingUserController private member accessors.
196 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
197 return existing_user_controller()->auto_login_timer_.get();
200 const std::string& auto_login_username() const {
201 return existing_user_controller()->public_session_auto_login_username_;
204 int auto_login_delay() const {
205 return existing_user_controller()->public_session_auto_login_delay_;
208 bool is_login_in_progress() const {
209 return existing_user_controller()->is_login_in_progress_;
212 scoped_ptr<ExistingUserController> existing_user_controller_;
214 // |mock_login_display_| is owned by the ExistingUserController, which calls
215 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
216 MockLoginDisplay* mock_login_display_;
217 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
219 // Owned by LoginUtilsWrapper.
220 MockLoginUtils* mock_login_utils_;
222 MockUserManager* mock_user_manager_; // Not owned.
223 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
225 scoped_ptr<TestingProfile> testing_profile_;
227 // Mock URLFetcher.
228 MockURLFetcherFactory<SuccessFetcher> factory_;
230 base::Callback<void(void)> profile_prepared_cb_;
232 private:
233 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest);
236 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, ExistingUserLogin) {
237 // This is disabled twice: once right after signin but before checking for
238 // auto-enrollment, and again after doing an ownership status check.
239 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
240 .Times(2);
241 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
242 .Times(1)
243 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword)));
244 EXPECT_CALL(*mock_login_utils_,
245 PrepareProfile(UserContext(kUsername, kPassword, "", kUsername),
246 _, _, _, _))
247 .Times(1)
248 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
249 &base::Callback<void(void)>::Run));
250 EXPECT_CALL(*mock_login_utils_,
251 DoBrowserLaunch(testing_profile_.get(),
252 mock_login_display_host_.get()))
253 .Times(1);
254 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername))
255 .Times(1);
256 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
257 .Times(1);
258 EXPECT_CALL(*mock_login_display_, OnFadeOut())
259 .Times(1);
260 EXPECT_CALL(*mock_login_display_host_,
261 StartWizardPtr(WizardController::kTermsOfServiceScreenName, NULL))
262 .Times(0);
263 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
264 .Times(AnyNumber())
265 .WillRepeatedly(Return(false));
266 existing_user_controller()->Login(UserContext(kUsername, kPassword, ""));
267 content::RunAllPendingInMessageLoop();
270 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, AutoEnrollAfterSignIn) {
271 EXPECT_CALL(*mock_login_display_host_,
272 StartWizardPtr(WizardController::kEnrollmentScreenName,
274 .Times(1);
275 EXPECT_CALL(*mock_login_display_, OnFadeOut())
276 .Times(1);
277 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
278 .Times(1);
279 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
280 .Times(AnyNumber())
281 .WillRepeatedly(Return(false));
282 // The order of these expected calls matters: the UI if first disabled
283 // during the login sequence, and is enabled again for the enrollment screen.
284 Sequence uiEnabledSequence;
285 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
286 .Times(1)
287 .InSequence(uiEnabledSequence);
288 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
289 .Times(1)
290 .InSequence(uiEnabledSequence);
291 existing_user_controller()->DoAutoEnrollment();
292 existing_user_controller()->CompleteLogin(
293 UserContext(kUsername, kPassword, ""));
294 content::RunAllPendingInMessageLoop();
297 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest,
298 NewUserDontAutoEnrollAfterSignIn) {
299 EXPECT_CALL(*mock_login_display_host_,
300 StartWizardPtr(WizardController::kEnrollmentScreenName,
302 .Times(0);
303 EXPECT_CALL(*mock_login_display_host_,
304 StartWizardPtr(WizardController::kTermsOfServiceScreenName,
305 NULL))
306 .Times(1);
307 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
308 .Times(1)
309 .WillOnce(WithArg<0>(CreateAuthenticator(kNewUsername, kPassword)));
310 EXPECT_CALL(*mock_login_utils_,
311 PrepareProfile(UserContext(kNewUsername,
312 kPassword,
313 std::string(),
314 kNewUsername),
315 _, _, _, _))
316 .Times(1)
317 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
318 &base::Callback<void(void)>::Run));
319 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername))
320 .Times(1);
321 EXPECT_CALL(*mock_login_display_, OnFadeOut())
322 .Times(1);
323 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
324 .Times(1);
325 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
326 .Times(AnyNumber())
327 .WillRepeatedly(Return(true));
329 // The order of these expected calls matters: the UI if first disabled
330 // during the login sequence, and is enabled again after login completion.
331 Sequence uiEnabledSequence;
332 // This is disabled twice: once right after signin but before checking for
333 // auto-enrollment, and again after doing an ownership status check.
334 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
335 .Times(2)
336 .InSequence(uiEnabledSequence);
337 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
338 .Times(1)
339 .InSequence(uiEnabledSequence);
341 existing_user_controller()->CompleteLogin(
342 UserContext(kNewUsername, kPassword, ""));
343 content::RunAllPendingInMessageLoop();
346 MATCHER_P(HasDetails, expected, "") {
347 return expected == *content::Details<const std::string>(arg).ptr();
350 class ExistingUserControllerPublicSessionTest
351 : public ExistingUserControllerTest {
352 protected:
353 ExistingUserControllerPublicSessionTest()
354 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId(
355 kPublicSessionAccountId,
356 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {
359 virtual void SetUpOnMainThread() OVERRIDE {
360 ExistingUserControllerTest::SetUpOnMainThread();
362 // Wait for the public session user to be created.
363 if (!chromeos::UserManager::Get()->IsKnownUser(public_session_user_id_)) {
364 content::WindowedNotificationObserver(
365 chrome::NOTIFICATION_USER_LIST_CHANGED,
366 base::Bind(&chromeos::UserManager::IsKnownUser,
367 base::Unretained(chromeos::UserManager::Get()),
368 public_session_user_id_)).Wait();
371 // Wait for the device local account policy to be installed.
372 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()->
373 browser_policy_connector()->GetDeviceLocalAccountPolicyService()->
374 GetBrokerForUser(public_session_user_id_)->core()->store();
375 if (!store->has_policy()) {
376 policy::MockCloudPolicyStoreObserver observer;
378 base::RunLoop loop;
379 store->AddObserver(&observer);
380 EXPECT_CALL(observer, OnStoreLoaded(store))
381 .Times(1)
382 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit));
383 loop.Run();
384 store->RemoveObserver(&observer);
388 virtual void SetUpSessionManager() OVERRIDE {
389 InstallOwnerKey();
391 // Setup the device policy.
392 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
393 em::DeviceLocalAccountInfoProto* account =
394 proto.mutable_device_local_accounts()->add_account();
395 account->set_account_id(kPublicSessionAccountId);
396 account->set_type(
397 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
398 RefreshDevicePolicy();
400 // Setup the device local account policy.
401 policy::UserPolicyBuilder device_local_account_policy;
402 device_local_account_policy.policy_data().set_username(
403 kPublicSessionAccountId);
404 device_local_account_policy.policy_data().set_policy_type(
405 policy::dm_protocol::kChromePublicAccountPolicyType);
406 device_local_account_policy.policy_data().set_settings_entity_id(
407 kPublicSessionAccountId);
408 device_local_account_policy.Build();
409 session_manager_client()->set_device_local_account_policy(
410 kPublicSessionAccountId,
411 device_local_account_policy.GetBlob());
414 virtual void SetUpLoginDisplay() OVERRIDE {
415 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
416 .Times(1)
417 .WillOnce(Return(mock_login_display_));
418 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
419 .Times(AnyNumber())
420 .WillRepeatedly(ReturnNull());
421 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
422 .Times(AnyNumber());
423 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _))
424 .Times(AnyNumber());
427 virtual void SetUpUserManager() OVERRIDE {
430 void ExpectSuccessfulLogin(const std::string& username,
431 const std::string& password) {
432 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
433 .Times(AnyNumber());
434 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
435 .Times(1)
436 .WillOnce(WithArg<0>(CreateAuthenticator(username, password)));
437 EXPECT_CALL(*mock_login_utils_,
438 PrepareProfile(UserContext(username, password, "", username),
439 _, _, _, _))
440 .Times(1)
441 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
442 &base::Callback<void(void)>::Run));
443 EXPECT_CALL(*mock_login_utils_,
444 DoBrowserLaunch(testing_profile_.get(),
445 mock_login_display_host_.get()))
446 .Times(1);
447 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username))
448 .Times(1);
449 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
450 .Times(1);
451 EXPECT_CALL(*mock_login_display_, OnFadeOut())
452 .Times(1);
453 EXPECT_CALL(*mock_login_display_host_,
454 StartWizardPtr(WizardController::kTermsOfServiceScreenName,
455 NULL))
456 .Times(0);
459 void SetAutoLoginPolicy(const std::string& username, int delay) {
460 // Wait until ExistingUserController has finished auto-login
461 // configuration by observing the same settings that trigger
462 // ConfigurePublicSessionAutoLogin.
464 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
466 // If both settings have changed we need to wait for both to
467 // propagate, so check the new values against the old ones.
468 scoped_refptr<content::MessageLoopRunner> runner1;
469 scoped_ptr<CrosSettings::ObserverSubscription> subscription1;
470 if (!proto.has_device_local_accounts() ||
471 !proto.device_local_accounts().has_auto_login_id() ||
472 proto.device_local_accounts().auto_login_id() != username) {
473 runner1 = new content::MessageLoopRunner;
474 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver(
475 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId,
476 runner1->QuitClosure());
478 scoped_refptr<content::MessageLoopRunner> runner2;
479 scoped_ptr<CrosSettings::ObserverSubscription> subscription2;
480 if (!proto.has_device_local_accounts() ||
481 !proto.device_local_accounts().has_auto_login_delay() ||
482 proto.device_local_accounts().auto_login_delay() != delay) {
483 runner1 = new content::MessageLoopRunner;
484 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver(
485 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay,
486 runner1->QuitClosure());
489 // Update the policy.
490 proto.mutable_device_local_accounts()->set_auto_login_id(username);
491 proto.mutable_device_local_accounts()->set_auto_login_delay(delay);
492 RefreshDevicePolicy();
494 // Wait for ExistingUserController to read the updated settings.
495 if (runner1.get())
496 runner1->Run();
497 if (runner2.get())
498 runner2->Run();
501 void ConfigureAutoLogin() {
502 existing_user_controller()->ConfigurePublicSessionAutoLogin();
505 void FireAutoLogin() {
506 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
509 const std::string public_session_user_id_;
511 private:
512 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
515 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
516 ConfigureAutoLoginUsingPolicy) {
517 existing_user_controller()->OnSigninScreenReady();
518 EXPECT_EQ("", auto_login_username());
519 EXPECT_EQ(0, auto_login_delay());
520 EXPECT_FALSE(auto_login_timer());
522 // Set the policy.
523 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
524 EXPECT_EQ(public_session_user_id_, auto_login_username());
525 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay());
526 ASSERT_TRUE(auto_login_timer());
527 EXPECT_TRUE(auto_login_timer()->IsRunning());
529 // Unset the policy.
530 SetAutoLoginPolicy("", 0);
531 EXPECT_EQ("", auto_login_username());
532 EXPECT_EQ(0, auto_login_delay());
533 ASSERT_TRUE(auto_login_timer());
534 EXPECT_FALSE(auto_login_timer()->IsRunning());
537 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
538 AutoLoginNoDelay) {
539 // Set up mocks to check login success.
540 ExpectSuccessfulLogin(public_session_user_id_, "");
541 existing_user_controller()->OnSigninScreenReady();
543 // Start auto-login and wait for login tasks to complete.
544 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginNoDelay);
545 content::RunAllPendingInMessageLoop();
548 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
549 AutoLoginShortDelay) {
550 // Set up mocks to check login success.
551 ExpectSuccessfulLogin(public_session_user_id_, "");
552 existing_user_controller()->OnSigninScreenReady();
553 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay);
554 ASSERT_TRUE(auto_login_timer());
555 // Don't assert that timer is running: with the short delay sometimes
556 // the trigger happens before the assert. We've already tested that
557 // the timer starts when it should.
559 // Wait for the timer to fire.
560 base::RunLoop runner;
561 base::OneShotTimer<base::RunLoop> timer;
562 timer.Start(FROM_HERE,
563 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1),
564 runner.QuitClosure());
565 runner.Run();
567 // Wait for login tasks to complete.
568 content::RunAllPendingInMessageLoop();
571 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
572 LoginStopsAutoLogin) {
573 // Set up mocks to check login success.
574 ExpectSuccessfulLogin(kUsername, kPassword);
576 existing_user_controller()->OnSigninScreenReady();
577 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
578 ASSERT_TRUE(auto_login_timer());
580 // Login and check that it stopped the timer.
581 existing_user_controller()->Login(UserContext(kUsername, kPassword, ""));
582 EXPECT_TRUE(is_login_in_progress());
583 ASSERT_TRUE(auto_login_timer());
584 EXPECT_FALSE(auto_login_timer()->IsRunning());
586 // Wait for login tasks to complete.
587 content::RunAllPendingInMessageLoop();
589 // Timer should still be stopped after login completes.
590 ASSERT_TRUE(auto_login_timer());
591 EXPECT_FALSE(auto_login_timer()->IsRunning());
594 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
595 GuestModeLoginStopsAutoLogin) {
596 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
597 .Times(1);
598 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
599 .Times(1)
600 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword)));
601 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_))
602 .Times(1);
604 existing_user_controller()->OnSigninScreenReady();
605 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
606 ASSERT_TRUE(auto_login_timer());
608 // Login and check that it stopped the timer.
609 existing_user_controller()->LoginAsGuest();
610 EXPECT_TRUE(is_login_in_progress());
611 ASSERT_TRUE(auto_login_timer());
612 EXPECT_FALSE(auto_login_timer()->IsRunning());
614 // Wait for login tasks to complete.
615 content::RunAllPendingInMessageLoop();
617 // Timer should still be stopped after login completes.
618 ASSERT_TRUE(auto_login_timer());
619 EXPECT_FALSE(auto_login_timer()->IsRunning());
622 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
623 CompleteLoginStopsAutoLogin) {
624 // Set up mocks to check login success.
625 ExpectSuccessfulLogin(kUsername, kPassword);
626 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
627 .Times(1);
629 existing_user_controller()->OnSigninScreenReady();
630 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
631 ASSERT_TRUE(auto_login_timer());
633 // Check that login completes and stops the timer.
634 existing_user_controller()->CompleteLogin(
635 UserContext(kUsername, kPassword, ""));
636 ASSERT_TRUE(auto_login_timer());
637 EXPECT_FALSE(auto_login_timer()->IsRunning());
639 // Wait for login tasks to complete.
640 content::RunAllPendingInMessageLoop();
642 // Timer should still be stopped after login completes.
643 ASSERT_TRUE(auto_login_timer());
644 EXPECT_FALSE(auto_login_timer()->IsRunning());
647 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
648 PublicSessionLoginStopsAutoLogin) {
649 // Set up mocks to check login success.
650 ExpectSuccessfulLogin(public_session_user_id_, "");
651 existing_user_controller()->OnSigninScreenReady();
652 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
653 ASSERT_TRUE(auto_login_timer());
655 // Login and check that it stopped the timer.
656 existing_user_controller()->LoginAsPublicAccount(public_session_user_id_);
657 EXPECT_TRUE(is_login_in_progress());
658 ASSERT_TRUE(auto_login_timer());
659 EXPECT_FALSE(auto_login_timer()->IsRunning());
661 // Wait for login tasks to complete.
662 content::RunAllPendingInMessageLoop();
664 // Timer should still be stopped after login completes.
665 ASSERT_TRUE(auto_login_timer());
666 EXPECT_FALSE(auto_login_timer()->IsRunning());
669 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
670 PRE_TestLoadingPublicUsersFromLocalState) {
671 // First run propagates public accounts and stores them in Local State.
674 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
675 TestLoadingPublicUsersFromLocalState) {
676 // Second run loads list of public accounts from Local State.
679 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation,
680 ExistingUserControllerTest,
681 testing::Bool());
683 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation,
684 ExistingUserControllerPublicSessionTest,
685 testing::Bool());
687 } // namespace chromeos