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

Side by Side Diff: chrome/browser/signin/signin_manager_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix InstantNTP test. Created 7 years, 5 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 "chrome/browser/signin/signin_manager.h" 5 #include "chrome/browser/signin/signin_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
12 #include "base/run_loop.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/prefs/browser_prefs.h" 16 #include "chrome/browser/prefs/browser_prefs.h"
16 #include "chrome/browser/signin/chrome_signin_manager_delegate.h" 17 #include "chrome/browser/signin/chrome_signin_manager_delegate.h"
17 #include "chrome/browser/signin/token_service.h" 18 #include "chrome/browser/signin/token_service.h"
18 #include "chrome/browser/signin/token_service_unittest.h" 19 #include "chrome/browser/signin/token_service_unittest.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
21 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "components/webdata/encryptor/encryptor.h" 24 #include "components/webdata/encryptor/encryptor.h"
24 #include "content/public/browser/child_process_security_policy.h" 25 #include "content/public/browser/child_process_security_policy.h"
25 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
26 #include "google_apis/gaia/gaia_constants.h" 27 #include "google_apis/gaia/gaia_constants.h"
27 #include "google_apis/gaia/gaia_urls.h" 28 #include "google_apis/gaia/gaia_urls.h"
28 #include "net/cookies/cookie_monster.h" 29 #include "net/cookies/cookie_monster.h"
29 #include "net/url_request/test_url_fetcher_factory.h" 30 #include "net/url_request/test_url_fetcher_factory.h"
30 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
31 #include "net/url_request/url_request_context_getter.h" 32 #include "net/url_request/url_request_context_getter.h"
32 #include "net/url_request/url_request_status.h" 33 #include "net/url_request/url_request_status.h"
33 34
34 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 37
37 using content::BrowserThread;
38
39 namespace { 38 namespace {
40 39
41 const char kGetTokenPairValidResponse[] = 40 const char kGetTokenPairValidResponse[] =
42 "{" 41 "{"
43 " \"refresh_token\": \"rt1\"," 42 " \"refresh_token\": \"rt1\","
44 " \"access_token\": \"at1\"," 43 " \"access_token\": \"at1\","
45 " \"expires_in\": 3600," 44 " \"expires_in\": 3600,"
46 " \"token_type\": \"Bearer\"" 45 " \"token_type\": \"Bearer\""
47 "}"; 46 "}";
48 47
49 const char kUberAuthTokenURLFormat[] = "%s?source=%s&issueuberauth=1"; 48 const char kUberAuthTokenURLFormat[] = "%s?source=%s&issueuberauth=1";
50 49
51 } // namespace 50 } // namespace
52 51
53 52
54 class SigninManagerTest : public TokenServiceTestHarness { 53 class SigninManagerTest : public TokenServiceTestHarness {
55 public: 54 public:
56 void SetUpOnIOThread(base::WaitableEvent* io_setup_complete) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
58 // This is a workaround for a bug in the TestingProfile.
59 // The URLRequestContext will be created by GetCookieMonster on the UI
60 // thread, if it does not already exist. But it must be created on the IO
61 // thread or else it will DCHECK upon destruction.
62 // Force it to be created here.
63 profile_->CreateRequestContext();
64 profile_->GetRequestContext()->GetURLRequestContext();
65 io_setup_complete->Signal();
66 }
67
68 virtual void SetUp() OVERRIDE { 55 virtual void SetUp() OVERRIDE {
69 prefs_.reset(new TestingPrefServiceSimple); 56 prefs_.reset(new TestingPrefServiceSimple);
70 chrome::RegisterLocalState(prefs_->registry()); 57 chrome::RegisterLocalState(prefs_->registry());
71 TestingBrowserProcess::GetGlobal()->SetLocalState( 58 TestingBrowserProcess::GetGlobal()->SetLocalState(
72 prefs_.get()); 59 prefs_.get());
73 TokenServiceTestHarness::SetUp(); 60 TokenServiceTestHarness::SetUp();
74 manager_.reset(new SigninManager( 61 manager_.reset(new SigninManager(
75 scoped_ptr<SigninManagerDelegate>( 62 scoped_ptr<SigninManagerDelegate>(
76 new ChromeSigninManagerDelegate(profile_.get())))); 63 new ChromeSigninManagerDelegate(profile()))));
77 google_login_success_.ListenFor( 64 google_login_success_.ListenFor(
78 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 65 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
79 content::Source<Profile>(profile_.get())); 66 content::Source<Profile>(profile()));
80 google_login_failure_.ListenFor(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, 67 google_login_failure_.ListenFor(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
81 content::Source<Profile>(profile_.get())); 68 content::Source<Profile>(profile()));
82
83 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO));
84 ASSERT_TRUE(io_thread_->Start());
85 base::WaitableEvent io_setup_complete(true, false);
86 BrowserThread::PostTask(
87 BrowserThread::IO, FROM_HERE,
88 base::Bind(&SigninManagerTest::SetUpOnIOThread,
89 base::Unretained(this), &io_setup_complete));
90 io_setup_complete.Wait();
91 } 69 }
92 70
93 virtual void TearDown() OVERRIDE { 71 virtual void TearDown() OVERRIDE {
94 // Destroy the SigninManager here, because it relies on profile_ which is 72 // Destroy the SigninManager here, because it relies on profile() which is
95 // freed in the base class. 73 // freed in the base class.
96 manager_->Shutdown(); 74 manager_->Shutdown();
97 manager_.reset(NULL); 75 manager_.reset(NULL);
98 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); 76 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
99 prefs_.reset(NULL); 77 prefs_.reset(NULL);
100 TokenServiceTestHarness::TearDown(); 78 TokenServiceTestHarness::TearDown();
101 io_thread_->Stop();
102 } 79 }
103 80
104 void SetupFetcherAndComplete(const std::string& url, 81 void SetupFetcherAndComplete(const std::string& url,
105 int response_code, 82 int response_code,
106 const net::ResponseCookies& cookies, 83 const net::ResponseCookies& cookies,
107 const std::string& response_string) { 84 const std::string& response_string) {
108 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); 85 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
109 DCHECK(fetcher); 86 DCHECK(fetcher);
110 DCHECK(fetcher->delegate()); 87 DCHECK(fetcher->delegate());
111 88
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 "source"); 140 "source");
164 SetupFetcherAndComplete(uberauth_token_gurl, 200, 141 SetupFetcherAndComplete(uberauth_token_gurl, 200,
165 net::ResponseCookies(), "ut1"); 142 net::ResponseCookies(), "ut1");
166 143
167 net::ResponseCookies cookies; 144 net::ResponseCookies cookies;
168 cookies.push_back("checkCookie = true"); 145 cookies.push_back("checkCookie = true");
169 SetupFetcherAndComplete(GaiaUrls::GetInstance()->merge_session_url(), 200, 146 SetupFetcherAndComplete(GaiaUrls::GetInstance()->merge_session_url(), 200,
170 cookies, "<html></html>"); 147 cookies, "<html></html>");
171 } 148 }
172 149
173 void WaitUntilUIDone() {
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
175 BrowserThread::PostTask(
176 BrowserThread::IO, FROM_HERE,
177 base::Bind(&SigninManagerTest::NotifyUIOnComplete,
178 base::Unretained(this)));
179 base::MessageLoop::current()->Run();
180 }
181
182 void NotifyUIOnComplete () {
183 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
184 // Redo on UI thread.
185 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
186 base::Bind(&SigninManagerTest::NotifyUIOnComplete,
187 base::Unretained(this)));
188 return;
189 }
190 base::MessageLoop::current()->Quit();
191 }
192
193 void ExpectSignInWithCredentialsSuccess() { 150 void ExpectSignInWithCredentialsSuccess() {
194 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 151 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
195 152
196 SimulateValidResponseSignInWithCredentials(); 153 SimulateValidResponseSignInWithCredentials();
197 154
198 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 155 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
199 156
200 // This is flow, the oauth2 credentials should already be available in 157 // This is flow, the oauth2 credentials should already be available in
201 // the token service. 158 // the token service.
202 EXPECT_TRUE(service_->HasOAuthLoginToken()); 159 EXPECT_TRUE(service()->HasOAuthLoginToken());
203 160
204 // Should go into token service and stop. 161 // Should go into token service and stop.
205 EXPECT_EQ(1U, google_login_success_.size()); 162 EXPECT_EQ(1U, google_login_success_.size());
206 EXPECT_EQ(0U, google_login_failure_.size()); 163 EXPECT_EQ(0U, google_login_failure_.size());
207 164
208 // Should persist across resets. 165 // Should persist across resets.
209 manager_->Shutdown(); 166 manager_->Shutdown();
210 manager_.reset(new SigninManager( 167 manager_.reset(new SigninManager(
211 scoped_ptr<SigninManagerDelegate>( 168 scoped_ptr<SigninManagerDelegate>(
212 new ChromeSigninManagerDelegate(profile_.get())))); 169 new ChromeSigninManagerDelegate(profile()))));
213 manager_->Initialize(profile_.get(), NULL); 170 manager_->Initialize(profile(), NULL);
214 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 171 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
215 } 172 }
216 173
217 // Helper method that wraps the logic when signin with credentials 174 // Helper method that wraps the logic when signin with credentials
218 // should fail. If |requestSent| is true, then simulate valid resopnse. 175 // should fail. If |requestSent| is true, then simulate valid resopnse.
219 // Otherwise the sign-in is aborted before any request is sent, thus no need 176 // Otherwise the sign-in is aborted before any request is sent, thus no need
220 // to simulatate response. 177 // to simulatate response.
221 void ExpectSignInWithCredentialsFail(bool requestSent) { 178 void ExpectSignInWithCredentialsFail(bool requestSent) {
222 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 179 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
223 180
224 if (requestSent) 181 if (requestSent)
225 SimulateValidResponseSignInWithCredentials(); 182 SimulateValidResponseSignInWithCredentials();
226 183
227 // The oauth2 credentials should not be available in the token service 184 // The oauth2 credentials should not be available in the token service
228 // because the email was incorrect. 185 // because the email was incorrect.
229 EXPECT_FALSE(service_->HasOAuthLoginToken()); 186 EXPECT_FALSE(service()->HasOAuthLoginToken());
230 187
231 // Should go into token service and stop. 188 // Should go into token service and stop.
232 EXPECT_EQ(0U, google_login_success_.size()); 189 EXPECT_EQ(0U, google_login_success_.size());
233 EXPECT_EQ(1U, google_login_failure_.size()); 190 EXPECT_EQ(1U, google_login_failure_.size());
234 } 191 }
235 192
236 void CompleteSigninCallback(const std::string& oauth_token) { 193 void CompleteSigninCallback(const std::string& oauth_token) {
237 oauth_tokens_fetched_.push_back(oauth_token); 194 oauth_tokens_fetched_.push_back(oauth_token);
238 manager_->CompletePendingSignin(); 195 manager_->CompletePendingSignin();
239 } 196 }
240 197
241 void CancelSigninCallback(const std::string& oauth_token) { 198 void CancelSigninCallback(const std::string& oauth_token) {
242 oauth_tokens_fetched_.push_back(oauth_token); 199 oauth_tokens_fetched_.push_back(oauth_token);
243 manager_->SignOut(); 200 manager_->SignOut();
244 } 201 }
245 202
246 net::TestURLFetcherFactory factory_; 203 net::TestURLFetcherFactory factory_;
247 scoped_ptr<SigninManager> manager_; 204 scoped_ptr<SigninManager> manager_;
248 content::TestNotificationTracker google_login_success_; 205 content::TestNotificationTracker google_login_success_;
249 content::TestNotificationTracker google_login_failure_; 206 content::TestNotificationTracker google_login_failure_;
250 std::vector<std::string> oauth_tokens_fetched_; 207 std::vector<std::string> oauth_tokens_fetched_;
251 scoped_ptr<TestingPrefServiceSimple> prefs_; 208 scoped_ptr<TestingPrefServiceSimple> prefs_;
252 scoped_ptr<content::TestBrowserThread> io_thread_;
253 std::vector<std::string> cookies_; 209 std::vector<std::string> cookies_;
254 }; 210 };
255 211
256 // NOTE: ClientLogin's "StartSignin" is called after collecting credentials 212 // NOTE: ClientLogin's "StartSignin" is called after collecting credentials
257 // from the user. 213 // from the user.
258 TEST_F(SigninManagerTest, SignInClientLogin) { 214 TEST_F(SigninManagerTest, SignInClientLogin) {
259 manager_->Initialize(profile_.get(), NULL); 215 manager_->Initialize(profile(), NULL);
260 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 216 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
261 217
262 manager_->StartSignIn( 218 manager_->StartSignIn(
263 "user@gmail.com", "password", std::string(), std::string()); 219 "user@gmail.com", "password", std::string(), std::string());
264 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 220 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
265 221
266 SimulateValidResponseClientLogin(true); 222 SimulateValidResponseClientLogin(true);
267 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 223 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
268 224
269 // Should go into token service and stop. 225 // Should go into token service and stop.
270 EXPECT_EQ(1U, google_login_success_.size()); 226 EXPECT_EQ(1U, google_login_success_.size());
271 EXPECT_EQ(0U, google_login_failure_.size()); 227 EXPECT_EQ(0U, google_login_failure_.size());
272 228
273 service_->OnIssueAuthTokenSuccess(GaiaConstants::kGaiaOAuth2LoginRefreshToken, 229 service()->OnIssueAuthTokenSuccess(
274 "oauth2Token"); 230 GaiaConstants::kGaiaOAuth2LoginRefreshToken,
231 "oauth2Token");
275 SimulateValidUberToken(); 232 SimulateValidUberToken();
276 // Check that the login cookie has been sent. 233 // Check that the login cookie has been sent.
277 ASSERT_NE(std::find(cookies_.begin(), cookies_.end(), "checkCookie = true"), 234 ASSERT_NE(std::find(cookies_.begin(), cookies_.end(), "checkCookie = true"),
278 cookies_.end()); 235 cookies_.end());
279 236
280 // Should persist across resets. 237 // Should persist across resets.
281 manager_->Shutdown(); 238 manager_->Shutdown();
282 manager_.reset(new SigninManager( 239 manager_.reset(new SigninManager(
283 scoped_ptr<SigninManagerDelegate>( 240 scoped_ptr<SigninManagerDelegate>(
284 new ChromeSigninManagerDelegate(profile_.get())))); 241 new ChromeSigninManagerDelegate(profile()))));
285 manager_->Initialize(profile_.get(), NULL); 242 manager_->Initialize(profile(), NULL);
286 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 243 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
287 } 244 }
288 245
289 TEST_F(SigninManagerTest, SignInWithCredentials) { 246 TEST_F(SigninManagerTest, SignInWithCredentials) {
290 manager_->Initialize(profile_.get(), NULL); 247 manager_->Initialize(profile(), NULL);
291 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 248 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
292 249
293 manager_->StartSignInWithCredentials( 250 manager_->StartSignInWithCredentials(
294 "0", 251 "0",
295 "user@gmail.com", 252 "user@gmail.com",
296 "password", 253 "password",
297 SigninManager::OAuthTokenFetchedCallback()); 254 SigninManager::OAuthTokenFetchedCallback());
298 255
299 ExpectSignInWithCredentialsSuccess(); 256 ExpectSignInWithCredentialsSuccess();
300 } 257 }
301 258
302 TEST_F(SigninManagerTest, SignInWithCredentialsNonCanonicalEmail) { 259 TEST_F(SigninManagerTest, SignInWithCredentialsNonCanonicalEmail) {
303 manager_->Initialize(profile_.get(), NULL); 260 manager_->Initialize(profile(), NULL);
304 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 261 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
305 262
306 manager_->StartSignInWithCredentials( 263 manager_->StartSignInWithCredentials(
307 "0", 264 "0",
308 "user", 265 "user",
309 "password", 266 "password",
310 SigninManager::OAuthTokenFetchedCallback()); 267 SigninManager::OAuthTokenFetchedCallback());
311 268
312 ExpectSignInWithCredentialsSuccess(); 269 ExpectSignInWithCredentialsSuccess();
313 } 270 }
314 271
315 TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) { 272 TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) {
316 manager_->Initialize(profile_.get(), NULL); 273 manager_->Initialize(profile(), NULL);
317 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 274 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
318 275
319 // If the email address used to start the sign in does not match the 276 // If the email address used to start the sign in does not match the
320 // email address returned by /GetUserInfo, the sign in should fail. 277 // email address returned by /GetUserInfo, the sign in should fail.
321 manager_->StartSignInWithCredentials( 278 manager_->StartSignInWithCredentials(
322 "0", 279 "0",
323 "user2@gmail.com", 280 "user2@gmail.com",
324 "password", 281 "password",
325 SigninManager::OAuthTokenFetchedCallback()); 282 SigninManager::OAuthTokenFetchedCallback());
326 283
327 ExpectSignInWithCredentialsFail(true /* requestSent */); 284 ExpectSignInWithCredentialsFail(true /* requestSent */);
328 } 285 }
329 286
330 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) { 287 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) {
331 manager_->Initialize(profile_.get(), NULL); 288 manager_->Initialize(profile(), NULL);
332 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 289 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
333 290
334 // Set a valid LSID cookie in the test cookie store. 291 // Set a valid LSID cookie in the test cookie store.
335 scoped_refptr<net::CookieMonster> cookie_monster = 292 scoped_refptr<net::CookieMonster> cookie_monster =
336 profile_->GetCookieMonster(); 293 profile()->GetCookieMonster();
337 net::CookieOptions options; 294 net::CookieOptions options;
338 options.set_include_httponly(); 295 options.set_include_httponly();
339 cookie_monster->SetCookieWithOptionsAsync( 296 cookie_monster->SetCookieWithOptionsAsync(
340 GURL("https://accounts.google.com"), 297 GURL("https://accounts.google.com"),
341 "LSID=1234; secure; httponly", options, 298 "LSID=1234; secure; httponly", options,
342 net::CookieMonster::SetCookiesCallback()); 299 net::CookieMonster::SetCookiesCallback());
343 300
344 // Since the password is empty, will verify the gaia cookies first. 301 // Since the password is empty, will verify the gaia cookies first.
345 manager_->StartSignInWithCredentials( 302 manager_->StartSignInWithCredentials(
346 "0", 303 "0",
347 "user@gmail.com", 304 "user@gmail.com",
348 std::string(), 305 std::string(),
349 SigninManager::OAuthTokenFetchedCallback()); 306 SigninManager::OAuthTokenFetchedCallback());
350 307
351 WaitUntilUIDone(); 308 base::RunLoop().RunUntilIdle();
352 309
353 // Verification should succeed and continue with auto signin. 310 // Verification should succeed and continue with auto signin.
354 ExpectSignInWithCredentialsSuccess(); 311 ExpectSignInWithCredentialsSuccess();
355 } 312 }
356 313
357 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordNoValidCookie) { 314 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordNoValidCookie) {
358 manager_->Initialize(profile_.get(), NULL); 315 manager_->Initialize(profile(), NULL);
359 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 316 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
360 317
361 // Since the password is empty, will verify the gaia cookies first. 318 // Since the password is empty, will verify the gaia cookies first.
362 manager_->StartSignInWithCredentials( 319 manager_->StartSignInWithCredentials(
363 "0", 320 "0",
364 "user@gmail.com", 321 "user@gmail.com",
365 std::string(), 322 std::string(),
366 SigninManager::OAuthTokenFetchedCallback()); 323 SigninManager::OAuthTokenFetchedCallback());
367 324
368 WaitUntilUIDone(); 325 base::RunLoop().RunUntilIdle();
369 326
370 // Since the test cookie store is empty, verification should fail and throws 327 // Since the test cookie store is empty, verification should fail and throws
371 // a login error. 328 // a login error.
372 ExpectSignInWithCredentialsFail(false /* requestSent */); 329 ExpectSignInWithCredentialsFail(false /* requestSent */);
373 } 330 }
374 331
375 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) { 332 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) {
376 manager_->Initialize(profile_.get(), NULL); 333 manager_->Initialize(profile(), NULL);
377 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 334 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
378 335
379 // Set an invalid LSID cookie in the test cookie store. 336 // Set an invalid LSID cookie in the test cookie store.
380 scoped_refptr<net::CookieMonster> cookie_monster = 337 scoped_refptr<net::CookieMonster> cookie_monster =
381 profile_->GetCookieMonster(); 338 profile()->GetCookieMonster();
382 net::CookieOptions options; 339 net::CookieOptions options;
383 options.set_include_httponly(); 340 options.set_include_httponly();
384 cookie_monster->SetCookieWithOptionsAsync( 341 cookie_monster->SetCookieWithOptionsAsync(
385 GURL("https://accounts.google.com"), 342 GURL("https://accounts.google.com"),
386 "LSID=1234; domain=google.com; secure; httponly", options, 343 "LSID=1234; domain=google.com; secure; httponly", options,
387 net::CookieMonster::SetCookiesCallback()); 344 net::CookieMonster::SetCookiesCallback());
388 345
389 // Since the password is empty, must verify the gaia cookies first. 346 // Since the password is empty, must verify the gaia cookies first.
390 manager_->StartSignInWithCredentials( 347 manager_->StartSignInWithCredentials(
391 "0", 348 "0",
392 "user@gmail.com", 349 "user@gmail.com",
393 std::string(), 350 std::string(),
394 SigninManager::OAuthTokenFetchedCallback()); 351 SigninManager::OAuthTokenFetchedCallback());
395 352
396 WaitUntilUIDone(); 353 base::RunLoop().RunUntilIdle();
397 354
398 // Since the LSID cookie is invalid, verification should fail and throws 355 // Since the LSID cookie is invalid, verification should fail and throws
399 // a login error. 356 // a login error.
400 ExpectSignInWithCredentialsFail(false /* requestSent */); 357 ExpectSignInWithCredentialsFail(false /* requestSent */);
401 } 358 }
402 359
403 TEST_F(SigninManagerTest, SignInWithCredentialsCallbackComplete) { 360 TEST_F(SigninManagerTest, SignInWithCredentialsCallbackComplete) {
404 manager_->Initialize(profile_.get(), NULL); 361 manager_->Initialize(profile(), NULL);
405 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 362 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
406 363
407 // Since the password is empty, must verify the gaia cookies first. 364 // Since the password is empty, must verify the gaia cookies first.
408 SigninManager::OAuthTokenFetchedCallback callback = 365 SigninManager::OAuthTokenFetchedCallback callback =
409 base::Bind(&SigninManagerTest::CompleteSigninCallback, 366 base::Bind(&SigninManagerTest::CompleteSigninCallback,
410 base::Unretained(this)); 367 base::Unretained(this));
411 manager_->StartSignInWithCredentials( 368 manager_->StartSignInWithCredentials(
412 "0", 369 "0",
413 "user@gmail.com", 370 "user@gmail.com",
414 "password", 371 "password",
415 callback); 372 callback);
416 373
417 ExpectSignInWithCredentialsSuccess(); 374 ExpectSignInWithCredentialsSuccess();
418 ASSERT_EQ(1U, oauth_tokens_fetched_.size()); 375 ASSERT_EQ(1U, oauth_tokens_fetched_.size());
419 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1"); 376 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1");
420 } 377 }
421 378
422 TEST_F(SigninManagerTest, SignInWithCredentialsCallbackCancel) { 379 TEST_F(SigninManagerTest, SignInWithCredentialsCallbackCancel) {
423 manager_->Initialize(profile_.get(), NULL); 380 manager_->Initialize(profile(), NULL);
424 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 381 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
425 382
426 // Since the password is empty, must verify the gaia cookies first. 383 // Since the password is empty, must verify the gaia cookies first.
427 SigninManager::OAuthTokenFetchedCallback callback = 384 SigninManager::OAuthTokenFetchedCallback callback =
428 base::Bind(&SigninManagerTest::CancelSigninCallback, 385 base::Bind(&SigninManagerTest::CancelSigninCallback,
429 base::Unretained(this)); 386 base::Unretained(this));
430 manager_->StartSignInWithCredentials( 387 manager_->StartSignInWithCredentials(
431 "0", 388 "0",
432 "user@gmail.com", 389 "user@gmail.com",
433 "password", 390 "password",
434 callback); 391 callback);
435 392
436 // Signin should fail since it would be cancelled by the callback. 393 // Signin should fail since it would be cancelled by the callback.
437 ExpectSignInWithCredentialsFail(true); 394 ExpectSignInWithCredentialsFail(true);
438 ASSERT_EQ(1U, oauth_tokens_fetched_.size()); 395 ASSERT_EQ(1U, oauth_tokens_fetched_.size());
439 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1"); 396 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1");
440 } 397 }
441 398
442 TEST_F(SigninManagerTest, SignInClientLoginNoGPlus) { 399 TEST_F(SigninManagerTest, SignInClientLoginNoGPlus) {
443 manager_->Initialize(profile_.get(), NULL); 400 manager_->Initialize(profile(), NULL);
444 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 401 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
445 402
446 manager_->StartSignIn("username", "password", std::string(), std::string()); 403 manager_->StartSignIn("username", "password", std::string(), std::string());
447 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 404 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
448 405
449 SimulateValidResponseClientLogin(false); 406 SimulateValidResponseClientLogin(false);
450 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 407 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
451 } 408 }
452 409
453 TEST_F(SigninManagerTest, ClearTransientSigninData) { 410 TEST_F(SigninManagerTest, ClearTransientSigninData) {
454 manager_->Initialize(profile_.get(), NULL); 411 manager_->Initialize(profile(), NULL);
455 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 412 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
456 413
457 manager_->StartSignIn("username", "password", std::string(), std::string()); 414 manager_->StartSignIn("username", "password", std::string(), std::string());
458 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 415 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
459 416
460 SimulateValidResponseClientLogin(false); 417 SimulateValidResponseClientLogin(false);
461 418
462 // Should go into token service and stop. 419 // Should go into token service and stop.
463 EXPECT_EQ(1U, google_login_success_.size()); 420 EXPECT_EQ(1U, google_login_success_.size());
464 EXPECT_EQ(0U, google_login_failure_.size()); 421 EXPECT_EQ(0U, google_login_failure_.size());
465 422
466 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 423 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
467 424
468 // Now clear the in memory data. 425 // Now clear the in memory data.
469 manager_->ClearTransientSigninData(); 426 manager_->ClearTransientSigninData();
470 EXPECT_TRUE(manager_->last_result_.data.empty()); 427 EXPECT_TRUE(manager_->last_result_.data.empty());
471 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 428 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
472 429
473 // Ensure preferences are not modified. 430 // Ensure preferences are not modified.
474 EXPECT_FALSE( 431 EXPECT_FALSE(
475 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty()); 432 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty());
476 433
477 // On reset it should be regenerated. 434 // On reset it should be regenerated.
478 manager_->Shutdown(); 435 manager_->Shutdown();
479 manager_.reset(new SigninManager( 436 manager_.reset(new SigninManager(
480 scoped_ptr<SigninManagerDelegate>( 437 scoped_ptr<SigninManagerDelegate>(
481 new ChromeSigninManagerDelegate(profile_.get())))); 438 new ChromeSigninManagerDelegate(profile()))));
482 manager_->Initialize(profile_.get(), NULL); 439 manager_->Initialize(profile(), NULL);
483 440
484 // Now make sure we have the right user name. 441 // Now make sure we have the right user name.
485 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 442 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
486 } 443 }
487 444
488 TEST_F(SigninManagerTest, SignOutClientLogin) { 445 TEST_F(SigninManagerTest, SignOutClientLogin) {
489 manager_->Initialize(profile_.get(), NULL); 446 manager_->Initialize(profile(), NULL);
490 manager_->StartSignIn("username", "password", std::string(), std::string()); 447 manager_->StartSignIn("username", "password", std::string(), std::string());
491 SimulateValidResponseClientLogin(false); 448 SimulateValidResponseClientLogin(false);
492 manager_->OnClientLoginSuccess(credentials_); 449 manager_->OnClientLoginSuccess(credentials());
493 450
494 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 451 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
495 manager_->SignOut(); 452 manager_->SignOut();
496 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 453 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
497 // Should not be persisted anymore 454 // Should not be persisted anymore
498 manager_->Shutdown(); 455 manager_->Shutdown();
499 manager_.reset(new SigninManager( 456 manager_.reset(new SigninManager(
500 scoped_ptr<SigninManagerDelegate>( 457 scoped_ptr<SigninManagerDelegate>(
501 new ChromeSigninManagerDelegate(profile_.get())))); 458 new ChromeSigninManagerDelegate(profile()))));
502 manager_->Initialize(profile_.get(), NULL); 459 manager_->Initialize(profile(), NULL);
503 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 460 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
504 } 461 }
505 462
506 TEST_F(SigninManagerTest, SignInFailureClientLogin) { 463 TEST_F(SigninManagerTest, SignInFailureClientLogin) {
507 manager_->Initialize(profile_.get(), NULL); 464 manager_->Initialize(profile(), NULL);
508 manager_->StartSignIn("username", "password", std::string(), std::string()); 465 manager_->StartSignIn("username", "password", std::string(), std::string());
509 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 466 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
510 manager_->OnClientLoginFailure(error); 467 manager_->OnClientLoginFailure(error);
511 468
512 EXPECT_EQ(0U, google_login_success_.size()); 469 EXPECT_EQ(0U, google_login_success_.size());
513 EXPECT_EQ(1U, google_login_failure_.size()); 470 EXPECT_EQ(1U, google_login_failure_.size());
514 471
515 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 472 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
516 473
517 // Should not be persisted 474 // Should not be persisted
518 manager_->Shutdown(); 475 manager_->Shutdown();
519 manager_.reset(new SigninManager( 476 manager_.reset(new SigninManager(
520 scoped_ptr<SigninManagerDelegate>( 477 scoped_ptr<SigninManagerDelegate>(
521 new ChromeSigninManagerDelegate(profile_.get())))); 478 new ChromeSigninManagerDelegate(profile()))));
522 manager_->Initialize(profile_.get(), NULL); 479 manager_->Initialize(profile(), NULL);
523 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 480 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
524 } 481 }
525 482
526 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) { 483 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) {
527 manager_->Initialize(profile_.get(), NULL); 484 manager_->Initialize(profile(), NULL);
528 manager_->StartSignIn("username", "password", std::string(), std::string()); 485 manager_->StartSignIn("username", "password", std::string(), std::string());
529 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); 486 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
530 manager_->OnClientLoginFailure(error); 487 manager_->OnClientLoginFailure(error);
531 488
532 EXPECT_EQ(0U, google_login_success_.size()); 489 EXPECT_EQ(0U, google_login_success_.size());
533 EXPECT_EQ(1U, google_login_failure_.size()); 490 EXPECT_EQ(1U, google_login_failure_.size());
534 491
535 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 492 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
536 EXPECT_FALSE(manager_->possibly_invalid_username_.empty()); 493 EXPECT_FALSE(manager_->possibly_invalid_username_.empty());
537 494
538 manager_->ProvideSecondFactorAccessCode("access"); 495 manager_->ProvideSecondFactorAccessCode("access");
539 SimulateValidResponseClientLogin(false); 496 SimulateValidResponseClientLogin(false);
540 497
541 EXPECT_EQ(1U, google_login_success_.size()); 498 EXPECT_EQ(1U, google_login_success_.size());
542 EXPECT_EQ(1U, google_login_failure_.size()); 499 EXPECT_EQ(1U, google_login_failure_.size());
543 } 500 }
544 501
545 TEST_F(SigninManagerTest, ProvideSecondFactorFailure) { 502 TEST_F(SigninManagerTest, ProvideSecondFactorFailure) {
546 manager_->Initialize(profile_.get(), NULL); 503 manager_->Initialize(profile(), NULL);
547 manager_->StartSignIn("username", "password", std::string(), std::string()); 504 manager_->StartSignIn("username", "password", std::string(), std::string());
548 GoogleServiceAuthError error1(GoogleServiceAuthError::TWO_FACTOR); 505 GoogleServiceAuthError error1(GoogleServiceAuthError::TWO_FACTOR);
549 manager_->OnClientLoginFailure(error1); 506 manager_->OnClientLoginFailure(error1);
550 507
551 EXPECT_EQ(0U, google_login_success_.size()); 508 EXPECT_EQ(0U, google_login_success_.size());
552 EXPECT_EQ(1U, google_login_failure_.size()); 509 EXPECT_EQ(1U, google_login_failure_.size());
553 510
554 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 511 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
555 EXPECT_FALSE(manager_->possibly_invalid_username_.empty()); 512 EXPECT_FALSE(manager_->possibly_invalid_username_.empty());
556 513
557 manager_->ProvideSecondFactorAccessCode("badaccess"); 514 manager_->ProvideSecondFactorAccessCode("badaccess");
558 GoogleServiceAuthError error2( 515 GoogleServiceAuthError error2(
559 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 516 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
560 manager_->OnClientLoginFailure(error2); 517 manager_->OnClientLoginFailure(error2);
561 518
562 EXPECT_EQ(0U, google_login_success_.size()); 519 EXPECT_EQ(0U, google_login_success_.size());
563 EXPECT_EQ(2U, google_login_failure_.size()); 520 EXPECT_EQ(2U, google_login_failure_.size());
564 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 521 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
565 522
566 manager_->ProvideSecondFactorAccessCode("badaccess"); 523 manager_->ProvideSecondFactorAccessCode("badaccess");
567 GoogleServiceAuthError error3(GoogleServiceAuthError::CONNECTION_FAILED); 524 GoogleServiceAuthError error3(GoogleServiceAuthError::CONNECTION_FAILED);
568 manager_->OnClientLoginFailure(error3); 525 manager_->OnClientLoginFailure(error3);
569 526
570 EXPECT_EQ(0U, google_login_success_.size()); 527 EXPECT_EQ(0U, google_login_success_.size());
571 EXPECT_EQ(3U, google_login_failure_.size()); 528 EXPECT_EQ(3U, google_login_failure_.size());
572 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 529 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
573 } 530 }
574 531
575 TEST_F(SigninManagerTest, SignOutMidConnect) { 532 TEST_F(SigninManagerTest, SignOutMidConnect) {
576 manager_->Initialize(profile_.get(), NULL); 533 manager_->Initialize(profile(), NULL);
577 manager_->StartSignIn("username", "password", std::string(), std::string()); 534 manager_->StartSignIn("username", "password", std::string(), std::string());
578 EXPECT_EQ("username", manager_->GetUsernameForAuthInProgress()); 535 EXPECT_EQ("username", manager_->GetUsernameForAuthInProgress());
579 manager_->SignOut(); 536 manager_->SignOut();
580 EXPECT_EQ(0U, google_login_success_.size()); 537 EXPECT_EQ(0U, google_login_success_.size());
581 EXPECT_EQ(1U, google_login_failure_.size()); 538 EXPECT_EQ(1U, google_login_failure_.size());
582 539
583 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 540 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
584 EXPECT_TRUE(manager_->GetUsernameForAuthInProgress().empty()); 541 EXPECT_TRUE(manager_->GetUsernameForAuthInProgress().empty());
585 } 542 }
586 543
587 TEST_F(SigninManagerTest, SignOutWhileProhibited) { 544 TEST_F(SigninManagerTest, SignOutWhileProhibited) {
588 manager_->Initialize(profile_.get(), NULL); 545 manager_->Initialize(profile(), NULL);
589 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 546 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
590 547
591 manager_->SetAuthenticatedUsername("user@gmail.com"); 548 manager_->SetAuthenticatedUsername("user@gmail.com");
592 manager_->ProhibitSignout(true); 549 manager_->ProhibitSignout(true);
593 manager_->SignOut(); 550 manager_->SignOut();
594 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 551 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
595 manager_->ProhibitSignout(false); 552 manager_->ProhibitSignout(false);
596 manager_->SignOut(); 553 manager_->SignOut();
597 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 554 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
598 } 555 }
(...skipping 11 matching lines...) Expand all
610 // chromiumsync is double-embedded in a continue query param. 567 // chromiumsync is double-embedded in a continue query param.
611 EXPECT_TRUE(SigninManager::IsWebBasedSigninFlowURL( 568 EXPECT_TRUE(SigninManager::IsWebBasedSigninFlowURL(
612 GURL("https://accounts.google.com/CheckCookie?" 569 GURL("https://accounts.google.com/CheckCookie?"
613 "continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen-US%2Fchrome" 570 "continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen-US%2Fchrome"
614 "%2Fblank.html%3Fsource%3D3%26nonadv%3D1&service=chromiumsync"))); 571 "%2Fblank.html%3Fsource%3D3%26nonadv%3D1&service=chromiumsync")));
615 } 572 }
616 573
617 TEST_F(SigninManagerTest, Prohibited) { 574 TEST_F(SigninManagerTest, Prohibited) {
618 g_browser_process->local_state()->SetString( 575 g_browser_process->local_state()->SetString(
619 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); 576 prefs::kGoogleServicesUsernamePattern, ".*@google.com");
620 manager_->Initialize(profile_.get(), g_browser_process->local_state()); 577 manager_->Initialize(profile(), g_browser_process->local_state());
621 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com")); 578 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com"));
622 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com")); 579 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com"));
623 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com")); 580 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com"));
624 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com")); 581 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com"));
625 EXPECT_FALSE(manager_->IsAllowedUsername(std::string())); 582 EXPECT_FALSE(manager_->IsAllowedUsername(std::string()));
626 } 583 }
627 584
628 TEST_F(SigninManagerTest, TestAlternateWildcard) { 585 TEST_F(SigninManagerTest, TestAlternateWildcard) {
629 // Test to make sure we accept "*@google.com" as a pattern (treat it as if 586 // Test to make sure we accept "*@google.com" as a pattern (treat it as if
630 // the admin entered ".*@google.com"). 587 // the admin entered ".*@google.com").
631 g_browser_process->local_state()->SetString( 588 g_browser_process->local_state()->SetString(
632 prefs::kGoogleServicesUsernamePattern, "*@google.com"); 589 prefs::kGoogleServicesUsernamePattern, "*@google.com");
633 manager_->Initialize(profile_.get(), g_browser_process->local_state()); 590 manager_->Initialize(profile(), g_browser_process->local_state());
634 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com")); 591 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com"));
635 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com")); 592 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com"));
636 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com")); 593 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com"));
637 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com")); 594 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com"));
638 EXPECT_FALSE(manager_->IsAllowedUsername(std::string())); 595 EXPECT_FALSE(manager_->IsAllowedUsername(std::string()));
639 } 596 }
640 597
641 TEST_F(SigninManagerTest, ProhibitedAtStartup) { 598 TEST_F(SigninManagerTest, ProhibitedAtStartup) {
642 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 599 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
643 "monkey@invalid.com"); 600 "monkey@invalid.com");
644 g_browser_process->local_state()->SetString( 601 g_browser_process->local_state()->SetString(
645 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); 602 prefs::kGoogleServicesUsernamePattern, ".*@google.com");
646 manager_->Initialize(profile_.get(), g_browser_process->local_state()); 603 manager_->Initialize(profile(), g_browser_process->local_state());
647 // Currently signed in user is prohibited by policy, so should be signed out. 604 // Currently signed in user is prohibited by policy, so should be signed out.
648 EXPECT_EQ("", manager_->GetAuthenticatedUsername()); 605 EXPECT_EQ("", manager_->GetAuthenticatedUsername());
649 } 606 }
650 607
651 TEST_F(SigninManagerTest, ProhibitedAfterStartup) { 608 TEST_F(SigninManagerTest, ProhibitedAfterStartup) {
652 std::string user("monkey@invalid.com"); 609 std::string user("monkey@invalid.com");
653 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); 610 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user);
654 manager_->Initialize(profile_.get(), g_browser_process->local_state()); 611 manager_->Initialize(profile(), g_browser_process->local_state());
655 EXPECT_EQ(user, manager_->GetAuthenticatedUsername()); 612 EXPECT_EQ(user, manager_->GetAuthenticatedUsername());
656 // Update the profile - user should be signed out. 613 // Update the profile - user should be signed out.
657 g_browser_process->local_state()->SetString( 614 g_browser_process->local_state()->SetString(
658 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); 615 prefs::kGoogleServicesUsernamePattern, ".*@google.com");
659 EXPECT_EQ("", manager_->GetAuthenticatedUsername()); 616 EXPECT_EQ("", manager_->GetAuthenticatedUsername());
660 } 617 }
661 618
662 TEST_F(SigninManagerTest, ExternalSignIn) { 619 TEST_F(SigninManagerTest, ExternalSignIn) {
663 manager_->Initialize(profile_.get(), g_browser_process->local_state()); 620 manager_->Initialize(profile(), g_browser_process->local_state());
664 EXPECT_EQ("", 621 EXPECT_EQ("",
665 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); 622 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
666 EXPECT_EQ("", manager_->GetAuthenticatedUsername()); 623 EXPECT_EQ("", manager_->GetAuthenticatedUsername());
667 EXPECT_EQ(0u, google_login_success_.size()); 624 EXPECT_EQ(0u, google_login_success_.size());
668 625
669 manager_->OnExternalSigninCompleted("external@example.com"); 626 manager_->OnExternalSigninCompleted("external@example.com");
670 EXPECT_EQ(1u, google_login_success_.size()); 627 EXPECT_EQ(1u, google_login_success_.size());
671 EXPECT_EQ(0u, google_login_failure_.size()); 628 EXPECT_EQ(0u, google_login_failure_.size());
672 EXPECT_EQ("external@example.com", 629 EXPECT_EQ("external@example.com",
673 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); 630 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
674 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); 631 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername());
675 } 632 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/profile_oauth2_token_service_unittest.cc ('k') | chrome/browser/signin/token_service_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698