| 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> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/files/scoped_temp_dir.h" | |
| 14 #include "base/location.h" | 12 #include "base/location.h" |
| 15 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 16 #include "base/path_service.h" | |
| 17 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 18 #include "base/stl_util.h" | |
| 19 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | |
| 20 #include "chrome/browser/chromeos/cros/cros_mock.h" | 15 #include "chrome/browser/chromeos/cros/cros_mock.h" |
| 21 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 16 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
| 22 #include "chrome/browser/chromeos/login/authenticator.h" | 17 #include "chrome/browser/chromeos/login/authenticator.h" |
| 23 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 18 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 24 #include "chrome/browser/chromeos/login/helper.h" | 19 #include "chrome/browser/chromeos/login/helper.h" |
| 25 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 20 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
| 26 #include "chrome/browser/chromeos/login/mock_authenticator.h" | 21 #include "chrome/browser/chromeos/login/mock_authenticator.h" |
| 27 #include "chrome/browser/chromeos/login/mock_login_display.h" | 22 #include "chrome/browser/chromeos/login/mock_login_display.h" |
| 28 #include "chrome/browser/chromeos/login/mock_login_display_host.h" | 23 #include "chrome/browser/chromeos/login/mock_login_display_host.h" |
| 29 #include "chrome/browser/chromeos/login/mock_login_utils.h" | 24 #include "chrome/browser/chromeos/login/mock_login_utils.h" |
| 30 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" | 25 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
| 31 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 26 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 32 #include "chrome/browser/chromeos/login/user_manager.h" | 27 #include "chrome/browser/chromeos/login/user_manager.h" |
| 33 #include "chrome/browser/chromeos/login/wizard_controller.h" | 28 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 34 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 29 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| 35 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 30 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| 36 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | |
| 37 #include "chrome/browser/chromeos/settings/cros_settings.h" | 31 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 38 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 32 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 39 #include "chrome/browser/policy/browser_policy_connector.h" | 33 #include "chrome/browser/policy/browser_policy_connector.h" |
| 40 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 34 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 41 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | 35 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
| 42 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 36 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
| 43 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" | 37 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
| 44 #include "chrome/browser/policy/cloud/policy_builder.h" | 38 #include "chrome/browser/policy/cloud/policy_builder.h" |
| 45 #include "chrome/common/chrome_notification_types.h" | 39 #include "chrome/common/chrome_notification_types.h" |
| 46 #include "chrome/common/chrome_paths.h" | |
| 47 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
| 48 #include "chrome/test/base/testing_browser_process.h" | |
| 49 #include "chrome/test/base/testing_profile.h" | 41 #include "chrome/test/base/testing_profile.h" |
| 50 #include "chrome/test/base/ui_test_utils.h" | 42 #include "chrome/test/base/ui_test_utils.h" |
| 51 #include "chromeos/chromeos_switches.h" | 43 #include "chromeos/chromeos_switches.h" |
| 52 #include "chromeos/dbus/fake_session_manager_client.h" | 44 #include "chromeos/dbus/fake_session_manager_client.h" |
| 53 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 45 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 54 #include "chromeos/dbus/mock_session_manager_client.h" | |
| 55 #include "chromeos/dbus/mock_shill_manager_client.h" | 46 #include "chromeos/dbus/mock_shill_manager_client.h" |
| 56 #include "chromeos/dbus/mock_update_engine_client.h" | 47 #include "chromeos/dbus/mock_update_engine_client.h" |
| 57 #include "content/public/browser/notification_details.h" | 48 #include "content/public/browser/notification_details.h" |
| 58 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
| 59 #include "content/public/test/mock_notification_observer.h" | 50 #include "content/public/test/mock_notification_observer.h" |
| 60 #include "crypto/rsa_private_key.h" | |
| 61 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 51 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
| 62 #include "grit/generated_resources.h" | 52 #include "grit/generated_resources.h" |
| 63 #include "testing/gmock/include/gmock/gmock.h" | 53 #include "testing/gmock/include/gmock/gmock.h" |
| 64 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
| 65 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 66 | 56 |
| 67 using ::testing::_; | 57 using ::testing::_; |
| 68 using ::testing::AnyNumber; | 58 using ::testing::AnyNumber; |
| 69 using ::testing::Invoke; | 59 using ::testing::Invoke; |
| 70 using ::testing::InvokeWithoutArgs; | 60 using ::testing::InvokeWithoutArgs; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 private: | 126 private: |
| 137 int type_; | 127 int type_; |
| 138 ConditionTestCallback callback_; | 128 ConditionTestCallback callback_; |
| 139 base::RunLoop run_loop_; | 129 base::RunLoop run_loop_; |
| 140 | 130 |
| 141 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher); | 131 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher); |
| 142 }; | 132 }; |
| 143 | 133 |
| 144 } // namespace | 134 } // namespace |
| 145 | 135 |
| 146 class ExistingUserControllerTest : public CrosInProcessBrowserTest { | 136 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { |
| 147 protected: | 137 protected: |
| 148 ExistingUserControllerTest() | 138 ExistingUserControllerTest() |
| 149 : mock_network_library_(NULL), | 139 : mock_network_library_(NULL), |
| 150 mock_login_display_(NULL), | 140 mock_login_display_(NULL), |
| 151 mock_login_display_host_(NULL), | 141 mock_login_display_host_(NULL), |
| 152 testing_profile_(NULL) { | 142 testing_profile_(NULL) { |
| 153 } | 143 } |
| 154 | 144 |
| 155 ExistingUserController* existing_user_controller() { | 145 ExistingUserController* existing_user_controller() { |
| 156 return ExistingUserController::current_controller(); | 146 return ExistingUserController::current_controller(); |
| 157 } | 147 } |
| 158 | 148 |
| 159 const ExistingUserController* existing_user_controller() const { | 149 const ExistingUserController* existing_user_controller() const { |
| 160 return ExistingUserController::current_controller(); | 150 return ExistingUserController::current_controller(); |
| 161 } | 151 } |
| 162 | 152 |
| 163 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 153 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 164 MockDBusThreadManager* mock_dbus_thread_manager = | 154 EXPECT_CALL(*mock_dbus_thread_manager(), GetSystemBus()) |
| 165 new MockDBusThreadManager; | |
| 166 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | |
| 167 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | 155 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); |
| 168 EXPECT_CALL(*mock_dbus_thread_manager, GetIBusInputContextClient()) | 156 EXPECT_CALL(*mock_dbus_thread_manager(), GetIBusInputContextClient()) |
| 169 .WillRepeatedly( | 157 .WillRepeatedly( |
| 170 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); | 158 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); |
| 171 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 159 EXPECT_CALL(*mock_dbus_thread_manager()->mock_shill_manager_client(), |
| 172 GetProperties(_)) | 160 GetProperties(_)) |
| 173 .Times(AnyNumber()); | 161 .Times(AnyNumber()); |
| 174 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 162 EXPECT_CALL(*mock_dbus_thread_manager()->mock_shill_manager_client(), |
| 175 AddPropertyChangedObserver(_)) | 163 AddPropertyChangedObserver(_)) |
| 176 .Times(AnyNumber()); | 164 .Times(AnyNumber()); |
| 177 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 165 EXPECT_CALL(*mock_dbus_thread_manager()->mock_shill_manager_client(), |
| 178 RemovePropertyChangedObserver(_)) | 166 RemovePropertyChangedObserver(_)) |
| 179 .Times(AnyNumber()); | 167 .Times(AnyNumber()); |
| 180 | 168 |
| 181 SetUpSessionManager(mock_dbus_thread_manager); | 169 SetUpSessionManager(); |
| 182 | 170 |
| 183 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 171 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 184 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 185 cros_mock_->InitStatusAreaMocks(); | 172 cros_mock_->InitStatusAreaMocks(); |
| 186 cros_mock_->SetStatusAreaMocksExpectations(); | 173 cros_mock_->SetStatusAreaMocksExpectations(); |
| 187 | 174 |
| 188 mock_network_library_ = cros_mock_->mock_network_library(); | 175 mock_network_library_ = cros_mock_->mock_network_library(); |
| 189 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) | 176 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) |
| 190 .Times(AnyNumber()); | 177 .Times(AnyNumber()); |
| 191 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) | 178 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) |
| 192 .WillRepeatedly(Return(true)); | 179 .WillRepeatedly(Return(true)); |
| 193 | 180 |
| 194 mock_login_utils_ = new MockLoginUtils(); | 181 mock_login_utils_ = new MockLoginUtils(); |
| 195 LoginUtils::Set(mock_login_utils_); | 182 LoginUtils::Set(mock_login_utils_); |
| 196 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) | 183 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) |
| 197 .Times(AnyNumber()); | 184 .Times(AnyNumber()); |
| 198 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) | 185 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) |
| 199 .Times(AnyNumber()); | 186 .Times(AnyNumber()); |
| 200 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) | 187 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) |
| 201 .Times(1); | 188 .Times(1); |
| 202 | 189 |
| 203 mock_login_display_host_.reset(new MockLoginDisplayHost()); | 190 mock_login_display_host_.reset(new MockLoginDisplayHost()); |
| 204 mock_login_display_ = new MockLoginDisplay(); | 191 mock_login_display_ = new MockLoginDisplay(); |
| 205 SetUpLoginDisplay(); | 192 SetUpLoginDisplay(); |
| 206 } | 193 } |
| 207 | 194 |
| 208 virtual void SetUpSessionManager( | 195 virtual void SetUpSessionManager() { |
| 209 MockDBusThreadManager* mock_dbus_thread_manager) { | |
| 210 mock_user_manager_.reset(new ScopedMockUserManagerEnabler); | 196 mock_user_manager_.reset(new ScopedMockUserManagerEnabler); |
| 211 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername)) | 197 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername)) |
| 212 .Times(AnyNumber()) | 198 .Times(AnyNumber()) |
| 213 .WillRepeatedly(Return(true)); | 199 .WillRepeatedly(Return(true)); |
| 214 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername)) | 200 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername)) |
| 215 .Times(AnyNumber()) | 201 .Times(AnyNumber()) |
| 216 .WillRepeatedly(Return(false)); | 202 .WillRepeatedly(Return(false)); |
| 217 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn()) | 203 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn()) |
| 218 .Times(AnyNumber()) | 204 .Times(AnyNumber()) |
| 219 .WillRepeatedly(Return(false)); | 205 .WillRepeatedly(Return(false)); |
| 220 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsGuest()) | 206 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsGuest()) |
| 221 .Times(AnyNumber()) | 207 .Times(AnyNumber()) |
| 222 .WillRepeatedly(Return(false)); | 208 .WillRepeatedly(Return(false)); |
| 223 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsDemoUser()) | 209 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsDemoUser()) |
| 224 .Times(AnyNumber()) | 210 .Times(AnyNumber()) |
| 225 .WillRepeatedly(Return(false)); | 211 .WillRepeatedly(Return(false)); |
| 226 EXPECT_CALL(*mock_user_manager_->user_manager(), | 212 EXPECT_CALL(*mock_user_manager_->user_manager(), |
| 227 IsLoggedInAsPublicAccount()) | 213 IsLoggedInAsPublicAccount()) |
| 228 .Times(AnyNumber()) | 214 .Times(AnyNumber()) |
| 229 .WillRepeatedly(Return(false)); | 215 .WillRepeatedly(Return(false)); |
| 230 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted()) | 216 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted()) |
| 231 .Times(AnyNumber()) | 217 .Times(AnyNumber()) |
| 232 .WillRepeatedly(Return(false)); | 218 .WillRepeatedly(Return(false)); |
| 233 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) | 219 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
| 234 .Times(AnyNumber()) | 220 .Times(AnyNumber()) |
| 235 .WillRepeatedly(Return(false)); | 221 .WillRepeatedly(Return(false)); |
| 236 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown()) | 222 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown()) |
| 237 .Times(1); | 223 .Times(1); |
| 238 | |
| 239 MockSessionManagerClient* mock_session_manager_client = | |
| 240 mock_dbus_thread_manager->mock_session_manager_client(); | |
| 241 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady()) | |
| 242 .Times(1); | |
| 243 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) | |
| 244 .Times(AnyNumber()); | |
| 245 } | 224 } |
| 246 | 225 |
| 247 virtual void SetUpLoginDisplay() { | 226 virtual void SetUpLoginDisplay() { |
| 248 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | 227 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
| 249 .Times(1) | 228 .Times(1) |
| 250 .WillOnce(Return(mock_login_display_)); | 229 .WillOnce(Return(mock_login_display_)); |
| 251 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 230 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
| 252 .Times(1) | 231 .Times(1) |
| 253 .WillOnce(ReturnNull()); | 232 .WillOnce(ReturnNull()); |
| 254 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) | 233 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 277 // ExistingUserController must be deleted before the thread is cleaned up: | 256 // ExistingUserController must be deleted before the thread is cleaned up: |
| 278 // If there is an outstanding login attempt when ExistingUserController is | 257 // If there is an outstanding login attempt when ExistingUserController is |
| 279 // deleted, its LoginPerformer instance will be deleted, which in turn | 258 // deleted, its LoginPerformer instance will be deleted, which in turn |
| 280 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must | 259 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must |
| 281 // be deleted on the UI thread. | 260 // be deleted on the UI thread. |
| 282 existing_user_controller_.reset(); | 261 existing_user_controller_.reset(); |
| 283 CrosInProcessBrowserTest::CleanUpOnMainThread(); | 262 CrosInProcessBrowserTest::CleanUpOnMainThread(); |
| 284 testing_profile_.reset(NULL); | 263 testing_profile_.reset(NULL); |
| 285 } | 264 } |
| 286 | 265 |
| 287 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | |
| 288 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | |
| 289 DBusThreadManager::Shutdown(); | |
| 290 } | |
| 291 | |
| 292 // ExistingUserController private member accessors. | 266 // ExistingUserController private member accessors. |
| 293 base::OneShotTimer<ExistingUserController>* auto_login_timer() { | 267 base::OneShotTimer<ExistingUserController>* auto_login_timer() { |
| 294 return existing_user_controller()->auto_login_timer_.get(); | 268 return existing_user_controller()->auto_login_timer_.get(); |
| 295 } | 269 } |
| 296 | 270 |
| 297 const std::string& auto_login_username() const { | 271 const std::string& auto_login_username() const { |
| 298 return existing_user_controller()->public_session_auto_login_username_; | 272 return existing_user_controller()->public_session_auto_login_username_; |
| 299 } | 273 } |
| 300 | 274 |
| 301 int auto_login_delay() const { | 275 int auto_login_delay() const { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 // Wait for the public session user to be created. | 429 // Wait for the public session user to be created. |
| 456 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) { | 430 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) { |
| 457 NotificationWatcher( | 431 NotificationWatcher( |
| 458 chrome::NOTIFICATION_USER_LIST_CHANGED, | 432 chrome::NOTIFICATION_USER_LIST_CHANGED, |
| 459 base::Bind(&chromeos::UserManager::IsKnownUser, | 433 base::Bind(&chromeos::UserManager::IsKnownUser, |
| 460 base::Unretained(chromeos::UserManager::Get()), | 434 base::Unretained(chromeos::UserManager::Get()), |
| 461 kAutoLoginUsername)).Run(); | 435 kAutoLoginUsername)).Run(); |
| 462 } | 436 } |
| 463 | 437 |
| 464 // Wait for the device local account policy to be installed. | 438 // Wait for the device local account policy to be installed. |
| 465 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()-> | 439 policy::CloudPolicyStore* store = browser_process()-> |
| 466 browser_policy_connector()->GetDeviceLocalAccountPolicyService()-> | 440 browser_policy_connector()->GetDeviceLocalAccountPolicyService()-> |
| 467 GetBrokerForAccount(kAutoLoginUsername)->core()->store(); | 441 GetBrokerForAccount(kAutoLoginUsername)->core()->store(); |
| 468 if (!store->has_policy()) { | 442 if (!store->has_policy()) { |
| 469 policy::MockCloudPolicyStoreObserver observer; | 443 policy::MockCloudPolicyStoreObserver observer; |
| 470 | 444 |
| 471 base::RunLoop loop; | 445 base::RunLoop loop; |
| 472 store->AddObserver(&observer); | 446 store->AddObserver(&observer); |
| 473 EXPECT_CALL(observer, OnStoreLoaded(store)) | 447 EXPECT_CALL(observer, OnStoreLoaded(store)) |
| 474 .Times(1) | 448 .Times(1) |
| 475 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); | 449 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); |
| 476 loop.Run(); | 450 loop.Run(); |
| 477 store->RemoveObserver(&observer); | 451 store->RemoveObserver(&observer); |
| 478 } | 452 } |
| 479 } | 453 } |
| 480 | 454 |
| 481 virtual void SetUpSessionManager( | 455 virtual void SetUpSessionManager() OVERRIDE { |
| 482 MockDBusThreadManager* mock_dbus_thread_manager) OVERRIDE { | 456 InstallOwnerKey(); |
| 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 | 457 |
| 499 // Setup the device policy. | 458 // Setup the device policy. |
| 500 em::ChromeDeviceSettingsProto& proto(device_policy_.payload()); | 459 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 501 proto.mutable_device_local_accounts()->add_account()->set_id( | 460 proto.mutable_device_local_accounts()->add_account()->set_id( |
| 502 kAutoLoginUsername); | 461 kAutoLoginUsername); |
| 503 RefreshDevicePolicy(); | 462 RefreshDevicePolicy(); |
| 504 | 463 |
| 505 // Setup the device local account policy. | 464 // Setup the device local account policy. |
| 506 policy::UserPolicyBuilder device_local_account_policy; | 465 policy::UserPolicyBuilder device_local_account_policy; |
| 507 device_local_account_policy.policy_data().set_username(kAutoLoginUsername); | 466 device_local_account_policy.policy_data().set_username(kAutoLoginUsername); |
| 508 device_local_account_policy.policy_data().set_policy_type( | 467 device_local_account_policy.policy_data().set_policy_type( |
| 509 policy::dm_protocol::kChromePublicAccountPolicyType); | 468 policy::dm_protocol::kChromePublicAccountPolicyType); |
| 510 device_local_account_policy.policy_data().set_settings_entity_id( | 469 device_local_account_policy.policy_data().set_settings_entity_id( |
| 511 kAutoLoginUsername); | 470 kAutoLoginUsername); |
| 512 device_local_account_policy.Build(); | 471 device_local_account_policy.Build(); |
| 513 session_manager_client_.set_device_local_account_policy( | 472 session_manager_client()->set_device_local_account_policy( |
| 514 kAutoLoginUsername, | 473 kAutoLoginUsername, |
| 515 device_local_account_policy.GetBlob()); | 474 device_local_account_policy.GetBlob()); |
| 516 } | 475 } |
| 517 | 476 |
| 518 virtual void SetUpLoginDisplay() OVERRIDE { | 477 virtual void SetUpLoginDisplay() OVERRIDE { |
| 519 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | 478 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
| 520 .Times(1) | 479 .Times(1) |
| 521 .WillOnce(Return(mock_login_display_)); | 480 .WillOnce(Return(mock_login_display_)); |
| 522 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 481 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
| 523 .Times(AnyNumber()) | 482 .Times(AnyNumber()) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 content::MockNotificationObserver& observer, const char* setting) { | 521 content::MockNotificationObserver& observer, const char* setting) { |
| 563 base::RunLoop* loop = new base::RunLoop; | 522 base::RunLoop* loop = new base::RunLoop; |
| 564 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, | 523 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, |
| 565 _, HasDetails(setting))) | 524 _, HasDetails(setting))) |
| 566 .Times(1) | 525 .Times(1) |
| 567 .WillOnce(InvokeWithoutArgs(loop, &base::RunLoop::Quit)); | 526 .WillOnce(InvokeWithoutArgs(loop, &base::RunLoop::Quit)); |
| 568 CrosSettings::Get()->AddSettingsObserver(setting, &observer); | 527 CrosSettings::Get()->AddSettingsObserver(setting, &observer); |
| 569 return make_scoped_ptr(loop); | 528 return make_scoped_ptr(loop); |
| 570 } | 529 } |
| 571 | 530 |
| 572 void RefreshDevicePolicy() { | |
| 573 // Reset the key to its original state. | |
| 574 device_policy_.set_signing_key( | |
| 575 policy::PolicyBuilder::CreateTestSigningKey()); | |
| 576 device_policy_.Build(); | |
| 577 // Trick the device into thinking it's enterprise-enrolled by | |
| 578 // removing the local private key. This will allow it to accept | |
| 579 // cloud policy for device owner settings. | |
| 580 device_policy_.set_signing_key( | |
| 581 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); | |
| 582 device_policy_.set_new_signing_key( | |
| 583 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); | |
| 584 session_manager_client_.set_device_policy(device_policy_.GetBlob()); | |
| 585 session_manager_client_.OnPropertyChangeComplete(true); | |
| 586 } | |
| 587 | |
| 588 void SetAutoLoginPolicy(const std::string& username, int delay) { | 531 void SetAutoLoginPolicy(const std::string& username, int delay) { |
| 589 // Wait until ExistingUserController has finished auto-login | 532 // Wait until ExistingUserController has finished auto-login |
| 590 // configuration by observing the same settings that trigger | 533 // configuration by observing the same settings that trigger |
| 591 // ConfigurePublicSessionAutoLogin. | 534 // ConfigurePublicSessionAutoLogin. |
| 592 content::MockNotificationObserver observer; | 535 content::MockNotificationObserver observer; |
| 593 | 536 |
| 594 em::ChromeDeviceSettingsProto& proto(device_policy_.payload()); | 537 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 595 | 538 |
| 596 // If both settings have changed we need to wait for both to | 539 // If both settings have changed we need to wait for both to |
| 597 // propagate, so check the new values against the old ones. | 540 // propagate, so check the new values against the old ones. |
| 598 scoped_ptr<base::RunLoop> runner1; | 541 scoped_ptr<base::RunLoop> runner1; |
| 599 if (!proto.has_device_local_accounts() || | 542 if (!proto.has_device_local_accounts() || |
| 600 !proto.device_local_accounts().has_auto_login_id() || | 543 !proto.device_local_accounts().has_auto_login_id() || |
| 601 proto.device_local_accounts().auto_login_id() != username) { | 544 proto.device_local_accounts().auto_login_id() != username) { |
| 602 runner1 = CreateSettingsObserverRunLoop( | 545 runner1 = CreateSettingsObserverRunLoop( |
| 603 observer, kAccountsPrefDeviceLocalAccountAutoLoginId); | 546 observer, kAccountsPrefDeviceLocalAccountAutoLoginId); |
| 604 } | 547 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 631 } | 574 } |
| 632 | 575 |
| 633 void ConfigureAutoLogin() { | 576 void ConfigureAutoLogin() { |
| 634 existing_user_controller()->ConfigurePublicSessionAutoLogin(); | 577 existing_user_controller()->ConfigurePublicSessionAutoLogin(); |
| 635 } | 578 } |
| 636 | 579 |
| 637 void FireAutoLogin() { | 580 void FireAutoLogin() { |
| 638 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); | 581 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); |
| 639 } | 582 } |
| 640 | 583 |
| 641 // Mock out policy loads/stores from/to the device. | |
| 642 FakeSessionManagerClient session_manager_client_; | |
| 643 | |
| 644 // Stores the device owner key. | |
| 645 base::ScopedTempDir temp_dir_; | |
| 646 | |
| 647 // Carries Chrome OS device policies for tests. | |
| 648 policy::DevicePolicyBuilder device_policy_; | |
| 649 | |
| 650 private: | 584 private: |
| 651 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); | 585 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); |
| 652 }; | 586 }; |
| 653 | 587 |
| 654 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 588 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 655 ConfigureAutoLoginUsingPolicy) { | 589 ConfigureAutoLoginUsingPolicy) { |
| 656 existing_user_controller()->OnSigninScreenReady(); | 590 existing_user_controller()->OnSigninScreenReady(); |
| 657 EXPECT_EQ("", auto_login_username()); | 591 EXPECT_EQ("", auto_login_username()); |
| 658 EXPECT_EQ(0, auto_login_delay()); | 592 EXPECT_EQ(0, auto_login_delay()); |
| 659 EXPECT_FALSE(auto_login_timer()); | 593 EXPECT_FALSE(auto_login_timer()); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 | 736 |
| 803 // Wait for login tasks to complete. | 737 // Wait for login tasks to complete. |
| 804 content::RunAllPendingInMessageLoop(); | 738 content::RunAllPendingInMessageLoop(); |
| 805 | 739 |
| 806 // Timer should still be stopped after login completes. | 740 // Timer should still be stopped after login completes. |
| 807 ASSERT_TRUE(auto_login_timer()); | 741 ASSERT_TRUE(auto_login_timer()); |
| 808 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 742 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 809 } | 743 } |
| 810 | 744 |
| 811 } // namespace chromeos | 745 } // namespace chromeos |
| OLD | NEW |