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

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

Powered by Google App Engine
This is Rietveld 408576698