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

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

Issue 590113004: Handle account removal correctly on all platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modify metrics Created 6 years, 3 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 MockAccountReconcilor(ProfileOAuth2TokenService* token_service, 44 MockAccountReconcilor(ProfileOAuth2TokenService* token_service,
45 SigninManagerBase* signin_manager, 45 SigninManagerBase* signin_manager,
46 SigninClient* client); 46 SigninClient* client);
47 virtual ~MockAccountReconcilor() {} 47 virtual ~MockAccountReconcilor() {}
48 48
49 virtual void StartFetchingExternalCcResult() OVERRIDE { 49 virtual void StartFetchingExternalCcResult() OVERRIDE {
50 // Don't do this in tests. 50 // Don't do this in tests.
51 } 51 }
52 52
53 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id)); 53 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id));
54 MOCK_METHOD1(PerformStartRemoveAction, void(const std::string& account_id));
55 MOCK_METHOD3(
56 PerformFinishRemoveAction,
57 void(const std::string& account_id,
58 const GoogleServiceAuthError& error,
59 const std::vector<std::pair<std::string, bool> >& accounts));
60 MOCK_METHOD3(PerformAddToChromeAction,
61 void(const std::string& account_id,
62 int session_index,
63 const std::string& signin_scoped_device_id));
64 MOCK_METHOD0(PerformLogoutAllAccountsAction, void()); 54 MOCK_METHOD0(PerformLogoutAllAccountsAction, void());
65 }; 55 };
66 56
67 // static 57 // static
68 KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) { 58 KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) {
69 Profile* profile = Profile::FromBrowserContext(context); 59 Profile* profile = Profile::FromBrowserContext(context);
70 AccountReconcilor* reconcilor = new MockAccountReconcilor( 60 AccountReconcilor* reconcilor = new MockAccountReconcilor(
71 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), 61 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
72 SigninManagerFactory::GetForProfile(profile), 62 SigninManagerFactory::GetForProfile(profile),
73 ChromeSigninClientFactory::GetForProfile(profile)); 63 ChromeSigninClientFactory::GetForProfile(profile));
(...skipping 28 matching lines...) Expand all
102 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); 92 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status);
103 } 93 }
104 94
105 MockAccountReconcilor* GetMockReconcilor(); 95 MockAccountReconcilor* GetMockReconcilor();
106 96
107 void SimulateMergeSessionCompleted( 97 void SimulateMergeSessionCompleted(
108 MergeSessionHelper::Observer* observer, 98 MergeSessionHelper::Observer* observer,
109 const std::string& account_id, 99 const std::string& account_id,
110 const GoogleServiceAuthError& error); 100 const GoogleServiceAuthError& error);
111 101
112 void SimulateRefreshTokenFetched(
113 AccountReconcilor* reconcilor,
114 const std::string& account_id,
115 const std::string& refresh_token);
116
117 private: 102 private:
118 content::TestBrowserThreadBundle bundle_; 103 content::TestBrowserThreadBundle bundle_;
119 TestingProfile* profile_; 104 TestingProfile* profile_;
120 FakeSigninManagerForTesting* signin_manager_; 105 FakeSigninManagerForTesting* signin_manager_;
121 FakeProfileOAuth2TokenService* token_service_; 106 FakeProfileOAuth2TokenService* token_service_;
122 MockAccountReconcilor* mock_reconcilor_; 107 MockAccountReconcilor* mock_reconcilor_;
123 net::FakeURLFetcherFactory url_fetcher_factory_; 108 net::FakeURLFetcherFactory url_fetcher_factory_;
124 scoped_ptr<TestingProfileManager> testing_profile_manager_; 109 scoped_ptr<TestingProfileManager> testing_profile_manager_;
125 base::HistogramTester histogram_tester_; 110 base::HistogramTester histogram_tester_;
126 111
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 return mock_reconcilor_; 165 return mock_reconcilor_;
181 } 166 }
182 167
183 void AccountReconcilorTest::SimulateMergeSessionCompleted( 168 void AccountReconcilorTest::SimulateMergeSessionCompleted(
184 MergeSessionHelper::Observer* observer, 169 MergeSessionHelper::Observer* observer,
185 const std::string& account_id, 170 const std::string& account_id,
186 const GoogleServiceAuthError& error) { 171 const GoogleServiceAuthError& error) {
187 observer->MergeSessionCompleted(account_id, error); 172 observer->MergeSessionCompleted(account_id, error);
188 } 173 }
189 174
190 void AccountReconcilorTest::SimulateRefreshTokenFetched(
191 AccountReconcilor* reconcilor,
192 const std::string& account_id,
193 const std::string& refresh_token) {
194 reconcilor->HandleRefreshTokenFetched(account_id, refresh_token);
195 }
196
197 TEST_F(AccountReconcilorTest, Basic) { 175 TEST_F(AccountReconcilorTest, Basic) {
198 AccountReconcilor* reconcilor = 176 AccountReconcilor* reconcilor =
199 AccountReconcilorFactory::GetForProfile(profile()); 177 AccountReconcilorFactory::GetForProfile(profile());
200 ASSERT_TRUE(reconcilor); 178 ASSERT_TRUE(reconcilor);
201 ASSERT_EQ(token_service(), reconcilor->token_service()); 179 ASSERT_EQ(token_service(), reconcilor->token_service());
202 } 180 }
203 181
204 #if !defined(OS_CHROMEOS) 182 #if !defined(OS_CHROMEOS)
205 183
206 // This method requires the use of the |TestSigninClient| to be created from the 184 // This method requires the use of the |TestSigninClient| to be created from the
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 226
249 AccountReconcilor* reconcilor = 227 AccountReconcilor* reconcilor =
250 AccountReconcilorFactory::GetForProfile(profile()); 228 AccountReconcilorFactory::GetForProfile(profile());
251 ASSERT_TRUE(reconcilor); 229 ASSERT_TRUE(reconcilor);
252 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); 230 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
253 } 231 }
254 232
255 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { 233 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) {
256 signin_manager()->SetAuthenticatedUsername(kTestEmail); 234 signin_manager()->SetAuthenticatedUsername(kTestEmail);
257 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); 235 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
236 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(kTestEmail));
258 AccountReconcilor* reconcilor = 237 AccountReconcilor* reconcilor =
259 AccountReconcilorFactory::GetForProfile(profile()); 238 AccountReconcilorFactory::GetForProfile(profile());
260 ASSERT_TRUE(reconcilor); 239 ASSERT_TRUE(reconcilor);
261 240
262 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 241 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
263 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", 242 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]",
264 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 243 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
265 244
266 reconcilor->StartReconcile(); 245 reconcilor->StartReconcile();
267 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 246 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
(...skipping 13 matching lines...) Expand all
281 AccountReconcilorFactory::GetForProfile(profile()); 260 AccountReconcilorFactory::GetForProfile(profile());
282 ASSERT_TRUE(reconcilor); 261 ASSERT_TRUE(reconcilor);
283 262
284 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), "", 263 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), "",
285 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); 264 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
286 265
287 reconcilor->StartReconcile(); 266 reconcilor->StartReconcile();
288 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 267 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
289 268
290 base::RunLoop().RunUntilIdle(); 269 base::RunLoop().RunUntilIdle();
291 ASSERT_EQ(0u, reconcilor->GetGaiaAccountsForTesting().size()); 270 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
292 }
293
294 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokens) {
295 signin_manager()->SetAuthenticatedUsername(kTestEmail);
296 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
297
298 AccountReconcilor* reconcilor =
299 AccountReconcilorFactory::GetForProfile(profile());
300 ASSERT_TRUE(reconcilor);
301
302 reconcilor->ValidateAccountsFromTokenService();
303 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
304
305 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
306 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
307 token_service()->IssueTokenForAllPendingRequests("access_token",
308 base::Time::Now() + base::TimeDelta::FromHours(1));
309
310 base::RunLoop().RunUntilIdle();
311 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
312 ASSERT_EQ(1u, reconcilor->GetValidChromeAccountsForTesting().size());
313 ASSERT_EQ(0u, reconcilor->GetInvalidChromeAccountsForTesting().size());
314 }
315
316 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedUserInfo) {
317 signin_manager()->SetAuthenticatedUsername(kTestEmail);
318 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
319
320 AccountReconcilor* reconcilor =
321 AccountReconcilorFactory::GetForProfile(profile());
322 ASSERT_TRUE(reconcilor);
323
324 reconcilor->ValidateAccountsFromTokenService();
325 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
326
327 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
328 "", net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
329 token_service()->IssueTokenForAllPendingRequests("access_token",
330 base::Time::Now() + base::TimeDelta::FromHours(1));
331
332 base::RunLoop().RunUntilIdle();
333 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
334 ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size());
335 ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size());
336 }
337
338 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedTokenRequest) {
339 signin_manager()->SetAuthenticatedUsername(kTestEmail);
340 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
341
342 AccountReconcilor* reconcilor =
343 AccountReconcilorFactory::GetForProfile(profile());
344 ASSERT_TRUE(reconcilor);
345
346 reconcilor->ValidateAccountsFromTokenService();
347 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
348
349 token_service()->IssueErrorForAllPendingRequests(
350 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
351
352 base::RunLoop().RunUntilIdle();
353 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
354 ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size());
355 ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size());
356 } 271 }
357 272
358 TEST_P(AccountReconcilorTest, StartReconcileNoop) { 273 TEST_P(AccountReconcilorTest, StartReconcileNoop) {
359 signin_manager()->SetAuthenticatedUsername(kTestEmail); 274 signin_manager()->SetAuthenticatedUsername(kTestEmail);
360 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); 275 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
361 276
362 AccountReconcilor* reconcilor = 277 AccountReconcilor* reconcilor =
363 AccountReconcilorFactory::GetForProfile(profile()); 278 AccountReconcilorFactory::GetForProfile(profile());
364 ASSERT_TRUE(reconcilor); 279 ASSERT_TRUE(reconcilor);
365 280
366 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 281 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
367 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 282 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
368 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 283 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
369 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
370 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
371 284
372 reconcilor->StartReconcile(); 285 reconcilor->StartReconcile();
286 ASSERT_TRUE(reconcilor->is_reconcile_started_);
373 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 287 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
374 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
375 288
376 base::RunLoop().RunUntilIdle(); 289 base::RunLoop().RunUntilIdle();
377 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
378 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size());
379 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
380
381 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
382 base::Time::Now() + base::TimeDelta::FromHours(1));
383
384 base::RunLoop().RunUntilIdle();
385 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
386 ASSERT_FALSE(reconcilor->is_reconcile_started_); 290 ASSERT_FALSE(reconcilor->is_reconcile_started_);
387 291
388 histogram_tester()->ExpectTotalCount( 292 histogram_tester()->ExpectTotalCount(
389 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); 293 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
390 histogram_tester()->ExpectUniqueSample( 294 histogram_tester()->ExpectUniqueSample(
391 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 295 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
392 signin_metrics::ACCOUNTS_SAME, 296 signin_metrics::ACCOUNTS_SAME,
393 1); 297 1);
394 } 298 }
395 299
396 // This is test is needed until chrome changes to use gaia obfuscated id. 300 // This is test is needed until chrome changes to use gaia obfuscated id.
397 // The signin manager and token service use the gaia "email" property, which 301 // The signin manager and token service use the gaia "email" property, which
398 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() 302 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData()
399 // however uses gaia "displayEmail" which does not preserve case, and then 303 // however uses gaia "displayEmail" which does not preserve case, and then
400 // passes the string through gaia::CanonicalizeEmail() which removes dots. This 304 // passes the string through gaia::CanonicalizeEmail() which removes dots. This
401 // tests makes sure that an email like "Dot.S@hmail.com", as seen by the 305 // tests makes sure that an email like "Dot.S@hmail.com", as seen by the
402 // token service, will be considered the same as "dots@gmail.com" as returned 306 // token service, will be considered the same as "dots@gmail.com" as returned
403 // by gaia::ParseListAccountsData(). 307 // by gaia::ParseListAccountsData().
404 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { 308 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) {
405 signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com"); 309 signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com");
406 token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token"); 310 token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token");
407 311
408 AccountReconcilor* reconcilor = 312 AccountReconcilor* reconcilor =
409 AccountReconcilorFactory::GetForProfile(profile()); 313 AccountReconcilorFactory::GetForProfile(profile());
410 ASSERT_TRUE(reconcilor); 314 ASSERT_TRUE(reconcilor);
411 315
412 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 316 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
413 "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 317 "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
414 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 318 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
415 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
416 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
417 319
418 reconcilor->StartReconcile(); 320 reconcilor->StartReconcile();
419 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 321 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
420 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
421 322
422 base::RunLoop().RunUntilIdle(); 323 base::RunLoop().RunUntilIdle();
423 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
424 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size());
425 ASSERT_STREQ("dots@gmail.com",
426 reconcilor->GetGaiaAccountsForTesting()[0].first.c_str());
427 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
428
429 token_service()->IssueAllTokensForAccount("Dot.S@gmail.com", "access_token",
430 base::Time::Now() + base::TimeDelta::FromHours(1));
431
432 base::RunLoop().RunUntilIdle();
433 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
434 ASSERT_FALSE(reconcilor->is_reconcile_started_); 324 ASSERT_FALSE(reconcilor->is_reconcile_started_);
435 325
436 histogram_tester()->ExpectUniqueSample( 326 histogram_tester()->ExpectUniqueSample(
437 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 327 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
438 signin_metrics::ACCOUNTS_SAME, 328 signin_metrics::ACCOUNTS_SAME,
439 1); 329 1);
440 } 330 }
441 331
442 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { 332 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) {
443 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 333 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
444 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 334 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
445 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 335 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
446 336
447 AccountReconcilor* reconcilor = 337 AccountReconcilor* reconcilor =
448 AccountReconcilorFactory::GetForProfile(profile()); 338 AccountReconcilorFactory::GetForProfile(profile());
449 ASSERT_TRUE(reconcilor); 339 ASSERT_TRUE(reconcilor);
450 340
451 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 341 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
452 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 342 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
453 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 343 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
454 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 344 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
455 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
456 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
457 345
458 reconcilor->StartReconcile(); 346 reconcilor->StartReconcile();
459 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 347 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
460 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
461
462 base::RunLoop().RunUntilIdle(); 348 base::RunLoop().RunUntilIdle();
463 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
464 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
465 ASSERT_EQ(2u, reconcilor->GetGaiaAccountsForTesting().size());
466
467 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
468 base::Time::Now() + base::TimeDelta::FromHours(1));
469
470 base::RunLoop().RunUntilIdle();
471 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
472
473 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
474 base::Time::Now() + base::TimeDelta::FromHours(1));
475
476 base::RunLoop().RunUntilIdle();
477 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
478 ASSERT_FALSE(reconcilor->is_reconcile_started_); 349 ASSERT_FALSE(reconcilor->is_reconcile_started_);
479 350
480 histogram_tester()->ExpectTotalCount( 351 histogram_tester()->ExpectTotalCount(
481 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); 352 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
482 histogram_tester()->ExpectUniqueSample( 353 histogram_tester()->ExpectUniqueSample(
483 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 354 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
484 signin_metrics::ACCOUNTS_SAME, 355 signin_metrics::ACCOUNTS_SAME,
485 1); 356 1);
486 } 357 }
487 358
488 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { 359 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
489 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 360 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
490 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 361 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
491 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 362 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
492 363
493 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); 364 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
494 365
495 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 366 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
496 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 367 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
497 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 368 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
498 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
499 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
500 369
501 AccountReconcilor* reconcilor = GetMockReconcilor(); 370 AccountReconcilor* reconcilor = GetMockReconcilor();
502 reconcilor->StartReconcile(); 371 reconcilor->StartReconcile();
503 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
504 base::Time::Now() + base::TimeDelta::FromHours(1));
505 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
506 base::Time::Now() + base::TimeDelta::FromHours(1));
507 372
508 base::RunLoop().RunUntilIdle(); 373 base::RunLoop().RunUntilIdle();
509 ASSERT_TRUE(reconcilor->is_reconcile_started_); 374 ASSERT_TRUE(reconcilor->is_reconcile_started_);
510 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", 375 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com",
511 GoogleServiceAuthError::AuthErrorNone()); 376 GoogleServiceAuthError::AuthErrorNone());
512 ASSERT_FALSE(reconcilor->is_reconcile_started_); 377 ASSERT_FALSE(reconcilor->is_reconcile_started_);
513 378
514 histogram_tester()->ExpectUniqueSample( 379 histogram_tester()->ExpectUniqueSample(
515 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 380 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
516 signin_metrics::ACCOUNTS_SAME, 381 signin_metrics::ACCOUNTS_SAME,
517 1); 382 1);
518 histogram_tester()->ExpectUniqueSample( 383 histogram_tester()->ExpectUniqueSample(
519 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 384 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
520 histogram_tester()->ExpectUniqueSample( 385 histogram_tester()->ExpectUniqueSample(
521 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); 386 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
Mike Lerman 2014/09/23 14:27:47 All of these references to the AddedToChrome metri
Roger Tawa OOO till Jul 10th 2014/09/23 21:25:58 Doh! I meant to fix this before submitting and fo
522 } 387 }
523 388
524 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { 389 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
525 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 390 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
526 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 391 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
527 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 392 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
528 393
529 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); 394 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
530 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); 395 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com"));
531 396
532 SetFakeResponse( 397 SetFakeResponse(
533 GaiaUrls::GetInstance()->list_accounts_url().spec(), 398 GaiaUrls::GetInstance()->list_accounts_url().spec(),
534 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 399 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
535 net::HTTP_OK, 400 net::HTTP_OK,
536 net::URLRequestStatus::SUCCESS); 401 net::URLRequestStatus::SUCCESS);
537 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
538 "{\"id\":\"foo\"}",
539 net::HTTP_OK,
540 net::URLRequestStatus::SUCCESS);
541 402
542 AccountReconcilor* reconcilor = GetMockReconcilor(); 403 AccountReconcilor* reconcilor = GetMockReconcilor();
543 reconcilor->StartReconcile(); 404 reconcilor->StartReconcile();
544 token_service()->IssueAllTokensForAccount(
545 "other@gmail.com",
546 "access_token",
547 base::Time::Now() + base::TimeDelta::FromHours(1));
548 token_service()->IssueAllTokensForAccount(
549 "user@gmail.com",
550 "access_token",
551 base::Time::Now() + base::TimeDelta::FromHours(1));
552 405
553 base::RunLoop().RunUntilIdle(); 406 base::RunLoop().RunUntilIdle();
554 ASSERT_TRUE(reconcilor->is_reconcile_started_); 407 ASSERT_TRUE(reconcilor->is_reconcile_started_);
555 SimulateMergeSessionCompleted( 408 SimulateMergeSessionCompleted(
556 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); 409 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone());
557 ASSERT_FALSE(reconcilor->is_reconcile_started_); 410 ASSERT_FALSE(reconcilor->is_reconcile_started_);
558 411
559 histogram_tester()->ExpectUniqueSample( 412 histogram_tester()->ExpectUniqueSample(
560 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 413 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
561 signin_metrics::ACCOUNTS_SAME, 414 signin_metrics::ACCOUNTS_SAME,
562 1); 415 1);
563 histogram_tester()->ExpectUniqueSample( 416 histogram_tester()->ExpectUniqueSample(
564 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 417 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
565 histogram_tester()->ExpectUniqueSample( 418 histogram_tester()->ExpectUniqueSample(
566 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); 419 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
567 420
568 // Do another pass after I've added a third account to the token service 421 // Do another pass after I've added a third account to the token service
569 422
570 SetFakeResponse( 423 SetFakeResponse(
571 GaiaUrls::GetInstance()->list_accounts_url().spec(), 424 GaiaUrls::GetInstance()->list_accounts_url().spec(),
572 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 425 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
573 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 426 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
574 net::HTTP_OK, 427 net::HTTP_OK,
575 net::URLRequestStatus::SUCCESS); 428 net::URLRequestStatus::SUCCESS);
576 // This will cause the reconcilor to fire. 429 // This will cause the reconcilor to fire.
577 token_service()->UpdateCredentials("third@gmail.com", "refresh_token"); 430 token_service()->UpdateCredentials("third@gmail.com", "refresh_token");
578 431
579 token_service()->IssueAllTokensForAccount(
580 "other@gmail.com",
581 "access_token",
582 base::Time::Now() + base::TimeDelta::FromHours(1));
583 token_service()->IssueAllTokensForAccount(
584 "user@gmail.com",
585 "access_token",
586 base::Time::Now() + base::TimeDelta::FromHours(1));
587 token_service()->IssueAllTokensForAccount(
588 "third@gmail.com",
589 "access_token",
590 base::Time::Now() + base::TimeDelta::FromHours(1));
591
592 base::RunLoop().RunUntilIdle(); 432 base::RunLoop().RunUntilIdle();
593 433
594 ASSERT_TRUE(reconcilor->is_reconcile_started_); 434 ASSERT_TRUE(reconcilor->is_reconcile_started_);
595 SimulateMergeSessionCompleted( 435 SimulateMergeSessionCompleted(
596 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); 436 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone());
597 ASSERT_FALSE(reconcilor->is_reconcile_started_); 437 ASSERT_FALSE(reconcilor->is_reconcile_started_);
598 438
599 histogram_tester()->ExpectUniqueSample( 439 histogram_tester()->ExpectUniqueSample(
600 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 440 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
601 signin_metrics::ACCOUNTS_SAME, 441 signin_metrics::ACCOUNTS_SAME,
602 1); 442 1);
603 histogram_tester()->ExpectUniqueSample( 443 histogram_tester()->ExpectUniqueSample(
604 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 444 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
605 histogram_tester()->ExpectUniqueSample( 445 histogram_tester()->ExpectUniqueSample(
606 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); 446 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
607 histogram_tester()->ExpectUniqueSample( 447 histogram_tester()->ExpectUniqueSample(
608 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", 448 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun",
609 signin_metrics::ACCOUNTS_SAME, 449 signin_metrics::ACCOUNTS_SAME,
610 1); 450 1);
611 histogram_tester()->ExpectUniqueSample( 451 histogram_tester()->ExpectUniqueSample(
612 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); 452 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1);
613 histogram_tester()->ExpectUniqueSample( 453 histogram_tester()->ExpectUniqueSample(
614 "Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1); 454 "Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1);
615 } 455 }
616 456
617 TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) {
618 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
619 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
620
621 EXPECT_CALL(*GetMockReconcilor(),
622 PerformAddToChromeAction("other@gmail.com", 1, ""));
623
624 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
625 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
626 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
627 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
628 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
629 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
630
631 AccountReconcilor* reconcilor = GetMockReconcilor();
632 reconcilor->StartReconcile();
633 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
634 base::Time::Now() + base::TimeDelta::FromHours(1));
635
636 base::RunLoop().RunUntilIdle();
637 ASSERT_TRUE(reconcilor->is_reconcile_started_);
638 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", "");
639 ASSERT_FALSE(reconcilor->is_reconcile_started_);
640
641 histogram_tester()->ExpectUniqueSample(
642 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
643 signin_metrics::ACCOUNTS_SAME,
644 1);
645 histogram_tester()->ExpectUniqueSample(
646 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1);
647 histogram_tester()->ExpectUniqueSample(
648 "Signin.Reconciler.AddedToChrome.FirstRun", 1, 1);
649 }
650
651 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { 457 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
652 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 458 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
653 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 459 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
654 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 460 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
655 461
656 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); 462 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
657 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); 463 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
658 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); 464 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
659 465
660 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 466 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
661 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 467 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
662 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 468 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
663 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 469 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
664 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
665 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
666 470
667 AccountReconcilor* reconcilor = GetMockReconcilor(); 471 AccountReconcilor* reconcilor = GetMockReconcilor();
668 reconcilor->StartReconcile(); 472 reconcilor->StartReconcile();
669 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
670 base::Time::Now() + base::TimeDelta::FromHours(1));
671 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
672 base::Time::Now() + base::TimeDelta::FromHours(1));
673 473
674 base::RunLoop().RunUntilIdle(); 474 base::RunLoop().RunUntilIdle();
675 ASSERT_TRUE(reconcilor->is_reconcile_started_); 475 ASSERT_TRUE(reconcilor->is_reconcile_started_);
676 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", 476 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com",
677 GoogleServiceAuthError::AuthErrorNone()); 477 GoogleServiceAuthError::AuthErrorNone());
678 ASSERT_TRUE(reconcilor->is_reconcile_started_); 478 ASSERT_TRUE(reconcilor->is_reconcile_started_);
679 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 479 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
680 GoogleServiceAuthError::AuthErrorNone()); 480 GoogleServiceAuthError::AuthErrorNone());
681 ASSERT_FALSE(reconcilor->is_reconcile_started_); 481 ASSERT_FALSE(reconcilor->is_reconcile_started_);
682 482
(...skipping 11 matching lines...) Expand all
694 signin_manager()->SetAuthenticatedUsername(kTestEmail); 494 signin_manager()->SetAuthenticatedUsername(kTestEmail);
695 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); 495 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
696 496
697 AccountReconcilor* reconcilor = 497 AccountReconcilor* reconcilor =
698 AccountReconcilorFactory::GetForProfile(profile()); 498 AccountReconcilorFactory::GetForProfile(profile());
699 ASSERT_TRUE(reconcilor); 499 ASSERT_TRUE(reconcilor);
700 500
701 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 501 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
702 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 502 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
703 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 503 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
704 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
705 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
706 504
707 ASSERT_FALSE(reconcilor->is_reconcile_started_); 505 ASSERT_FALSE(reconcilor->is_reconcile_started_);
708 reconcilor->StartReconcile(); 506 reconcilor->StartReconcile();
709 ASSERT_TRUE(reconcilor->is_reconcile_started_); 507 ASSERT_TRUE(reconcilor->is_reconcile_started_);
710 508
711 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
712 base::Time::Now() + base::TimeDelta::FromHours(1));
713
714 base::RunLoop().RunUntilIdle(); 509 base::RunLoop().RunUntilIdle();
715 ASSERT_FALSE(reconcilor->is_reconcile_started_); 510 ASSERT_FALSE(reconcilor->is_reconcile_started_);
716 } 511 }
717 512
718 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { 513 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) {
719 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 514 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
720 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 515 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
721 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 516 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
722 517
723 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); 518 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
724 519
725 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 520 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
726 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]," 521 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0],"
727 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 522 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
728 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 523 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
729 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
730 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
731 524
732 AccountReconcilor* reconcilor = 525 AccountReconcilor* reconcilor =
733 AccountReconcilorFactory::GetForProfile(profile()); 526 AccountReconcilorFactory::GetForProfile(profile());
734 ASSERT_TRUE(reconcilor); 527 ASSERT_TRUE(reconcilor);
735 528
736 ASSERT_FALSE(reconcilor->is_reconcile_started_); 529 ASSERT_FALSE(reconcilor->is_reconcile_started_);
737 reconcilor->StartReconcile(); 530 reconcilor->StartReconcile();
738 ASSERT_TRUE(reconcilor->is_reconcile_started_); 531 ASSERT_TRUE(reconcilor->is_reconcile_started_);
739 532
740 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
741 base::Time::Now() + base::TimeDelta::FromHours(1));
742 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
743 base::Time::Now() + base::TimeDelta::FromHours(1));
744
745 base::RunLoop().RunUntilIdle(); 533 base::RunLoop().RunUntilIdle();
746 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 534 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
747 GoogleServiceAuthError::AuthErrorNone()); 535 GoogleServiceAuthError::AuthErrorNone());
748 ASSERT_FALSE(reconcilor->is_reconcile_started_); 536 ASSERT_FALSE(reconcilor->is_reconcile_started_);
749 } 537 }
750 538
751 TEST_F(AccountReconcilorTest, MergeSessionCompletedWithBogusAccount) { 539 TEST_F(AccountReconcilorTest, MergeSessionCompletedWithBogusAccount) {
752 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 540 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
753 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 541 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
754 542
755 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); 543 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
756 544
757 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 545 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
758 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", 546 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]",
759 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 547 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
760 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
761 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
762 548
763 AccountReconcilor* reconcilor = 549 AccountReconcilor* reconcilor =
764 AccountReconcilorFactory::GetForProfile(profile()); 550 AccountReconcilorFactory::GetForProfile(profile());
765 ASSERT_TRUE(reconcilor); 551 ASSERT_TRUE(reconcilor);
766 552
767 ASSERT_FALSE(reconcilor->is_reconcile_started_); 553 ASSERT_FALSE(reconcilor->is_reconcile_started_);
768 reconcilor->StartReconcile(); 554 reconcilor->StartReconcile();
769 ASSERT_TRUE(reconcilor->is_reconcile_started_); 555 ASSERT_TRUE(reconcilor->is_reconcile_started_);
770 556
771 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
772 base::Time::Now() + base::TimeDelta::FromHours(1));
773 base::RunLoop().RunUntilIdle(); 557 base::RunLoop().RunUntilIdle();
774 558
775 // If an unknown account id is sent, it should not upset the state. 559 // If an unknown account id is sent, it should not upset the state.
776 SimulateMergeSessionCompleted(reconcilor, "bogus@gmail.com", 560 SimulateMergeSessionCompleted(reconcilor, "bogus@gmail.com",
777 GoogleServiceAuthError::AuthErrorNone()); 561 GoogleServiceAuthError::AuthErrorNone());
778 ASSERT_TRUE(reconcilor->is_reconcile_started_); 562 ASSERT_TRUE(reconcilor->is_reconcile_started_);
779 563
780 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 564 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
781 GoogleServiceAuthError::AuthErrorNone()); 565 GoogleServiceAuthError::AuthErrorNone());
782 ASSERT_FALSE(reconcilor->is_reconcile_started_); 566 ASSERT_FALSE(reconcilor->is_reconcile_started_);
783 } 567 }
784 568
785 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, 569 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled,
786 AccountReconcilorTest, 570 AccountReconcilorTest,
787 testing::Bool()); 571 testing::Bool());
788 572
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698