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..2719843ba74c0132cd76a13ba4ddc3fc0bb05a15 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,13 @@ |
namespace { |
const char kTestEmail[] = "user@gmail.com"; |
+const char* kHistogramsToSnapshot[] = { |
Ilya Sherman
2014/06/13 19:58:11
nit: "const char* const" (MOAR const :P)
Mike Lerman
2014/06/16 14:59:13
Done. KKKKAAAAAHHHHHHHHNNNNNst!
|
+ "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 +83,7 @@ MockAccountReconcilor::MockAccountReconcilor( |
} // namespace |
-class AccountReconcilorTest : public testing::Test { |
+class AccountReconcilorTest : public ::testing::TestWithParam<bool> { |
public: |
AccountReconcilorTest(); |
virtual void SetUp() OVERRIDE; |
@@ -84,6 +91,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 +120,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 +130,12 @@ AccountReconcilorTest::AccountReconcilorTest() |
url_fetcher_factory_(NULL) {} |
void AccountReconcilorTest::SetUp() { |
- CommandLine::ForCurrentProcess()->AppendSwitch( |
- switches::kNewProfileManagement); |
+ // If it's a non-parameterized test, or we have a parameter of true, set flag. |
+ if (!::testing::UnitTest::GetInstance()->current_test_info()->value_param() |
+ || GetParam()) { |
+ 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(kHistogramsToSnapshot, |
+ arraysize(kHistogramsToSnapshot)); |
Ilya Sherman
2014/06/13 19:58:11
nit: Please align the params, or have them both be
Mike Lerman
2014/06/16 14:59:13
TIL about git cl format. Thanks!
|
} |
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()); |