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

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

Issue 12218078: Implement a policy to autologin a public account. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bartfab review comments; split out NotificationWatcher Created 7 years, 9 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 "ash/shell.h"
6 #include "ash/wm/user_activity_detector.h"
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/command_line.h" 8 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h"
12 #include "base/stl_util.h"
9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" 13 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
10 #include "chrome/browser/chromeos/cros/cros_mock.h" 14 #include "chrome/browser/chromeos/cros/cros_mock.h"
11 #include "chrome/browser/chromeos/cros/mock_network_library.h" 15 #include "chrome/browser/chromeos/cros/mock_network_library.h"
12 #include "chrome/browser/chromeos/login/existing_user_controller.h" 16 #include "chrome/browser/chromeos/login/existing_user_controller.h"
13 #include "chrome/browser/chromeos/login/helper.h" 17 #include "chrome/browser/chromeos/login/helper.h"
14 #include "chrome/browser/chromeos/login/login_display.h" 18 #include "chrome/browser/chromeos/login/login_display.h"
15 #include "chrome/browser/chromeos/login/login_display_host.h" 19 #include "chrome/browser/chromeos/login/login_display_host.h"
16 #include "chrome/browser/chromeos/login/login_performer.h" 20 #include "chrome/browser/chromeos/login/login_performer.h"
17 #include "chrome/browser/chromeos/login/login_status_consumer.h" 21 #include "chrome/browser/chromeos/login/login_status_consumer.h"
18 #include "chrome/browser/chromeos/login/login_utils.h" 22 #include "chrome/browser/chromeos/login/login_utils.h"
19 #include "chrome/browser/chromeos/login/mock_authenticator.h" 23 #include "chrome/browser/chromeos/login/mock_authenticator.h"
20 #include "chrome/browser/chromeos/login/mock_login_utils.h" 24 #include "chrome/browser/chromeos/login/mock_login_utils.h"
21 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" 25 #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
22 #include "chrome/browser/chromeos/login/mock_user_manager.h" 26 #include "chrome/browser/chromeos/login/mock_user_manager.h"
23 #include "chrome/browser/chromeos/login/wizard_controller.h" 27 #include "chrome/browser/chromeos/login/wizard_controller.h"
28 #include "chrome/browser/chromeos/settings/cros_settings.h"
29 #include "chrome/browser/policy/browser_policy_connector.h"
30 #include "chrome/browser/policy/cloud_policy_constants.h"
31 #include "chrome/browser/policy/cloud_policy_store.h"
32 #include "chrome/browser/policy/device_local_account_policy_service.h"
33 #include "chrome/browser/policy/policy_builder.h"
34 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
35 #include "chrome/common/chrome_notification_types.h"
36 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
38 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h" 39 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/ui_test_utils.h" 40 #include "chrome/test/base/ui_test_utils.h"
41 #include "chromeos/dbus/fake_session_manager_client.h"
27 #include "chromeos/dbus/mock_dbus_thread_manager.h" 42 #include "chromeos/dbus/mock_dbus_thread_manager.h"
28 #include "chromeos/dbus/mock_session_manager_client.h" 43 #include "chromeos/dbus/mock_session_manager_client.h"
29 #include "chromeos/dbus/mock_shill_manager_client.h" 44 #include "chromeos/dbus/mock_shill_manager_client.h"
45 #include "content/public/browser/notification_watcher.h"
46 #include "content/public/test/mock_notification_observer.h"
30 #include "google_apis/gaia/mock_url_fetcher_factory.h" 47 #include "google_apis/gaia/mock_url_fetcher_factory.h"
31 #include "grit/generated_resources.h" 48 #include "grit/generated_resources.h"
32 #include "testing/gmock/include/gmock/gmock.h" 49 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 50 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/base/l10n/l10n_util.h" 51 #include "ui/base/l10n/l10n_util.h"
35 52
36 using ::testing::_; 53 using ::testing::_;
37 using ::testing::AnyNumber; 54 using ::testing::AnyNumber;
38 using ::testing::AnyOf; 55 using ::testing::AnyOf;
39 using ::testing::Invoke; 56 using ::testing::Invoke;
40 using ::testing::InvokeWithoutArgs; 57 using ::testing::InvokeWithoutArgs;
41 using ::testing::Return; 58 using ::testing::Return;
59 using ::testing::ReturnRef;
42 using ::testing::ReturnNull; 60 using ::testing::ReturnNull;
43 using ::testing::Sequence; 61 using ::testing::Sequence;
44 using ::testing::WithArg; 62 using ::testing::WithArg;
45 63
64 namespace em = enterprise_management;
65
46 namespace chromeos { 66 namespace chromeos {
47 67
48 namespace { 68 namespace {
49 69
50 const char kUsername[] = "test_user@gmail.com"; 70 const char kUsername[] = "test_user@gmail.com";
51 const char kNewUsername[] = "test_new_user@gmail.com"; 71 const char kNewUsername[] = "test_new_user@gmail.com";
52 const char kPassword[] = "test_password"; 72 const char kPassword[] = "test_password";
53 73
74 const char kAutoLoginUsername[] = "public_session_user@localhost";
75 const int kAutoLoginNoDelay = 0;
76 const int kAutoLoginShortDelay = 100;
77 const int kAutoLoginLongDelay = 10000;
78
54 class MockLoginDisplay : public LoginDisplay { 79 class MockLoginDisplay : public LoginDisplay {
55 public: 80 public:
56 MockLoginDisplay() 81 MockLoginDisplay()
57 : LoginDisplay(NULL, gfx::Rect()) { 82 : LoginDisplay(NULL, gfx::Rect()) {
58 } 83 }
59 84
60 MOCK_METHOD4(Init, void(const UserList&, bool, bool, bool)); 85 MOCK_METHOD4(Init, void(const UserList&, bool, bool, bool));
61 MOCK_METHOD0(OnPreferencesChanged, void(void)); 86 MOCK_METHOD0(OnPreferencesChanged, void(void));
62 MOCK_METHOD1(OnUserImageChanged, void(const User&)); 87 MOCK_METHOD1(OnUserImageChanged, void(const User&));
63 MOCK_METHOD0(OnFadeOut, void(void)); 88 MOCK_METHOD0(OnFadeOut, void(void));
(...skipping 30 matching lines...) Expand all
94 MOCK_METHOD0(CheckForAutoEnrollment, void(void)); 119 MOCK_METHOD0(CheckForAutoEnrollment, void(void));
95 MOCK_METHOD2(StartWizard, void(const std::string&, DictionaryValue*)); 120 MOCK_METHOD2(StartWizard, void(const std::string&, DictionaryValue*));
96 MOCK_METHOD0(StartSignInScreen, void(void)); 121 MOCK_METHOD0(StartSignInScreen, void(void));
97 MOCK_METHOD0(ResumeSignInScreen, void(void)); 122 MOCK_METHOD0(ResumeSignInScreen, void(void));
98 MOCK_METHOD0(OnPreferencesChanged, void(void)); 123 MOCK_METHOD0(OnPreferencesChanged, void(void));
99 124
100 private: 125 private:
101 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplayHost); 126 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplayHost);
102 }; 127 };
103 128
129 class MockCloudPolicyStoreObserver : public policy::CloudPolicyStore::Observer {
130 public:
131 MockCloudPolicyStoreObserver() {
132 }
133
134 MOCK_METHOD1(OnStoreLoaded, void(policy::CloudPolicyStore*));
135 MOCK_METHOD1(OnStoreError, void(policy::CloudPolicyStore*));
136
137 private:
138 DISALLOW_COPY_AND_ASSIGN(MockCloudPolicyStoreObserver);
139 };
140
104 scoped_refptr<Authenticator> CreateAuthenticator( 141 scoped_refptr<Authenticator> CreateAuthenticator(
105 LoginStatusConsumer* consumer) { 142 LoginStatusConsumer* consumer) {
106 return new MockAuthenticator(consumer, kUsername, kPassword); 143 return new MockAuthenticator(consumer, kUsername, kPassword);
107 } 144 }
108 145
109 scoped_refptr<Authenticator> CreateAuthenticatorNewUser( 146 scoped_refptr<Authenticator> CreateAuthenticatorNewUser(
110 LoginStatusConsumer* consumer) { 147 LoginStatusConsumer* consumer) {
111 return new MockAuthenticator(consumer, kNewUsername, kPassword); 148 return new MockAuthenticator(consumer, kNewUsername, kPassword);
112 } 149 }
113 150
151 scoped_refptr<Authenticator> CreateAuthenticatorPublicSession(
152 LoginStatusConsumer* consumer) {
153 return new MockAuthenticator(consumer, kAutoLoginUsername, "");
154 }
155
114 } // namespace 156 } // namespace
115 157
116 class ExistingUserControllerTest : public CrosInProcessBrowserTest { 158 class ExistingUserControllerTest : public CrosInProcessBrowserTest {
117 protected: 159 protected:
118 ExistingUserControllerTest() 160 ExistingUserControllerTest()
119 : mock_network_library_(NULL), 161 : mock_network_library_(NULL),
120 mock_login_display_(NULL), 162 mock_login_display_(NULL),
121 mock_login_display_host_(NULL), 163 mock_login_display_host_(NULL),
122 testing_profile_(NULL) { 164 testing_profile_(NULL) {
123 } 165 }
(...skipping 12 matching lines...) Expand all
136 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); 178 Return(reinterpret_cast<IBusInputContextClient*>(NULL)));
137 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 179 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
138 GetProperties(_)) 180 GetProperties(_))
139 .Times(AnyNumber()); 181 .Times(AnyNumber());
140 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 182 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
141 AddPropertyChangedObserver(_)) 183 AddPropertyChangedObserver(_))
142 .Times(AnyNumber()); 184 .Times(AnyNumber());
143 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 185 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
144 RemovePropertyChangedObserver(_)) 186 RemovePropertyChangedObserver(_))
145 .Times(AnyNumber()); 187 .Times(AnyNumber());
188
189 SetUpSessionManager(mock_dbus_thread_manager);
190
146 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); 191 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
147 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); 192 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
148 cros_mock_->InitStatusAreaMocks(); 193 cros_mock_->InitStatusAreaMocks();
149 cros_mock_->SetStatusAreaMocksExpectations(); 194 cros_mock_->SetStatusAreaMocksExpectations();
150 195
151 mock_network_library_ = cros_mock_->mock_network_library(); 196 mock_network_library_ = cros_mock_->mock_network_library();
152 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) 197 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_))
153 .Times(AnyNumber()); 198 .Times(AnyNumber());
154 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) 199 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _))
155 .WillRepeatedly(Return(true)); 200 .WillRepeatedly(Return(true));
156 201
157 MockSessionManagerClient* mock_session_manager_client =
158 mock_dbus_thread_manager->mock_session_manager_client();
159 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady())
160 .Times(1);
161 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_))
162 .Times(AnyNumber());
163
164 mock_login_utils_ = new MockLoginUtils(); 202 mock_login_utils_ = new MockLoginUtils();
165 LoginUtils::Set(mock_login_utils_); 203 LoginUtils::Set(mock_login_utils_);
166 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) 204 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication())
167 .Times(AnyNumber()); 205 .Times(AnyNumber());
168 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) 206 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers())
169 .Times(AnyNumber()); 207 .Times(AnyNumber());
170 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) 208 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_))
171 .Times(1); 209 .Times(1);
172 210
173 mock_login_display_host_.reset(new MockLoginDisplayHost()); 211 mock_login_display_host_.reset(new MockLoginDisplayHost());
212 mock_login_display_ = new MockLoginDisplay();
213 SetUpLoginDisplay();
214 }
174 215
175 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kUsername)) 216 virtual void SetUpSessionManager(
217 MockDBusThreadManager* mock_dbus_thread_manager) {
218 mock_user_manager_.reset(new ScopedMockUserManagerEnabler);
219 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername))
176 .Times(AnyNumber()) 220 .Times(AnyNumber())
177 .WillRepeatedly(Return(true)); 221 .WillRepeatedly(Return(true));
178 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kNewUsername)) 222 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername))
179 .Times(AnyNumber()) 223 .Times(AnyNumber())
180 .WillRepeatedly(Return(false)); 224 .WillRepeatedly(Return(false));
181 EXPECT_CALL(*mock_user_manager_.user_manager(), IsUserLoggedIn()) 225 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn())
182 .Times(AnyNumber()) 226 .Times(AnyNumber())
183 .WillRepeatedly(Return(false)); 227 .WillRepeatedly(Return(false));
184 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsGuest()) 228 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsGuest())
185 .Times(AnyNumber()) 229 .Times(AnyNumber())
186 .WillRepeatedly(Return(false)); 230 .WillRepeatedly(Return(false));
187 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsDemoUser()) 231 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsDemoUser())
188 .Times(AnyNumber()) 232 .Times(AnyNumber())
189 .WillRepeatedly(Return(false)); 233 .WillRepeatedly(Return(false));
190 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsPublicAccount()) 234 EXPECT_CALL(*mock_user_manager_->user_manager(),
235 IsLoggedInAsPublicAccount())
191 .Times(AnyNumber()) 236 .Times(AnyNumber())
192 .WillRepeatedly(Return(false)); 237 .WillRepeatedly(Return(false));
193 EXPECT_CALL(*mock_user_manager_.user_manager(), IsSessionStarted()) 238 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted())
194 .Times(AnyNumber()) 239 .Times(AnyNumber())
195 .WillRepeatedly(Return(false)); 240 .WillRepeatedly(Return(false));
241 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
242 .Times(AnyNumber())
243 .WillRepeatedly(Return(false));
244 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown())
245 .Times(1);
196 246
247 MockSessionManagerClient* mock_session_manager_client =
248 mock_dbus_thread_manager->mock_session_manager_client();
249 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady())
250 .Times(1);
251 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_))
252 .Times(AnyNumber());
253 }
254
255 virtual void SetUpLoginDisplay() {
197 // |mock_login_display_| is owned by the ExistingUserController, which calls 256 // |mock_login_display_| is owned by the ExistingUserController, which calls
198 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. 257 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
199 mock_login_display_ = new MockLoginDisplay();
200 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) 258 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
201 .Times(1) 259 .Times(1)
202 .WillOnce(Return(mock_login_display_)); 260 .WillOnce(Return(mock_login_display_));
203 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) 261 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
204 .Times(1) 262 .Times(1)
205 .WillOnce(ReturnNull()); 263 .WillOnce(ReturnNull());
206 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) 264 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
207 .Times(1); 265 .Times(1);
208 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) 266 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true))
209 .Times(1); 267 .Times(1);
210 } 268 }
211 269
212 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 270 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
213 command_line->AppendSwitch(switches::kLoginManager); 271 command_line->AppendSwitch(switches::kLoginManager);
214 } 272 }
215 273
216 virtual void SetUpOnMainThread() OVERRIDE { 274 virtual void SetUpOnMainThread() OVERRIDE {
217 testing_profile_.reset(new TestingProfile()); 275 testing_profile_.reset(new TestingProfile());
218 existing_user_controller_.reset( 276 existing_user_controller_.reset(
219 new ExistingUserController(mock_login_display_host_.get())); 277 new ExistingUserController(mock_login_display_host_.get()));
220 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); 278 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get());
221 existing_user_controller_->Init(UserList()); 279 existing_user_controller_->Init(UserList());
222 profile_prepared_cb_ = 280 profile_prepared_cb_ =
223 base::Bind(&ExistingUserController::OnProfilePrepared, 281 base::Bind(&ExistingUserController::OnProfilePrepared,
224 base::Unretained(existing_user_controller()), 282 base::Unretained(existing_user_controller()),
225 testing_profile_.get()); 283 testing_profile_.get());
226 } 284 }
227 285
228 virtual void CleanUpOnMainThread() OVERRIDE { 286 virtual void CleanUpOnMainThread() OVERRIDE {
287 // ExistingUserController must be deleted before the thread is cleaned up:
288 // if there is an outstanding login attempt when ExistingUserController is
289 // deleted, its LoginPerformer instance will be deleted, which in turn
290 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
291 // be deleted on the UI thread.
292 existing_user_controller_.reset();
229 CrosInProcessBrowserTest::CleanUpOnMainThread(); 293 CrosInProcessBrowserTest::CleanUpOnMainThread();
230 testing_profile_.reset(NULL); 294 testing_profile_.reset(NULL);
231 } 295 }
232 296
233 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 297 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
234 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); 298 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
235 DBusThreadManager::Shutdown(); 299 DBusThreadManager::Shutdown();
236 } 300 }
237 301
302 // ExistingUserController private member accessors.
303 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
304 return &existing_user_controller()->auto_login_timer();
305 }
306
307 std::string auto_login_username() {
308 return existing_user_controller()->public_session_auto_login_username_;
309 }
310 void set_auto_login_username(const std::string& username) {
311 existing_user_controller()->public_session_auto_login_username_ = username;
312 }
313
314 int auto_login_delay() {
315 return existing_user_controller()->public_session_auto_login_delay_;
316 }
317 void set_auto_login_delay(int delay) {
318 existing_user_controller()->public_session_auto_login_delay_ = delay;
319 }
320
321 bool is_login_in_progress() {
322 return existing_user_controller()->is_login_in_progress_;
323 }
324 void set_is_login_in_progress(bool is_login_in_progress) {
325 existing_user_controller()->is_login_in_progress_ = is_login_in_progress;
326 }
327
238 scoped_ptr<ExistingUserController> existing_user_controller_; 328 scoped_ptr<ExistingUserController> existing_user_controller_;
239 329
240 // These mocks are owned by CrosLibrary class. 330 // These mocks are owned by CrosLibrary class.
241 MockNetworkLibrary* mock_network_library_; 331 MockNetworkLibrary* mock_network_library_;
242 332
243 MockLoginDisplay* mock_login_display_; 333 MockLoginDisplay* mock_login_display_;
244 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; 334 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
245 335
246 ScopedMockUserManagerEnabler mock_user_manager_; 336 scoped_ptr<ScopedMockUserManagerEnabler> mock_user_manager_;
247 337
248 // Owned by LoginUtilsWrapper. 338 // Owned by LoginUtilsWrapper.
249 MockLoginUtils* mock_login_utils_; 339 MockLoginUtils* mock_login_utils_;
250 340
251 scoped_ptr<TestingProfile> testing_profile_; 341 scoped_ptr<TestingProfile> testing_profile_;
252 342
253 // Mock URLFetcher. 343 // Mock URLFetcher.
254 MockURLFetcherFactory<SuccessFetcher> factory_; 344 MockURLFetcherFactory<SuccessFetcher> factory_;
255 345
256 base::Callback<void(void)> profile_prepared_cb_; 346 base::Callback<void(void)> profile_prepared_cb_;
(...skipping 21 matching lines...) Expand all
278 .Times(1); 368 .Times(1);
279 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) 369 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername))
280 .Times(1); 370 .Times(1);
281 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 371 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
282 .Times(1); 372 .Times(1);
283 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 373 EXPECT_CALL(*mock_login_display_, OnFadeOut())
284 .Times(1); 374 .Times(1);
285 EXPECT_CALL(*mock_login_display_host_, 375 EXPECT_CALL(*mock_login_display_host_,
286 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) 376 StartWizard(WizardController::kTermsOfServiceScreenName, NULL))
287 .Times(0); 377 .Times(0);
288 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 378 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
289 .Times(AnyNumber()) 379 .Times(AnyNumber())
290 .WillRepeatedly(Return(false)); 380 .WillRepeatedly(Return(false));
291 existing_user_controller()->Login(kUsername, kPassword); 381 existing_user_controller()->Login(kUsername, kPassword);
292 content::RunAllPendingInMessageLoop(); 382 content::RunAllPendingInMessageLoop();
293 } 383 }
294 384
295 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) { 385 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) {
296 EXPECT_CALL(*mock_login_display_host_, 386 EXPECT_CALL(*mock_login_display_host_,
297 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _)) 387 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _))
298 .Times(1); 388 .Times(1);
299 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 389 EXPECT_CALL(*mock_login_display_, OnFadeOut())
300 .Times(1); 390 .Times(1);
301 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) 391 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
302 .Times(1); 392 .Times(1);
303 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 393 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
304 .Times(AnyNumber()) 394 .Times(AnyNumber())
305 .WillRepeatedly(Return(false)); 395 .WillRepeatedly(Return(false));
306 // The order of these expected calls matters: the UI if first disabled 396 // The order of these expected calls matters: the UI if first disabled
307 // during the login sequence, and is enabled again for the enrollment screen. 397 // during the login sequence, and is enabled again for the enrollment screen.
308 Sequence uiEnabledSequence; 398 Sequence uiEnabledSequence;
309 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 399 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
310 .Times(1) 400 .Times(1)
311 .InSequence(uiEnabledSequence); 401 .InSequence(uiEnabledSequence);
312 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 402 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
313 .Times(1) 403 .Times(1)
(...skipping 24 matching lines...) Expand all
338 PrepareProfile(kNewUsername, _, kPassword, _, _, _)) 428 PrepareProfile(kNewUsername, _, kPassword, _, _, _))
339 .Times(1) 429 .Times(1)
340 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, 430 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
341 &base::Callback<void(void)>::Run)); 431 &base::Callback<void(void)>::Run));
342 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) 432 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername))
343 .Times(1); 433 .Times(1);
344 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 434 EXPECT_CALL(*mock_login_display_, OnFadeOut())
345 .Times(1); 435 .Times(1);
346 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) 436 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
347 .Times(1); 437 .Times(1);
348 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 438 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
349 .Times(AnyNumber()) 439 .Times(AnyNumber())
350 .WillRepeatedly(Return(true)); 440 .WillRepeatedly(Return(true));
351 441
352 // The order of these expected calls matters: the UI if first disabled 442 // The order of these expected calls matters: the UI if first disabled
353 // during the login sequence, and is enabled again after login completion. 443 // during the login sequence, and is enabled again after login completion.
354 Sequence uiEnabledSequence; 444 Sequence uiEnabledSequence;
355 // This is disabled twice: once right after signin but before checking for 445 // This is disabled twice: once right after signin but before checking for
356 // auto-enrollment, and again after doing an ownership status check. 446 // auto-enrollment, and again after doing an ownership status check.
357 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 447 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
358 .Times(2) 448 .Times(2)
359 .InSequence(uiEnabledSequence); 449 .InSequence(uiEnabledSequence);
360 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 450 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
361 .Times(1) 451 .Times(1)
362 .InSequence(uiEnabledSequence); 452 .InSequence(uiEnabledSequence);
363 453
364 existing_user_controller()->CompleteLogin(kNewUsername, kPassword); 454 existing_user_controller()->CompleteLogin(kNewUsername, kPassword);
365 content::RunAllPendingInMessageLoop(); 455 content::RunAllPendingInMessageLoop();
366 } 456 }
367 457
458 MATCHER_P(HasDetails, expected, "") {
459 return expected == *content::Details<const std::string>(arg).ptr();
460 }
461
462 class ExistingUserControllerPublicSessionTest
463 : public ExistingUserControllerTest {
464 protected:
465 ExistingUserControllerPublicSessionTest() {
466 }
467
468 virtual void SetUpOnMainThread() OVERRIDE {
469 ExistingUserControllerTest::SetUpOnMainThread();
470
471 // Wait for the public session user to be created.
472 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) {
473 content::NotificationWatcher(
474 chrome::NOTIFICATION_USER_LIST_CHANGED,
475 base::Bind(&chromeos::UserManager::IsKnownUser,
476 base::Unretained(chromeos::UserManager::Get()),
477 kAutoLoginUsername)).Run();
478 }
479
480 // Wait for the device local account policy to be installed.
481 MockCloudPolicyStoreObserver observer;
482 content::MessageLoopRunner* runner = new content::MessageLoopRunner;
483 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()->
484 browser_policy_connector()->GetDeviceLocalAccountPolicyService()->
485 GetBrokerForAccount(kAutoLoginUsername)->core()->store();
486 store->AddObserver(&observer);
487 EXPECT_CALL(observer, OnStoreLoaded(store))
488 .Times(1)
489 .WillOnce(InvokeWithoutArgs(runner, &content::MessageLoopRunner::Quit));
490 runner->Run();
491 store->RemoveObserver(&observer);
492 }
493
494 virtual void SetUpSessionManager(
495 MockDBusThreadManager* mock_dbus_thread_manager) OVERRIDE {
496 EXPECT_CALL(*mock_dbus_thread_manager, GetSessionManagerClient())
497 .WillRepeatedly(Return(&session_manager_client_));
498
499 // Install the owner key.
500 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
501 base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key");
502 std::vector<uint8> owner_key_bits;
503 ASSERT_TRUE(device_policy_.signing_key()->ExportPublicKey(&owner_key_bits));
504 ASSERT_EQ(
505 file_util::WriteFile(
506 owner_key_file,
507 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)),
508 owner_key_bits.size()),
509 static_cast<int>(owner_key_bits.size()));
510 ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file));
511
512 // Setup the device policy.
513 em::ChromeDeviceSettingsProto& proto(device_policy_.payload());
514 proto.mutable_device_local_accounts()->add_account()->set_id(
515 kAutoLoginUsername);
516 RefreshDevicePolicy();
517
518 // Setup the device local account policy.
519 policy::UserPolicyBuilder device_local_account_policy;
520 device_local_account_policy.policy_data().set_username(kAutoLoginUsername);
521 device_local_account_policy.policy_data().set_policy_type(
522 policy::dm_protocol::kChromePublicAccountPolicyType);
523 device_local_account_policy.policy_data().set_settings_entity_id(
524 kAutoLoginUsername);
525 device_local_account_policy.Build();
526 session_manager_client_.set_device_local_account_policy(
527 kAutoLoginUsername,
528 device_local_account_policy.GetBlob());
529 }
530
531 virtual void SetUpLoginDisplay() {
532 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
533 .Times(1)
534 .WillOnce(Return(mock_login_display_));
535 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
536 .Times(AnyNumber())
537 .WillRepeatedly(ReturnNull());
538 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
539 .Times(AnyNumber());
540 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _))
541 .Times(AnyNumber());
542 }
543
544 void DisableAutoLoginPolicyNotifications() {
545 CrosSettings::Get()->RemoveSettingsObserver(
546 kAccountsPrefDeviceLocalAccountAutoLoginId,
547 existing_user_controller());
548 CrosSettings::Get()->RemoveSettingsObserver(
549 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
550 existing_user_controller());
551 }
552
553 void ExpectSuccessfulLogin(const std::string& username,
554 const std::string& password,
555 scoped_refptr<Authenticator> create_authenticator(
556 LoginStatusConsumer* consumer)) {
557 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
558 .Times(AnyNumber());
559 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
560 .Times(1)
561 .WillOnce(WithArg<0>(Invoke(create_authenticator)));
562 EXPECT_CALL(*mock_login_utils_,
563 PrepareProfile(username, _, password, _, _, _))
564 .Times(1)
565 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
566 &base::Callback<void(void)>::Run));
567 EXPECT_CALL(*mock_login_utils_,
568 DoBrowserLaunch(testing_profile_.get(),
569 mock_login_display_host_.get()))
570 .Times(1);
571 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username))
572 .Times(1);
573 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
574 .Times(1);
575 EXPECT_CALL(*mock_login_display_, OnFadeOut())
576 .Times(1);
577 EXPECT_CALL(*mock_login_display_host_,
578 StartWizard(WizardController::kTermsOfServiceScreenName, NULL))
579 .Times(0);
580 }
581
582 content::MessageLoopRunner* CreateSettingsObserverRunLoop(
583 content::MockNotificationObserver& observer, const char* setting) {
584 content::MessageLoopRunner* runner = new content::MessageLoopRunner;
585 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
586 _, HasDetails(setting)))
587 .Times(1)
588 .WillOnce(InvokeWithoutArgs(runner, &content::MessageLoopRunner::Quit));
589 CrosSettings::Get()->AddSettingsObserver(setting, &observer);
590 return runner;
591 }
592
593 void RefreshDevicePolicy() {
594 // Reset the key to its original state.
595 device_policy_.set_signing_key(
596 policy::PolicyBuilder::CreateTestSigningKey());
597 device_policy_.Build();
598 // Clear the key so the device can't write owner settings.
599 device_policy_.set_signing_key(
600 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
601 device_policy_.set_new_signing_key(
602 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
603 session_manager_client_.set_device_policy(device_policy_.GetBlob());
604 }
605
606 void SetAutoLoginPolicy(const std::string& username, int delay) {
607 // Wait until ExistingUserController has finished auto-login
608 // configuration by observing the same settings that trigger
609 // ConfigurePublicSessionAutoLogin.
610 content::MockNotificationObserver observer;
611
612 em::ChromeDeviceSettingsProto& proto(device_policy_.payload());
613
614 // If both settings have changed we need to wait for both to
615 // propagate, so check the new values against the old ones.
616 content::MessageLoopRunner* runner1 = NULL;
617 if (!proto.has_device_local_accounts() ||
618 !proto.device_local_accounts().has_auto_login_id() ||
619 proto.device_local_accounts().auto_login_id() != username) {
620 runner1 = CreateSettingsObserverRunLoop(
621 observer, kAccountsPrefDeviceLocalAccountAutoLoginId);
622 }
623 content::MessageLoopRunner* runner2 = NULL;
624 if (!proto.has_device_local_accounts() ||
625 !proto.device_local_accounts().has_auto_login_delay() ||
626 proto.device_local_accounts().auto_login_delay() != delay) {
627 runner2 = CreateSettingsObserverRunLoop(
628 observer, kAccountsPrefDeviceLocalAccountAutoLoginDelay);
629 }
630
631 // Update the policy.
632 proto.mutable_device_local_accounts()->set_auto_login_id(username);
633 proto.mutable_device_local_accounts()->set_auto_login_delay(delay);
634 RefreshDevicePolicy();
635
636 // Wait for ExistingUserController.
637 if (runner1)
638 runner1->Run();
639 if (runner2)
640 runner2->Run();
641
642 // Clean up.
643 CrosSettings::Get()->RemoveSettingsObserver(
644 kAccountsPrefDeviceLocalAccountAutoLoginId,
645 &observer);
646 CrosSettings::Get()->RemoveSettingsObserver(
647 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
648 &observer);
649 }
650
651 // Enables public sessions in tests.
652 FakeSessionManagerClient session_manager_client_;
653
654 // Stores the device owner key.
655 base::ScopedTempDir temp_dir_;
656
657 // Carries Chrome OS device policies for tests.
658 policy::DevicePolicyBuilder device_policy_;
659
660 private:
661 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
662 };
663
664 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
665 StartAutoLoginTimer) {
666 DisableAutoLoginPolicyNotifications();
667
668 // Timer shouldn't start until signin screen is ready.
669 set_auto_login_username(kAutoLoginUsername);
670 set_auto_login_delay(kAutoLoginLongDelay);
671 existing_user_controller()->StartPublicSessionAutoLoginTimer();
672 EXPECT_FALSE(auto_login_timer()->IsRunning());
673
674 // Timer shouldn't start if the policy isn't set.
675 set_auto_login_username("");
676 existing_user_controller()->OnSigninScreenReady();
677 existing_user_controller()->StartPublicSessionAutoLoginTimer();
678 EXPECT_FALSE(auto_login_timer()->IsRunning());
679
680 // Timer shouldn't fire in the middle of a login attempt.
681 set_auto_login_username(kAutoLoginUsername);
682 set_is_login_in_progress(true);
683 existing_user_controller()->StartPublicSessionAutoLoginTimer();
684 EXPECT_FALSE(auto_login_timer()->IsRunning());
685
686 // Otherwise start.
687 set_is_login_in_progress(false);
688 existing_user_controller()->StartPublicSessionAutoLoginTimer();
689 EXPECT_TRUE(auto_login_timer()->IsRunning());
690 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
691 kAutoLoginLongDelay);
692 }
693
694 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
695 StopAutoLoginTimer) {
696 existing_user_controller()->OnSigninScreenReady();
697 set_auto_login_username(kAutoLoginUsername);
698 set_auto_login_delay(kAutoLoginLongDelay);
699
700 existing_user_controller()->StartPublicSessionAutoLoginTimer();
701 EXPECT_TRUE(auto_login_timer()->IsRunning());
702
703 existing_user_controller()->StopPublicSessionAutoLoginTimer();
704 EXPECT_FALSE(auto_login_timer()->IsRunning());
705 }
706
707 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
708 UserActivityRestartsAutoLogin) {
709 existing_user_controller()->OnSigninScreenReady();
710 set_auto_login_username(kAutoLoginUsername);
711
712 // Timer starts off not running.
713 EXPECT_FALSE(auto_login_timer()->IsRunning());
714
715 // When the timer isn't running, nothing should happen.
716 existing_user_controller()->OnUserActivity();
717 EXPECT_FALSE(auto_login_timer()->IsRunning());
718
719 // Start the timer.
720 set_auto_login_delay(kAutoLoginLongDelay);
721 existing_user_controller()->StartPublicSessionAutoLoginTimer();
722 EXPECT_TRUE(auto_login_timer()->IsRunning());
723 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
724 kAutoLoginLongDelay);
725
726 // User activity should restart the timer, so check to see that the
727 // timer delay was modified.
728 set_auto_login_delay(kAutoLoginShortDelay);
729 existing_user_controller()->OnUserActivity();
730 EXPECT_TRUE(auto_login_timer()->IsRunning());
731 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
732 kAutoLoginShortDelay);
733 }
734
735 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
736 ConfigureAutoLogin) {
737 ash::UserActivityDetector* detector =
738 ash::Shell::GetInstance()->user_activity_detector();
739 existing_user_controller()->OnSigninScreenReady();
740
741 // Turn off settings notifications to ExistingUserController.
742 DisableAutoLoginPolicyNotifications();
743
744 // Timer shouldn't start when the policy is disabled.
745 SetAutoLoginPolicy("", 0);
746 existing_user_controller()->ConfigurePublicSessionAutoLogin();
747 EXPECT_FALSE(auto_login_timer()->IsRunning());
748 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 0);
749 EXPECT_EQ(auto_login_delay(), 0);
750 EXPECT_EQ(auto_login_username(), "");
751 EXPECT_FALSE(detector->HasObserver(existing_user_controller()));
752
753 // Timer shouldn't start when the delay alone is set.
754 SetAutoLoginPolicy("", kAutoLoginShortDelay);
755 existing_user_controller()->ConfigurePublicSessionAutoLogin();
756 EXPECT_FALSE(auto_login_timer()->IsRunning());
757 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 0);
758 EXPECT_EQ(auto_login_delay(), kAutoLoginShortDelay);
759 EXPECT_EQ(auto_login_username(), "");
760 EXPECT_FALSE(detector->HasObserver(existing_user_controller()));
761
762 // Timer should start when the username is set.
763 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
764 existing_user_controller()->ConfigurePublicSessionAutoLogin();
765 EXPECT_TRUE(auto_login_timer()->IsRunning());
766 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
767 kAutoLoginShortDelay);
768 EXPECT_EQ(auto_login_delay(), kAutoLoginShortDelay);
769 EXPECT_EQ(auto_login_username(), kAutoLoginUsername);
770 EXPECT_TRUE(detector->HasObserver(existing_user_controller()));
771
772 // Timer should restart when the delay is changed.
773 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
774 existing_user_controller()->ConfigurePublicSessionAutoLogin();
775 EXPECT_TRUE(auto_login_timer()->IsRunning());
776 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
777 kAutoLoginLongDelay);
778 EXPECT_EQ(auto_login_delay(), kAutoLoginLongDelay);
779 EXPECT_EQ(auto_login_username(), kAutoLoginUsername);
780 EXPECT_TRUE(detector->HasObserver(existing_user_controller()));
781
782 // Timer should stop when the username is unset.
783 SetAutoLoginPolicy("", kAutoLoginLongDelay);
784 existing_user_controller()->ConfigurePublicSessionAutoLogin();
785 EXPECT_FALSE(auto_login_timer()->IsRunning());
786 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
787 kAutoLoginLongDelay);
788 EXPECT_EQ(auto_login_username(), "");
789 EXPECT_EQ(auto_login_delay(), kAutoLoginLongDelay);
790 EXPECT_FALSE(detector->HasObserver(existing_user_controller()));
791 }
792
793 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
794 ConfigureAutoLoginUsingPolicy) {
795 ash::UserActivityDetector* detector =
796 ash::Shell::GetInstance()->user_activity_detector();
797 existing_user_controller()->OnSigninScreenReady();
798 EXPECT_EQ("", auto_login_username());
799 EXPECT_EQ(0, auto_login_delay());
800 EXPECT_FALSE(auto_login_timer()->IsRunning());
801 EXPECT_FALSE(detector->HasObserver(existing_user_controller()));
802
803 // Set the policy.
804 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
805 EXPECT_EQ(kAutoLoginUsername, auto_login_username());
806 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay());
807 EXPECT_TRUE(auto_login_timer()->IsRunning());
808 EXPECT_TRUE(detector->HasObserver(existing_user_controller()));
809
810 // Unset the policy.
811 SetAutoLoginPolicy("", 0);
812 EXPECT_EQ("", auto_login_username());
813 EXPECT_EQ(0, auto_login_delay());
814 EXPECT_FALSE(auto_login_timer()->IsRunning());
815 EXPECT_FALSE(detector->HasObserver(existing_user_controller()));
816 }
817
818 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
819 OnAutoLoginFire) {
820 // Set up mocks to check login success.
821 ExpectSuccessfulLogin(kAutoLoginUsername, "",
822 CreateAuthenticatorPublicSession);
823 existing_user_controller()->OnSigninScreenReady();
824
825 // Directly set auto-login parameters to avoid starting the timer.
826 set_auto_login_username(kAutoLoginUsername);
827 set_auto_login_delay(kAutoLoginLongDelay);
828
829 // Manually fire auto-login and wait for the login tasks to complete.
830 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
831 content::RunAllPendingInMessageLoop();
832 }
833
834 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
835 AutoLoginNoDelay) {
836 // Set up mocks to check login success.
837 ExpectSuccessfulLogin(kAutoLoginUsername, "",
838 CreateAuthenticatorPublicSession);
839 existing_user_controller()->OnSigninScreenReady();
840
841 // Start auto-login and wait for login tasks to complete.
842 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginNoDelay);
843 content::RunAllPendingInMessageLoop();
844 }
845
846 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
847 AutoLoginShortDelay) {
848 // Set up mocks to check login success.
849 ExpectSuccessfulLogin(kAutoLoginUsername, "",
850 CreateAuthenticatorPublicSession);
851 existing_user_controller()->OnSigninScreenReady();
852 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
853 ASSERT_TRUE(auto_login_timer()->IsRunning());
854
855 // Wait for the timer to fire.
856 content::MessageLoopRunner* runner = new content::MessageLoopRunner;
857 base::OneShotTimer<content::MessageLoopRunner> timer;
858 timer.Start(FROM_HERE,
859 base::TimeDelta::FromMilliseconds(2 * kAutoLoginShortDelay),
860 base::Bind(&content::MessageLoopRunner::Quit,
861 base::Unretained(runner)));
862 runner->Run();
863
864 // Wait for login tasks to complete.
865 content::RunAllPendingInMessageLoop();
866 }
867
868 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
869 LoginStopsAutoLogin) {
870 // Set up mocks to check login success.
871 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator);
872
873 existing_user_controller()->OnSigninScreenReady();
874 set_auto_login_username(kAutoLoginUsername);
875 set_auto_login_delay(kAutoLoginLongDelay);
876 existing_user_controller()->StartPublicSessionAutoLoginTimer();
877 EXPECT_TRUE(auto_login_timer()->IsRunning());
878
879 // Login and check that it stopped the timer.
880 existing_user_controller()->Login(kUsername, kPassword);
881 EXPECT_TRUE(is_login_in_progress());
882 EXPECT_FALSE(auto_login_timer()->IsRunning());
883
884 // Wait for login tasks to complete.
885 content::RunAllPendingInMessageLoop();
886
887 // Timer should still be stopped after login completes.
888 EXPECT_FALSE(auto_login_timer()->IsRunning());
889 }
890
891 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
892 GuestModeLoginStopsAutoLogin) {
893 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
894 .Times(1);
895 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
896 .Times(1)
897 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator)));
898 ScopedMockUserManagerEnabler mock_user_manager;
899 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_))
900 .Times(1);
901
902 existing_user_controller()->OnSigninScreenReady();
903 set_auto_login_username(kAutoLoginUsername);
904 set_auto_login_delay(kAutoLoginLongDelay);
905 existing_user_controller()->StartPublicSessionAutoLoginTimer();
906 EXPECT_TRUE(auto_login_timer()->IsRunning());
907
908 // Login and check that it stopped the timer.
909 existing_user_controller()->LoginAsGuest();
910 EXPECT_TRUE(is_login_in_progress());
911 EXPECT_FALSE(auto_login_timer()->IsRunning());
912
913 // Wait for login tasks to complete.
914 content::RunAllPendingInMessageLoop();
915
916 // Timer should still be stopped after login completes.
917 EXPECT_FALSE(auto_login_timer()->IsRunning());
918 }
919
920 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
921 CompleteLoginStopsAutoLogin) {
922 // Set up mocks to check login success.
923 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator);
924 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
925 .Times(1);
926
927 existing_user_controller()->OnSigninScreenReady();
928 set_auto_login_username(kAutoLoginUsername);
929 set_auto_login_delay(kAutoLoginLongDelay);
930 existing_user_controller()->StartPublicSessionAutoLoginTimer();
931 EXPECT_TRUE(auto_login_timer()->IsRunning());
932
933 // Check that login completes and stops the timer.
934 existing_user_controller()->CompleteLogin(kUsername, kPassword);
935 EXPECT_FALSE(auto_login_timer()->IsRunning());
936
937 // Wait for login tasks to complete.
938 content::RunAllPendingInMessageLoop();
939
940 // Timer should still be stopped after login completes.
941 EXPECT_FALSE(auto_login_timer()->IsRunning());
942 }
943
944 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
945 PublicSessionLoginStopsAutoLogin) {
946 // Set up mocks to check login success.
947 ExpectSuccessfulLogin(kAutoLoginUsername, "",
948 CreateAuthenticatorPublicSession);
949 existing_user_controller()->OnSigninScreenReady();
950 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
951 EXPECT_TRUE(auto_login_timer()->IsRunning());
952
953 // Login and check that it stopped the timer.
954 existing_user_controller()->LoginAsPublicAccount(kAutoLoginUsername);
955 EXPECT_TRUE(is_login_in_progress());
956 EXPECT_FALSE(auto_login_timer()->IsRunning());
957
958 // Wait for login tasks to complete.
959 content::RunAllPendingInMessageLoop();
960
961 // Timer should still be stopped after login completes.
962 EXPECT_FALSE(auto_login_timer()->IsRunning());
963 }
964
368 } // namespace chromeos 965 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698