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

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

Powered by Google App Engine
This is Rietveld 408576698