| 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 <vector> |
| 6 |
| 5 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" |
| 6 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 7 #include "base/compiler_specific.h" | 11 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/location.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/path_service.h" |
| 17 #include "base/run_loop.h" |
| 18 #include "base/stl_util.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 19 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_mock.h" | 20 #include "chrome/browser/chromeos/cros/cros_mock.h" |
| 11 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 21 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
| 22 #include "chrome/browser/chromeos/login/authenticator.h" |
| 12 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 23 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 13 #include "chrome/browser/chromeos/login/helper.h" | 24 #include "chrome/browser/chromeos/login/helper.h" |
| 14 #include "chrome/browser/chromeos/login/login_display.h" | |
| 15 #include "chrome/browser/chromeos/login/login_display_host.h" | |
| 16 #include "chrome/browser/chromeos/login/login_performer.h" | |
| 17 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 25 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
| 18 #include "chrome/browser/chromeos/login/login_utils.h" | |
| 19 #include "chrome/browser/chromeos/login/mock_authenticator.h" | 26 #include "chrome/browser/chromeos/login/mock_authenticator.h" |
| 27 #include "chrome/browser/chromeos/login/mock_login_display.h" |
| 28 #include "chrome/browser/chromeos/login/mock_login_display_host.h" |
| 20 #include "chrome/browser/chromeos/login/mock_login_utils.h" | 29 #include "chrome/browser/chromeos/login/mock_login_utils.h" |
| 21 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" | 30 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
| 22 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 31 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 32 #include "chrome/browser/chromeos/login/user_manager.h" |
| 23 #include "chrome/browser/chromeos/login/wizard_controller.h" | 33 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 34 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 35 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 36 #include "chrome/browser/policy/browser_policy_connector.h" |
| 37 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 38 #include "chrome/browser/policy/cloud_policy_core.h" |
| 39 #include "chrome/browser/policy/cloud_policy_store.h" |
| 40 #include "chrome/browser/policy/device_local_account_policy_service.h" |
| 41 #include "chrome/browser/policy/mock_cloud_policy_store.h" |
| 42 #include "chrome/browser/policy/policy_builder.h" |
| 43 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
| 44 #include "chrome/common/chrome_notification_types.h" |
| 45 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/chrome_switches.h" | 46 #include "chrome/common/chrome_switches.h" |
| 47 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 48 #include "chrome/test/base/testing_profile.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 49 #include "chrome/test/base/ui_test_utils.h" |
| 50 #include "chromeos/dbus/fake_session_manager_client.h" |
| 27 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 51 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 28 #include "chromeos/dbus/mock_session_manager_client.h" | 52 #include "chromeos/dbus/mock_session_manager_client.h" |
| 29 #include "chromeos/dbus/mock_shill_manager_client.h" | 53 #include "chromeos/dbus/mock_shill_manager_client.h" |
| 54 #include "content/public/browser/notification_details.h" |
| 55 #include "content/public/test/mock_notification_observer.h" |
| 56 #include "content/public/test/test_utils.h" |
| 57 #include "crypto/rsa_private_key.h" |
| 30 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 58 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
| 31 #include "grit/generated_resources.h" | 59 #include "grit/generated_resources.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 60 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 61 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 62 #include "ui/base/l10n/l10n_util.h" |
| 35 | 63 |
| 36 using ::testing::_; | 64 using ::testing::_; |
| 37 using ::testing::AnyNumber; | 65 using ::testing::AnyNumber; |
| 38 using ::testing::AnyOf; | 66 using ::testing::AnyOf; |
| 39 using ::testing::Invoke; | 67 using ::testing::Invoke; |
| 40 using ::testing::InvokeWithoutArgs; | 68 using ::testing::InvokeWithoutArgs; |
| 41 using ::testing::Return; | 69 using ::testing::Return; |
| 42 using ::testing::ReturnNull; | 70 using ::testing::ReturnNull; |
| 43 using ::testing::Sequence; | 71 using ::testing::Sequence; |
| 44 using ::testing::WithArg; | 72 using ::testing::WithArg; |
| 45 | 73 |
| 74 namespace em = enterprise_management; |
| 75 |
| 46 namespace chromeos { | 76 namespace chromeos { |
| 47 | 77 |
| 48 namespace { | 78 namespace { |
| 49 | 79 |
| 50 const char kUsername[] = "test_user@gmail.com"; | 80 const char kUsername[] = "test_user@gmail.com"; |
| 51 const char kNewUsername[] = "test_new_user@gmail.com"; | 81 const char kNewUsername[] = "test_new_user@gmail.com"; |
| 52 const char kPassword[] = "test_password"; | 82 const char kPassword[] = "test_password"; |
| 53 | 83 |
| 54 class MockLoginDisplay : public LoginDisplay { | 84 const char kAutoLoginUsername[] = "public_session_user@localhost"; |
| 55 public: | 85 const int kAutoLoginNoDelay = 0; |
| 56 MockLoginDisplay() | 86 const int kAutoLoginShortDelay = 1; |
| 57 : LoginDisplay(NULL, gfx::Rect()) { | 87 const int kAutoLoginLongDelay = 10000; |
| 58 } | |
| 59 | |
| 60 MOCK_METHOD4(Init, void(const UserList&, bool, bool, bool)); | |
| 61 MOCK_METHOD0(OnPreferencesChanged, void(void)); | |
| 62 MOCK_METHOD1(OnUserImageChanged, void(const User&)); | |
| 63 MOCK_METHOD0(OnFadeOut, void(void)); | |
| 64 MOCK_METHOD1(OnLoginSuccess, void(const std::string&)); | |
| 65 MOCK_METHOD1(SetUIEnabled, void(bool)); | |
| 66 MOCK_METHOD1(SelectPod, void(int)); | |
| 67 MOCK_METHOD3(ShowError, void(int, int, HelpAppLauncher::HelpTopic)); | |
| 68 MOCK_METHOD1(ShowErrorScreen, void(LoginDisplay::SigninError)); | |
| 69 MOCK_METHOD1(ShowGaiaPasswordChanged, void(const std::string&)); | |
| 70 MOCK_METHOD1(ShowPasswordChangedDialog, void(bool)); | |
| 71 MOCK_METHOD1(ShowSigninUI, void(const std::string&)); | |
| 72 MOCK_METHOD1(OnBeforeUserRemoved, void(const std::string&)); | |
| 73 MOCK_METHOD1(OnUserRemoved, void(const std::string&)); | |
| 74 | |
| 75 private: | |
| 76 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplay); | |
| 77 }; | |
| 78 | |
| 79 class MockLoginDisplayHost : public LoginDisplayHost { | |
| 80 public: | |
| 81 MockLoginDisplayHost() { | |
| 82 } | |
| 83 | |
| 84 MOCK_METHOD1(CreateLoginDisplay, LoginDisplay*(LoginDisplay::Delegate*)); | |
| 85 MOCK_CONST_METHOD0(GetNativeWindow, gfx::NativeWindow(void)); | |
| 86 MOCK_CONST_METHOD0(GetWidget, views::Widget*(void)); | |
| 87 MOCK_METHOD0(BeforeSessionStart, void(void)); | |
| 88 MOCK_METHOD0(OnSessionStart, void(void)); | |
| 89 MOCK_METHOD0(OnCompleteLogin, void(void)); | |
| 90 MOCK_METHOD0(OpenProxySettings, void(void)); | |
| 91 MOCK_METHOD1(SetOobeProgressBarVisible, void(bool)); | |
| 92 MOCK_METHOD1(SetShutdownButtonEnabled, void(bool)); | |
| 93 MOCK_METHOD1(SetStatusAreaVisible, void(bool)); | |
| 94 MOCK_METHOD0(ShowBackground, void(void)); | |
| 95 MOCK_METHOD0(CheckForAutoEnrollment, void(void)); | |
| 96 MOCK_METHOD2(StartWizard, void(const std::string&, DictionaryValue*)); | |
| 97 MOCK_METHOD0(StartSignInScreen, void(void)); | |
| 98 MOCK_METHOD0(ResumeSignInScreen, void(void)); | |
| 99 MOCK_METHOD0(OnPreferencesChanged, void(void)); | |
| 100 | |
| 101 private: | |
| 102 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplayHost); | |
| 103 }; | |
| 104 | 88 |
| 105 scoped_refptr<Authenticator> CreateAuthenticator( | 89 scoped_refptr<Authenticator> CreateAuthenticator( |
| 106 LoginStatusConsumer* consumer) { | 90 LoginStatusConsumer* consumer) { |
| 107 return new MockAuthenticator(consumer, kUsername, kPassword); | 91 return new MockAuthenticator(consumer, kUsername, kPassword); |
| 108 } | 92 } |
| 109 | 93 |
| 110 scoped_refptr<Authenticator> CreateAuthenticatorNewUser( | 94 scoped_refptr<Authenticator> CreateAuthenticatorNewUser( |
| 111 LoginStatusConsumer* consumer) { | 95 LoginStatusConsumer* consumer) { |
| 112 return new MockAuthenticator(consumer, kNewUsername, kPassword); | 96 return new MockAuthenticator(consumer, kNewUsername, kPassword); |
| 113 } | 97 } |
| 114 | 98 |
| 99 scoped_refptr<Authenticator> CreateAuthenticatorForPublicSession( |
| 100 LoginStatusConsumer* consumer) { |
| 101 return new MockAuthenticator(consumer, kAutoLoginUsername, ""); |
| 102 } |
| 103 |
| 104 // Observes a specific notification type and quits the message loop once a |
| 105 // condition holds. |
| 106 class NotificationWatcher : public content::NotificationObserver { |
| 107 public: |
| 108 // Callback invoked on notifications. Should return true when the condition |
| 109 // that the caller is waiting for is satisfied. |
| 110 typedef base::Callback<bool(void)> ConditionTestCallback; |
| 111 |
| 112 explicit NotificationWatcher(int notification_type, |
| 113 const ConditionTestCallback& callback) |
| 114 : type_(notification_type), |
| 115 callback_(callback) {} |
| 116 |
| 117 void Run() { |
| 118 if (callback_.Run()) |
| 119 return; |
| 120 |
| 121 content::NotificationRegistrar registrar; |
| 122 registrar.Add(this, type_, content::NotificationService::AllSources()); |
| 123 run_loop_.Run(); |
| 124 } |
| 125 |
| 126 // content::NotificationObserver: |
| 127 virtual void Observe(int type, |
| 128 const content::NotificationSource& source, |
| 129 const content::NotificationDetails& details) OVERRIDE { |
| 130 if (callback_.Run()) |
| 131 run_loop_.Quit(); |
| 132 } |
| 133 |
| 134 private: |
| 135 int type_; |
| 136 ConditionTestCallback callback_; |
| 137 base::RunLoop run_loop_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher); |
| 140 }; |
| 141 |
| 115 } // namespace | 142 } // namespace |
| 116 | 143 |
| 117 class ExistingUserControllerTest : public CrosInProcessBrowserTest { | 144 class ExistingUserControllerTest : public CrosInProcessBrowserTest { |
| 118 protected: | 145 protected: |
| 119 ExistingUserControllerTest() | 146 ExistingUserControllerTest() |
| 120 : mock_network_library_(NULL), | 147 : mock_network_library_(NULL), |
| 121 mock_login_display_(NULL), | 148 mock_login_display_(NULL), |
| 122 mock_login_display_host_(NULL), | 149 mock_login_display_host_(NULL), |
| 123 testing_profile_(NULL) { | 150 testing_profile_(NULL) { |
| 124 } | 151 } |
| 125 | 152 |
| 126 ExistingUserController* existing_user_controller() { | 153 ExistingUserController* existing_user_controller() { |
| 127 return ExistingUserController::current_controller(); | 154 return ExistingUserController::current_controller(); |
| 128 } | 155 } |
| 129 | 156 |
| 157 const ExistingUserController* existing_user_controller() const { |
| 158 return ExistingUserController::current_controller(); |
| 159 } |
| 160 |
| 130 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 161 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 131 MockDBusThreadManager* mock_dbus_thread_manager = | 162 MockDBusThreadManager* mock_dbus_thread_manager = |
| 132 new MockDBusThreadManager; | 163 new MockDBusThreadManager; |
| 133 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | 164 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) |
| 134 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | 165 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); |
| 135 EXPECT_CALL(*mock_dbus_thread_manager, GetIBusInputContextClient()) | 166 EXPECT_CALL(*mock_dbus_thread_manager, GetIBusInputContextClient()) |
| 136 .WillRepeatedly( | 167 .WillRepeatedly( |
| 137 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); | 168 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); |
| 138 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 169 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), |
| 139 GetProperties(_)) | 170 GetProperties(_)) |
| 140 .Times(AnyNumber()); | 171 .Times(AnyNumber()); |
| 141 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 172 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), |
| 142 AddPropertyChangedObserver(_)) | 173 AddPropertyChangedObserver(_)) |
| 143 .Times(AnyNumber()); | 174 .Times(AnyNumber()); |
| 144 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 175 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), |
| 145 RemovePropertyChangedObserver(_)) | 176 RemovePropertyChangedObserver(_)) |
| 146 .Times(AnyNumber()); | 177 .Times(AnyNumber()); |
| 178 |
| 179 SetUpSessionManager(mock_dbus_thread_manager); |
| 180 |
| 147 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 181 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
| 148 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 182 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 149 cros_mock_->InitStatusAreaMocks(); | 183 cros_mock_->InitStatusAreaMocks(); |
| 150 cros_mock_->SetStatusAreaMocksExpectations(); | 184 cros_mock_->SetStatusAreaMocksExpectations(); |
| 151 | 185 |
| 152 mock_network_library_ = cros_mock_->mock_network_library(); | 186 mock_network_library_ = cros_mock_->mock_network_library(); |
| 153 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) | 187 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) |
| 154 .Times(AnyNumber()); | 188 .Times(AnyNumber()); |
| 155 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) | 189 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) |
| 156 .WillRepeatedly(Return(true)); | 190 .WillRepeatedly(Return(true)); |
| 157 | 191 |
| 158 MockSessionManagerClient* mock_session_manager_client = | |
| 159 mock_dbus_thread_manager->mock_session_manager_client(); | |
| 160 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady()) | |
| 161 .Times(1); | |
| 162 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) | |
| 163 .Times(AnyNumber()); | |
| 164 | |
| 165 mock_login_utils_ = new MockLoginUtils(); | 192 mock_login_utils_ = new MockLoginUtils(); |
| 166 LoginUtils::Set(mock_login_utils_); | 193 LoginUtils::Set(mock_login_utils_); |
| 167 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) | 194 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) |
| 168 .Times(AnyNumber()); | 195 .Times(AnyNumber()); |
| 169 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) | 196 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) |
| 170 .Times(AnyNumber()); | 197 .Times(AnyNumber()); |
| 171 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) | 198 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) |
| 172 .Times(1); | 199 .Times(1); |
| 173 | 200 |
| 174 mock_login_display_host_.reset(new MockLoginDisplayHost()); | 201 mock_login_display_host_.reset(new MockLoginDisplayHost()); |
| 202 mock_login_display_ = new MockLoginDisplay(); |
| 203 SetUpLoginDisplay(); |
| 204 } |
| 175 | 205 |
| 176 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kUsername)) | 206 virtual void SetUpSessionManager( |
| 207 MockDBusThreadManager* mock_dbus_thread_manager) { |
| 208 mock_user_manager_.reset(new ScopedMockUserManagerEnabler); |
| 209 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername)) |
| 177 .Times(AnyNumber()) | 210 .Times(AnyNumber()) |
| 178 .WillRepeatedly(Return(true)); | 211 .WillRepeatedly(Return(true)); |
| 179 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kNewUsername)) | 212 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername)) |
| 180 .Times(AnyNumber()) | 213 .Times(AnyNumber()) |
| 181 .WillRepeatedly(Return(false)); | 214 .WillRepeatedly(Return(false)); |
| 182 EXPECT_CALL(*mock_user_manager_.user_manager(), IsUserLoggedIn()) | 215 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn()) |
| 183 .Times(AnyNumber()) | 216 .Times(AnyNumber()) |
| 184 .WillRepeatedly(Return(false)); | 217 .WillRepeatedly(Return(false)); |
| 185 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsGuest()) | 218 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsGuest()) |
| 186 .Times(AnyNumber()) | 219 .Times(AnyNumber()) |
| 187 .WillRepeatedly(Return(false)); | 220 .WillRepeatedly(Return(false)); |
| 188 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsDemoUser()) | 221 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsDemoUser()) |
| 189 .Times(AnyNumber()) | 222 .Times(AnyNumber()) |
| 190 .WillRepeatedly(Return(false)); | 223 .WillRepeatedly(Return(false)); |
| 191 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsPublicAccount()) | 224 EXPECT_CALL(*mock_user_manager_->user_manager(), |
| 225 IsLoggedInAsPublicAccount()) |
| 192 .Times(AnyNumber()) | 226 .Times(AnyNumber()) |
| 193 .WillRepeatedly(Return(false)); | 227 .WillRepeatedly(Return(false)); |
| 194 EXPECT_CALL(*mock_user_manager_.user_manager(), IsSessionStarted()) | 228 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted()) |
| 195 .Times(AnyNumber()) | 229 .Times(AnyNumber()) |
| 196 .WillRepeatedly(Return(false)); | 230 .WillRepeatedly(Return(false)); |
| 231 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
| 232 .Times(AnyNumber()) |
| 233 .WillRepeatedly(Return(false)); |
| 234 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown()) |
| 235 .Times(1); |
| 197 | 236 |
| 198 // |mock_login_display_| is owned by the ExistingUserController, which calls | 237 MockSessionManagerClient* mock_session_manager_client = |
| 199 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. | 238 mock_dbus_thread_manager->mock_session_manager_client(); |
| 200 mock_login_display_ = new MockLoginDisplay(); | 239 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady()) |
| 240 .Times(1); |
| 241 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) |
| 242 .Times(AnyNumber()); |
| 243 } |
| 244 |
| 245 virtual void SetUpLoginDisplay() { |
| 201 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | 246 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
| 202 .Times(1) | 247 .Times(1) |
| 203 .WillOnce(Return(mock_login_display_)); | 248 .WillOnce(Return(mock_login_display_)); |
| 204 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 249 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
| 205 .Times(1) | 250 .Times(1) |
| 206 .WillOnce(ReturnNull()); | 251 .WillOnce(ReturnNull()); |
| 207 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) | 252 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
| 208 .Times(1); | 253 .Times(1); |
| 209 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) | 254 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) |
| 210 .Times(1); | 255 .Times(1); |
| 211 } | 256 } |
| 212 | 257 |
| 213 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 258 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 214 command_line->AppendSwitch(switches::kLoginManager); | 259 command_line->AppendSwitch(switches::kLoginManager); |
| 215 } | 260 } |
| 216 | 261 |
| 217 virtual void SetUpOnMainThread() OVERRIDE { | 262 virtual void SetUpOnMainThread() OVERRIDE { |
| 218 testing_profile_.reset(new TestingProfile()); | 263 testing_profile_.reset(new TestingProfile()); |
| 219 existing_user_controller_.reset( | 264 existing_user_controller_.reset( |
| 220 new ExistingUserController(mock_login_display_host_.get())); | 265 new ExistingUserController(mock_login_display_host_.get())); |
| 221 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); | 266 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); |
| 222 existing_user_controller_->Init(UserList()); | 267 existing_user_controller_->Init(UserList()); |
| 223 profile_prepared_cb_ = | 268 profile_prepared_cb_ = |
| 224 base::Bind(&ExistingUserController::OnProfilePrepared, | 269 base::Bind(&ExistingUserController::OnProfilePrepared, |
| 225 base::Unretained(existing_user_controller()), | 270 base::Unretained(existing_user_controller()), |
| 226 testing_profile_.get()); | 271 testing_profile_.get()); |
| 227 } | 272 } |
| 228 | 273 |
| 229 virtual void CleanUpOnMainThread() OVERRIDE { | 274 virtual void CleanUpOnMainThread() OVERRIDE { |
| 275 // ExistingUserController must be deleted before the thread is cleaned up: |
| 276 // If there is an outstanding login attempt when ExistingUserController is |
| 277 // deleted, its LoginPerformer instance will be deleted, which in turn |
| 278 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must |
| 279 // be deleted on the UI thread. |
| 280 existing_user_controller_.reset(); |
| 230 CrosInProcessBrowserTest::CleanUpOnMainThread(); | 281 CrosInProcessBrowserTest::CleanUpOnMainThread(); |
| 231 testing_profile_.reset(NULL); | 282 testing_profile_.reset(NULL); |
| 232 } | 283 } |
| 233 | 284 |
| 234 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | 285 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 235 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 286 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
| 236 DBusThreadManager::Shutdown(); | 287 DBusThreadManager::Shutdown(); |
| 237 } | 288 } |
| 238 | 289 |
| 290 // ExistingUserController private member accessors. |
| 291 base::OneShotTimer<ExistingUserController>* auto_login_timer() { |
| 292 return existing_user_controller()->auto_login_timer_.get(); |
| 293 } |
| 294 |
| 295 const std::string& auto_login_username() const { |
| 296 return existing_user_controller()->public_session_auto_login_username_; |
| 297 } |
| 298 |
| 299 int auto_login_delay() const { |
| 300 return existing_user_controller()->public_session_auto_login_delay_; |
| 301 } |
| 302 |
| 303 bool is_login_in_progress() const { |
| 304 return existing_user_controller()->is_login_in_progress_; |
| 305 } |
| 306 |
| 239 scoped_ptr<ExistingUserController> existing_user_controller_; | 307 scoped_ptr<ExistingUserController> existing_user_controller_; |
| 240 | 308 |
| 241 // These mocks are owned by CrosLibrary class. | 309 // These mocks are owned by CrosLibrary class. |
| 242 MockNetworkLibrary* mock_network_library_; | 310 MockNetworkLibrary* mock_network_library_; |
| 243 | 311 |
| 312 // |mock_login_display_| is owned by the ExistingUserController, which calls |
| 313 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. |
| 244 MockLoginDisplay* mock_login_display_; | 314 MockLoginDisplay* mock_login_display_; |
| 245 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; | 315 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; |
| 246 | 316 |
| 247 ScopedMockUserManagerEnabler mock_user_manager_; | 317 scoped_ptr<ScopedMockUserManagerEnabler> mock_user_manager_; |
| 248 | 318 |
| 249 // Owned by LoginUtilsWrapper. | 319 // Owned by LoginUtilsWrapper. |
| 250 MockLoginUtils* mock_login_utils_; | 320 MockLoginUtils* mock_login_utils_; |
| 251 | 321 |
| 252 scoped_ptr<TestingProfile> testing_profile_; | 322 scoped_ptr<TestingProfile> testing_profile_; |
| 253 | 323 |
| 254 // Mock URLFetcher. | 324 // Mock URLFetcher. |
| 255 MockURLFetcherFactory<SuccessFetcher> factory_; | 325 MockURLFetcherFactory<SuccessFetcher> factory_; |
| 256 | 326 |
| 257 base::Callback<void(void)> profile_prepared_cb_; | 327 base::Callback<void(void)> profile_prepared_cb_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 279 .Times(1); | 349 .Times(1); |
| 280 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) | 350 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) |
| 281 .Times(1); | 351 .Times(1); |
| 282 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 352 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
| 283 .Times(1); | 353 .Times(1); |
| 284 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 354 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
| 285 .Times(1); | 355 .Times(1); |
| 286 EXPECT_CALL(*mock_login_display_host_, | 356 EXPECT_CALL(*mock_login_display_host_, |
| 287 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) | 357 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) |
| 288 .Times(0); | 358 .Times(0); |
| 289 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) | 359 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
| 290 .Times(AnyNumber()) | 360 .Times(AnyNumber()) |
| 291 .WillRepeatedly(Return(false)); | 361 .WillRepeatedly(Return(false)); |
| 292 existing_user_controller()->Login(kUsername, kPassword); | 362 existing_user_controller()->Login(kUsername, kPassword); |
| 293 content::RunAllPendingInMessageLoop(); | 363 content::RunAllPendingInMessageLoop(); |
| 294 } | 364 } |
| 295 | 365 |
| 296 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) { | 366 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) { |
| 297 EXPECT_CALL(*mock_login_display_host_, | 367 EXPECT_CALL(*mock_login_display_host_, |
| 298 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _)) | 368 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _)) |
| 299 .Times(1); | 369 .Times(1); |
| 300 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 370 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
| 301 .Times(1); | 371 .Times(1); |
| 302 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) | 372 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) |
| 303 .Times(1); | 373 .Times(1); |
| 304 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) | 374 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
| 305 .Times(AnyNumber()) | 375 .Times(AnyNumber()) |
| 306 .WillRepeatedly(Return(false)); | 376 .WillRepeatedly(Return(false)); |
| 307 // The order of these expected calls matters: the UI if first disabled | 377 // The order of these expected calls matters: the UI if first disabled |
| 308 // during the login sequence, and is enabled again for the enrollment screen. | 378 // during the login sequence, and is enabled again for the enrollment screen. |
| 309 Sequence uiEnabledSequence; | 379 Sequence uiEnabledSequence; |
| 310 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 380 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 311 .Times(1) | 381 .Times(1) |
| 312 .InSequence(uiEnabledSequence); | 382 .InSequence(uiEnabledSequence); |
| 313 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 383 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
| 314 .Times(1) | 384 .Times(1) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 339 PrepareProfile(kNewUsername, _, kPassword, _, _, _)) | 409 PrepareProfile(kNewUsername, _, kPassword, _, _, _)) |
| 340 .Times(1) | 410 .Times(1) |
| 341 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | 411 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
| 342 &base::Callback<void(void)>::Run)); | 412 &base::Callback<void(void)>::Run)); |
| 343 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) | 413 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) |
| 344 .Times(1); | 414 .Times(1); |
| 345 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 415 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
| 346 .Times(1); | 416 .Times(1); |
| 347 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) | 417 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) |
| 348 .Times(1); | 418 .Times(1); |
| 349 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) | 419 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
| 350 .Times(AnyNumber()) | 420 .Times(AnyNumber()) |
| 351 .WillRepeatedly(Return(true)); | 421 .WillRepeatedly(Return(true)); |
| 352 | 422 |
| 353 // The order of these expected calls matters: the UI if first disabled | 423 // The order of these expected calls matters: the UI if first disabled |
| 354 // during the login sequence, and is enabled again after login completion. | 424 // during the login sequence, and is enabled again after login completion. |
| 355 Sequence uiEnabledSequence; | 425 Sequence uiEnabledSequence; |
| 356 // This is disabled twice: once right after signin but before checking for | 426 // This is disabled twice: once right after signin but before checking for |
| 357 // auto-enrollment, and again after doing an ownership status check. | 427 // auto-enrollment, and again after doing an ownership status check. |
| 358 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 428 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 359 .Times(2) | 429 .Times(2) |
| 360 .InSequence(uiEnabledSequence); | 430 .InSequence(uiEnabledSequence); |
| 361 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 431 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
| 362 .Times(1) | 432 .Times(1) |
| 363 .InSequence(uiEnabledSequence); | 433 .InSequence(uiEnabledSequence); |
| 364 | 434 |
| 365 existing_user_controller()->CompleteLogin(kNewUsername, kPassword); | 435 existing_user_controller()->CompleteLogin(kNewUsername, kPassword); |
| 366 content::RunAllPendingInMessageLoop(); | 436 content::RunAllPendingInMessageLoop(); |
| 367 } | 437 } |
| 368 | 438 |
| 439 MATCHER_P(HasDetails, expected, "") { |
| 440 return expected == *content::Details<const std::string>(arg).ptr(); |
| 441 } |
| 442 |
| 443 class ExistingUserControllerPublicSessionTest |
| 444 : public ExistingUserControllerTest { |
| 445 protected: |
| 446 ExistingUserControllerPublicSessionTest() { |
| 447 } |
| 448 |
| 449 virtual void SetUpOnMainThread() OVERRIDE { |
| 450 ExistingUserControllerTest::SetUpOnMainThread(); |
| 451 |
| 452 // Wait for the public session user to be created. |
| 453 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) { |
| 454 NotificationWatcher( |
| 455 chrome::NOTIFICATION_USER_LIST_CHANGED, |
| 456 base::Bind(&chromeos::UserManager::IsKnownUser, |
| 457 base::Unretained(chromeos::UserManager::Get()), |
| 458 kAutoLoginUsername)).Run(); |
| 459 } |
| 460 |
| 461 // Wait for the device local account policy to be installed. |
| 462 policy::MockCloudPolicyStoreObserver observer; |
| 463 content::MessageLoopRunner* runner = new content::MessageLoopRunner; |
| 464 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()-> |
| 465 browser_policy_connector()->GetDeviceLocalAccountPolicyService()-> |
| 466 GetBrokerForAccount(kAutoLoginUsername)->core()->store(); |
| 467 store->AddObserver(&observer); |
| 468 EXPECT_CALL(observer, OnStoreLoaded(store)) |
| 469 .Times(1) |
| 470 .WillOnce(InvokeWithoutArgs(runner, &content::MessageLoopRunner::Quit)); |
| 471 runner->Run(); |
| 472 store->RemoveObserver(&observer); |
| 473 } |
| 474 |
| 475 virtual void SetUpSessionManager( |
| 476 MockDBusThreadManager* mock_dbus_thread_manager) OVERRIDE { |
| 477 EXPECT_CALL(*mock_dbus_thread_manager, GetSessionManagerClient()) |
| 478 .WillRepeatedly(Return(&session_manager_client_)); |
| 479 |
| 480 // Install the owner key. |
| 481 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 482 base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key"); |
| 483 std::vector<uint8> owner_key_bits; |
| 484 ASSERT_TRUE(device_policy_.signing_key()->ExportPublicKey(&owner_key_bits)); |
| 485 ASSERT_EQ( |
| 486 file_util::WriteFile( |
| 487 owner_key_file, |
| 488 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)), |
| 489 owner_key_bits.size()), |
| 490 static_cast<int>(owner_key_bits.size())); |
| 491 ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file)); |
| 492 |
| 493 // Setup the device policy. |
| 494 em::ChromeDeviceSettingsProto& proto(device_policy_.payload()); |
| 495 proto.mutable_device_local_accounts()->add_account()->set_id( |
| 496 kAutoLoginUsername); |
| 497 RefreshDevicePolicy(); |
| 498 |
| 499 // Setup the device local account policy. |
| 500 policy::UserPolicyBuilder device_local_account_policy; |
| 501 device_local_account_policy.policy_data().set_username(kAutoLoginUsername); |
| 502 device_local_account_policy.policy_data().set_policy_type( |
| 503 policy::dm_protocol::kChromePublicAccountPolicyType); |
| 504 device_local_account_policy.policy_data().set_settings_entity_id( |
| 505 kAutoLoginUsername); |
| 506 device_local_account_policy.Build(); |
| 507 session_manager_client_.set_device_local_account_policy( |
| 508 kAutoLoginUsername, |
| 509 device_local_account_policy.GetBlob()); |
| 510 } |
| 511 |
| 512 virtual void SetUpLoginDisplay() OVERRIDE { |
| 513 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
| 514 .Times(1) |
| 515 .WillOnce(Return(mock_login_display_)); |
| 516 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
| 517 .Times(AnyNumber()) |
| 518 .WillRepeatedly(ReturnNull()); |
| 519 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
| 520 .Times(AnyNumber()); |
| 521 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) |
| 522 .Times(AnyNumber()); |
| 523 } |
| 524 |
| 525 void ExpectSuccessfulLogin(const std::string& username, |
| 526 const std::string& password, |
| 527 scoped_refptr<Authenticator> create_authenticator( |
| 528 LoginStatusConsumer* consumer)) { |
| 529 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 530 .Times(AnyNumber()); |
| 531 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
| 532 .Times(1) |
| 533 .WillOnce(WithArg<0>(Invoke(create_authenticator))); |
| 534 EXPECT_CALL(*mock_login_utils_, |
| 535 PrepareProfile(username, _, password, _, _, _)) |
| 536 .Times(1) |
| 537 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
| 538 &base::Callback<void(void)>::Run)); |
| 539 EXPECT_CALL(*mock_login_utils_, |
| 540 DoBrowserLaunch(testing_profile_.get(), |
| 541 mock_login_display_host_.get())) |
| 542 .Times(1); |
| 543 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username)) |
| 544 .Times(1); |
| 545 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
| 546 .Times(1); |
| 547 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
| 548 .Times(1); |
| 549 EXPECT_CALL(*mock_login_display_host_, |
| 550 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) |
| 551 .Times(0); |
| 552 } |
| 553 |
| 554 content::MessageLoopRunner* CreateSettingsObserverRunLoop( |
| 555 content::MockNotificationObserver& observer, const char* setting) { |
| 556 content::MessageLoopRunner* runner = new content::MessageLoopRunner; |
| 557 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, |
| 558 _, HasDetails(setting))) |
| 559 .Times(1) |
| 560 .WillOnce(InvokeWithoutArgs(runner, &content::MessageLoopRunner::Quit)); |
| 561 CrosSettings::Get()->AddSettingsObserver(setting, &observer); |
| 562 return runner; |
| 563 } |
| 564 |
| 565 void RefreshDevicePolicy() { |
| 566 // Reset the key to its original state. |
| 567 device_policy_.set_signing_key( |
| 568 policy::PolicyBuilder::CreateTestSigningKey()); |
| 569 device_policy_.Build(); |
| 570 // Trick the device into thinking it's enterprise-enrolled by |
| 571 // removing the local private key. This will allow it to accept |
| 572 // cloud policy for device owner settings. |
| 573 device_policy_.set_signing_key( |
| 574 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); |
| 575 device_policy_.set_new_signing_key( |
| 576 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); |
| 577 session_manager_client_.set_device_policy(device_policy_.GetBlob()); |
| 578 session_manager_client_.OnPropertyChangeComplete(true); |
| 579 } |
| 580 |
| 581 void SetAutoLoginPolicy(const std::string& username, int delay) { |
| 582 // Wait until ExistingUserController has finished auto-login |
| 583 // configuration by observing the same settings that trigger |
| 584 // ConfigurePublicSessionAutoLogin. |
| 585 content::MockNotificationObserver observer; |
| 586 |
| 587 em::ChromeDeviceSettingsProto& proto(device_policy_.payload()); |
| 588 |
| 589 // If both settings have changed we need to wait for both to |
| 590 // propagate, so check the new values against the old ones. |
| 591 content::MessageLoopRunner* runner1 = NULL; |
| 592 if (!proto.has_device_local_accounts() || |
| 593 !proto.device_local_accounts().has_auto_login_id() || |
| 594 proto.device_local_accounts().auto_login_id() != username) { |
| 595 runner1 = CreateSettingsObserverRunLoop( |
| 596 observer, kAccountsPrefDeviceLocalAccountAutoLoginId); |
| 597 } |
| 598 content::MessageLoopRunner* runner2 = NULL; |
| 599 if (!proto.has_device_local_accounts() || |
| 600 !proto.device_local_accounts().has_auto_login_delay() || |
| 601 proto.device_local_accounts().auto_login_delay() != delay) { |
| 602 runner2 = CreateSettingsObserverRunLoop( |
| 603 observer, kAccountsPrefDeviceLocalAccountAutoLoginDelay); |
| 604 } |
| 605 |
| 606 // Update the policy. |
| 607 proto.mutable_device_local_accounts()->set_auto_login_id(username); |
| 608 proto.mutable_device_local_accounts()->set_auto_login_delay(delay); |
| 609 RefreshDevicePolicy(); |
| 610 |
| 611 // Wait for ExistingUserController to read the updated settings. |
| 612 if (runner1) |
| 613 runner1->Run(); |
| 614 if (runner2) |
| 615 runner2->Run(); |
| 616 |
| 617 // Clean up. |
| 618 CrosSettings::Get()->RemoveSettingsObserver( |
| 619 kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 620 &observer); |
| 621 CrosSettings::Get()->RemoveSettingsObserver( |
| 622 kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| 623 &observer); |
| 624 } |
| 625 |
| 626 void ConfigureAutoLogin() { |
| 627 existing_user_controller()->ConfigurePublicSessionAutoLogin(); |
| 628 } |
| 629 |
| 630 void FireAutoLogin() { |
| 631 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); |
| 632 } |
| 633 |
| 634 // Mock out policy loads/stores from/to the device. |
| 635 FakeSessionManagerClient session_manager_client_; |
| 636 |
| 637 // Stores the device owner key. |
| 638 base::ScopedTempDir temp_dir_; |
| 639 |
| 640 // Carries Chrome OS device policies for tests. |
| 641 policy::DevicePolicyBuilder device_policy_; |
| 642 |
| 643 private: |
| 644 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); |
| 645 }; |
| 646 |
| 647 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 648 ConfigureAutoLoginUsingPolicy) { |
| 649 existing_user_controller()->OnSigninScreenReady(); |
| 650 EXPECT_EQ("", auto_login_username()); |
| 651 EXPECT_EQ(0, auto_login_delay()); |
| 652 EXPECT_FALSE(auto_login_timer()); |
| 653 |
| 654 // Set the policy. |
| 655 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 656 EXPECT_EQ(kAutoLoginUsername, auto_login_username()); |
| 657 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay()); |
| 658 ASSERT_TRUE(auto_login_timer()); |
| 659 EXPECT_TRUE(auto_login_timer()->IsRunning()); |
| 660 |
| 661 // Unset the policy. |
| 662 SetAutoLoginPolicy("", 0); |
| 663 EXPECT_EQ("", auto_login_username()); |
| 664 EXPECT_EQ(0, auto_login_delay()); |
| 665 ASSERT_TRUE(auto_login_timer()); |
| 666 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 667 } |
| 668 |
| 669 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 670 AutoLoginNoDelay) { |
| 671 // Set up mocks to check login success. |
| 672 ExpectSuccessfulLogin(kAutoLoginUsername, "", |
| 673 CreateAuthenticatorForPublicSession); |
| 674 existing_user_controller()->OnSigninScreenReady(); |
| 675 |
| 676 // Start auto-login and wait for login tasks to complete. |
| 677 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginNoDelay); |
| 678 content::RunAllPendingInMessageLoop(); |
| 679 } |
| 680 |
| 681 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 682 AutoLoginShortDelay) { |
| 683 // Set up mocks to check login success. |
| 684 ExpectSuccessfulLogin(kAutoLoginUsername, "", |
| 685 CreateAuthenticatorForPublicSession); |
| 686 existing_user_controller()->OnSigninScreenReady(); |
| 687 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay); |
| 688 ASSERT_TRUE(auto_login_timer()); |
| 689 // Don't assert that timer is running: with the short delay sometimes |
| 690 // the trigger happens before the assert. We've already tested that |
| 691 // the timer starts when it should. |
| 692 |
| 693 // Wait for the timer to fire. |
| 694 content::MessageLoopRunner* runner = new content::MessageLoopRunner; |
| 695 base::OneShotTimer<content::MessageLoopRunner> timer; |
| 696 timer.Start(FROM_HERE, |
| 697 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), |
| 698 base::Bind(&content::MessageLoopRunner::Quit, |
| 699 base::Unretained(runner))); |
| 700 runner->Run(); |
| 701 |
| 702 // Wait for login tasks to complete. |
| 703 content::RunAllPendingInMessageLoop(); |
| 704 } |
| 705 |
| 706 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 707 LoginStopsAutoLogin) { |
| 708 // Set up mocks to check login success. |
| 709 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator); |
| 710 |
| 711 existing_user_controller()->OnSigninScreenReady(); |
| 712 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 713 ASSERT_TRUE(auto_login_timer()); |
| 714 |
| 715 // Login and check that it stopped the timer. |
| 716 existing_user_controller()->Login(kUsername, kPassword); |
| 717 EXPECT_TRUE(is_login_in_progress()); |
| 718 ASSERT_TRUE(auto_login_timer()); |
| 719 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 720 |
| 721 // Wait for login tasks to complete. |
| 722 content::RunAllPendingInMessageLoop(); |
| 723 |
| 724 // Timer should still be stopped after login completes. |
| 725 ASSERT_TRUE(auto_login_timer()); |
| 726 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 727 } |
| 728 |
| 729 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 730 GuestModeLoginStopsAutoLogin) { |
| 731 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 732 .Times(1); |
| 733 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
| 734 .Times(1) |
| 735 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator))); |
| 736 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_)) |
| 737 .Times(1); |
| 738 |
| 739 existing_user_controller()->OnSigninScreenReady(); |
| 740 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 741 ASSERT_TRUE(auto_login_timer()); |
| 742 |
| 743 // Login and check that it stopped the timer. |
| 744 existing_user_controller()->LoginAsGuest(); |
| 745 EXPECT_TRUE(is_login_in_progress()); |
| 746 ASSERT_TRUE(auto_login_timer()); |
| 747 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 748 |
| 749 // Wait for login tasks to complete. |
| 750 content::RunAllPendingInMessageLoop(); |
| 751 |
| 752 // Timer should still be stopped after login completes. |
| 753 ASSERT_TRUE(auto_login_timer()); |
| 754 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 755 } |
| 756 |
| 757 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 758 CompleteLoginStopsAutoLogin) { |
| 759 // Set up mocks to check login success. |
| 760 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator); |
| 761 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) |
| 762 .Times(1); |
| 763 |
| 764 existing_user_controller()->OnSigninScreenReady(); |
| 765 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 766 ASSERT_TRUE(auto_login_timer()); |
| 767 |
| 768 // Check that login completes and stops the timer. |
| 769 existing_user_controller()->CompleteLogin(kUsername, kPassword); |
| 770 ASSERT_TRUE(auto_login_timer()); |
| 771 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 772 |
| 773 // Wait for login tasks to complete. |
| 774 content::RunAllPendingInMessageLoop(); |
| 775 |
| 776 // Timer should still be stopped after login completes. |
| 777 ASSERT_TRUE(auto_login_timer()); |
| 778 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 779 } |
| 780 |
| 781 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 782 PublicSessionLoginStopsAutoLogin) { |
| 783 // Set up mocks to check login success. |
| 784 ExpectSuccessfulLogin(kAutoLoginUsername, "", |
| 785 CreateAuthenticatorForPublicSession); |
| 786 existing_user_controller()->OnSigninScreenReady(); |
| 787 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay); |
| 788 ASSERT_TRUE(auto_login_timer()); |
| 789 |
| 790 // Login and check that it stopped the timer. |
| 791 existing_user_controller()->LoginAsPublicAccount(kAutoLoginUsername); |
| 792 EXPECT_TRUE(is_login_in_progress()); |
| 793 ASSERT_TRUE(auto_login_timer()); |
| 794 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 795 |
| 796 // Wait for login tasks to complete. |
| 797 content::RunAllPendingInMessageLoop(); |
| 798 |
| 799 // Timer should still be stopped after login completes. |
| 800 ASSERT_TRUE(auto_login_timer()); |
| 801 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 802 } |
| 803 |
| 369 } // namespace chromeos | 804 } // namespace chromeos |
| OLD | NEW |