Chromium Code Reviews| Index: chrome/browser/signin/account_reconcilor_unittest.cc |
| diff --git a/chrome/browser/signin/account_reconcilor_unittest.cc b/chrome/browser/signin/account_reconcilor_unittest.cc |
| index 26bdac96f60c15fe2d5926664cb46da48ace2bd0..b8485c1120c3875670036fcc2db311cc5ff5274b 100644 |
| --- a/chrome/browser/signin/account_reconcilor_unittest.cc |
| +++ b/chrome/browser/signin/account_reconcilor_unittest.cc |
| @@ -19,10 +19,10 @@ |
| #include "chrome/test/base/testing_browser_process.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "chrome/test/base/testing_profile_manager.h" |
| +#include "chrome/test/base/uma_histogram_helper.h" |
| #include "components/signin/core/browser/account_reconcilor.h" |
| #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| #include "components/signin/core/browser/signin_manager.h" |
| -//#include "components/signin/core/browser/test_signin_client.h" |
| #include "components/signin/core/common/signin_switches.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
| #include "google_apis/gaia/gaia_urls.h" |
| @@ -33,6 +33,14 @@ |
| namespace { |
| const char kTestEmail[] = "user@gmail.com"; |
| +const int kNumHistogramsForSnapshot = 6; |
|
Alexei Svitkine (slow)
2014/06/12 17:09:11
You don't need this. Just use [] below and use arr
Mike Lerman
2014/06/12 18:12:15
Done.
|
| +const char* histograms_to_snapshot[kNumHistogramsForSnapshot] = { |
|
Alexei Svitkine (slow)
2014/06/12 17:09:11
kHistogramsToSnapshot?
Mike Lerman
2014/06/12 18:12:15
Done.
|
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| + "Signin.Reconciler.AddedToCookieJar.FirstRun", |
| + "Signin.Reconciler.AddedToChrome.FirstRun", |
| + "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", |
| + "Signin.Reconciler.AddedToCookieJar.SubsequentRun", |
| + "Signin.Reconciler.AddedToChrome.SubsequentRun"}; |
| class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { |
| public: |
| @@ -76,7 +84,7 @@ MockAccountReconcilor::MockAccountReconcilor( |
| } // namespace |
| -class AccountReconcilorTest : public testing::Test { |
| +class AccountReconcilorTest : public ::testing::TestWithParam<bool> { |
| public: |
| AccountReconcilorTest(); |
| virtual void SetUp() OVERRIDE; |
| @@ -84,6 +92,7 @@ class AccountReconcilorTest : public testing::Test { |
| TestingProfile* profile() { return profile_; } |
| FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } |
| FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
| + UMAHistogramHelper* histogram_helper() { return &histogram_helper_; } |
| void SetFakeResponse(const std::string& url, |
| const std::string& data, |
| @@ -112,6 +121,7 @@ class AccountReconcilorTest : public testing::Test { |
| MockAccountReconcilor* mock_reconcilor_; |
| net::FakeURLFetcherFactory url_fetcher_factory_; |
| scoped_ptr<TestingProfileManager> testing_profile_manager_; |
| + UMAHistogramHelper histogram_helper_; |
| }; |
| AccountReconcilorTest::AccountReconcilorTest() |
| @@ -121,8 +131,11 @@ AccountReconcilorTest::AccountReconcilorTest() |
| url_fetcher_factory_(NULL) {} |
| void AccountReconcilorTest::SetUp() { |
| - CommandLine::ForCurrentProcess()->AppendSwitch( |
| - switches::kNewProfileManagement); |
| + if (!::testing::UnitTest::GetInstance()->current_test_info()->value_param() |
|
Alexei Svitkine (slow)
2014/06/12 17:09:11
I don't understand this line. What's it for?
(Eac
Mike Lerman
2014/06/12 18:12:15
Some of the tests are TEST_F and some are TEST_P (
|
| + || GetParam() == true) { |
| + CommandLine::ForCurrentProcess()->AppendSwitch( |
| + switches::kNewProfileManagement); |
| + } |
| testing_profile_manager_.reset( |
| new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| @@ -151,6 +164,10 @@ void AccountReconcilorTest::SetUp() { |
| token_service_ = |
| static_cast<FakeProfileOAuth2TokenService*>( |
| ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); |
| + |
| + // Take a new snapshot of the concerned histograms before each test |
| + histogram_helper_.PrepareSnapshot(histograms_to_snapshot, |
| + kNumHistogramsForSnapshot); |
| } |
| MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { |
| @@ -338,7 +355,7 @@ TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedTokenRequest) { |
| ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size()); |
| } |
| -TEST_F(AccountReconcilorTest, StartReconcileNoop) { |
| +TEST_P(AccountReconcilorTest, StartReconcileNoop) { |
| signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| @@ -367,6 +384,12 @@ TEST_F(AccountReconcilorTest, StartReconcileNoop) { |
| base::RunLoop().RunUntilIdle(); |
| ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); |
| ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| + |
| + histogram_helper()->Fetch(); |
| + histogram_helper()->ExpectTotalCount( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 0, 1); |
| } |
| // This is test is needed until chrome changes to use gaia obfuscated id. |
| @@ -377,7 +400,7 @@ TEST_F(AccountReconcilorTest, StartReconcileNoop) { |
| // tests makes sure that an email like "Dot.S@hmail.com", as seen by the |
| // token service, will be considered the same as "dots@gmail.com" as returned |
| // by gaia::ParseListAccountsData(). |
| -TEST_F(AccountReconcilorTest, StartReconcileNoopWithDots) { |
| +TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { |
| signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com"); |
| token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token"); |
| @@ -408,9 +431,13 @@ TEST_F(AccountReconcilorTest, StartReconcileNoopWithDots) { |
| base::RunLoop().RunUntilIdle(); |
| ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); |
| ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| + |
| + histogram_helper()->Fetch(); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 0, 1); |
| } |
| -TEST_F(AccountReconcilorTest, StartReconcileNoopMultiple) { |
| +TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { |
| signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| @@ -447,9 +474,15 @@ TEST_F(AccountReconcilorTest, StartReconcileNoopMultiple) { |
| base::RunLoop().RunUntilIdle(); |
| ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); |
| ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| + |
| + histogram_helper()->Fetch(); |
| + histogram_helper()->ExpectTotalCount( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 0, 1); |
| } |
| -TEST_F(AccountReconcilorTest, StartReconcileAddToCookie) { |
| +TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { |
| signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| @@ -474,9 +507,90 @@ TEST_F(AccountReconcilorTest, StartReconcileAddToCookie) { |
| SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", |
| GoogleServiceAuthError::AuthErrorNone()); |
| ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| + |
| + histogram_helper()->Fetch(); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 0, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); |
| } |
| -TEST_F(AccountReconcilorTest, StartReconcileAddToChrome) { |
| +TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { |
| + signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| + token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| + token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| + |
| + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
| + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); |
| + |
| + SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| + "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(GaiaUrls::GetInstance()->people_get_url().spec(), |
| + "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| + |
| + AccountReconcilor* reconcilor = GetMockReconcilor(); |
| + reconcilor->StartReconcile(); |
| + token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", |
| + base::Time::Now() + base::TimeDelta::FromHours(1)); |
| + token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| + base::Time::Now() + base::TimeDelta::FromHours(1)); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| + SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", |
| + GoogleServiceAuthError::AuthErrorNone()); |
| + ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| + |
| + histogram_helper()->Fetch(); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 0, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); |
| + |
| + // Do another pass after I've added a third account to the token service |
| + |
| + SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| + "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
| + "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| + // This will cause the reconcilor to fire. |
| + token_service()->UpdateCredentials("third@gmail.com", "refresh_token"); |
| + |
| + token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", |
| + base::Time::Now() + base::TimeDelta::FromHours(1)); |
| + token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| + base::Time::Now() + base::TimeDelta::FromHours(1)); |
| + token_service()->IssueAllTokensForAccount("third@gmail.com", "access_token", |
| + base::Time::Now() + base::TimeDelta::FromHours(1)); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| + SimulateMergeSessionCompleted(reconcilor, "third@gmail.com", |
| + GoogleServiceAuthError::AuthErrorNone()); |
| + ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| + |
| + histogram_helper()->Fetch(); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 0, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", 0, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1); |
| +} |
| + |
| +TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) { |
| signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| @@ -499,9 +613,17 @@ TEST_F(AccountReconcilorTest, StartReconcileAddToChrome) { |
| ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", ""); |
| ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| + |
| + histogram_helper()->Fetch(); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 0, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToChrome.FirstRun", 1, 1); |
| } |
| -TEST_F(AccountReconcilorTest, StartReconcileBadPrimary) { |
| +TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { |
| signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| @@ -532,9 +654,17 @@ TEST_F(AccountReconcilorTest, StartReconcileBadPrimary) { |
| SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
| GoogleServiceAuthError::AuthErrorNone()); |
| ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| + |
| + histogram_helper()->Fetch(); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToCookieJar.FirstRun", 2, 1); |
| + histogram_helper()->ExpectUniqueSample( |
| + "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); |
| } |
| -TEST_F(AccountReconcilorTest, StartReconcileOnlyOnce) { |
| +TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { |
| signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| @@ -559,7 +689,7 @@ TEST_F(AccountReconcilorTest, StartReconcileOnlyOnce) { |
| ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| } |
| -TEST_F(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { |
| +TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { |
| signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| @@ -591,3 +721,7 @@ TEST_F(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { |
| GoogleServiceAuthError::AuthErrorNone()); |
| ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| } |
| + |
| +INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, |
| + AccountReconcilorTest, |
| + testing::Bool()); |