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

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: split out FakeSessionManagerClient Created 7 years, 10 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"
bartfab (slow) 2013/02/25 16:51:23 I trust you checked that the list of includes matc
dconnelly 2013/02/26 18:04:15 Done.
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/chromeos/settings/cros_settings.h"
30 #include "chrome/browser/policy/browser_policy_connector.h"
31 #include "chrome/browser/policy/cloud_policy_constants.h"
32 #include "chrome/browser/policy/cloud_policy_store.h"
33 #include "chrome/browser/policy/device_local_account_policy_service.h"
34 #include "chrome/browser/policy/policy_builder.h"
35 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
36 #include "chrome/common/chrome_notification_types.h"
37 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h" 38 #include "chrome/common/chrome_switches.h"
39 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h" 40 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/ui_test_utils.h" 41 #include "chrome/test/base/ui_test_utils.h"
42 #include "chromeos/dbus/fake_session_manager_client.h"
27 #include "chromeos/dbus/mock_dbus_thread_manager.h" 43 #include "chromeos/dbus/mock_dbus_thread_manager.h"
28 #include "chromeos/dbus/mock_session_manager_client.h" 44 #include "chromeos/dbus/mock_session_manager_client.h"
29 #include "chromeos/dbus/mock_shill_manager_client.h" 45 #include "chromeos/dbus/mock_shill_manager_client.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
156 // Observes user list change notifications and quits the message loop once a
bartfab (slow) 2013/02/25 16:51:23 Is this not a straight copy & paste from Mattias'
dconnelly 2013/02/26 18:04:15 He refactored it into a different thing and I miss
157 // specified user appears.
158 class UserListObserver : public content::NotificationObserver {
159 public:
160 explicit UserListObserver(const std::string& user_to_watch_for)
161 : user_to_watch_for_(user_to_watch_for) {}
162
163 void Run() {
164 if (chromeos::UserManager::Get()->IsKnownUser(user_to_watch_for_))
165 return;
166
167 content::NotificationRegistrar registrar;
168 registrar.Add(this, chrome::NOTIFICATION_USER_LIST_CHANGED,
169 content::NotificationService::AllSources());
170 run_loop_.Run();
171 }
172
173 // content::NotificationObserver:
174 virtual void Observe(int type,
175 const content::NotificationSource& source,
176 const content::NotificationDetails& details) OVERRIDE {
177 if (chromeos::UserManager::Get()->IsKnownUser(user_to_watch_for_))
178 run_loop_.Quit();
179 }
180
181 private:
182 const std::string user_to_watch_for_;
183 base::RunLoop run_loop_;
184 };
185
114 } // namespace 186 } // namespace
115 187
116 class ExistingUserControllerTest : public CrosInProcessBrowserTest { 188 class ExistingUserControllerTest : public CrosInProcessBrowserTest {
117 protected: 189 protected:
118 ExistingUserControllerTest() 190 ExistingUserControllerTest()
119 : mock_network_library_(NULL), 191 : mock_network_library_(NULL),
120 mock_login_display_(NULL), 192 mock_login_display_(NULL),
121 mock_login_display_host_(NULL), 193 mock_login_display_host_(NULL),
122 testing_profile_(NULL) { 194 testing_profile_(NULL) {
123 } 195 }
(...skipping 12 matching lines...) Expand all
136 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); 208 Return(reinterpret_cast<IBusInputContextClient*>(NULL)));
137 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 209 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
138 GetProperties(_)) 210 GetProperties(_))
139 .Times(AnyNumber()); 211 .Times(AnyNumber());
140 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 212 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
141 AddPropertyChangedObserver(_)) 213 AddPropertyChangedObserver(_))
142 .Times(AnyNumber()); 214 .Times(AnyNumber());
143 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 215 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
144 RemovePropertyChangedObserver(_)) 216 RemovePropertyChangedObserver(_))
145 .Times(AnyNumber()); 217 .Times(AnyNumber());
218
219 SetUpSessionManager(mock_dbus_thread_manager);
220
146 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); 221 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
147 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); 222 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
148 cros_mock_->InitStatusAreaMocks(); 223 cros_mock_->InitStatusAreaMocks();
149 cros_mock_->SetStatusAreaMocksExpectations(); 224 cros_mock_->SetStatusAreaMocksExpectations();
150 225
151 mock_network_library_ = cros_mock_->mock_network_library(); 226 mock_network_library_ = cros_mock_->mock_network_library();
152 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) 227 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_))
153 .Times(AnyNumber()); 228 .Times(AnyNumber());
154 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) 229 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _))
155 .WillRepeatedly(Return(true)); 230 .WillRepeatedly(Return(true));
156 231
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(); 232 mock_login_utils_ = new MockLoginUtils();
165 LoginUtils::Set(mock_login_utils_); 233 LoginUtils::Set(mock_login_utils_);
166 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) 234 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication())
167 .Times(AnyNumber()); 235 .Times(AnyNumber());
168 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) 236 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers())
169 .Times(AnyNumber()); 237 .Times(AnyNumber());
170 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) 238 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_))
171 .Times(1); 239 .Times(1);
172 240
173 mock_login_display_host_.reset(new MockLoginDisplayHost()); 241 mock_login_display_host_.reset(new MockLoginDisplayHost());
242 mock_login_display_ = new MockLoginDisplay();
243 SetUpLoginDisplay();
244 }
174 245
175 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kUsername)) 246 virtual void SetUpSessionManager(
247 MockDBusThreadManager* mock_dbus_thread_manager) {
248 mock_user_manager_.reset(new ScopedMockUserManagerEnabler);
249 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername))
176 .Times(AnyNumber()) 250 .Times(AnyNumber())
177 .WillRepeatedly(Return(true)); 251 .WillRepeatedly(Return(true));
178 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kNewUsername)) 252 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername))
179 .Times(AnyNumber()) 253 .Times(AnyNumber())
180 .WillRepeatedly(Return(false)); 254 .WillRepeatedly(Return(false));
181 EXPECT_CALL(*mock_user_manager_.user_manager(), IsUserLoggedIn()) 255 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn())
182 .Times(AnyNumber()) 256 .Times(AnyNumber())
183 .WillRepeatedly(Return(false)); 257 .WillRepeatedly(Return(false));
184 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsGuest()) 258 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsGuest())
185 .Times(AnyNumber()) 259 .Times(AnyNumber())
186 .WillRepeatedly(Return(false)); 260 .WillRepeatedly(Return(false));
187 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsDemoUser()) 261 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsDemoUser())
188 .Times(AnyNumber()) 262 .Times(AnyNumber())
189 .WillRepeatedly(Return(false)); 263 .WillRepeatedly(Return(false));
190 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsPublicAccount()) 264 EXPECT_CALL(*mock_user_manager_->user_manager(),
265 IsLoggedInAsPublicAccount())
191 .Times(AnyNumber()) 266 .Times(AnyNumber())
192 .WillRepeatedly(Return(false)); 267 .WillRepeatedly(Return(false));
193 EXPECT_CALL(*mock_user_manager_.user_manager(), IsSessionStarted()) 268 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted())
194 .Times(AnyNumber()) 269 .Times(AnyNumber())
195 .WillRepeatedly(Return(false)); 270 .WillRepeatedly(Return(false));
271 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
272 .Times(AnyNumber())
273 .WillRepeatedly(Return(false));
274 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown())
275 .Times(1);
196 276
277 MockSessionManagerClient* mock_session_manager_client =
278 mock_dbus_thread_manager->mock_session_manager_client();
279 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady())
280 .Times(1);
281 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_))
282 .Times(AnyNumber());
283 }
284
285 virtual void SetUpLoginDisplay() {
197 // |mock_login_display_| is owned by the ExistingUserController, which calls 286 // |mock_login_display_| is owned by the ExistingUserController, which calls
198 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. 287 // 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(_)) 288 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
201 .Times(1) 289 .Times(1)
202 .WillOnce(Return(mock_login_display_)); 290 .WillOnce(Return(mock_login_display_));
203 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) 291 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
204 .Times(1) 292 .Times(1)
205 .WillOnce(ReturnNull()); 293 .WillOnce(ReturnNull());
206 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) 294 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
207 .Times(1); 295 .Times(1);
208 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) 296 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true))
209 .Times(1); 297 .Times(1);
210 } 298 }
211 299
212 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 300 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
213 command_line->AppendSwitch(switches::kLoginManager); 301 command_line->AppendSwitch(switches::kLoginManager);
214 } 302 }
215 303
216 virtual void SetUpOnMainThread() OVERRIDE { 304 virtual void SetUpOnMainThread() OVERRIDE {
217 testing_profile_.reset(new TestingProfile()); 305 testing_profile_.reset(new TestingProfile());
218 existing_user_controller_.reset( 306 existing_user_controller_.reset(
219 new ExistingUserController(mock_login_display_host_.get())); 307 new ExistingUserController(mock_login_display_host_.get()));
220 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); 308 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get());
221 existing_user_controller_->Init(UserList()); 309 existing_user_controller_->Init(UserList());
222 profile_prepared_cb_ = 310 profile_prepared_cb_ =
223 base::Bind(&ExistingUserController::OnProfilePrepared, 311 base::Bind(&ExistingUserController::OnProfilePrepared,
224 base::Unretained(existing_user_controller()), 312 base::Unretained(existing_user_controller()),
225 testing_profile_.get()); 313 testing_profile_.get());
226 } 314 }
227 315
228 virtual void CleanUpOnMainThread() OVERRIDE { 316 virtual void CleanUpOnMainThread() OVERRIDE {
317 // ExistingUserController must be cleaned up before
318 // CrosInProcessBrowserTest::CleanUpOnMainThread or it sometimes
bartfab (slow) 2013/02/25 16:51:23 "or it sometimes crashes" sounds like something is
dconnelly 2013/02/26 18:04:15 Done.
319 // crashes in the destructor.
320 existing_user_controller_.reset(NULL);
229 CrosInProcessBrowserTest::CleanUpOnMainThread(); 321 CrosInProcessBrowserTest::CleanUpOnMainThread();
230 testing_profile_.reset(NULL); 322 testing_profile_.reset(NULL);
231 } 323 }
232 324
233 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 325 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
234 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); 326 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
235 DBusThreadManager::Shutdown(); 327 DBusThreadManager::Shutdown();
236 } 328 }
237 329
330 // ExistingUserController private member accessors.
331 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
332 return &existing_user_controller()->auto_login_timer_;
333 }
334
335 std::string auto_login_username() {
336 return existing_user_controller()->public_session_auto_login_username_;
337 }
338 void set_auto_login_username(const std::string& username) {
339 existing_user_controller()->public_session_auto_login_username_ = username;
340 }
341
342 int auto_login_delay() {
343 return existing_user_controller()->public_session_auto_login_delay_;
344 }
345 void set_auto_login_delay(int delay) {
346 existing_user_controller()->public_session_auto_login_delay_ = delay;
347 }
348
349 bool is_login_in_progress() {
350 return existing_user_controller()->is_login_in_progress_;
351 }
352 void set_is_login_in_progress(bool is_login_in_progress) {
353 existing_user_controller()->is_login_in_progress_ = is_login_in_progress;
354 }
355
238 scoped_ptr<ExistingUserController> existing_user_controller_; 356 scoped_ptr<ExistingUserController> existing_user_controller_;
239 357
240 // These mocks are owned by CrosLibrary class. 358 // These mocks are owned by CrosLibrary class.
241 MockNetworkLibrary* mock_network_library_; 359 MockNetworkLibrary* mock_network_library_;
242 360
243 MockLoginDisplay* mock_login_display_; 361 MockLoginDisplay* mock_login_display_;
244 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; 362 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
245 363
246 ScopedMockUserManagerEnabler mock_user_manager_; 364 scoped_ptr<ScopedMockUserManagerEnabler> mock_user_manager_;
247 365
248 // Owned by LoginUtilsWrapper. 366 // Owned by LoginUtilsWrapper.
249 MockLoginUtils* mock_login_utils_; 367 MockLoginUtils* mock_login_utils_;
250 368
251 scoped_ptr<TestingProfile> testing_profile_; 369 scoped_ptr<TestingProfile> testing_profile_;
252 370
253 // Mock URLFetcher. 371 // Mock URLFetcher.
254 MockURLFetcherFactory<SuccessFetcher> factory_; 372 MockURLFetcherFactory<SuccessFetcher> factory_;
255 373
256 base::Callback<void(void)> profile_prepared_cb_; 374 base::Callback<void(void)> profile_prepared_cb_;
(...skipping 21 matching lines...) Expand all
278 .Times(1); 396 .Times(1);
279 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) 397 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername))
280 .Times(1); 398 .Times(1);
281 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 399 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
282 .Times(1); 400 .Times(1);
283 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 401 EXPECT_CALL(*mock_login_display_, OnFadeOut())
284 .Times(1); 402 .Times(1);
285 EXPECT_CALL(*mock_login_display_host_, 403 EXPECT_CALL(*mock_login_display_host_,
286 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) 404 StartWizard(WizardController::kTermsOfServiceScreenName, NULL))
287 .Times(0); 405 .Times(0);
288 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 406 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
289 .Times(AnyNumber()) 407 .Times(AnyNumber())
290 .WillRepeatedly(Return(false)); 408 .WillRepeatedly(Return(false));
291 existing_user_controller()->Login(kUsername, kPassword); 409 existing_user_controller()->Login(kUsername, kPassword);
292 content::RunAllPendingInMessageLoop(); 410 content::RunAllPendingInMessageLoop();
293 } 411 }
294 412
295 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) { 413 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) {
296 EXPECT_CALL(*mock_login_display_host_, 414 EXPECT_CALL(*mock_login_display_host_,
297 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _)) 415 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _))
298 .Times(1); 416 .Times(1);
299 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 417 EXPECT_CALL(*mock_login_display_, OnFadeOut())
300 .Times(1); 418 .Times(1);
301 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) 419 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
302 .Times(1); 420 .Times(1);
303 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 421 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
304 .Times(AnyNumber()) 422 .Times(AnyNumber())
305 .WillRepeatedly(Return(false)); 423 .WillRepeatedly(Return(false));
306 // The order of these expected calls matters: the UI if first disabled 424 // The order of these expected calls matters: the UI if first disabled
307 // during the login sequence, and is enabled again for the enrollment screen. 425 // during the login sequence, and is enabled again for the enrollment screen.
308 Sequence uiEnabledSequence; 426 Sequence uiEnabledSequence;
309 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 427 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
310 .Times(1) 428 .Times(1)
311 .InSequence(uiEnabledSequence); 429 .InSequence(uiEnabledSequence);
312 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 430 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
313 .Times(1) 431 .Times(1)
(...skipping 24 matching lines...) Expand all
338 PrepareProfile(kNewUsername, _, kPassword, _, _, _)) 456 PrepareProfile(kNewUsername, _, kPassword, _, _, _))
339 .Times(1) 457 .Times(1)
340 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, 458 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
341 &base::Callback<void(void)>::Run)); 459 &base::Callback<void(void)>::Run));
342 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) 460 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername))
343 .Times(1); 461 .Times(1);
344 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 462 EXPECT_CALL(*mock_login_display_, OnFadeOut())
345 .Times(1); 463 .Times(1);
346 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) 464 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
347 .Times(1); 465 .Times(1);
348 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 466 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
349 .Times(AnyNumber()) 467 .Times(AnyNumber())
350 .WillRepeatedly(Return(true)); 468 .WillRepeatedly(Return(true));
351 469
352 // The order of these expected calls matters: the UI if first disabled 470 // The order of these expected calls matters: the UI if first disabled
353 // during the login sequence, and is enabled again after login completion. 471 // during the login sequence, and is enabled again after login completion.
354 Sequence uiEnabledSequence; 472 Sequence uiEnabledSequence;
355 // This is disabled twice: once right after signin but before checking for 473 // This is disabled twice: once right after signin but before checking for
356 // auto-enrollment, and again after doing an ownership status check. 474 // auto-enrollment, and again after doing an ownership status check.
357 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 475 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
358 .Times(2) 476 .Times(2)
359 .InSequence(uiEnabledSequence); 477 .InSequence(uiEnabledSequence);
360 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 478 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
361 .Times(1) 479 .Times(1)
362 .InSequence(uiEnabledSequence); 480 .InSequence(uiEnabledSequence);
363 481
364 existing_user_controller()->CompleteLogin(kNewUsername, kPassword); 482 existing_user_controller()->CompleteLogin(kNewUsername, kPassword);
365 content::RunAllPendingInMessageLoop(); 483 content::RunAllPendingInMessageLoop();
366 } 484 }
367 485
486 MATCHER_P(HasDetails, expected, "") {
487 std::string actual = *content::Details<const std::string>(arg).ptr();
488 return expected == actual;
bartfab (slow) 2013/02/25 16:51:23 Why not do the dereferencing and comparison all on
dconnelly 2013/02/26 18:04:15 Done.
489 }
490
491 class ExistingUserControllerPublicSessionTest
492 : public ExistingUserControllerTest {
493 protected:
494 ExistingUserControllerPublicSessionTest() {
495 }
496
497 virtual void SetUpOnMainThread() OVERRIDE {
498 ExistingUserControllerTest::SetUpOnMainThread();
499
500 // Wait for the public session user to be created.
501 UserListObserver(kAutoLoginUsername).Run();
502
503 // Wait for the device local account policy to be installed.
504 MockCloudPolicyStoreObserver observer;
505 content::MessageLoopRunner* runner = new content::MessageLoopRunner;
506 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()->
507 browser_policy_connector()->GetDeviceLocalAccountPolicyService()->
bartfab (slow) 2013/02/25 16:51:23 Indent 4 spaces.
dconnelly 2013/02/26 18:04:15 Done.
508 GetBrokerForAccount(kAutoLoginUsername)->core()->store();
bartfab (slow) 2013/02/25 16:51:23 Indent 4 spaces.
dconnelly 2013/02/26 18:04:15 Done.
509 store->AddObserver(&observer);
510 EXPECT_CALL(observer, OnStoreLoaded(store))
511 .Times(1)
512 .WillOnce(InvokeWithoutArgs(runner, &content::MessageLoopRunner::Quit));
513 runner->Run();
514 store->RemoveObserver(&observer);
515 }
516
517 virtual void SetUpSessionManager(
518 MockDBusThreadManager* mock_dbus_thread_manager) OVERRIDE {
519 EXPECT_CALL(*mock_dbus_thread_manager, GetSessionManagerClient())
520 .WillRepeatedly(Return(&session_manager_client_));
bartfab (slow) 2013/02/25 16:51:23 Indent 4 spaces.
dconnelly 2013/02/26 18:04:15 Done.
521
522 // Install the owner key.
523 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
524 base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key");
525 std::vector<uint8> owner_key_bits;
526 ASSERT_TRUE(device_policy_.signing_key()->ExportPublicKey(&owner_key_bits));
527 ASSERT_EQ(
528 file_util::WriteFile(
529 owner_key_file,
530 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)),
531 owner_key_bits.size()),
532 static_cast<int>(owner_key_bits.size()));
533 ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file));
534
535 // Setup the device policy.
536 em::ChromeDeviceSettingsProto& proto(device_policy_.payload());
537 proto.mutable_device_local_accounts()->add_account()->set_id(
538 kAutoLoginUsername);
539 RefreshDevicePolicy();
540
541 // Setup the device local account policy.
542 policy::UserPolicyBuilder device_local_account_policy;
543 device_local_account_policy.policy_data().set_username(kAutoLoginUsername);
544 device_local_account_policy.policy_data().set_policy_type(
545 policy::dm_protocol::kChromePublicAccountPolicyType);
546 device_local_account_policy.policy_data().set_settings_entity_id(
547 kAutoLoginUsername);
548 device_local_account_policy.Build();
549 session_manager_client_.set_device_local_account_policy(
550 kAutoLoginUsername,
551 device_local_account_policy.GetBlob());
552 }
553
554 virtual void SetUpLoginDisplay() {
555 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
556 .Times(1)
557 .WillOnce(Return(mock_login_display_));
558 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
559 .Times(AnyNumber())
560 .WillRepeatedly(ReturnNull());
561 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
562 .Times(AnyNumber());
563 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _))
564 .Times(AnyNumber());
565 }
566
567 void DisableAutoLoginPolicyNotifications() {
568 CrosSettings::Get()->RemoveSettingsObserver(
569 kAccountsPrefDeviceLocalAccountAutoLoginId,
570 existing_user_controller());
571 CrosSettings::Get()->RemoveSettingsObserver(
572 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
573 existing_user_controller());
574 }
575
576 void PrepareLogin(
577 const std::string& username, const std::string& password,
bartfab (slow) 2013/02/25 16:51:23 The arguments should either *all* fit on one line
dconnelly 2013/02/26 18:04:15 Done.
578 scoped_refptr<Authenticator> create_authenticator(
579 LoginStatusConsumer* consumer)) {
580 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
581 .Times(AnyNumber());
582 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
583 .Times(1)
584 .WillOnce(WithArg<0>(Invoke(create_authenticator)));
585 EXPECT_CALL(*mock_login_utils_,
586 PrepareProfile(username, _, password, _, _, _))
587 .Times(1)
588 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
589 &base::Callback<void(void)>::Run));
590 EXPECT_CALL(*mock_login_utils_,
591 DoBrowserLaunch(testing_profile_.get(),
592 mock_login_display_host_.get()))
593 .Times(1);
594 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username))
595 .Times(1);
596 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
597 .Times(1);
598 EXPECT_CALL(*mock_login_display_, OnFadeOut())
599 .Times(1);
600 EXPECT_CALL(*mock_login_display_host_,
601 StartWizard(WizardController::kTermsOfServiceScreenName, NULL))
602 .Times(0);
603 }
604
605 content::MessageLoopRunner* CreateSettingsObserverRunLoop(
606 content::MockNotificationObserver& observer, const char* setting) {
607 content::MessageLoopRunner* runner = new content::MessageLoopRunner;
608 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
609 _, HasDetails(setting)))
610 .Times(1)
611 .WillOnce(InvokeWithoutArgs(runner, &content::MessageLoopRunner::Quit));
612 CrosSettings::Get()->AddSettingsObserver(setting, &observer);
613 return runner;
614 }
615
616 void RefreshDevicePolicy() {
617 // Reset the key to its original state.
618 device_policy_.set_signing_key(
619 policy::PolicyBuilder::CreateTestSigningKey());
620 device_policy_.Build();
621 // Clear the key so the device can't write owner settings.
622 device_policy_.set_signing_key(
623 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
624 device_policy_.set_new_signing_key(
625 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
626 session_manager_client_.set_device_policy(device_policy_.GetBlob());
627 }
628
629 void SetAutoLoginPolicy(const std::string& username, int delay) {
630 // Wait until ExistingUserController has finished auto-login
631 // configuration by observing the same settings that trigger
632 // ConfigurePublicSessionAutoLogin.
633 content::MockNotificationObserver observer;
634
635 em::ChromeDeviceSettingsProto& proto(device_policy_.payload());
636
637 // If both settings have changed we need to wait for both to
638 // propagate, so check the new values against the old ones.
639 content::MessageLoopRunner* runner1 = NULL;
640 if (!proto.has_device_local_accounts() ||
641 !proto.device_local_accounts().has_auto_login_id() ||
642 proto.device_local_accounts().auto_login_id() != username) {
643 runner1 = CreateSettingsObserverRunLoop(
644 observer, kAccountsPrefDeviceLocalAccountAutoLoginId);
645 }
646 content::MessageLoopRunner* runner2 = NULL;
647 if (!proto.has_device_local_accounts() ||
648 !proto.device_local_accounts().has_auto_login_delay() ||
649 proto.device_local_accounts().auto_login_delay() != delay) {
650 runner2 = CreateSettingsObserverRunLoop(
651 observer, kAccountsPrefDeviceLocalAccountAutoLoginDelay);
652 }
653
654 // Update the policy.
655 proto.mutable_device_local_accounts()->set_auto_login_id(username);
656 proto.mutable_device_local_accounts()->set_auto_login_delay(delay);
657 RefreshDevicePolicy();
658
659 // Wait for ExistingUserController.
660 if (runner1)
661 runner1->Run();
662 if (runner2)
663 runner2->Run();
664
665 // Cleanup.
bartfab (slow) 2013/02/25 16:51:23 To match the other comments, this should be a verb
dconnelly 2013/02/26 18:04:15 Done.
666 CrosSettings::Get()->RemoveSettingsObserver(
667 kAccountsPrefDeviceLocalAccountAutoLoginId,
668 &observer);
669 CrosSettings::Get()->RemoveSettingsObserver(
670 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
671 &observer);
672 }
673
674 // Enables public sessions in tests.
675 FakeSessionManagerClient session_manager_client_;
676
677 // Stores the device owner key.
678 base::ScopedTempDir temp_dir_;
679
680 // Carries Chrome OS device policies for tests.
681 policy::DevicePolicyBuilder device_policy_;
682
683 private:
684 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
685 };
686
687 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
688 StartAutoLoginTimer) {
689 ExistingUserController* euc = existing_user_controller();
bartfab (slow) 2013/02/25 16:51:23 The style guide discourages abbreviations. |euc| i
dconnelly 2013/02/26 18:04:15 Done.
690 DisableAutoLoginPolicyNotifications();
691
692 // Timer shouldn't start until signin screen is ready.
693 set_auto_login_username(kAutoLoginUsername);
694 set_auto_login_delay(kAutoLoginLongDelay);
695 euc->StartPublicSessionAutoLoginTimer();
696 ASSERT_FALSE(auto_login_timer()->IsRunning());
bartfab (slow) 2013/02/25 16:51:23 Here and in general: You should be using ASSERT_*
dconnelly 2013/02/26 18:04:15 Done.
697
698 // Timer shouldn't start if the policy isn't set.
699 set_auto_login_username("");
700 euc->OnSigninScreenReady();
701 euc->StartPublicSessionAutoLoginTimer();
702 ASSERT_FALSE(auto_login_timer()->IsRunning());
703
704 // Timer shouldn't fire in the middle of a login attempt.
705 set_auto_login_username(kAutoLoginUsername);
706 set_is_login_in_progress(true);
707 euc->StartPublicSessionAutoLoginTimer();
708 ASSERT_FALSE(auto_login_timer()->IsRunning());
709
710 // Otherwise start.
711 set_is_login_in_progress(false);
712 euc->StartPublicSessionAutoLoginTimer();
713 ASSERT_TRUE(auto_login_timer()->IsRunning());
714 ASSERT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
715 kAutoLoginLongDelay);
716
717 content::RunAllPendingInMessageLoop();
bartfab (slow) 2013/02/25 16:51:23 Could you document what tasks this drains from the
dconnelly 2013/02/26 18:04:15 Done.
718 }
719
720 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
721 StopAutoLoginTimer) {
722 ExistingUserController* euc = existing_user_controller();
723 euc->OnSigninScreenReady();
724 set_auto_login_username(kAutoLoginUsername);
725 set_auto_login_delay(kAutoLoginLongDelay);
726
727 euc->StartPublicSessionAutoLoginTimer();
728 ASSERT_TRUE(auto_login_timer()->IsRunning());
729
730 euc->StopPublicSessionAutoLoginTimer();
731 ASSERT_FALSE(auto_login_timer()->IsRunning());
732
733 content::RunAllPendingInMessageLoop();
734 }
735
736 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
737 UserActivityRestartsAutoLogin) {
738 ExistingUserController* euc = existing_user_controller();
739 euc->OnSigninScreenReady();
740 set_auto_login_username(kAutoLoginUsername);
741
742 // Timer starts off not running.
743 ASSERT_FALSE(auto_login_timer()->IsRunning());
744
745 // When the timer isn't running, nothing should happen.
746 euc->OnUserActivity();
747 ASSERT_FALSE(auto_login_timer()->IsRunning());
748
749 // Start the timer.
750 set_auto_login_delay(kAutoLoginLongDelay);
751 euc->StartPublicSessionAutoLoginTimer();
752 ASSERT_TRUE(auto_login_timer()->IsRunning());
753 ASSERT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
754 kAutoLoginLongDelay);
755
756 // User activity should restart the timer.
757 set_auto_login_delay(kAutoLoginShortDelay);
bartfab (slow) 2013/02/25 16:51:23 If I understand correctly, you detect that the tim
dconnelly 2013/02/26 18:04:15 Done.
758 euc->OnUserActivity();
759 ASSERT_TRUE(auto_login_timer()->IsRunning());
760 ASSERT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
761 kAutoLoginShortDelay);
762
763 content::RunAllPendingInMessageLoop();
764 }
765
766 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
767 ConfigureAutoLogin) {
768 ExistingUserController* euc = existing_user_controller();
769 ash::UserActivityDetector* detector =
770 ash::Shell::GetInstance()->user_activity_detector();
771 euc->OnSigninScreenReady();
772
773 // Turn off settings notifications to EUC.
bartfab (slow) 2013/02/25 16:51:23 Just as in variable names, you should not be using
dconnelly 2013/02/26 18:04:15 Done.
774 DisableAutoLoginPolicyNotifications();
775
776 // Timer shouldn't start when the policy is disabled.
777 SetAutoLoginPolicy("", 0);
778 euc->ConfigurePublicSessionAutoLogin();
779 ASSERT_FALSE(auto_login_timer()->IsRunning());
780 ASSERT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 0);
781 ASSERT_EQ(auto_login_delay(), 0);
782 ASSERT_EQ(auto_login_username(), "");
783 ASSERT_FALSE(detector->HasObserver(euc));
784
785 // Timer shouldn't start when the delay alone is set.
786 SetAutoLoginPolicy("", kAutoLoginShortDelay);
787 euc->ConfigurePublicSessionAutoLogin();
788 ASSERT_FALSE(auto_login_timer()->IsRunning());
789 ASSERT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 0);
790 ASSERT_EQ(auto_login_delay(), kAutoLoginShortDelay);
791 ASSERT_EQ(auto_login_username(), "");
792 ASSERT_FALSE(detector->HasObserver(euc));
793
794 // Timer should start when the username is set.
795 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
796 euc->ConfigurePublicSessionAutoLogin();
797 ASSERT_TRUE(auto_login_timer()->IsRunning());
798 ASSERT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
799 kAutoLoginShortDelay);
800 ASSERT_EQ(auto_login_delay(), kAutoLoginShortDelay);
801 ASSERT_EQ(auto_login_username(), kAutoLoginUsername);
802 ASSERT_TRUE(detector->HasObserver(euc));
803
804 // Timer should restart when the delay is changed.
805 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
806 euc->ConfigurePublicSessionAutoLogin();
807 ASSERT_TRUE(auto_login_timer()->IsRunning());
808 ASSERT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
809 kAutoLoginLongDelay);
810 ASSERT_EQ(auto_login_delay(), kAutoLoginLongDelay);
811 ASSERT_EQ(auto_login_username(), kAutoLoginUsername);
812 ASSERT_TRUE(detector->HasObserver(euc));
813
814 // Timer should stop when the username is unset.
815 SetAutoLoginPolicy("", kAutoLoginLongDelay);
816 euc->ConfigurePublicSessionAutoLogin();
817 ASSERT_FALSE(auto_login_timer()->IsRunning());
818 ASSERT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
819 kAutoLoginLongDelay);
820 ASSERT_EQ(auto_login_username(), "");
821 ASSERT_EQ(auto_login_delay(), kAutoLoginLongDelay);
822 ASSERT_FALSE(detector->HasObserver(euc));
823
824 content::RunAllPendingInMessageLoop();
825 }
826
827 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
828 ConfigureAutoLoginUsingPolicy) {
829 ExistingUserController* euc = existing_user_controller();
830 ash::UserActivityDetector* detector =
831 ash::Shell::GetInstance()->user_activity_detector();
832 euc->OnSigninScreenReady();
833 ASSERT_EQ("", auto_login_username());
834 ASSERT_EQ(0, auto_login_delay());
835 ASSERT_FALSE(auto_login_timer()->IsRunning());
836 ASSERT_FALSE(detector->HasObserver(euc));
837
838 // Set the policy.
839 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
840 ASSERT_EQ(kAutoLoginUsername, auto_login_username());
841 ASSERT_EQ(kAutoLoginLongDelay, auto_login_delay());
842 ASSERT_TRUE(auto_login_timer()->IsRunning());
843 ASSERT_TRUE(detector->HasObserver(euc));
844
845 // Unset the policy.
846 SetAutoLoginPolicy("", 0);
847 ASSERT_EQ("", auto_login_username());
848 ASSERT_EQ(0, auto_login_delay());
849 ASSERT_FALSE(auto_login_timer()->IsRunning());
850 ASSERT_FALSE(detector->HasObserver(euc));
851
852 content::RunAllPendingInMessageLoop();
853 }
854
855 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
856 OnAutoLoginFire) {
857 PrepareLogin(kAutoLoginUsername, "", CreateAuthenticatorPublicSession);
858 existing_user_controller()->OnSigninScreenReady();
859
860 // Directly set auto-login parameters to avoid starting the timer.
861 set_auto_login_username(kAutoLoginUsername);
862 set_auto_login_delay(kAutoLoginLongDelay);
863
864 // Manually fire auto-login.
865 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
866 content::RunAllPendingInMessageLoop();
bartfab (slow) 2013/02/25 16:51:23 Nit: You have an emtpy line before the content::Ru
dconnelly 2013/02/26 18:04:15 Done.
867 }
868
869 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
870 AutoLoginNoDelay) {
871 PrepareLogin(kAutoLoginUsername, "", CreateAuthenticatorPublicSession);
872 existing_user_controller()->OnSigninScreenReady();
873 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginNoDelay);
874 // Timer should fire immediately.
bartfab (slow) 2013/02/25 16:51:23 Here and in the other tests: Can you document that
dconnelly 2013/02/26 18:04:15 Done.
875 content::RunAllPendingInMessageLoop();
876 }
877
878 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
879 AutoLoginShortDelay) {
880 PrepareLogin(kAutoLoginUsername, "", CreateAuthenticatorPublicSession);
881 existing_user_controller()->OnSigninScreenReady();
882 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
883 ASSERT_TRUE(auto_login_timer()->IsRunning());
884
885 // Wait for the timer to fire.
886 content::MessageLoopRunner* runner = new content::MessageLoopRunner;
887 base::OneShotTimer<content::MessageLoopRunner> timer;
888 timer.Start(FROM_HERE,
889 base::TimeDelta::FromMilliseconds(2 * kAutoLoginShortDelay),
bartfab (slow) 2013/02/25 16:51:23 Boo, waiting 200ms :(. Could you inspect the time
dconnelly 2013/02/26 18:04:15 There's no real point to this test, then. There's
bartfab (slow) 2013/02/28 10:21:33 No, I think there is value in it - I would keep th
890 base::Bind(&content::MessageLoopRunner::Quit,
891 base::Unretained(runner)));
892 runner->Run();
893 content::RunAllPendingInMessageLoop();
894 }
895
896 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
897 LoginStopsAutoLogin) {
898 PrepareLogin(kUsername, kPassword, CreateAuthenticator);
899
900 ExistingUserController* euc = existing_user_controller();
901 euc->OnSigninScreenReady();
902 set_auto_login_username(kAutoLoginUsername);
903 set_auto_login_delay(kAutoLoginLongDelay);
904 euc->StartPublicSessionAutoLoginTimer();
905 ASSERT_TRUE(auto_login_timer()->IsRunning());
906
907 // Login and check that it stopped the timer.
908 euc->Login(kUsername, kPassword);
909 ASSERT_TRUE(is_login_in_progress());
910 ASSERT_FALSE(auto_login_timer()->IsRunning());
911
912 content::RunAllPendingInMessageLoop();
913
914 // Timer should still be stopped after login completes.
915 ASSERT_FALSE(auto_login_timer()->IsRunning());
916 }
917
918 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
919 RetailModeLoginStopsAutoLogin) {
bartfab (slow) 2013/02/25 16:51:23 This is not necessary. Public sessions and retail
dconnelly 2013/02/26 18:04:15 Done.
920 PrepareLogin(kRetailModeUserEMail, "", CreateAuthenticator);
921
922 ExistingUserController* euc = existing_user_controller();
923 euc->OnSigninScreenReady();
924 set_auto_login_username(kAutoLoginUsername);
925 set_auto_login_delay(kAutoLoginLongDelay);
926 euc->StartPublicSessionAutoLoginTimer();
927 ASSERT_TRUE(auto_login_timer()->IsRunning());
928
929 // Login and check that it stopped the timer.
930 euc->LoginAsRetailModeUser();
931 ASSERT_TRUE(is_login_in_progress());
932 ASSERT_FALSE(auto_login_timer()->IsRunning());
933
934 content::RunAllPendingInMessageLoop();
935
936 // Timer should still be stopped after login completes.
937 ASSERT_FALSE(auto_login_timer()->IsRunning());
938 }
939
940 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
941 GuestModeLoginStopsAutoLogin) {
942 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
943 .Times(1);
944 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
945 .Times(1)
946 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator)));
947 ScopedMockUserManagerEnabler mock_user_manager;
948 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_))
949 .Times(1);
950
951 ExistingUserController* euc = existing_user_controller();
952 euc->OnSigninScreenReady();
953 set_auto_login_username(kAutoLoginUsername);
954 set_auto_login_delay(kAutoLoginLongDelay);
955 euc->StartPublicSessionAutoLoginTimer();
956 ASSERT_TRUE(auto_login_timer()->IsRunning());
957
958 // Login and check that it stopped the timer.
959 euc->LoginAsGuest();
960 ASSERT_TRUE(is_login_in_progress());
961 ASSERT_FALSE(auto_login_timer()->IsRunning());
962
963 content::RunAllPendingInMessageLoop();
964
965 // Timer should still be stopped after login completes.
966 ASSERT_FALSE(auto_login_timer()->IsRunning());
967 }
968
969 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
970 CompleteLoginStopsAutoLogin) {
971 PrepareLogin(kUsername, kPassword, CreateAuthenticator);
972 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
973 .Times(1);
974
975 ExistingUserController* euc = existing_user_controller();
976 euc->OnSigninScreenReady();
977 set_auto_login_username(kAutoLoginUsername);
978 set_auto_login_delay(kAutoLoginLongDelay);
979 euc->StartPublicSessionAutoLoginTimer();
980 ASSERT_TRUE(auto_login_timer()->IsRunning());
981
982 // Check that login completes and stops the timer.
983 euc->CompleteLogin(kUsername, kPassword);
984 ASSERT_FALSE(auto_login_timer()->IsRunning());
985 content::RunAllPendingInMessageLoop();
986
987 // Timer should still be stopped after login completes.
988 ASSERT_FALSE(auto_login_timer()->IsRunning());
989 }
990
991 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
992 PublicSessionLoginStopsAutoLogin) {
993 PrepareLogin(kAutoLoginUsername, "", CreateAuthenticatorPublicSession);
994 existing_user_controller()->OnSigninScreenReady();
995 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
996 ASSERT_TRUE(auto_login_timer()->IsRunning());
997
998 // Login and check that it stopped the timer.
999 existing_user_controller()->LoginAsPublicAccount(kAutoLoginUsername);
1000 ASSERT_TRUE(is_login_in_progress());
1001 ASSERT_FALSE(auto_login_timer()->IsRunning());
1002 content::RunAllPendingInMessageLoop();
1003
1004 // Timer should still be stopped after login completes.
1005 ASSERT_FALSE(auto_login_timer()->IsRunning());
1006 }
1007
368 } // namespace chromeos 1008 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698