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