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

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller_auto_login_unittest.cc

Issue 1693383003: ChromeOS cryptohome should be able to use gaia id as user identifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests. Created 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/existing_user_controller.h" 9 #include "chrome/browser/chromeos/login/existing_user_controller.h"
10 #include "chrome/browser/chromeos/login/ui/mock_login_display.h" 10 #include "chrome/browser/chromeos/login/ui/mock_login_display.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 CrosSettings::Get()->SetInteger( 94 CrosSettings::Get()->SetInteger(
95 kAccountsPrefDeviceLocalAccountAutoLoginDelay, 95 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
96 delay); 96 delay);
97 } 97 }
98 98
99 // ExistingUserController private member accessors. 99 // ExistingUserController private member accessors.
100 base::OneShotTimer* auto_login_timer() { 100 base::OneShotTimer* auto_login_timer() {
101 return existing_user_controller()->auto_login_timer_.get(); 101 return existing_user_controller()->auto_login_timer_.get();
102 } 102 }
103 103
104 const std::string& auto_login_username() const { 104 const AccountId& auto_login_account_id() const {
105 return existing_user_controller()->public_session_auto_login_username_; 105 return existing_user_controller()->public_session_auto_login_account_id_;
106 } 106 }
107 void set_auto_login_username(const std::string& username) { 107 void set_auto_login_account_id(const AccountId& account_id) {
108 existing_user_controller()->public_session_auto_login_username_ = username; 108 existing_user_controller()->public_session_auto_login_account_id_ =
109 account_id;
109 } 110 }
110 111
111 int auto_login_delay() const { 112 int auto_login_delay() const {
112 return existing_user_controller()->public_session_auto_login_delay_; 113 return existing_user_controller()->public_session_auto_login_delay_;
113 } 114 }
114 void set_auto_login_delay(int delay) { 115 void set_auto_login_delay(int delay) {
115 existing_user_controller()->public_session_auto_login_delay_ = delay; 116 existing_user_controller()->public_session_auto_login_delay_ = delay;
116 } 117 }
117 118
118 bool is_login_in_progress() const { 119 bool is_login_in_progress() const {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 MockUserManager* mock_user_manager_; 151 MockUserManager* mock_user_manager_;
151 ScopedUserManagerEnabler scoped_user_manager_; 152 ScopedUserManagerEnabler scoped_user_manager_;
152 153
153 // |existing_user_controller_| must be destroyed before 154 // |existing_user_controller_| must be destroyed before
154 // |device_settings_test_helper_|. 155 // |device_settings_test_helper_|.
155 scoped_ptr<ExistingUserController> existing_user_controller_; 156 scoped_ptr<ExistingUserController> existing_user_controller_;
156 }; 157 };
157 158
158 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) { 159 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) {
159 // Timer shouldn't start until signin screen is ready. 160 // Timer shouldn't start until signin screen is ready.
160 set_auto_login_username(auto_login_account_id_.GetUserEmail()); 161 set_auto_login_account_id(auto_login_account_id_);
161 set_auto_login_delay(kAutoLoginDelay2); 162 set_auto_login_delay(kAutoLoginDelay2);
162 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 163 existing_user_controller()->StartPublicSessionAutoLoginTimer();
163 EXPECT_FALSE(auto_login_timer()); 164 EXPECT_FALSE(auto_login_timer());
164 165
165 // Timer shouldn't start if the policy isn't set. 166 // Timer shouldn't start if the policy isn't set.
166 set_auto_login_username(""); 167 set_auto_login_account_id(EmptyAccountId());
167 existing_user_controller()->OnSigninScreenReady(); 168 existing_user_controller()->OnSigninScreenReady();
168 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 169 existing_user_controller()->StartPublicSessionAutoLoginTimer();
169 EXPECT_FALSE(auto_login_timer()); 170 EXPECT_FALSE(auto_login_timer());
170 171
171 // Timer shouldn't fire in the middle of a login attempt. 172 // Timer shouldn't fire in the middle of a login attempt.
172 set_auto_login_username(auto_login_account_id_.GetUserEmail()); 173 set_auto_login_account_id(auto_login_account_id_);
173 set_is_login_in_progress(true); 174 set_is_login_in_progress(true);
174 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 175 existing_user_controller()->StartPublicSessionAutoLoginTimer();
175 EXPECT_FALSE(auto_login_timer()); 176 EXPECT_FALSE(auto_login_timer());
176 177
177 // Otherwise start. 178 // Otherwise start.
178 set_is_login_in_progress(false); 179 set_is_login_in_progress(false);
179 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 180 existing_user_controller()->StartPublicSessionAutoLoginTimer();
180 ASSERT_TRUE(auto_login_timer()); 181 ASSERT_TRUE(auto_login_timer());
181 EXPECT_TRUE(auto_login_timer()->IsRunning()); 182 EXPECT_TRUE(auto_login_timer()->IsRunning());
182 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 183 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
183 kAutoLoginDelay2); 184 kAutoLoginDelay2);
184 } 185 }
185 186
186 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) { 187 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) {
187 existing_user_controller()->OnSigninScreenReady(); 188 existing_user_controller()->OnSigninScreenReady();
188 set_auto_login_username(auto_login_account_id_.GetUserEmail()); 189 set_auto_login_account_id(auto_login_account_id_);
189 set_auto_login_delay(kAutoLoginDelay2); 190 set_auto_login_delay(kAutoLoginDelay2);
190 191
191 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 192 existing_user_controller()->StartPublicSessionAutoLoginTimer();
192 ASSERT_TRUE(auto_login_timer()); 193 ASSERT_TRUE(auto_login_timer());
193 EXPECT_TRUE(auto_login_timer()->IsRunning()); 194 EXPECT_TRUE(auto_login_timer()->IsRunning());
194 195
195 existing_user_controller()->StopPublicSessionAutoLoginTimer(); 196 existing_user_controller()->StopPublicSessionAutoLoginTimer();
196 ASSERT_TRUE(auto_login_timer()); 197 ASSERT_TRUE(auto_login_timer());
197 EXPECT_FALSE(auto_login_timer()->IsRunning()); 198 EXPECT_FALSE(auto_login_timer()->IsRunning());
198 } 199 }
199 200
200 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) { 201 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) {
201 existing_user_controller()->OnSigninScreenReady(); 202 existing_user_controller()->OnSigninScreenReady();
202 set_auto_login_username(auto_login_account_id_.GetUserEmail()); 203 set_auto_login_account_id(auto_login_account_id_);
203 204
204 // Timer starts off not running. 205 // Timer starts off not running.
205 EXPECT_FALSE(auto_login_timer()); 206 EXPECT_FALSE(auto_login_timer());
206 207
207 // When the timer isn't running, nothing should happen. 208 // When the timer isn't running, nothing should happen.
208 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); 209 existing_user_controller()->ResetPublicSessionAutoLoginTimer();
209 EXPECT_FALSE(auto_login_timer()); 210 EXPECT_FALSE(auto_login_timer());
210 211
211 // Start the timer. 212 // Start the timer.
212 set_auto_login_delay(kAutoLoginDelay2); 213 set_auto_login_delay(kAutoLoginDelay2);
(...skipping 13 matching lines...) Expand all
226 kAutoLoginDelay1); 227 kAutoLoginDelay1);
227 } 228 }
228 229
229 TEST_F(ExistingUserControllerAutoLoginTest, ConfigureAutoLogin) { 230 TEST_F(ExistingUserControllerAutoLoginTest, ConfigureAutoLogin) {
230 existing_user_controller()->OnSigninScreenReady(); 231 existing_user_controller()->OnSigninScreenReady();
231 232
232 // Timer shouldn't start when the policy is disabled. 233 // Timer shouldn't start when the policy is disabled.
233 ConfigureAutoLogin(); 234 ConfigureAutoLogin();
234 EXPECT_FALSE(auto_login_timer()); 235 EXPECT_FALSE(auto_login_timer());
235 EXPECT_EQ(auto_login_delay(), 0); 236 EXPECT_EQ(auto_login_delay(), 0);
236 EXPECT_EQ(auto_login_username(), ""); 237 EXPECT_EQ(auto_login_account_id(), EmptyAccountId());
237 238
238 // Timer shouldn't start when the delay alone is set. 239 // Timer shouldn't start when the delay alone is set.
239 SetAutoLoginSettings("", kAutoLoginDelay1); 240 SetAutoLoginSettings("", kAutoLoginDelay1);
240 ConfigureAutoLogin(); 241 ConfigureAutoLogin();
241 EXPECT_FALSE(auto_login_timer()); 242 EXPECT_FALSE(auto_login_timer());
242 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay1); 243 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay1);
243 EXPECT_EQ(auto_login_username(), ""); 244 EXPECT_EQ(auto_login_account_id(), EmptyAccountId());
244 245
245 // Timer should start when the account ID is set. 246 // Timer should start when the account ID is set.
246 SetAutoLoginSettings(auto_login_user_id_, kAutoLoginDelay1); 247 SetAutoLoginSettings(auto_login_user_id_, kAutoLoginDelay1);
247 ConfigureAutoLogin(); 248 ConfigureAutoLogin();
248 ASSERT_TRUE(auto_login_timer()); 249 ASSERT_TRUE(auto_login_timer());
249 EXPECT_TRUE(auto_login_timer()->IsRunning()); 250 EXPECT_TRUE(auto_login_timer()->IsRunning());
250 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 251 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
251 kAutoLoginDelay1); 252 kAutoLoginDelay1);
252 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay1); 253 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay1);
253 EXPECT_EQ(auto_login_username(), auto_login_account_id_.GetUserEmail()); 254 EXPECT_EQ(auto_login_account_id(), auto_login_account_id_);
254 255
255 // Timer should restart when the delay is changed. 256 // Timer should restart when the delay is changed.
256 SetAutoLoginSettings(auto_login_user_id_, kAutoLoginDelay2); 257 SetAutoLoginSettings(auto_login_user_id_, kAutoLoginDelay2);
257 ConfigureAutoLogin(); 258 ConfigureAutoLogin();
258 ASSERT_TRUE(auto_login_timer()); 259 ASSERT_TRUE(auto_login_timer());
259 EXPECT_TRUE(auto_login_timer()->IsRunning()); 260 EXPECT_TRUE(auto_login_timer()->IsRunning());
260 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 261 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
261 kAutoLoginDelay2); 262 kAutoLoginDelay2);
262 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2); 263 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2);
263 EXPECT_EQ(auto_login_username(), auto_login_account_id_.GetUserEmail()); 264 EXPECT_EQ(auto_login_account_id(), auto_login_account_id_);
264 265
265 // Timer should stop when the account ID is unset. 266 // Timer should stop when the account ID is unset.
266 SetAutoLoginSettings("", kAutoLoginDelay2); 267 SetAutoLoginSettings("", kAutoLoginDelay2);
267 ConfigureAutoLogin(); 268 ConfigureAutoLogin();
268 ASSERT_TRUE(auto_login_timer()); 269 ASSERT_TRUE(auto_login_timer());
269 EXPECT_FALSE(auto_login_timer()->IsRunning()); 270 EXPECT_FALSE(auto_login_timer()->IsRunning());
270 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 271 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
271 kAutoLoginDelay2); 272 kAutoLoginDelay2);
272 EXPECT_EQ(auto_login_username(), ""); 273 EXPECT_EQ(auto_login_account_id(), EmptyAccountId());
273 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2); 274 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2);
274 } 275 }
275 276
276 } // namespace chromeos 277 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698