| OLD | NEW |
| 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/time/time.h" | 10 #include "base/time/time.h" |
| 10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 11 #include "chrome/browser/prefs/pref_service_syncable.h" | 12 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 12 #include "chrome/browser/signin/account_reconcilor_factory.h" | 13 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 13 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 14 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 14 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 15 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 15 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 16 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 16 #include "chrome/browser/signin/fake_signin_manager.h" | 17 #include "chrome/browser/signin/fake_signin_manager.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/signin/test_signin_client_builder.h" | 20 #include "chrome/browser/signin/test_signin_client_builder.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 22 #include "chrome/test/base/testing_profile_manager.h" | 23 #include "chrome/test/base/testing_profile_manager.h" |
| 23 #include "chrome/test/base/uma_histogram_helper.h" | |
| 24 #include "components/signin/core/browser/account_reconcilor.h" | 24 #include "components/signin/core/browser/account_reconcilor.h" |
| 25 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 25 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 26 #include "components/signin/core/browser/signin_manager.h" | 26 #include "components/signin/core/browser/signin_manager.h" |
| 27 #include "components/signin/core/browser/signin_metrics.h" | 27 #include "components/signin/core/browser/signin_metrics.h" |
| 28 #include "components/signin/core/common/profile_management_switches.h" | 28 #include "components/signin/core/common/profile_management_switches.h" |
| 29 #include "components/signin/core/common/signin_switches.h" | 29 #include "components/signin/core/common/signin_switches.h" |
| 30 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
| 31 #include "google_apis/gaia/gaia_urls.h" | 31 #include "google_apis/gaia/gaia_urls.h" |
| 32 #include "net/url_request/test_url_fetcher_factory.h" | 32 #include "net/url_request/test_url_fetcher_factory.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const char kTestEmail[] = "user@gmail.com"; | 38 const char kTestEmail[] = "user@gmail.com"; |
| 39 const char* const kHistogramsToSnapshot[] = { | |
| 40 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | |
| 41 "Signin.Reconciler.AddedToCookieJar.FirstRun", | |
| 42 "Signin.Reconciler.AddedToChrome.FirstRun", | |
| 43 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", | |
| 44 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", | |
| 45 "Signin.Reconciler.AddedToChrome.SubsequentRun"}; | |
| 46 | 39 |
| 47 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { | 40 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { |
| 48 public: | 41 public: |
| 49 static KeyedService* Build(content::BrowserContext* context); | 42 static KeyedService* Build(content::BrowserContext* context); |
| 50 | 43 |
| 51 MockAccountReconcilor(ProfileOAuth2TokenService* token_service, | 44 MockAccountReconcilor(ProfileOAuth2TokenService* token_service, |
| 52 SigninManagerBase* signin_manager, | 45 SigninManagerBase* signin_manager, |
| 53 SigninClient* client); | 46 SigninClient* client); |
| 54 virtual ~MockAccountReconcilor() {} | 47 virtual ~MockAccountReconcilor() {} |
| 55 | 48 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } // namespace | 86 } // namespace |
| 94 | 87 |
| 95 class AccountReconcilorTest : public ::testing::TestWithParam<bool> { | 88 class AccountReconcilorTest : public ::testing::TestWithParam<bool> { |
| 96 public: | 89 public: |
| 97 AccountReconcilorTest(); | 90 AccountReconcilorTest(); |
| 98 virtual void SetUp() OVERRIDE; | 91 virtual void SetUp() OVERRIDE; |
| 99 | 92 |
| 100 TestingProfile* profile() { return profile_; } | 93 TestingProfile* profile() { return profile_; } |
| 101 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } | 94 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } |
| 102 FakeProfileOAuth2TokenService* token_service() { return token_service_; } | 95 FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
| 103 UMAHistogramHelper* histogram_helper() { return &histogram_helper_; } | 96 base::HistogramTester* histogram_tester() { return &histogram_tester_; } |
| 104 | 97 |
| 105 void SetFakeResponse(const std::string& url, | 98 void SetFakeResponse(const std::string& url, |
| 106 const std::string& data, | 99 const std::string& data, |
| 107 net::HttpStatusCode code, | 100 net::HttpStatusCode code, |
| 108 net::URLRequestStatus::Status status) { | 101 net::URLRequestStatus::Status status) { |
| 109 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); | 102 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); |
| 110 } | 103 } |
| 111 | 104 |
| 112 MockAccountReconcilor* GetMockReconcilor(); | 105 MockAccountReconcilor* GetMockReconcilor(); |
| 113 | 106 |
| 114 void SimulateMergeSessionCompleted( | 107 void SimulateMergeSessionCompleted( |
| 115 MergeSessionHelper::Observer* observer, | 108 MergeSessionHelper::Observer* observer, |
| 116 const std::string& account_id, | 109 const std::string& account_id, |
| 117 const GoogleServiceAuthError& error); | 110 const GoogleServiceAuthError& error); |
| 118 | 111 |
| 119 void SimulateRefreshTokenFetched( | 112 void SimulateRefreshTokenFetched( |
| 120 AccountReconcilor* reconcilor, | 113 AccountReconcilor* reconcilor, |
| 121 const std::string& account_id, | 114 const std::string& account_id, |
| 122 const std::string& refresh_token); | 115 const std::string& refresh_token); |
| 123 | 116 |
| 124 private: | 117 private: |
| 125 content::TestBrowserThreadBundle bundle_; | 118 content::TestBrowserThreadBundle bundle_; |
| 126 TestingProfile* profile_; | 119 TestingProfile* profile_; |
| 127 FakeSigninManagerForTesting* signin_manager_; | 120 FakeSigninManagerForTesting* signin_manager_; |
| 128 FakeProfileOAuth2TokenService* token_service_; | 121 FakeProfileOAuth2TokenService* token_service_; |
| 129 MockAccountReconcilor* mock_reconcilor_; | 122 MockAccountReconcilor* mock_reconcilor_; |
| 130 net::FakeURLFetcherFactory url_fetcher_factory_; | 123 net::FakeURLFetcherFactory url_fetcher_factory_; |
| 131 scoped_ptr<TestingProfileManager> testing_profile_manager_; | 124 scoped_ptr<TestingProfileManager> testing_profile_manager_; |
| 132 UMAHistogramHelper histogram_helper_; | 125 base::HistogramTester histogram_tester_; |
| 133 | 126 |
| 134 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest); | 127 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest); |
| 135 }; | 128 }; |
| 136 | 129 |
| 137 AccountReconcilorTest::AccountReconcilorTest() | 130 AccountReconcilorTest::AccountReconcilorTest() |
| 138 : signin_manager_(NULL), | 131 : signin_manager_(NULL), |
| 139 token_service_(NULL), | 132 token_service_(NULL), |
| 140 mock_reconcilor_(NULL), | 133 mock_reconcilor_(NULL), |
| 141 url_fetcher_factory_(NULL) {} | 134 url_fetcher_factory_(NULL) {} |
| 142 | 135 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 168 base::UTF8ToUTF16("name"), 0, std::string(), | 161 base::UTF8ToUTF16("name"), 0, std::string(), |
| 169 factories); | 162 factories); |
| 170 | 163 |
| 171 signin_manager_ = | 164 signin_manager_ = |
| 172 static_cast<FakeSigninManagerForTesting*>( | 165 static_cast<FakeSigninManagerForTesting*>( |
| 173 SigninManagerFactory::GetForProfile(profile())); | 166 SigninManagerFactory::GetForProfile(profile())); |
| 174 | 167 |
| 175 token_service_ = | 168 token_service_ = |
| 176 static_cast<FakeProfileOAuth2TokenService*>( | 169 static_cast<FakeProfileOAuth2TokenService*>( |
| 177 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); | 170 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); |
| 178 | |
| 179 // Take a new snapshot of the concerned histograms before each test | |
| 180 histogram_helper_.PrepareSnapshot(kHistogramsToSnapshot, | |
| 181 arraysize(kHistogramsToSnapshot)); | |
| 182 } | 171 } |
| 183 | 172 |
| 184 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { | 173 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { |
| 185 if (!mock_reconcilor_) { | 174 if (!mock_reconcilor_) { |
| 186 mock_reconcilor_ = | 175 mock_reconcilor_ = |
| 187 static_cast<MockAccountReconcilor*>( | 176 static_cast<MockAccountReconcilor*>( |
| 188 AccountReconcilorFactory::GetForProfile(profile())); | 177 AccountReconcilorFactory::GetForProfile(profile())); |
| 189 } | 178 } |
| 190 | 179 |
| 191 return mock_reconcilor_; | 180 return mock_reconcilor_; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size()); | 378 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size()); |
| 390 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | 379 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); |
| 391 | 380 |
| 392 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | 381 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 393 base::Time::Now() + base::TimeDelta::FromHours(1)); | 382 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 394 | 383 |
| 395 base::RunLoop().RunUntilIdle(); | 384 base::RunLoop().RunUntilIdle(); |
| 396 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | 385 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); |
| 397 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 386 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 398 | 387 |
| 399 histogram_helper()->Fetch(); | 388 histogram_tester()->ExpectTotalCount( |
| 400 histogram_helper()->ExpectTotalCount( | |
| 401 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); | 389 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); |
| 402 histogram_helper()->ExpectUniqueSample( | 390 histogram_tester()->ExpectUniqueSample( |
| 403 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 391 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 404 signin_metrics::ACCOUNTS_SAME, | 392 signin_metrics::ACCOUNTS_SAME, |
| 405 1); | 393 1); |
| 406 } | 394 } |
| 407 | 395 |
| 408 // This is test is needed until chrome changes to use gaia obfuscated id. | 396 // This is test is needed until chrome changes to use gaia obfuscated id. |
| 409 // The signin manager and token service use the gaia "email" property, which | 397 // The signin manager and token service use the gaia "email" property, which |
| 410 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() | 398 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() |
| 411 // however uses gaia "displayEmail" which does not preserve case, and then | 399 // however uses gaia "displayEmail" which does not preserve case, and then |
| 412 // passes the string through gaia::CanonicalizeEmail() which removes dots. This | 400 // passes the string through gaia::CanonicalizeEmail() which removes dots. This |
| (...skipping 25 matching lines...) Expand all Loading... |
| 438 reconcilor->GetGaiaAccountsForTesting()[0].first.c_str()); | 426 reconcilor->GetGaiaAccountsForTesting()[0].first.c_str()); |
| 439 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | 427 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); |
| 440 | 428 |
| 441 token_service()->IssueAllTokensForAccount("Dot.S@gmail.com", "access_token", | 429 token_service()->IssueAllTokensForAccount("Dot.S@gmail.com", "access_token", |
| 442 base::Time::Now() + base::TimeDelta::FromHours(1)); | 430 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 443 | 431 |
| 444 base::RunLoop().RunUntilIdle(); | 432 base::RunLoop().RunUntilIdle(); |
| 445 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | 433 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); |
| 446 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 434 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 447 | 435 |
| 448 histogram_helper()->Fetch(); | 436 histogram_tester()->ExpectUniqueSample( |
| 449 histogram_helper()->ExpectUniqueSample( | |
| 450 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 437 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 451 signin_metrics::ACCOUNTS_SAME, | 438 signin_metrics::ACCOUNTS_SAME, |
| 452 1); | 439 1); |
| 453 } | 440 } |
| 454 | 441 |
| 455 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { | 442 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { |
| 456 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 443 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 457 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 444 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 458 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 445 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 459 | 446 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 483 base::RunLoop().RunUntilIdle(); | 470 base::RunLoop().RunUntilIdle(); |
| 484 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | 471 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); |
| 485 | 472 |
| 486 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | 473 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 487 base::Time::Now() + base::TimeDelta::FromHours(1)); | 474 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 488 | 475 |
| 489 base::RunLoop().RunUntilIdle(); | 476 base::RunLoop().RunUntilIdle(); |
| 490 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | 477 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); |
| 491 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 478 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 492 | 479 |
| 493 histogram_helper()->Fetch(); | 480 histogram_tester()->ExpectTotalCount( |
| 494 histogram_helper()->ExpectTotalCount( | |
| 495 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); | 481 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); |
| 496 histogram_helper()->ExpectUniqueSample( | 482 histogram_tester()->ExpectUniqueSample( |
| 497 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 483 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 498 signin_metrics::ACCOUNTS_SAME, | 484 signin_metrics::ACCOUNTS_SAME, |
| 499 1); | 485 1); |
| 500 } | 486 } |
| 501 | 487 |
| 502 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { | 488 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { |
| 503 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 489 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 504 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 490 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 505 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 491 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 506 | 492 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 518 base::Time::Now() + base::TimeDelta::FromHours(1)); | 504 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 519 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | 505 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 520 base::Time::Now() + base::TimeDelta::FromHours(1)); | 506 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 521 | 507 |
| 522 base::RunLoop().RunUntilIdle(); | 508 base::RunLoop().RunUntilIdle(); |
| 523 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 509 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 524 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", | 510 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", |
| 525 GoogleServiceAuthError::AuthErrorNone()); | 511 GoogleServiceAuthError::AuthErrorNone()); |
| 526 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 512 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 527 | 513 |
| 528 histogram_helper()->Fetch(); | 514 histogram_tester()->ExpectUniqueSample( |
| 529 histogram_helper()->ExpectUniqueSample( | |
| 530 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 515 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 531 signin_metrics::ACCOUNTS_SAME, | 516 signin_metrics::ACCOUNTS_SAME, |
| 532 1); | 517 1); |
| 533 histogram_helper()->ExpectUniqueSample( | 518 histogram_tester()->ExpectUniqueSample( |
| 534 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); | 519 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
| 535 histogram_helper()->ExpectUniqueSample( | 520 histogram_tester()->ExpectUniqueSample( |
| 536 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); | 521 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); |
| 537 } | 522 } |
| 538 | 523 |
| 539 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { | 524 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { |
| 540 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 525 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 541 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 526 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 542 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 527 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 543 | 528 |
| 544 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 529 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
| 545 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); | 530 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 564 "user@gmail.com", | 549 "user@gmail.com", |
| 565 "access_token", | 550 "access_token", |
| 566 base::Time::Now() + base::TimeDelta::FromHours(1)); | 551 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 567 | 552 |
| 568 base::RunLoop().RunUntilIdle(); | 553 base::RunLoop().RunUntilIdle(); |
| 569 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 554 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 570 SimulateMergeSessionCompleted( | 555 SimulateMergeSessionCompleted( |
| 571 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); | 556 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); |
| 572 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 557 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 573 | 558 |
| 574 histogram_helper()->Fetch(); | 559 histogram_tester()->ExpectUniqueSample( |
| 575 histogram_helper()->ExpectUniqueSample( | |
| 576 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 560 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 577 signin_metrics::ACCOUNTS_SAME, | 561 signin_metrics::ACCOUNTS_SAME, |
| 578 1); | 562 1); |
| 579 histogram_helper()->ExpectUniqueSample( | 563 histogram_tester()->ExpectUniqueSample( |
| 580 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); | 564 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
| 581 histogram_helper()->ExpectUniqueSample( | 565 histogram_tester()->ExpectUniqueSample( |
| 582 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); | 566 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); |
| 583 | 567 |
| 584 // Do another pass after I've added a third account to the token service | 568 // Do another pass after I've added a third account to the token service |
| 585 | 569 |
| 586 SetFakeResponse( | 570 SetFakeResponse( |
| 587 GaiaUrls::GetInstance()->list_accounts_url().spec(), | 571 GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 588 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | 572 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
| 589 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 573 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 590 net::HTTP_OK, | 574 net::HTTP_OK, |
| 591 net::URLRequestStatus::SUCCESS); | 575 net::URLRequestStatus::SUCCESS); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 605 "access_token", | 589 "access_token", |
| 606 base::Time::Now() + base::TimeDelta::FromHours(1)); | 590 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 607 | 591 |
| 608 base::RunLoop().RunUntilIdle(); | 592 base::RunLoop().RunUntilIdle(); |
| 609 | 593 |
| 610 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 594 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 611 SimulateMergeSessionCompleted( | 595 SimulateMergeSessionCompleted( |
| 612 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); | 596 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); |
| 613 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 597 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 614 | 598 |
| 615 histogram_helper()->Fetch(); | 599 histogram_tester()->ExpectUniqueSample( |
| 616 histogram_helper()->ExpectUniqueSample( | |
| 617 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 600 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 618 signin_metrics::ACCOUNTS_SAME, | 601 signin_metrics::ACCOUNTS_SAME, |
| 619 1); | 602 1); |
| 620 histogram_helper()->ExpectUniqueSample( | 603 histogram_tester()->ExpectUniqueSample( |
| 621 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); | 604 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
| 622 histogram_helper()->ExpectUniqueSample( | 605 histogram_tester()->ExpectUniqueSample( |
| 623 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); | 606 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); |
| 624 histogram_helper()->ExpectUniqueSample( | 607 histogram_tester()->ExpectUniqueSample( |
| 625 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", | 608 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", |
| 626 signin_metrics::ACCOUNTS_SAME, | 609 signin_metrics::ACCOUNTS_SAME, |
| 627 1); | 610 1); |
| 628 histogram_helper()->ExpectUniqueSample( | 611 histogram_tester()->ExpectUniqueSample( |
| 629 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); | 612 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); |
| 630 histogram_helper()->ExpectUniqueSample( | 613 histogram_tester()->ExpectUniqueSample( |
| 631 "Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1); | 614 "Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1); |
| 632 } | 615 } |
| 633 | 616 |
| 634 TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) { | 617 TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) { |
| 635 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 618 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 636 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 619 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 637 | 620 |
| 638 EXPECT_CALL(*GetMockReconcilor(), | 621 EXPECT_CALL(*GetMockReconcilor(), |
| 639 PerformAddToChromeAction("other@gmail.com", 1, "")); | 622 PerformAddToChromeAction("other@gmail.com", 1, "")); |
| 640 | 623 |
| 641 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 624 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 642 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | 625 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
| 643 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 626 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 644 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 627 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 645 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | 628 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", |
| 646 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 629 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 647 | 630 |
| 648 AccountReconcilor* reconcilor = GetMockReconcilor(); | 631 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 649 reconcilor->StartReconcile(); | 632 reconcilor->StartReconcile(); |
| 650 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | 633 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 651 base::Time::Now() + base::TimeDelta::FromHours(1)); | 634 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 652 | 635 |
| 653 base::RunLoop().RunUntilIdle(); | 636 base::RunLoop().RunUntilIdle(); |
| 654 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 637 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 655 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", ""); | 638 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", ""); |
| 656 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 639 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 657 | 640 |
| 658 histogram_helper()->Fetch(); | 641 histogram_tester()->ExpectUniqueSample( |
| 659 histogram_helper()->ExpectUniqueSample( | |
| 660 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 642 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 661 signin_metrics::ACCOUNTS_SAME, | 643 signin_metrics::ACCOUNTS_SAME, |
| 662 1); | 644 1); |
| 663 histogram_helper()->ExpectUniqueSample( | 645 histogram_tester()->ExpectUniqueSample( |
| 664 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); | 646 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); |
| 665 histogram_helper()->ExpectUniqueSample( | 647 histogram_tester()->ExpectUniqueSample( |
| 666 "Signin.Reconciler.AddedToChrome.FirstRun", 1, 1); | 648 "Signin.Reconciler.AddedToChrome.FirstRun", 1, 1); |
| 667 } | 649 } |
| 668 | 650 |
| 669 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { | 651 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { |
| 670 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 652 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 671 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 653 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 672 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 654 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 673 | 655 |
| 674 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); | 656 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); |
| 675 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 657 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 691 | 673 |
| 692 base::RunLoop().RunUntilIdle(); | 674 base::RunLoop().RunUntilIdle(); |
| 693 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 675 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 694 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", | 676 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", |
| 695 GoogleServiceAuthError::AuthErrorNone()); | 677 GoogleServiceAuthError::AuthErrorNone()); |
| 696 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 678 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 697 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", | 679 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
| 698 GoogleServiceAuthError::AuthErrorNone()); | 680 GoogleServiceAuthError::AuthErrorNone()); |
| 699 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 681 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 700 | 682 |
| 701 histogram_helper()->Fetch(); | 683 histogram_tester()->ExpectUniqueSample( |
| 702 histogram_helper()->ExpectUniqueSample( | |
| 703 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 684 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 704 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT, | 685 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT, |
| 705 1); | 686 1); |
| 706 histogram_helper()->ExpectUniqueSample( | 687 histogram_tester()->ExpectUniqueSample( |
| 707 "Signin.Reconciler.AddedToCookieJar.FirstRun", 2, 1); | 688 "Signin.Reconciler.AddedToCookieJar.FirstRun", 2, 1); |
| 708 histogram_helper()->ExpectUniqueSample( | 689 histogram_tester()->ExpectUniqueSample( |
| 709 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); | 690 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); |
| 710 } | 691 } |
| 711 | 692 |
| 712 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { | 693 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { |
| 713 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 694 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 714 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 695 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 715 | 696 |
| 716 AccountReconcilor* reconcilor = | 697 AccountReconcilor* reconcilor = |
| 717 AccountReconcilorFactory::GetForProfile(profile()); | 698 AccountReconcilorFactory::GetForProfile(profile()); |
| 718 ASSERT_TRUE(reconcilor); | 699 ASSERT_TRUE(reconcilor); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 | 779 |
| 799 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", | 780 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
| 800 GoogleServiceAuthError::AuthErrorNone()); | 781 GoogleServiceAuthError::AuthErrorNone()); |
| 801 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 782 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 802 } | 783 } |
| 803 | 784 |
| 804 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, | 785 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, |
| 805 AccountReconcilorTest, | 786 AccountReconcilorTest, |
| 806 testing::Bool()); | 787 testing::Bool()); |
| 807 | 788 |
| OLD | NEW |