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

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: add test asserts for timer 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
6 #include "base/command_line.h" 7 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h"
11 #include "base/stl_util.h"
9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" 12 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
10 #include "chrome/browser/chromeos/cros/cros_mock.h" 13 #include "chrome/browser/chromeos/cros/cros_mock.h"
11 #include "chrome/browser/chromeos/cros/mock_network_library.h" 14 #include "chrome/browser/chromeos/cros/mock_network_library.h"
12 #include "chrome/browser/chromeos/login/existing_user_controller.h" 15 #include "chrome/browser/chromeos/login/existing_user_controller.h"
13 #include "chrome/browser/chromeos/login/helper.h" 16 #include "chrome/browser/chromeos/login/helper.h"
14 #include "chrome/browser/chromeos/login/login_display.h" 17 #include "chrome/browser/chromeos/login/login_display.h"
15 #include "chrome/browser/chromeos/login/login_display_host.h" 18 #include "chrome/browser/chromeos/login/login_display_host.h"
16 #include "chrome/browser/chromeos/login/login_performer.h" 19 #include "chrome/browser/chromeos/login/login_performer.h"
17 #include "chrome/browser/chromeos/login/login_status_consumer.h" 20 #include "chrome/browser/chromeos/login/login_status_consumer.h"
18 #include "chrome/browser/chromeos/login/login_utils.h" 21 #include "chrome/browser/chromeos/login/login_utils.h"
19 #include "chrome/browser/chromeos/login/mock_authenticator.h" 22 #include "chrome/browser/chromeos/login/mock_authenticator.h"
20 #include "chrome/browser/chromeos/login/mock_login_utils.h" 23 #include "chrome/browser/chromeos/login/mock_login_utils.h"
21 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" 24 #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
22 #include "chrome/browser/chromeos/login/mock_user_manager.h" 25 #include "chrome/browser/chromeos/login/mock_user_manager.h"
23 #include "chrome/browser/chromeos/login/wizard_controller.h" 26 #include "chrome/browser/chromeos/login/wizard_controller.h"
27 #include "chrome/browser/chromeos/settings/cros_settings.h"
28 #include "chrome/browser/policy/browser_policy_connector.h"
29 #include "chrome/browser/policy/cloud_policy_constants.h"
30 #include "chrome/browser/policy/cloud_policy_store.h"
31 #include "chrome/browser/policy/device_local_account_policy_service.h"
32 #include "chrome/browser/policy/policy_builder.h"
33 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
34 #include "chrome/common/chrome_notification_types.h"
35 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
37 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h" 38 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/ui_test_utils.h" 39 #include "chrome/test/base/ui_test_utils.h"
40 #include "chromeos/dbus/fake_session_manager_client.h"
27 #include "chromeos/dbus/mock_dbus_thread_manager.h" 41 #include "chromeos/dbus/mock_dbus_thread_manager.h"
28 #include "chromeos/dbus/mock_session_manager_client.h" 42 #include "chromeos/dbus/mock_session_manager_client.h"
29 #include "chromeos/dbus/mock_shill_manager_client.h" 43 #include "chromeos/dbus/mock_shill_manager_client.h"
44 #include "content/public/browser/notification_watcher.h"
45 #include "content/public/test/mock_notification_observer.h"
30 #include "google_apis/gaia/mock_url_fetcher_factory.h" 46 #include "google_apis/gaia/mock_url_fetcher_factory.h"
31 #include "grit/generated_resources.h" 47 #include "grit/generated_resources.h"
32 #include "testing/gmock/include/gmock/gmock.h" 48 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 49 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/base/l10n/l10n_util.h" 50 #include "ui/base/l10n/l10n_util.h"
35 51
36 using ::testing::_; 52 using ::testing::_;
37 using ::testing::AnyNumber; 53 using ::testing::AnyNumber;
38 using ::testing::AnyOf; 54 using ::testing::AnyOf;
39 using ::testing::Invoke; 55 using ::testing::Invoke;
40 using ::testing::InvokeWithoutArgs; 56 using ::testing::InvokeWithoutArgs;
41 using ::testing::Return; 57 using ::testing::Return;
58 using ::testing::ReturnRef;
42 using ::testing::ReturnNull; 59 using ::testing::ReturnNull;
43 using ::testing::Sequence; 60 using ::testing::Sequence;
44 using ::testing::WithArg; 61 using ::testing::WithArg;
45 62
63 namespace em = enterprise_management;
64
46 namespace chromeos { 65 namespace chromeos {
47 66
48 namespace { 67 namespace {
49 68
50 const char kUsername[] = "test_user@gmail.com"; 69 const char kUsername[] = "test_user@gmail.com";
51 const char kNewUsername[] = "test_new_user@gmail.com"; 70 const char kNewUsername[] = "test_new_user@gmail.com";
52 const char kPassword[] = "test_password"; 71 const char kPassword[] = "test_password";
53 72
73 const char kAutoLoginUsername[] = "public_session_user@localhost";
74 const int kAutoLoginNoDelay = 0;
75 const int kAutoLoginShortDelay = 100;
76 const int kAutoLoginLongDelay = 10000;
77
54 class MockLoginDisplay : public LoginDisplay { 78 class MockLoginDisplay : public LoginDisplay {
55 public: 79 public:
56 MockLoginDisplay() 80 MockLoginDisplay()
57 : LoginDisplay(NULL, gfx::Rect()) { 81 : LoginDisplay(NULL, gfx::Rect()) {
58 } 82 }
59 83
60 MOCK_METHOD4(Init, void(const UserList&, bool, bool, bool)); 84 MOCK_METHOD4(Init, void(const UserList&, bool, bool, bool));
61 MOCK_METHOD0(OnPreferencesChanged, void(void)); 85 MOCK_METHOD0(OnPreferencesChanged, void(void));
62 MOCK_METHOD1(OnUserImageChanged, void(const User&)); 86 MOCK_METHOD1(OnUserImageChanged, void(const User&));
63 MOCK_METHOD0(OnFadeOut, void(void)); 87 MOCK_METHOD0(OnFadeOut, void(void));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 MOCK_METHOD0(CheckForAutoEnrollment, void(void)); 119 MOCK_METHOD0(CheckForAutoEnrollment, void(void));
96 MOCK_METHOD2(StartWizard, void(const std::string&, DictionaryValue*)); 120 MOCK_METHOD2(StartWizard, void(const std::string&, DictionaryValue*));
97 MOCK_METHOD0(StartSignInScreen, void(void)); 121 MOCK_METHOD0(StartSignInScreen, void(void));
98 MOCK_METHOD0(ResumeSignInScreen, void(void)); 122 MOCK_METHOD0(ResumeSignInScreen, void(void));
99 MOCK_METHOD0(OnPreferencesChanged, void(void)); 123 MOCK_METHOD0(OnPreferencesChanged, void(void));
100 124
101 private: 125 private:
102 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplayHost); 126 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplayHost);
103 }; 127 };
104 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
105 scoped_refptr<Authenticator> CreateAuthenticator( 141 scoped_refptr<Authenticator> CreateAuthenticator(
106 LoginStatusConsumer* consumer) { 142 LoginStatusConsumer* consumer) {
107 return new MockAuthenticator(consumer, kUsername, kPassword); 143 return new MockAuthenticator(consumer, kUsername, kPassword);
108 } 144 }
109 145
110 scoped_refptr<Authenticator> CreateAuthenticatorNewUser( 146 scoped_refptr<Authenticator> CreateAuthenticatorNewUser(
111 LoginStatusConsumer* consumer) { 147 LoginStatusConsumer* consumer) {
112 return new MockAuthenticator(consumer, kNewUsername, kPassword); 148 return new MockAuthenticator(consumer, kNewUsername, kPassword);
113 } 149 }
114 150
151 scoped_refptr<Authenticator> CreateAuthenticatorPublicSession(
152 LoginStatusConsumer* consumer) {
153 return new MockAuthenticator(consumer, kAutoLoginUsername, "");
154 }
155
115 } // namespace 156 } // namespace
116 157
117 class ExistingUserControllerTest : public CrosInProcessBrowserTest { 158 class ExistingUserControllerTest : public CrosInProcessBrowserTest {
118 protected: 159 protected:
119 ExistingUserControllerTest() 160 ExistingUserControllerTest()
120 : mock_network_library_(NULL), 161 : mock_network_library_(NULL),
121 mock_login_display_(NULL), 162 mock_login_display_(NULL),
122 mock_login_display_host_(NULL), 163 mock_login_display_host_(NULL),
123 testing_profile_(NULL) { 164 testing_profile_(NULL) {
124 } 165 }
(...skipping 12 matching lines...) Expand all
137 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); 178 Return(reinterpret_cast<IBusInputContextClient*>(NULL)));
138 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 179 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
139 GetProperties(_)) 180 GetProperties(_))
140 .Times(AnyNumber()); 181 .Times(AnyNumber());
141 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 182 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
142 AddPropertyChangedObserver(_)) 183 AddPropertyChangedObserver(_))
143 .Times(AnyNumber()); 184 .Times(AnyNumber());
144 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 185 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
145 RemovePropertyChangedObserver(_)) 186 RemovePropertyChangedObserver(_))
146 .Times(AnyNumber()); 187 .Times(AnyNumber());
188
189 SetUpSessionManager(mock_dbus_thread_manager);
190
147 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); 191 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
148 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); 192 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
149 cros_mock_->InitStatusAreaMocks(); 193 cros_mock_->InitStatusAreaMocks();
150 cros_mock_->SetStatusAreaMocksExpectations(); 194 cros_mock_->SetStatusAreaMocksExpectations();
151 195
152 mock_network_library_ = cros_mock_->mock_network_library(); 196 mock_network_library_ = cros_mock_->mock_network_library();
153 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) 197 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_))
154 .Times(AnyNumber()); 198 .Times(AnyNumber());
155 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) 199 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _))
156 .WillRepeatedly(Return(true)); 200 .WillRepeatedly(Return(true));
157 201
158 MockSessionManagerClient* mock_session_manager_client =
159 mock_dbus_thread_manager->mock_session_manager_client();
160 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady())
161 .Times(1);
162 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_))
163 .Times(AnyNumber());
164
165 mock_login_utils_ = new MockLoginUtils(); 202 mock_login_utils_ = new MockLoginUtils();
166 LoginUtils::Set(mock_login_utils_); 203 LoginUtils::Set(mock_login_utils_);
167 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) 204 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication())
168 .Times(AnyNumber()); 205 .Times(AnyNumber());
169 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) 206 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers())
170 .Times(AnyNumber()); 207 .Times(AnyNumber());
171 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) 208 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_))
172 .Times(1); 209 .Times(1);
173 210
174 mock_login_display_host_.reset(new MockLoginDisplayHost()); 211 mock_login_display_host_.reset(new MockLoginDisplayHost());
212 mock_login_display_ = new MockLoginDisplay();
213 SetUpLoginDisplay();
214 }
175 215
176 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))
177 .Times(AnyNumber()) 220 .Times(AnyNumber())
178 .WillRepeatedly(Return(true)); 221 .WillRepeatedly(Return(true));
179 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kNewUsername)) 222 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername))
180 .Times(AnyNumber()) 223 .Times(AnyNumber())
181 .WillRepeatedly(Return(false)); 224 .WillRepeatedly(Return(false));
182 EXPECT_CALL(*mock_user_manager_.user_manager(), IsUserLoggedIn()) 225 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn())
183 .Times(AnyNumber()) 226 .Times(AnyNumber())
184 .WillRepeatedly(Return(false)); 227 .WillRepeatedly(Return(false));
185 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsGuest()) 228 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsGuest())
186 .Times(AnyNumber()) 229 .Times(AnyNumber())
187 .WillRepeatedly(Return(false)); 230 .WillRepeatedly(Return(false));
188 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsDemoUser()) 231 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsDemoUser())
189 .Times(AnyNumber()) 232 .Times(AnyNumber())
190 .WillRepeatedly(Return(false)); 233 .WillRepeatedly(Return(false));
191 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsPublicAccount()) 234 EXPECT_CALL(*mock_user_manager_->user_manager(),
235 IsLoggedInAsPublicAccount())
192 .Times(AnyNumber()) 236 .Times(AnyNumber())
193 .WillRepeatedly(Return(false)); 237 .WillRepeatedly(Return(false));
194 EXPECT_CALL(*mock_user_manager_.user_manager(), IsSessionStarted()) 238 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted())
195 .Times(AnyNumber()) 239 .Times(AnyNumber())
196 .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);
197 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() {
198 // |mock_login_display_| is owned by the ExistingUserController, which calls 256 // |mock_login_display_| is owned by the ExistingUserController, which calls
199 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. 257 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
200 mock_login_display_ = new MockLoginDisplay();
201 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) 258 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
202 .Times(1) 259 .Times(1)
203 .WillOnce(Return(mock_login_display_)); 260 .WillOnce(Return(mock_login_display_));
204 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) 261 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
205 .Times(1) 262 .Times(1)
206 .WillOnce(ReturnNull()); 263 .WillOnce(ReturnNull());
207 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) 264 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
208 .Times(1); 265 .Times(1);
209 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) 266 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true))
210 .Times(1); 267 .Times(1);
211 } 268 }
212 269
213 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 270 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
214 command_line->AppendSwitch(switches::kLoginManager); 271 command_line->AppendSwitch(switches::kLoginManager);
215 } 272 }
216 273
217 virtual void SetUpOnMainThread() OVERRIDE { 274 virtual void SetUpOnMainThread() OVERRIDE {
218 testing_profile_.reset(new TestingProfile()); 275 testing_profile_.reset(new TestingProfile());
219 existing_user_controller_.reset( 276 existing_user_controller_.reset(
220 new ExistingUserController(mock_login_display_host_.get())); 277 new ExistingUserController(mock_login_display_host_.get()));
221 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); 278 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get());
222 existing_user_controller_->Init(UserList()); 279 existing_user_controller_->Init(UserList());
223 profile_prepared_cb_ = 280 profile_prepared_cb_ =
224 base::Bind(&ExistingUserController::OnProfilePrepared, 281 base::Bind(&ExistingUserController::OnProfilePrepared,
225 base::Unretained(existing_user_controller()), 282 base::Unretained(existing_user_controller()),
226 testing_profile_.get()); 283 testing_profile_.get());
227 } 284 }
228 285
229 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();
230 CrosInProcessBrowserTest::CleanUpOnMainThread(); 293 CrosInProcessBrowserTest::CleanUpOnMainThread();
231 testing_profile_.reset(NULL); 294 testing_profile_.reset(NULL);
232 } 295 }
233 296
234 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 297 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
235 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); 298 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
236 DBusThreadManager::Shutdown(); 299 DBusThreadManager::Shutdown();
237 } 300 }
238 301
302 // ExistingUserController private member accessors.
303 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
304 return existing_user_controller()->auto_login_timer_.get();
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
239 scoped_ptr<ExistingUserController> existing_user_controller_; 328 scoped_ptr<ExistingUserController> existing_user_controller_;
240 329
241 // These mocks are owned by CrosLibrary class. 330 // These mocks are owned by CrosLibrary class.
242 MockNetworkLibrary* mock_network_library_; 331 MockNetworkLibrary* mock_network_library_;
243 332
244 MockLoginDisplay* mock_login_display_; 333 MockLoginDisplay* mock_login_display_;
245 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; 334 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
246 335
247 ScopedMockUserManagerEnabler mock_user_manager_; 336 scoped_ptr<ScopedMockUserManagerEnabler> mock_user_manager_;
248 337
249 // Owned by LoginUtilsWrapper. 338 // Owned by LoginUtilsWrapper.
250 MockLoginUtils* mock_login_utils_; 339 MockLoginUtils* mock_login_utils_;
251 340
252 scoped_ptr<TestingProfile> testing_profile_; 341 scoped_ptr<TestingProfile> testing_profile_;
253 342
254 // Mock URLFetcher. 343 // Mock URLFetcher.
255 MockURLFetcherFactory<SuccessFetcher> factory_; 344 MockURLFetcherFactory<SuccessFetcher> factory_;
256 345
257 base::Callback<void(void)> profile_prepared_cb_; 346 base::Callback<void(void)> profile_prepared_cb_;
(...skipping 21 matching lines...) Expand all
279 .Times(1); 368 .Times(1);
280 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) 369 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername))
281 .Times(1); 370 .Times(1);
282 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 371 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
283 .Times(1); 372 .Times(1);
284 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 373 EXPECT_CALL(*mock_login_display_, OnFadeOut())
285 .Times(1); 374 .Times(1);
286 EXPECT_CALL(*mock_login_display_host_, 375 EXPECT_CALL(*mock_login_display_host_,
287 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) 376 StartWizard(WizardController::kTermsOfServiceScreenName, NULL))
288 .Times(0); 377 .Times(0);
289 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 378 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
290 .Times(AnyNumber()) 379 .Times(AnyNumber())
291 .WillRepeatedly(Return(false)); 380 .WillRepeatedly(Return(false));
292 existing_user_controller()->Login(kUsername, kPassword); 381 existing_user_controller()->Login(kUsername, kPassword);
293 content::RunAllPendingInMessageLoop(); 382 content::RunAllPendingInMessageLoop();
294 } 383 }
295 384
296 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) { 385 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) {
297 EXPECT_CALL(*mock_login_display_host_, 386 EXPECT_CALL(*mock_login_display_host_,
298 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _)) 387 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _))
299 .Times(1); 388 .Times(1);
300 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 389 EXPECT_CALL(*mock_login_display_, OnFadeOut())
301 .Times(1); 390 .Times(1);
302 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) 391 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
303 .Times(1); 392 .Times(1);
304 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 393 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
305 .Times(AnyNumber()) 394 .Times(AnyNumber())
306 .WillRepeatedly(Return(false)); 395 .WillRepeatedly(Return(false));
307 // 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
308 // 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.
309 Sequence uiEnabledSequence; 398 Sequence uiEnabledSequence;
310 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 399 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
311 .Times(1) 400 .Times(1)
312 .InSequence(uiEnabledSequence); 401 .InSequence(uiEnabledSequence);
313 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 402 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
314 .Times(1) 403 .Times(1)
(...skipping 24 matching lines...) Expand all
339 PrepareProfile(kNewUsername, _, kPassword, _, _, _)) 428 PrepareProfile(kNewUsername, _, kPassword, _, _, _))
340 .Times(1) 429 .Times(1)
341 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, 430 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
342 &base::Callback<void(void)>::Run)); 431 &base::Callback<void(void)>::Run));
343 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) 432 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername))
344 .Times(1); 433 .Times(1);
345 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 434 EXPECT_CALL(*mock_login_display_, OnFadeOut())
346 .Times(1); 435 .Times(1);
347 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) 436 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
348 .Times(1); 437 .Times(1);
349 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 438 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
350 .Times(AnyNumber()) 439 .Times(AnyNumber())
351 .WillRepeatedly(Return(true)); 440 .WillRepeatedly(Return(true));
352 441
353 // 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
354 // during the login sequence, and is enabled again after login completion. 443 // during the login sequence, and is enabled again after login completion.
355 Sequence uiEnabledSequence; 444 Sequence uiEnabledSequence;
356 // 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
357 // auto-enrollment, and again after doing an ownership status check. 446 // auto-enrollment, and again after doing an ownership status check.
358 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 447 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
359 .Times(2) 448 .Times(2)
360 .InSequence(uiEnabledSequence); 449 .InSequence(uiEnabledSequence);
361 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 450 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
362 .Times(1) 451 .Times(1)
363 .InSequence(uiEnabledSequence); 452 .InSequence(uiEnabledSequence);
364 453
365 existing_user_controller()->CompleteLogin(kNewUsername, kPassword); 454 existing_user_controller()->CompleteLogin(kNewUsername, kPassword);
366 content::RunAllPendingInMessageLoop(); 455 content::RunAllPendingInMessageLoop();
367 } 456 }
368 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 void ConfigureAutoLogin() {
652 existing_user_controller()->ConfigurePublicSessionAutoLogin();
653 }
654
655 void FireAutoLogin() {
656 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
657 }
658
659 // Enables public sessions in tests.
660 FakeSessionManagerClient session_manager_client_;
661
662 // Stores the device owner key.
663 base::ScopedTempDir temp_dir_;
664
665 // Carries Chrome OS device policies for tests.
666 policy::DevicePolicyBuilder device_policy_;
667
668 private:
669 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
670 };
671
672 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
673 StartAutoLoginTimer) {
674 DisableAutoLoginPolicyNotifications();
675
676 // Timer shouldn't start until signin screen is ready.
677 set_auto_login_username(kAutoLoginUsername);
678 set_auto_login_delay(kAutoLoginLongDelay);
679 existing_user_controller()->StartPublicSessionAutoLoginTimer();
680 EXPECT_FALSE(auto_login_timer());
681
682 // Timer shouldn't start if the policy isn't set.
683 set_auto_login_username("");
684 existing_user_controller()->OnSigninScreenReady();
685 existing_user_controller()->StartPublicSessionAutoLoginTimer();
686 EXPECT_FALSE(auto_login_timer());
687
688 // Timer shouldn't fire in the middle of a login attempt.
689 set_auto_login_username(kAutoLoginUsername);
690 set_is_login_in_progress(true);
691 existing_user_controller()->StartPublicSessionAutoLoginTimer();
692 EXPECT_FALSE(auto_login_timer());
693
694 // Otherwise start.
695 set_is_login_in_progress(false);
696 existing_user_controller()->StartPublicSessionAutoLoginTimer();
697 ASSERT_TRUE(auto_login_timer());
698 EXPECT_TRUE(auto_login_timer()->IsRunning());
699 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
700 kAutoLoginLongDelay);
701 }
702
703 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
704 StopAutoLoginTimer) {
705 existing_user_controller()->OnSigninScreenReady();
706 set_auto_login_username(kAutoLoginUsername);
707 set_auto_login_delay(kAutoLoginLongDelay);
708
709 existing_user_controller()->StartPublicSessionAutoLoginTimer();
710 ASSERT_TRUE(auto_login_timer());
711 EXPECT_TRUE(auto_login_timer()->IsRunning());
712
713 existing_user_controller()->StopPublicSessionAutoLoginTimer();
714 ASSERT_TRUE(auto_login_timer());
715 EXPECT_FALSE(auto_login_timer()->IsRunning());
716 }
717
718 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
719 ResetAutoLoginTimer) {
720 existing_user_controller()->OnSigninScreenReady();
721 set_auto_login_username(kAutoLoginUsername);
722
723 // Timer starts off not running.
724 EXPECT_FALSE(auto_login_timer());
725
726 // When the timer isn't running, nothing should happen.
727 existing_user_controller()->ResetPublicSessionAutoLoginTimer();
728 EXPECT_FALSE(auto_login_timer());
729
730 // Start the timer.
731 set_auto_login_delay(kAutoLoginLongDelay);
732 existing_user_controller()->StartPublicSessionAutoLoginTimer();
733 ASSERT_TRUE(auto_login_timer());
734 EXPECT_TRUE(auto_login_timer()->IsRunning());
735 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
736 kAutoLoginLongDelay);
737
738 // User activity should restart the timer, so check to see that the
739 // timer delay was modified.
740 set_auto_login_delay(kAutoLoginShortDelay);
741 existing_user_controller()->ResetPublicSessionAutoLoginTimer();
742 ASSERT_TRUE(auto_login_timer());
743 EXPECT_TRUE(auto_login_timer()->IsRunning());
744 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
745 kAutoLoginShortDelay);
746 }
747
748 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
749 ConfigureAutoLogin) {
750 existing_user_controller()->OnSigninScreenReady();
751
752 // Turn off settings notifications to ExistingUserController.
753 DisableAutoLoginPolicyNotifications();
754
755 // Timer shouldn't start when the policy is disabled.
756 SetAutoLoginPolicy("", 0);
757 ConfigureAutoLogin();
758 EXPECT_FALSE(auto_login_timer());
759 EXPECT_EQ(auto_login_delay(), 0);
760 EXPECT_EQ(auto_login_username(), "");
761
762 // Timer shouldn't start when the delay alone is set.
763 SetAutoLoginPolicy("", kAutoLoginShortDelay);
764 ConfigureAutoLogin();
765 EXPECT_FALSE(auto_login_timer());
766 EXPECT_EQ(auto_login_delay(), kAutoLoginShortDelay);
767 EXPECT_EQ(auto_login_username(), "");
768
769 // Timer should start when the username is set.
770 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
771 ConfigureAutoLogin();
772 ASSERT_TRUE(auto_login_timer());
773 EXPECT_TRUE(auto_login_timer()->IsRunning());
774 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
775 kAutoLoginShortDelay);
776 EXPECT_EQ(auto_login_delay(), kAutoLoginShortDelay);
777 EXPECT_EQ(auto_login_username(), kAutoLoginUsername);
778
779 // Timer should restart when the delay is changed.
780 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
781 ConfigureAutoLogin();
782 ASSERT_TRUE(auto_login_timer());
783 EXPECT_TRUE(auto_login_timer()->IsRunning());
784 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
785 kAutoLoginLongDelay);
786 EXPECT_EQ(auto_login_delay(), kAutoLoginLongDelay);
787 EXPECT_EQ(auto_login_username(), kAutoLoginUsername);
788
789 // Timer should stop when the username is unset.
790 SetAutoLoginPolicy("", kAutoLoginLongDelay);
791 ConfigureAutoLogin();
792 ASSERT_TRUE(auto_login_timer());
793 EXPECT_FALSE(auto_login_timer()->IsRunning());
794 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
795 kAutoLoginLongDelay);
796 EXPECT_EQ(auto_login_username(), "");
797 EXPECT_EQ(auto_login_delay(), kAutoLoginLongDelay);
798 }
799
800 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
801 ConfigureAutoLoginUsingPolicy) {
802 existing_user_controller()->OnSigninScreenReady();
803 EXPECT_EQ("", auto_login_username());
804 EXPECT_EQ(0, auto_login_delay());
805 EXPECT_FALSE(auto_login_timer());
806
807 // Set the policy.
808 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
809 EXPECT_EQ(kAutoLoginUsername, auto_login_username());
810 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay());
811 ASSERT_TRUE(auto_login_timer());
812 EXPECT_TRUE(auto_login_timer()->IsRunning());
813
814 // Unset the policy.
815 SetAutoLoginPolicy("", 0);
816 EXPECT_EQ("", auto_login_username());
817 EXPECT_EQ(0, auto_login_delay());
818 ASSERT_TRUE(auto_login_timer());
819 EXPECT_FALSE(auto_login_timer()->IsRunning());
820 }
821
822 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
823 OnAutoLoginFire) {
824 // Set up mocks to check login success.
825 ExpectSuccessfulLogin(kAutoLoginUsername, "",
826 CreateAuthenticatorPublicSession);
827 existing_user_controller()->OnSigninScreenReady();
828
829 // Directly set auto-login parameters to avoid starting the timer.
830 set_auto_login_username(kAutoLoginUsername);
831 set_auto_login_delay(kAutoLoginLongDelay);
832
833 // Manually fire auto-login and wait for the login tasks to complete.
834 FireAutoLogin();
835 content::RunAllPendingInMessageLoop();
836 }
837
838 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
839 AutoLoginNoDelay) {
840 // Set up mocks to check login success.
841 ExpectSuccessfulLogin(kAutoLoginUsername, "",
842 CreateAuthenticatorPublicSession);
843 existing_user_controller()->OnSigninScreenReady();
844
845 // Start auto-login and wait for login tasks to complete.
846 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginNoDelay);
847 content::RunAllPendingInMessageLoop();
848 }
849
850 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
851 AutoLoginShortDelay) {
852 // Set up mocks to check login success.
853 ExpectSuccessfulLogin(kAutoLoginUsername, "",
854 CreateAuthenticatorPublicSession);
855 existing_user_controller()->OnSigninScreenReady();
856 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
857 ASSERT_TRUE(auto_login_timer() && auto_login_timer()->IsRunning());
bartfab (slow) 2013/02/28 13:29:14 Nit: If you break this into two ASSERTs, it will b
dconnelly 2013/02/28 13:32:48 Done.
858
859 // Wait for the timer to fire.
860 content::MessageLoopRunner* runner = new content::MessageLoopRunner;
861 base::OneShotTimer<content::MessageLoopRunner> timer;
862 timer.Start(FROM_HERE,
863 base::TimeDelta::FromMilliseconds(2 * kAutoLoginShortDelay),
864 base::Bind(&content::MessageLoopRunner::Quit,
865 base::Unretained(runner)));
866 runner->Run();
867
868 // Wait for login tasks to complete.
869 content::RunAllPendingInMessageLoop();
870 }
871
872 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
873 LoginStopsAutoLogin) {
874 // Set up mocks to check login success.
875 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator);
876
877 existing_user_controller()->OnSigninScreenReady();
878 set_auto_login_username(kAutoLoginUsername);
879 set_auto_login_delay(kAutoLoginLongDelay);
880 existing_user_controller()->StartPublicSessionAutoLoginTimer();
881 ASSERT_TRUE(auto_login_timer());
882 EXPECT_TRUE(auto_login_timer()->IsRunning());
883
884 // Login and check that it stopped the timer.
885 existing_user_controller()->Login(kUsername, kPassword);
886 EXPECT_TRUE(is_login_in_progress());
887 ASSERT_TRUE(auto_login_timer());
888 EXPECT_FALSE(auto_login_timer()->IsRunning());
889
890 // Wait for login tasks to complete.
891 content::RunAllPendingInMessageLoop();
892
893 // Timer should still be stopped after login completes.
894 ASSERT_TRUE(auto_login_timer());
895 EXPECT_FALSE(auto_login_timer()->IsRunning());
896 }
897
898 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
899 GuestModeLoginStopsAutoLogin) {
900 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
901 .Times(1);
902 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
903 .Times(1)
904 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator)));
905 ScopedMockUserManagerEnabler mock_user_manager;
906 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_))
907 .Times(1);
908
909 existing_user_controller()->OnSigninScreenReady();
910 set_auto_login_username(kAutoLoginUsername);
911 set_auto_login_delay(kAutoLoginLongDelay);
912 existing_user_controller()->StartPublicSessionAutoLoginTimer();
913 ASSERT_TRUE(auto_login_timer());
914 EXPECT_TRUE(auto_login_timer()->IsRunning());
915
916 // Login and check that it stopped the timer.
917 existing_user_controller()->LoginAsGuest();
918 EXPECT_TRUE(is_login_in_progress());
919 ASSERT_TRUE(auto_login_timer());
920 EXPECT_FALSE(auto_login_timer()->IsRunning());
921
922 // Wait for login tasks to complete.
923 content::RunAllPendingInMessageLoop();
924
925 // Timer should still be stopped after login completes.
926 ASSERT_TRUE(auto_login_timer());
927 EXPECT_FALSE(auto_login_timer()->IsRunning());
928 }
929
930 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
931 CompleteLoginStopsAutoLogin) {
932 // Set up mocks to check login success.
933 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator);
934 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
935 .Times(1);
936
937 existing_user_controller()->OnSigninScreenReady();
938 set_auto_login_username(kAutoLoginUsername);
939 set_auto_login_delay(kAutoLoginLongDelay);
940 existing_user_controller()->StartPublicSessionAutoLoginTimer();
941 ASSERT_TRUE(auto_login_timer());
942 EXPECT_TRUE(auto_login_timer()->IsRunning());
943
944 // Check that login completes and stops the timer.
945 existing_user_controller()->CompleteLogin(kUsername, kPassword);
946 ASSERT_TRUE(auto_login_timer());
947 EXPECT_FALSE(auto_login_timer()->IsRunning());
948
949 // Wait for login tasks to complete.
950 content::RunAllPendingInMessageLoop();
951
952 // Timer should still be stopped after login completes.
953 ASSERT_TRUE(auto_login_timer());
954 EXPECT_FALSE(auto_login_timer()->IsRunning());
955 }
956
957 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
958 PublicSessionLoginStopsAutoLogin) {
959 // Set up mocks to check login success.
960 ExpectSuccessfulLogin(kAutoLoginUsername, "",
961 CreateAuthenticatorPublicSession);
962 existing_user_controller()->OnSigninScreenReady();
963 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
964 ASSERT_TRUE(auto_login_timer());
965 EXPECT_TRUE(auto_login_timer()->IsRunning());
966
967 // Login and check that it stopped the timer.
968 existing_user_controller()->LoginAsPublicAccount(kAutoLoginUsername);
969 EXPECT_TRUE(is_login_in_progress());
970 ASSERT_TRUE(auto_login_timer());
971 EXPECT_FALSE(auto_login_timer()->IsRunning());
972
973 // Wait for login tasks to complete.
974 content::RunAllPendingInMessageLoop();
975
976 // Timer should still be stopped after login completes.
977 ASSERT_TRUE(auto_login_timer());
978 EXPECT_FALSE(auto_login_timer()->IsRunning());
979 }
980
369 } // namespace chromeos 981 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/existing_user_controller.cc ('k') | chrome/browser/chromeos/login/login_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698