Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller_browsertest.cc

Issue 14268009: Support VariationsRestrictParameter in VariationsService for Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Browser tests refactored Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_browsertest.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" 46 #include "chromeos/dbus/mock_session_manager_client.h"
55 #include "chromeos/dbus/mock_shill_manager_client.h" 47 #include "chromeos/dbus/mock_shill_manager_client.h"
56 #include "chromeos/dbus/mock_update_engine_client.h" 48 #include "chromeos/dbus/mock_update_engine_client.h"
57 #include "content/public/browser/notification_details.h" 49 #include "content/public/browser/notification_details.h"
58 #include "content/public/browser/notification_service.h" 50 #include "content/public/browser/notification_service.h"
59 #include "content/public/test/mock_notification_observer.h" 51 #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" 52 #include "google_apis/gaia/mock_url_fetcher_factory.h"
62 #include "grit/generated_resources.h" 53 #include "grit/generated_resources.h"
63 #include "testing/gmock/include/gmock/gmock.h" 54 #include "testing/gmock/include/gmock/gmock.h"
64 #include "testing/gtest/include/gtest/gtest.h" 55 #include "testing/gtest/include/gtest/gtest.h"
65 #include "ui/base/l10n/l10n_util.h" 56 #include "ui/base/l10n/l10n_util.h"
66 57
67 using ::testing::_; 58 using ::testing::_;
68 using ::testing::AnyNumber; 59 using ::testing::AnyNumber;
69 using ::testing::Invoke; 60 using ::testing::Invoke;
70 using ::testing::InvokeWithoutArgs; 61 using ::testing::InvokeWithoutArgs;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 private: 127 private:
137 int type_; 128 int type_;
138 ConditionTestCallback callback_; 129 ConditionTestCallback callback_;
139 base::RunLoop run_loop_; 130 base::RunLoop run_loop_;
140 131
141 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher); 132 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher);
142 }; 133 };
143 134
144 } // namespace 135 } // namespace
145 136
146 class ExistingUserControllerTest : public CrosInProcessBrowserTest { 137 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest {
147 protected: 138 protected:
148 ExistingUserControllerTest() 139 ExistingUserControllerTest()
149 : mock_network_library_(NULL), 140 : mock_network_library_(NULL),
150 mock_login_display_(NULL), 141 mock_login_display_(NULL),
151 mock_login_display_host_(NULL), 142 mock_login_display_host_(NULL),
152 testing_profile_(NULL) { 143 testing_profile_(NULL) {
153 } 144 }
154 145
155 ExistingUserController* existing_user_controller() { 146 ExistingUserController* existing_user_controller() {
156 return ExistingUserController::current_controller(); 147 return ExistingUserController::current_controller();
157 } 148 }
158 149
159 const ExistingUserController* existing_user_controller() const { 150 const ExistingUserController* existing_user_controller() const {
160 return ExistingUserController::current_controller(); 151 return ExistingUserController::current_controller();
161 } 152 }
162 153
163 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 154 virtual void SetMockDBusThreadManagerExpectations() OVERRIDE {
164 MockDBusThreadManager* mock_dbus_thread_manager = 155 DevicePolicyCrosBrowserTest::SetMockDBusThreadManagerExpectations();
165 new MockDBusThreadManager; 156 EXPECT_CALL(*mock_dbus_thread_manager(), GetSystemBus())
166 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
167 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); 157 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
168 EXPECT_CALL(*mock_dbus_thread_manager, GetIBusInputContextClient()) 158 EXPECT_CALL(*mock_dbus_thread_manager(), GetIBusInputContextClient())
169 .WillRepeatedly( 159 .WillRepeatedly(
170 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); 160 Return(reinterpret_cast<IBusInputContextClient*>(NULL)));
171 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 161 EXPECT_CALL(*mock_dbus_thread_manager()->mock_shill_manager_client(),
172 GetProperties(_)) 162 GetProperties(_))
173 .Times(AnyNumber()); 163 .Times(AnyNumber());
174 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 164 EXPECT_CALL(*mock_dbus_thread_manager()->mock_shill_manager_client(),
175 AddPropertyChangedObserver(_)) 165 AddPropertyChangedObserver(_))
176 .Times(AnyNumber()); 166 .Times(AnyNumber());
177 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 167 EXPECT_CALL(*mock_dbus_thread_manager()->mock_shill_manager_client(),
178 RemovePropertyChangedObserver(_)) 168 RemovePropertyChangedObserver(_))
179 .Times(AnyNumber()); 169 .Times(AnyNumber());
180
181 SetUpSessionManager(mock_dbus_thread_manager);
182
183 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
184 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
185 cros_mock_->InitStatusAreaMocks();
186 cros_mock_->SetStatusAreaMocksExpectations();
187
188 mock_network_library_ = cros_mock_->mock_network_library();
189 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_))
190 .Times(AnyNumber());
191 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _))
192 .WillRepeatedly(Return(true));
193
194 mock_login_utils_ = new MockLoginUtils();
195 LoginUtils::Set(mock_login_utils_);
196 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication())
197 .Times(AnyNumber());
198 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers())
199 .Times(AnyNumber());
200 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_))
201 .Times(1);
202
203 mock_login_display_host_.reset(new MockLoginDisplayHost());
204 mock_login_display_ = new MockLoginDisplay();
205 SetUpLoginDisplay();
206 } 170 }
207 171
208 virtual void SetUpSessionManager( 172 virtual void SetUpSessionManager() OVERRIDE {
209 MockDBusThreadManager* mock_dbus_thread_manager) {
210 mock_user_manager_.reset(new ScopedMockUserManagerEnabler); 173 mock_user_manager_.reset(new ScopedMockUserManagerEnabler);
211 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername)) 174 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername))
212 .Times(AnyNumber()) 175 .Times(AnyNumber())
213 .WillRepeatedly(Return(true)); 176 .WillRepeatedly(Return(true));
214 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername)) 177 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername))
215 .Times(AnyNumber()) 178 .Times(AnyNumber())
216 .WillRepeatedly(Return(false)); 179 .WillRepeatedly(Return(false));
217 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn()) 180 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn())
218 .Times(AnyNumber()) 181 .Times(AnyNumber())
219 .WillRepeatedly(Return(false)); 182 .WillRepeatedly(Return(false));
(...skipping 10 matching lines...) Expand all
230 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted()) 193 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted())
231 .Times(AnyNumber()) 194 .Times(AnyNumber())
232 .WillRepeatedly(Return(false)); 195 .WillRepeatedly(Return(false));
233 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) 196 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
234 .Times(AnyNumber()) 197 .Times(AnyNumber())
235 .WillRepeatedly(Return(false)); 198 .WillRepeatedly(Return(false));
236 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown()) 199 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown())
237 .Times(1); 200 .Times(1);
238 201
239 MockSessionManagerClient* mock_session_manager_client = 202 MockSessionManagerClient* mock_session_manager_client =
240 mock_dbus_thread_manager->mock_session_manager_client(); 203 mock_dbus_thread_manager()->mock_session_manager_client();
241 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady()) 204 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady())
242 .Times(1); 205 .Times(1);
243 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) 206 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_))
244 .Times(AnyNumber()); 207 .Times(AnyNumber());
245 } 208 }
246 209
210 virtual void SetUpAdditionalCrosMocks() OVERRIDE {
211 cros_mock_->InitStatusAreaMocks();
212 cros_mock_->SetStatusAreaMocksExpectations();
213
214 mock_network_library_ = cros_mock_->mock_network_library();
215 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_))
216 .Times(AnyNumber());
217 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _))
218 .WillRepeatedly(Return(true));
219
220 mock_login_utils_ = new MockLoginUtils();
221 LoginUtils::Set(mock_login_utils_);
222 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication())
223 .Times(AnyNumber());
224 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers())
225 .Times(AnyNumber());
226 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_))
227 .Times(1);
228
229 mock_login_display_host_.reset(new MockLoginDisplayHost());
230 mock_login_display_ = new MockLoginDisplay();
231 SetUpLoginDisplay();
232 }
233
247 virtual void SetUpLoginDisplay() { 234 virtual void SetUpLoginDisplay() {
248 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) 235 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
249 .Times(1) 236 .Times(1)
250 .WillOnce(Return(mock_login_display_)); 237 .WillOnce(Return(mock_login_display_));
251 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) 238 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
252 .Times(1) 239 .Times(1)
253 .WillOnce(ReturnNull()); 240 .WillOnce(ReturnNull());
254 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) 241 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
255 .Times(1); 242 .Times(1);
256 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) 243 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true))
(...skipping 20 matching lines...) Expand all
277 // ExistingUserController must be deleted before the thread is cleaned up: 264 // ExistingUserController must be deleted before the thread is cleaned up:
278 // If there is an outstanding login attempt when ExistingUserController is 265 // If there is an outstanding login attempt when ExistingUserController is
279 // deleted, its LoginPerformer instance will be deleted, which in turn 266 // deleted, its LoginPerformer instance will be deleted, which in turn
280 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must 267 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
281 // be deleted on the UI thread. 268 // be deleted on the UI thread.
282 existing_user_controller_.reset(); 269 existing_user_controller_.reset();
283 CrosInProcessBrowserTest::CleanUpOnMainThread(); 270 CrosInProcessBrowserTest::CleanUpOnMainThread();
284 testing_profile_.reset(NULL); 271 testing_profile_.reset(NULL);
285 } 272 }
286 273
287 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
288 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
289 DBusThreadManager::Shutdown();
290 }
291
292 // ExistingUserController private member accessors. 274 // ExistingUserController private member accessors.
293 base::OneShotTimer<ExistingUserController>* auto_login_timer() { 275 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
294 return existing_user_controller()->auto_login_timer_.get(); 276 return existing_user_controller()->auto_login_timer_.get();
295 } 277 }
296 278
297 const std::string& auto_login_username() const { 279 const std::string& auto_login_username() const {
298 return existing_user_controller()->public_session_auto_login_username_; 280 return existing_user_controller()->public_session_auto_login_username_;
299 } 281 }
300 282
301 int auto_login_delay() const { 283 int auto_login_delay() const {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 // Wait for the public session user to be created. 437 // Wait for the public session user to be created.
456 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) { 438 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) {
457 NotificationWatcher( 439 NotificationWatcher(
458 chrome::NOTIFICATION_USER_LIST_CHANGED, 440 chrome::NOTIFICATION_USER_LIST_CHANGED,
459 base::Bind(&chromeos::UserManager::IsKnownUser, 441 base::Bind(&chromeos::UserManager::IsKnownUser,
460 base::Unretained(chromeos::UserManager::Get()), 442 base::Unretained(chromeos::UserManager::Get()),
461 kAutoLoginUsername)).Run(); 443 kAutoLoginUsername)).Run();
462 } 444 }
463 445
464 // Wait for the device local account policy to be installed. 446 // Wait for the device local account policy to be installed.
465 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()-> 447 policy::CloudPolicyStore* store = browser_process()->
466 browser_policy_connector()->GetDeviceLocalAccountPolicyService()-> 448 browser_policy_connector()->GetDeviceLocalAccountPolicyService()->
467 GetBrokerForAccount(kAutoLoginUsername)->core()->store(); 449 GetBrokerForAccount(kAutoLoginUsername)->core()->store();
468 if (!store->has_policy()) { 450 if (!store->has_policy()) {
469 policy::MockCloudPolicyStoreObserver observer; 451 policy::MockCloudPolicyStoreObserver observer;
470 452
471 base::RunLoop loop; 453 base::RunLoop loop;
472 store->AddObserver(&observer); 454 store->AddObserver(&observer);
473 EXPECT_CALL(observer, OnStoreLoaded(store)) 455 EXPECT_CALL(observer, OnStoreLoaded(store))
474 .Times(1) 456 .Times(1)
475 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); 457 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit));
476 loop.Run(); 458 loop.Run();
477 store->RemoveObserver(&observer); 459 store->RemoveObserver(&observer);
478 } 460 }
479 } 461 }
480 462
481 virtual void SetUpSessionManager( 463 virtual void SetUpSessionManager() OVERRIDE {
482 MockDBusThreadManager* mock_dbus_thread_manager) OVERRIDE { 464 // Bypass ExistingUserControllerTest.
483 EXPECT_CALL(*mock_dbus_thread_manager, GetSessionManagerClient()) 465 DevicePolicyCrosBrowserTest::SetUpSessionManager();
484 .WillRepeatedly(Return(&session_manager_client_)); 466 }
485 467
486 // Install the owner key. 468 virtual void SetSpecificDevicePolicies() OVERRIDE {
487 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 469 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
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( 470 proto.mutable_device_local_accounts()->add_account()->set_id(
502 kAutoLoginUsername); 471 kAutoLoginUsername);
503 RefreshDevicePolicy(); 472 }
504 473
505 // Setup the device local account policy. 474 virtual void SetDeviceLocalAccountPolicy() OVERRIDE {
475 // Setup the device local account policy.
506 policy::UserPolicyBuilder device_local_account_policy; 476 policy::UserPolicyBuilder device_local_account_policy;
507 device_local_account_policy.policy_data().set_username(kAutoLoginUsername); 477 device_local_account_policy.policy_data().set_username(kAutoLoginUsername);
508 device_local_account_policy.policy_data().set_policy_type( 478 device_local_account_policy.policy_data().set_policy_type(
509 policy::dm_protocol::kChromePublicAccountPolicyType); 479 policy::dm_protocol::kChromePublicAccountPolicyType);
510 device_local_account_policy.policy_data().set_settings_entity_id( 480 device_local_account_policy.policy_data().set_settings_entity_id(
511 kAutoLoginUsername); 481 kAutoLoginUsername);
512 device_local_account_policy.Build(); 482 device_local_account_policy.Build();
513 session_manager_client_.set_device_local_account_policy( 483 session_manager_client()->set_device_local_account_policy(
514 kAutoLoginUsername, 484 kAutoLoginUsername,
515 device_local_account_policy.GetBlob()); 485 device_local_account_policy.GetBlob());
516 } 486 }
517 487
518 virtual void SetUpLoginDisplay() OVERRIDE { 488 virtual void SetUpLoginDisplay() OVERRIDE {
519 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) 489 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
520 .Times(1) 490 .Times(1)
521 .WillOnce(Return(mock_login_display_)); 491 .WillOnce(Return(mock_login_display_));
522 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) 492 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
523 .Times(AnyNumber()) 493 .Times(AnyNumber())
524 .WillRepeatedly(ReturnNull()); 494 .WillRepeatedly(ReturnNull());
525 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) 495 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
526 .Times(AnyNumber()); 496 .Times(AnyNumber());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 content::MockNotificationObserver& observer, const char* setting) { 532 content::MockNotificationObserver& observer, const char* setting) {
563 base::RunLoop* loop = new base::RunLoop; 533 base::RunLoop* loop = new base::RunLoop;
564 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, 534 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
565 _, HasDetails(setting))) 535 _, HasDetails(setting)))
566 .Times(1) 536 .Times(1)
567 .WillOnce(InvokeWithoutArgs(loop, &base::RunLoop::Quit)); 537 .WillOnce(InvokeWithoutArgs(loop, &base::RunLoop::Quit));
568 CrosSettings::Get()->AddSettingsObserver(setting, &observer); 538 CrosSettings::Get()->AddSettingsObserver(setting, &observer);
569 return make_scoped_ptr(loop); 539 return make_scoped_ptr(loop);
570 } 540 }
571 541
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) { 542 void SetAutoLoginPolicy(const std::string& username, int delay) {
589 // Wait until ExistingUserController has finished auto-login 543 // Wait until ExistingUserController has finished auto-login
590 // configuration by observing the same settings that trigger 544 // configuration by observing the same settings that trigger
591 // ConfigurePublicSessionAutoLogin. 545 // ConfigurePublicSessionAutoLogin.
592 content::MockNotificationObserver observer; 546 content::MockNotificationObserver observer;
593 547
594 em::ChromeDeviceSettingsProto& proto(device_policy_.payload()); 548 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
595 549
596 // If both settings have changed we need to wait for both to 550 // If both settings have changed we need to wait for both to
597 // propagate, so check the new values against the old ones. 551 // propagate, so check the new values against the old ones.
598 scoped_ptr<base::RunLoop> runner1; 552 scoped_ptr<base::RunLoop> runner1;
599 if (!proto.has_device_local_accounts() || 553 if (!proto.has_device_local_accounts() ||
600 !proto.device_local_accounts().has_auto_login_id() || 554 !proto.device_local_accounts().has_auto_login_id() ||
601 proto.device_local_accounts().auto_login_id() != username) { 555 proto.device_local_accounts().auto_login_id() != username) {
602 runner1 = CreateSettingsObserverRunLoop( 556 runner1 = CreateSettingsObserverRunLoop(
603 observer, kAccountsPrefDeviceLocalAccountAutoLoginId); 557 observer, kAccountsPrefDeviceLocalAccountAutoLoginId);
604 } 558 }
(...skipping 26 matching lines...) Expand all
631 } 585 }
632 586
633 void ConfigureAutoLogin() { 587 void ConfigureAutoLogin() {
634 existing_user_controller()->ConfigurePublicSessionAutoLogin(); 588 existing_user_controller()->ConfigurePublicSessionAutoLogin();
635 } 589 }
636 590
637 void FireAutoLogin() { 591 void FireAutoLogin() {
638 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); 592 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
639 } 593 }
640 594
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: 595 private:
651 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); 596 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
652 }; 597 };
653 598
654 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, 599 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
655 ConfigureAutoLoginUsingPolicy) { 600 ConfigureAutoLoginUsingPolicy) {
656 existing_user_controller()->OnSigninScreenReady(); 601 existing_user_controller()->OnSigninScreenReady();
657 EXPECT_EQ("", auto_login_username()); 602 EXPECT_EQ("", auto_login_username());
658 EXPECT_EQ(0, auto_login_delay()); 603 EXPECT_EQ(0, auto_login_delay());
659 EXPECT_FALSE(auto_login_timer()); 604 EXPECT_FALSE(auto_login_timer());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 747
803 // Wait for login tasks to complete. 748 // Wait for login tasks to complete.
804 content::RunAllPendingInMessageLoop(); 749 content::RunAllPendingInMessageLoop();
805 750
806 // Timer should still be stopped after login completes. 751 // Timer should still be stopped after login completes.
807 ASSERT_TRUE(auto_login_timer()); 752 ASSERT_TRUE(auto_login_timer());
808 EXPECT_FALSE(auto_login_timer()->IsRunning()); 753 EXPECT_FALSE(auto_login_timer()->IsRunning());
809 } 754 }
810 755
811 } // namespace chromeos 756 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698