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

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: r3b@$3 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 <vector>
6
5 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
6 #include "base/command_line.h" 10 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 11 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 12 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h"
14 #include "base/location.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/path_service.h"
17 #include "base/run_loop.h"
18 #include "base/stl_util.h"
9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" 19 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
10 #include "chrome/browser/chromeos/cros/cros_mock.h" 20 #include "chrome/browser/chromeos/cros/cros_mock.h"
11 #include "chrome/browser/chromeos/cros/mock_network_library.h" 21 #include "chrome/browser/chromeos/cros/mock_network_library.h"
22 #include "chrome/browser/chromeos/login/authenticator.h"
12 #include "chrome/browser/chromeos/login/existing_user_controller.h" 23 #include "chrome/browser/chromeos/login/existing_user_controller.h"
13 #include "chrome/browser/chromeos/login/helper.h" 24 #include "chrome/browser/chromeos/login/helper.h"
14 #include "chrome/browser/chromeos/login/login_display.h"
15 #include "chrome/browser/chromeos/login/login_display_host.h"
16 #include "chrome/browser/chromeos/login/login_performer.h"
17 #include "chrome/browser/chromeos/login/login_status_consumer.h" 25 #include "chrome/browser/chromeos/login/login_status_consumer.h"
18 #include "chrome/browser/chromeos/login/login_utils.h"
19 #include "chrome/browser/chromeos/login/mock_authenticator.h" 26 #include "chrome/browser/chromeos/login/mock_authenticator.h"
27 #include "chrome/browser/chromeos/login/mock_login_display.h"
28 #include "chrome/browser/chromeos/login/mock_login_display_host.h"
20 #include "chrome/browser/chromeos/login/mock_login_utils.h" 29 #include "chrome/browser/chromeos/login/mock_login_utils.h"
21 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" 30 #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
22 #include "chrome/browser/chromeos/login/mock_user_manager.h" 31 #include "chrome/browser/chromeos/login/mock_user_manager.h"
32 #include "chrome/browser/chromeos/login/user_manager.h"
23 #include "chrome/browser/chromeos/login/wizard_controller.h" 33 #include "chrome/browser/chromeos/login/wizard_controller.h"
34 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
35 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
36 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
37 #include "chrome/browser/chromeos/settings/cros_settings.h"
38 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
39 #include "chrome/browser/policy/browser_policy_connector.h"
40 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
41 #include "chrome/browser/policy/cloud/cloud_policy_core.h"
42 #include "chrome/browser/policy/cloud/cloud_policy_store.h"
43 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h"
44 #include "chrome/browser/policy/cloud/policy_builder.h"
45 #include "chrome/common/chrome_notification_types.h"
46 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
48 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h" 49 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/ui_test_utils.h" 50 #include "chrome/test/base/ui_test_utils.h"
51 #include "chromeos/dbus/fake_session_manager_client.h"
27 #include "chromeos/dbus/mock_dbus_thread_manager.h" 52 #include "chromeos/dbus/mock_dbus_thread_manager.h"
28 #include "chromeos/dbus/mock_session_manager_client.h" 53 #include "chromeos/dbus/mock_session_manager_client.h"
29 #include "chromeos/dbus/mock_shill_manager_client.h" 54 #include "chromeos/dbus/mock_shill_manager_client.h"
55 #include "content/public/browser/notification_details.h"
56 #include "content/public/test/mock_notification_observer.h"
57 #include "content/public/test/test_utils.h"
58 #include "crypto/rsa_private_key.h"
30 #include "google_apis/gaia/mock_url_fetcher_factory.h" 59 #include "google_apis/gaia/mock_url_fetcher_factory.h"
31 #include "grit/generated_resources.h" 60 #include "grit/generated_resources.h"
32 #include "testing/gmock/include/gmock/gmock.h" 61 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 62 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/base/l10n/l10n_util.h" 63 #include "ui/base/l10n/l10n_util.h"
35 64
36 using ::testing::_; 65 using ::testing::_;
37 using ::testing::AnyNumber; 66 using ::testing::AnyNumber;
38 using ::testing::AnyOf; 67 using ::testing::AnyOf;
39 using ::testing::Invoke; 68 using ::testing::Invoke;
40 using ::testing::InvokeWithoutArgs; 69 using ::testing::InvokeWithoutArgs;
41 using ::testing::Return; 70 using ::testing::Return;
42 using ::testing::ReturnNull; 71 using ::testing::ReturnNull;
43 using ::testing::Sequence; 72 using ::testing::Sequence;
44 using ::testing::WithArg; 73 using ::testing::WithArg;
45 74
75 namespace em = enterprise_management;
76
46 namespace chromeos { 77 namespace chromeos {
47 78
48 namespace { 79 namespace {
49 80
50 const char kUsername[] = "test_user@gmail.com"; 81 const char kUsername[] = "test_user@gmail.com";
51 const char kNewUsername[] = "test_new_user@gmail.com"; 82 const char kNewUsername[] = "test_new_user@gmail.com";
52 const char kPassword[] = "test_password"; 83 const char kPassword[] = "test_password";
53 84
54 class MockLoginDisplay : public LoginDisplay { 85 const char kAutoLoginUsername[] = "public_session_user@localhost";
55 public: 86 const int kAutoLoginNoDelay = 0;
56 MockLoginDisplay() 87 const int kAutoLoginShortDelay = 1;
57 : LoginDisplay(NULL, gfx::Rect()) { 88 const int kAutoLoginLongDelay = 10000;
58 }
59
60 MOCK_METHOD4(Init, void(const UserList&, bool, bool, bool));
61 MOCK_METHOD0(OnPreferencesChanged, void(void));
62 MOCK_METHOD1(OnUserImageChanged, void(const User&));
63 MOCK_METHOD0(OnFadeOut, void(void));
64 MOCK_METHOD1(OnLoginSuccess, void(const std::string&));
65 MOCK_METHOD1(SetUIEnabled, void(bool));
66 MOCK_METHOD1(SelectPod, void(int));
67 MOCK_METHOD3(ShowError, void(int, int, HelpAppLauncher::HelpTopic));
68 MOCK_METHOD1(ShowErrorScreen, void(LoginDisplay::SigninError));
69 MOCK_METHOD1(ShowGaiaPasswordChanged, void(const std::string&));
70 MOCK_METHOD1(ShowPasswordChangedDialog, void(bool));
71 MOCK_METHOD1(ShowSigninUI, void(const std::string&));
72 MOCK_METHOD1(OnBeforeUserRemoved, void(const std::string&));
73 MOCK_METHOD1(OnUserRemoved, void(const std::string&));
74
75 private:
76 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplay);
77 };
78
79 class MockLoginDisplayHost : public LoginDisplayHost {
80 public:
81 MockLoginDisplayHost() {
82 }
83
84 MOCK_METHOD1(CreateLoginDisplay, LoginDisplay*(LoginDisplay::Delegate*));
85 MOCK_CONST_METHOD0(GetNativeWindow, gfx::NativeWindow(void));
86 MOCK_CONST_METHOD0(GetWidget, views::Widget*(void));
87 MOCK_METHOD0(BeforeSessionStart, void(void));
88 MOCK_METHOD0(OnSessionStart, void(void));
89 MOCK_METHOD0(OnCompleteLogin, void(void));
90 MOCK_METHOD0(OpenProxySettings, void(void));
91 MOCK_METHOD1(SetOobeProgressBarVisible, void(bool));
92 MOCK_METHOD1(SetShutdownButtonEnabled, void(bool));
93 MOCK_METHOD1(SetStatusAreaVisible, void(bool));
94 MOCK_METHOD0(ShowBackground, void(void));
95 MOCK_METHOD0(CheckForAutoEnrollment, void(void));
96 MOCK_METHOD2(StartWizard, void(const std::string&, DictionaryValue*));
97 MOCK_METHOD0(StartSignInScreen, void(void));
98 MOCK_METHOD0(ResumeSignInScreen, void(void));
99 MOCK_METHOD0(OnPreferencesChanged, void(void));
100
101 private:
102 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplayHost);
103 };
104 89
105 scoped_refptr<Authenticator> CreateAuthenticator( 90 scoped_refptr<Authenticator> CreateAuthenticator(
106 LoginStatusConsumer* consumer) { 91 LoginStatusConsumer* consumer) {
107 return new MockAuthenticator(consumer, kUsername, kPassword); 92 return new MockAuthenticator(consumer, kUsername, kPassword);
108 } 93 }
109 94
110 scoped_refptr<Authenticator> CreateAuthenticatorNewUser( 95 scoped_refptr<Authenticator> CreateAuthenticatorNewUser(
111 LoginStatusConsumer* consumer) { 96 LoginStatusConsumer* consumer) {
112 return new MockAuthenticator(consumer, kNewUsername, kPassword); 97 return new MockAuthenticator(consumer, kNewUsername, kPassword);
113 } 98 }
114 99
100 scoped_refptr<Authenticator> CreateAuthenticatorForPublicSession(
101 LoginStatusConsumer* consumer) {
102 return new MockAuthenticator(consumer, kAutoLoginUsername, "");
103 }
104
105 // Observes a specific notification type and quits the message loop once a
106 // condition holds.
107 class NotificationWatcher : public content::NotificationObserver {
108 public:
109 // Callback invoked on notifications. Should return true when the condition
110 // that the caller is waiting for is satisfied.
111 typedef base::Callback<bool(void)> ConditionTestCallback;
112
113 explicit NotificationWatcher(int notification_type,
114 const ConditionTestCallback& callback)
115 : type_(notification_type),
116 callback_(callback) {}
117
118 void Run() {
119 if (callback_.Run())
120 return;
121
122 content::NotificationRegistrar registrar;
123 registrar.Add(this, type_, content::NotificationService::AllSources());
124 run_loop_.Run();
125 }
126
127 // content::NotificationObserver:
128 virtual void Observe(int type,
129 const content::NotificationSource& source,
130 const content::NotificationDetails& details) OVERRIDE {
131 if (callback_.Run())
132 run_loop_.Quit();
133 }
134
135 private:
136 int type_;
137 ConditionTestCallback callback_;
138 base::RunLoop run_loop_;
139
140 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher);
141 };
142
115 } // namespace 143 } // namespace
116 144
117 class ExistingUserControllerTest : public CrosInProcessBrowserTest { 145 class ExistingUserControllerTest : public CrosInProcessBrowserTest {
118 protected: 146 protected:
119 ExistingUserControllerTest() 147 ExistingUserControllerTest()
120 : mock_network_library_(NULL), 148 : mock_network_library_(NULL),
121 mock_login_display_(NULL), 149 mock_login_display_(NULL),
122 mock_login_display_host_(NULL), 150 mock_login_display_host_(NULL),
123 testing_profile_(NULL) { 151 testing_profile_(NULL) {
124 } 152 }
125 153
126 ExistingUserController* existing_user_controller() { 154 ExistingUserController* existing_user_controller() {
127 return ExistingUserController::current_controller(); 155 return ExistingUserController::current_controller();
128 } 156 }
129 157
158 const ExistingUserController* existing_user_controller() const {
159 return ExistingUserController::current_controller();
160 }
161
130 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 162 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
131 MockDBusThreadManager* mock_dbus_thread_manager = 163 MockDBusThreadManager* mock_dbus_thread_manager =
132 new MockDBusThreadManager; 164 new MockDBusThreadManager;
133 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) 165 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
134 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); 166 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
135 EXPECT_CALL(*mock_dbus_thread_manager, GetIBusInputContextClient()) 167 EXPECT_CALL(*mock_dbus_thread_manager, GetIBusInputContextClient())
136 .WillRepeatedly( 168 .WillRepeatedly(
137 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); 169 Return(reinterpret_cast<IBusInputContextClient*>(NULL)));
138 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 170 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
139 GetProperties(_)) 171 GetProperties(_))
140 .Times(AnyNumber()); 172 .Times(AnyNumber());
141 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 173 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
142 AddPropertyChangedObserver(_)) 174 AddPropertyChangedObserver(_))
143 .Times(AnyNumber()); 175 .Times(AnyNumber());
144 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), 176 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(),
145 RemovePropertyChangedObserver(_)) 177 RemovePropertyChangedObserver(_))
146 .Times(AnyNumber()); 178 .Times(AnyNumber());
179
180 SetUpSessionManager(mock_dbus_thread_manager);
181
147 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); 182 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
148 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); 183 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
149 cros_mock_->InitStatusAreaMocks(); 184 cros_mock_->InitStatusAreaMocks();
150 cros_mock_->SetStatusAreaMocksExpectations(); 185 cros_mock_->SetStatusAreaMocksExpectations();
151 186
152 mock_network_library_ = cros_mock_->mock_network_library(); 187 mock_network_library_ = cros_mock_->mock_network_library();
153 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) 188 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_))
154 .Times(AnyNumber()); 189 .Times(AnyNumber());
155 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) 190 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _))
156 .WillRepeatedly(Return(true)); 191 .WillRepeatedly(Return(true));
157 192
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(); 193 mock_login_utils_ = new MockLoginUtils();
166 LoginUtils::Set(mock_login_utils_); 194 LoginUtils::Set(mock_login_utils_);
167 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) 195 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication())
168 .Times(AnyNumber()); 196 .Times(AnyNumber());
169 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) 197 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers())
170 .Times(AnyNumber()); 198 .Times(AnyNumber());
171 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) 199 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_))
172 .Times(1); 200 .Times(1);
173 201
174 mock_login_display_host_.reset(new MockLoginDisplayHost()); 202 mock_login_display_host_.reset(new MockLoginDisplayHost());
203 mock_login_display_ = new MockLoginDisplay();
204 SetUpLoginDisplay();
205 }
175 206
176 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kUsername)) 207 virtual void SetUpSessionManager(
208 MockDBusThreadManager* mock_dbus_thread_manager) {
209 mock_user_manager_.reset(new ScopedMockUserManagerEnabler);
210 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername))
177 .Times(AnyNumber()) 211 .Times(AnyNumber())
178 .WillRepeatedly(Return(true)); 212 .WillRepeatedly(Return(true));
179 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kNewUsername)) 213 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername))
180 .Times(AnyNumber()) 214 .Times(AnyNumber())
181 .WillRepeatedly(Return(false)); 215 .WillRepeatedly(Return(false));
182 EXPECT_CALL(*mock_user_manager_.user_manager(), IsUserLoggedIn()) 216 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn())
183 .Times(AnyNumber()) 217 .Times(AnyNumber())
184 .WillRepeatedly(Return(false)); 218 .WillRepeatedly(Return(false));
185 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsGuest()) 219 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsGuest())
186 .Times(AnyNumber()) 220 .Times(AnyNumber())
187 .WillRepeatedly(Return(false)); 221 .WillRepeatedly(Return(false));
188 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsDemoUser()) 222 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsDemoUser())
189 .Times(AnyNumber()) 223 .Times(AnyNumber())
190 .WillRepeatedly(Return(false)); 224 .WillRepeatedly(Return(false));
191 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsPublicAccount()) 225 EXPECT_CALL(*mock_user_manager_->user_manager(),
226 IsLoggedInAsPublicAccount())
192 .Times(AnyNumber()) 227 .Times(AnyNumber())
193 .WillRepeatedly(Return(false)); 228 .WillRepeatedly(Return(false));
194 EXPECT_CALL(*mock_user_manager_.user_manager(), IsSessionStarted()) 229 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted())
195 .Times(AnyNumber()) 230 .Times(AnyNumber())
196 .WillRepeatedly(Return(false)); 231 .WillRepeatedly(Return(false));
232 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
233 .Times(AnyNumber())
234 .WillRepeatedly(Return(false));
235 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown())
236 .Times(1);
197 237
198 // |mock_login_display_| is owned by the ExistingUserController, which calls 238 MockSessionManagerClient* mock_session_manager_client =
199 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. 239 mock_dbus_thread_manager->mock_session_manager_client();
200 mock_login_display_ = new MockLoginDisplay(); 240 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady())
241 .Times(1);
242 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_))
243 .Times(AnyNumber());
244 }
245
246 virtual void SetUpLoginDisplay() {
201 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) 247 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
202 .Times(1) 248 .Times(1)
203 .WillOnce(Return(mock_login_display_)); 249 .WillOnce(Return(mock_login_display_));
204 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) 250 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
205 .Times(1) 251 .Times(1)
206 .WillOnce(ReturnNull()); 252 .WillOnce(ReturnNull());
207 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) 253 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
208 .Times(1); 254 .Times(1);
209 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) 255 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true))
210 .Times(1); 256 .Times(1);
211 } 257 }
212 258
213 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 259 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
214 command_line->AppendSwitch(switches::kLoginManager); 260 command_line->AppendSwitch(switches::kLoginManager);
215 } 261 }
216 262
217 virtual void SetUpOnMainThread() OVERRIDE { 263 virtual void SetUpOnMainThread() OVERRIDE {
218 testing_profile_.reset(new TestingProfile()); 264 testing_profile_.reset(new TestingProfile());
219 existing_user_controller_.reset( 265 existing_user_controller_.reset(
220 new ExistingUserController(mock_login_display_host_.get())); 266 new ExistingUserController(mock_login_display_host_.get()));
221 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); 267 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get());
222 existing_user_controller_->Init(UserList()); 268 existing_user_controller_->Init(UserList());
223 profile_prepared_cb_ = 269 profile_prepared_cb_ =
224 base::Bind(&ExistingUserController::OnProfilePrepared, 270 base::Bind(&ExistingUserController::OnProfilePrepared,
225 base::Unretained(existing_user_controller()), 271 base::Unretained(existing_user_controller()),
226 testing_profile_.get()); 272 testing_profile_.get());
227 } 273 }
228 274
229 virtual void CleanUpOnMainThread() OVERRIDE { 275 virtual void CleanUpOnMainThread() OVERRIDE {
276 // ExistingUserController must be deleted before the thread is cleaned up:
277 // If there is an outstanding login attempt when ExistingUserController is
278 // deleted, its LoginPerformer instance will be deleted, which in turn
279 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
280 // be deleted on the UI thread.
281 existing_user_controller_.reset();
230 CrosInProcessBrowserTest::CleanUpOnMainThread(); 282 CrosInProcessBrowserTest::CleanUpOnMainThread();
231 testing_profile_.reset(NULL); 283 testing_profile_.reset(NULL);
232 } 284 }
233 285
234 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 286 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
235 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); 287 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
236 DBusThreadManager::Shutdown(); 288 DBusThreadManager::Shutdown();
237 } 289 }
238 290
291 // ExistingUserController private member accessors.
292 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
293 return existing_user_controller()->auto_login_timer_.get();
294 }
295
296 const std::string& auto_login_username() const {
297 return existing_user_controller()->public_session_auto_login_username_;
298 }
299
300 int auto_login_delay() const {
301 return existing_user_controller()->public_session_auto_login_delay_;
302 }
303
304 bool is_login_in_progress() const {
305 return existing_user_controller()->is_login_in_progress_;
306 }
307
239 scoped_ptr<ExistingUserController> existing_user_controller_; 308 scoped_ptr<ExistingUserController> existing_user_controller_;
240 309
241 // These mocks are owned by CrosLibrary class. 310 // These mocks are owned by CrosLibrary class.
242 MockNetworkLibrary* mock_network_library_; 311 MockNetworkLibrary* mock_network_library_;
243 312
313 // |mock_login_display_| is owned by the ExistingUserController, which calls
314 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
244 MockLoginDisplay* mock_login_display_; 315 MockLoginDisplay* mock_login_display_;
245 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; 316 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
246 317
247 ScopedMockUserManagerEnabler mock_user_manager_; 318 scoped_ptr<ScopedMockUserManagerEnabler> mock_user_manager_;
248 319
249 // Owned by LoginUtilsWrapper. 320 // Owned by LoginUtilsWrapper.
250 MockLoginUtils* mock_login_utils_; 321 MockLoginUtils* mock_login_utils_;
251 322
252 scoped_ptr<TestingProfile> testing_profile_; 323 scoped_ptr<TestingProfile> testing_profile_;
253 324
254 // Mock URLFetcher. 325 // Mock URLFetcher.
255 MockURLFetcherFactory<SuccessFetcher> factory_; 326 MockURLFetcherFactory<SuccessFetcher> factory_;
256 327
257 base::Callback<void(void)> profile_prepared_cb_; 328 base::Callback<void(void)> profile_prepared_cb_;
(...skipping 21 matching lines...) Expand all
279 .Times(1); 350 .Times(1);
280 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) 351 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername))
281 .Times(1); 352 .Times(1);
282 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 353 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
283 .Times(1); 354 .Times(1);
284 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 355 EXPECT_CALL(*mock_login_display_, OnFadeOut())
285 .Times(1); 356 .Times(1);
286 EXPECT_CALL(*mock_login_display_host_, 357 EXPECT_CALL(*mock_login_display_host_,
287 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) 358 StartWizard(WizardController::kTermsOfServiceScreenName, NULL))
288 .Times(0); 359 .Times(0);
289 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 360 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
290 .Times(AnyNumber()) 361 .Times(AnyNumber())
291 .WillRepeatedly(Return(false)); 362 .WillRepeatedly(Return(false));
292 existing_user_controller()->Login(kUsername, kPassword); 363 existing_user_controller()->Login(kUsername, kPassword);
293 content::RunAllPendingInMessageLoop(); 364 content::RunAllPendingInMessageLoop();
294 } 365 }
295 366
296 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) { 367 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) {
297 EXPECT_CALL(*mock_login_display_host_, 368 EXPECT_CALL(*mock_login_display_host_,
298 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _)) 369 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _))
299 .Times(1); 370 .Times(1);
300 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 371 EXPECT_CALL(*mock_login_display_, OnFadeOut())
301 .Times(1); 372 .Times(1);
302 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) 373 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
303 .Times(1); 374 .Times(1);
304 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 375 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
305 .Times(AnyNumber()) 376 .Times(AnyNumber())
306 .WillRepeatedly(Return(false)); 377 .WillRepeatedly(Return(false));
307 // The order of these expected calls matters: the UI if first disabled 378 // 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. 379 // during the login sequence, and is enabled again for the enrollment screen.
309 Sequence uiEnabledSequence; 380 Sequence uiEnabledSequence;
310 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 381 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
311 .Times(1) 382 .Times(1)
312 .InSequence(uiEnabledSequence); 383 .InSequence(uiEnabledSequence);
313 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 384 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
314 .Times(1) 385 .Times(1)
(...skipping 24 matching lines...) Expand all
339 PrepareProfile(kNewUsername, _, kPassword, _, _, _)) 410 PrepareProfile(kNewUsername, _, kPassword, _, _, _))
340 .Times(1) 411 .Times(1)
341 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, 412 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
342 &base::Callback<void(void)>::Run)); 413 &base::Callback<void(void)>::Run));
343 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) 414 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername))
344 .Times(1); 415 .Times(1);
345 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 416 EXPECT_CALL(*mock_login_display_, OnFadeOut())
346 .Times(1); 417 .Times(1);
347 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) 418 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
348 .Times(1); 419 .Times(1);
349 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) 420 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew())
350 .Times(AnyNumber()) 421 .Times(AnyNumber())
351 .WillRepeatedly(Return(true)); 422 .WillRepeatedly(Return(true));
352 423
353 // 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
354 // during the login sequence, and is enabled again after login completion. 425 // during the login sequence, and is enabled again after login completion.
355 Sequence uiEnabledSequence; 426 Sequence uiEnabledSequence;
356 // This is disabled twice: once right after signin but before checking for 427 // This is disabled twice: once right after signin but before checking for
357 // auto-enrollment, and again after doing an ownership status check. 428 // auto-enrollment, and again after doing an ownership status check.
358 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 429 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
359 .Times(2) 430 .Times(2)
360 .InSequence(uiEnabledSequence); 431 .InSequence(uiEnabledSequence);
361 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 432 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
362 .Times(1) 433 .Times(1)
363 .InSequence(uiEnabledSequence); 434 .InSequence(uiEnabledSequence);
364 435
365 existing_user_controller()->CompleteLogin(kNewUsername, kPassword); 436 existing_user_controller()->CompleteLogin(kNewUsername, kPassword);
366 content::RunAllPendingInMessageLoop(); 437 content::RunAllPendingInMessageLoop();
367 } 438 }
368 439
440 MATCHER_P(HasDetails, expected, "") {
441 return expected == *content::Details<const std::string>(arg).ptr();
442 }
443
444 class ExistingUserControllerPublicSessionTest
445 : public ExistingUserControllerTest {
446 protected:
447 ExistingUserControllerPublicSessionTest() {
448 }
449
450 virtual void SetUpOnMainThread() OVERRIDE {
451 ExistingUserControllerTest::SetUpOnMainThread();
452
453 // Wait for the public session user to be created.
454 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) {
455 NotificationWatcher(
456 chrome::NOTIFICATION_USER_LIST_CHANGED,
457 base::Bind(&chromeos::UserManager::IsKnownUser,
458 base::Unretained(chromeos::UserManager::Get()),
459 kAutoLoginUsername)).Run();
460 }
461
462 // Wait for the device local account policy to be installed.
463 policy::MockCloudPolicyStoreObserver observer;
464 scoped_refptr<content::MessageLoopRunner> runner =
465 new content::MessageLoopRunner;
466 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()->
467 browser_policy_connector()->GetDeviceLocalAccountPolicyService()->
468 GetBrokerForAccount(kAutoLoginUsername)->core()->store();
469 store->AddObserver(&observer);
470 EXPECT_CALL(observer, OnStoreLoaded(store))
471 .Times(1)
472 .WillOnce(InvokeWithoutArgs(runner.get(),
473 &content::MessageLoopRunner::Quit));
474 runner->Run();
475 store->RemoveObserver(&observer);
476 }
477
478 virtual void SetUpSessionManager(
479 MockDBusThreadManager* mock_dbus_thread_manager) OVERRIDE {
480 EXPECT_CALL(*mock_dbus_thread_manager, GetSessionManagerClient())
481 .WillRepeatedly(Return(&session_manager_client_));
482
483 // Install the owner key.
484 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
485 base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key");
486 std::vector<uint8> owner_key_bits;
487 ASSERT_TRUE(device_policy_.signing_key()->ExportPublicKey(&owner_key_bits));
488 ASSERT_EQ(
489 file_util::WriteFile(
490 owner_key_file,
491 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)),
492 owner_key_bits.size()),
493 static_cast<int>(owner_key_bits.size()));
494 ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file));
495
496 // Setup the device policy.
497 em::ChromeDeviceSettingsProto& proto(device_policy_.payload());
498 proto.mutable_device_local_accounts()->add_account()->set_id(
499 kAutoLoginUsername);
500 RefreshDevicePolicy();
501
502 // Setup the device local account policy.
503 policy::UserPolicyBuilder device_local_account_policy;
504 device_local_account_policy.policy_data().set_username(kAutoLoginUsername);
505 device_local_account_policy.policy_data().set_policy_type(
506 policy::dm_protocol::kChromePublicAccountPolicyType);
507 device_local_account_policy.policy_data().set_settings_entity_id(
508 kAutoLoginUsername);
509 device_local_account_policy.Build();
510 session_manager_client_.set_device_local_account_policy(
511 kAutoLoginUsername,
512 device_local_account_policy.GetBlob());
513 }
514
515 virtual void SetUpLoginDisplay() OVERRIDE {
516 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
517 .Times(1)
518 .WillOnce(Return(mock_login_display_));
519 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
520 .Times(AnyNumber())
521 .WillRepeatedly(ReturnNull());
522 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
523 .Times(AnyNumber());
524 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _))
525 .Times(AnyNumber());
526 }
527
528 void ExpectSuccessfulLogin(const std::string& username,
529 const std::string& password,
530 scoped_refptr<Authenticator> create_authenticator(
531 LoginStatusConsumer* consumer)) {
532 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
533 .Times(AnyNumber());
534 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
535 .Times(1)
536 .WillOnce(WithArg<0>(Invoke(create_authenticator)));
537 EXPECT_CALL(*mock_login_utils_,
538 PrepareProfile(username, _, password, _, _, _))
539 .Times(1)
540 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
541 &base::Callback<void(void)>::Run));
542 EXPECT_CALL(*mock_login_utils_,
543 DoBrowserLaunch(testing_profile_.get(),
544 mock_login_display_host_.get()))
545 .Times(1);
546 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username))
547 .Times(1);
548 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
549 .Times(1);
550 EXPECT_CALL(*mock_login_display_, OnFadeOut())
551 .Times(1);
552 EXPECT_CALL(*mock_login_display_host_,
553 StartWizard(WizardController::kTermsOfServiceScreenName, NULL))
554 .Times(0);
555 }
556
557 scoped_refptr<content::MessageLoopRunner> CreateSettingsObserverRunLoop(
558 content::MockNotificationObserver& observer, const char* setting) {
559 scoped_refptr<content::MessageLoopRunner> runner =
560 new content::MessageLoopRunner;
561 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
562 _, HasDetails(setting)))
563 .Times(1)
564 .WillOnce(InvokeWithoutArgs(runner.get(),
565 &content::MessageLoopRunner::Quit));
566 CrosSettings::Get()->AddSettingsObserver(setting, &observer);
567 return runner;
568 }
569
570 void RefreshDevicePolicy() {
571 // Reset the key to its original state.
572 device_policy_.set_signing_key(
573 policy::PolicyBuilder::CreateTestSigningKey());
574 device_policy_.Build();
575 // Trick the device into thinking it's enterprise-enrolled by
576 // removing the local private key. This will allow it to accept
577 // cloud policy for device owner settings.
578 device_policy_.set_signing_key(
579 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
580 device_policy_.set_new_signing_key(
581 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
582 session_manager_client_.set_device_policy(device_policy_.GetBlob());
583 session_manager_client_.OnPropertyChangeComplete(true);
584 }
585
586 void SetAutoLoginPolicy(const std::string& username, int delay) {
587 // Wait until ExistingUserController has finished auto-login
588 // configuration by observing the same settings that trigger
589 // ConfigurePublicSessionAutoLogin.
590 content::MockNotificationObserver observer;
591
592 em::ChromeDeviceSettingsProto& proto(device_policy_.payload());
593
594 // If both settings have changed we need to wait for both to
595 // propagate, so check the new values against the old ones.
596 scoped_refptr<content::MessageLoopRunner> runner1 = NULL;
597 if (!proto.has_device_local_accounts() ||
598 !proto.device_local_accounts().has_auto_login_id() ||
599 proto.device_local_accounts().auto_login_id() != username) {
600 runner1 = CreateSettingsObserverRunLoop(
601 observer, kAccountsPrefDeviceLocalAccountAutoLoginId);
602 }
603 scoped_refptr<content::MessageLoopRunner> runner2 = NULL;
604 if (!proto.has_device_local_accounts() ||
605 !proto.device_local_accounts().has_auto_login_delay() ||
606 proto.device_local_accounts().auto_login_delay() != delay) {
607 runner2 = CreateSettingsObserverRunLoop(
608 observer, kAccountsPrefDeviceLocalAccountAutoLoginDelay);
609 }
610
611 // Update the policy.
612 proto.mutable_device_local_accounts()->set_auto_login_id(username);
613 proto.mutable_device_local_accounts()->set_auto_login_delay(delay);
614 RefreshDevicePolicy();
615
616 // Wait for ExistingUserController to read the updated settings.
617 if (runner1)
618 runner1->Run();
619 if (runner2)
620 runner2->Run();
621
622 // Clean up.
623 CrosSettings::Get()->RemoveSettingsObserver(
624 kAccountsPrefDeviceLocalAccountAutoLoginId,
625 &observer);
626 CrosSettings::Get()->RemoveSettingsObserver(
627 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
628 &observer);
629 }
630
631 void ConfigureAutoLogin() {
632 existing_user_controller()->ConfigurePublicSessionAutoLogin();
633 }
634
635 void FireAutoLogin() {
636 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
637 }
638
639 // Mock out policy loads/stores from/to the device.
640 FakeSessionManagerClient session_manager_client_;
641
642 // Stores the device owner key.
643 base::ScopedTempDir temp_dir_;
644
645 // Carries Chrome OS device policies for tests.
646 policy::DevicePolicyBuilder device_policy_;
647
648 private:
649 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
650 };
651
652 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
653 ConfigureAutoLoginUsingPolicy) {
654 existing_user_controller()->OnSigninScreenReady();
655 EXPECT_EQ("", auto_login_username());
656 EXPECT_EQ(0, auto_login_delay());
657 EXPECT_FALSE(auto_login_timer());
658
659 // Set the policy.
660 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
661 EXPECT_EQ(kAutoLoginUsername, auto_login_username());
662 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay());
663 ASSERT_TRUE(auto_login_timer());
664 EXPECT_TRUE(auto_login_timer()->IsRunning());
665
666 // Unset the policy.
667 SetAutoLoginPolicy("", 0);
668 EXPECT_EQ("", auto_login_username());
669 EXPECT_EQ(0, auto_login_delay());
670 ASSERT_TRUE(auto_login_timer());
671 EXPECT_FALSE(auto_login_timer()->IsRunning());
672 }
673
674 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
675 AutoLoginNoDelay) {
676 // Set up mocks to check login success.
677 ExpectSuccessfulLogin(kAutoLoginUsername, "",
678 CreateAuthenticatorForPublicSession);
679 existing_user_controller()->OnSigninScreenReady();
680
681 // Start auto-login and wait for login tasks to complete.
682 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginNoDelay);
683 content::RunAllPendingInMessageLoop();
684 }
685
686 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
687 AutoLoginShortDelay) {
688 // Set up mocks to check login success.
689 ExpectSuccessfulLogin(kAutoLoginUsername, "",
690 CreateAuthenticatorForPublicSession);
691 existing_user_controller()->OnSigninScreenReady();
692 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay);
693 ASSERT_TRUE(auto_login_timer());
694 // Don't assert that timer is running: with the short delay sometimes
695 // the trigger happens before the assert. We've already tested that
696 // the timer starts when it should.
697
698 // Wait for the timer to fire.
699 scoped_refptr<content::MessageLoopRunner> runner
700 = new content::MessageLoopRunner;
701 base::OneShotTimer<content::MessageLoopRunner> timer;
702 timer.Start(FROM_HERE,
703 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1),
704 base::Bind(&content::MessageLoopRunner::Quit, runner));
705 runner->Run();
706
707 // Wait for login tasks to complete.
708 content::RunAllPendingInMessageLoop();
709 }
710
711 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
712 LoginStopsAutoLogin) {
713 // Set up mocks to check login success.
714 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator);
715
716 existing_user_controller()->OnSigninScreenReady();
717 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
718 ASSERT_TRUE(auto_login_timer());
719
720 // Login and check that it stopped the timer.
721 existing_user_controller()->Login(kUsername, kPassword);
722 EXPECT_TRUE(is_login_in_progress());
723 ASSERT_TRUE(auto_login_timer());
724 EXPECT_FALSE(auto_login_timer()->IsRunning());
725
726 // Wait for login tasks to complete.
727 content::RunAllPendingInMessageLoop();
728
729 // Timer should still be stopped after login completes.
730 ASSERT_TRUE(auto_login_timer());
731 EXPECT_FALSE(auto_login_timer()->IsRunning());
732 }
733
734 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
735 GuestModeLoginStopsAutoLogin) {
736 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
737 .Times(1);
738 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
739 .Times(1)
740 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator)));
741 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_))
742 .Times(1);
743
744 existing_user_controller()->OnSigninScreenReady();
745 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
746 ASSERT_TRUE(auto_login_timer());
747
748 // Login and check that it stopped the timer.
749 existing_user_controller()->LoginAsGuest();
750 EXPECT_TRUE(is_login_in_progress());
751 ASSERT_TRUE(auto_login_timer());
752 EXPECT_FALSE(auto_login_timer()->IsRunning());
753
754 // Wait for login tasks to complete.
755 content::RunAllPendingInMessageLoop();
756
757 // Timer should still be stopped after login completes.
758 ASSERT_TRUE(auto_login_timer());
759 EXPECT_FALSE(auto_login_timer()->IsRunning());
760 }
761
762 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
763 CompleteLoginStopsAutoLogin) {
764 // Set up mocks to check login success.
765 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator);
766 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
767 .Times(1);
768
769 existing_user_controller()->OnSigninScreenReady();
770 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
771 ASSERT_TRUE(auto_login_timer());
772
773 // Check that login completes and stops the timer.
774 existing_user_controller()->CompleteLogin(kUsername, kPassword);
775 ASSERT_TRUE(auto_login_timer());
776 EXPECT_FALSE(auto_login_timer()->IsRunning());
777
778 // Wait for login tasks to complete.
779 content::RunAllPendingInMessageLoop();
780
781 // Timer should still be stopped after login completes.
782 ASSERT_TRUE(auto_login_timer());
783 EXPECT_FALSE(auto_login_timer()->IsRunning());
784 }
785
786 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest,
787 PublicSessionLoginStopsAutoLogin) {
788 // Set up mocks to check login success.
789 ExpectSuccessfulLogin(kAutoLoginUsername, "",
790 CreateAuthenticatorForPublicSession);
791 existing_user_controller()->OnSigninScreenReady();
792 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay);
793 ASSERT_TRUE(auto_login_timer());
794
795 // Login and check that it stopped the timer.
796 existing_user_controller()->LoginAsPublicAccount(kAutoLoginUsername);
797 EXPECT_TRUE(is_login_in_progress());
798 ASSERT_TRUE(auto_login_timer());
799 EXPECT_FALSE(auto_login_timer()->IsRunning());
800
801 // Wait for login tasks to complete.
802 content::RunAllPendingInMessageLoop();
803
804 // Timer should still be stopped after login completes.
805 ASSERT_TRUE(auto_login_timer());
806 EXPECT_FALSE(auto_login_timer()->IsRunning());
807 }
808
369 } // namespace chromeos 809 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698