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

Unified Diff: chrome/browser/signin/account_reconcilor_unittest.cc

Issue 309843002: Improve UMA tests; improve no-op reconcilor; new reconcilor test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/statistics_delta_reader.h ('k') | chrome/test/base/uma_histogram_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a7ec9ef2a15b0320b00d8a58d496fc3d286bf651..4845527826d8a0d95aa84833de03bd3114b23086 100644
--- a/chrome/browser/signin/account_reconcilor_unittest.cc
+++ b/chrome/browser/signin/account_reconcilor_unittest.cc
@@ -20,6 +20,7 @@
#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"
@@ -34,6 +35,13 @@
namespace {
const char kTestEmail[] = "user@gmail.com";
+const char* const kHistogramsToSnapshot[] = {
+ "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:
@@ -77,7 +85,7 @@ MockAccountReconcilor::MockAccountReconcilor(
} // namespace
-class AccountReconcilorTest : public testing::Test {
+class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
public:
AccountReconcilorTest();
virtual void SetUp() OVERRIDE;
@@ -85,6 +93,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,
@@ -113,6 +122,9 @@ class AccountReconcilorTest : public testing::Test {
MockAccountReconcilor* mock_reconcilor_;
net::FakeURLFetcherFactory url_fetcher_factory_;
scoped_ptr<TestingProfileManager> testing_profile_manager_;
+ UMAHistogramHelper histogram_helper_;
+
+ DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest);
};
AccountReconcilorTest::AccountReconcilorTest()
@@ -122,8 +134,12 @@ AccountReconcilorTest::AccountReconcilorTest()
url_fetcher_factory_(NULL) {}
void AccountReconcilorTest::SetUp() {
- CommandLine::ForCurrentProcess()->AppendSwitch(
- switches::kEnableNewProfileManagement);
+ // 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::kEnableNewProfileManagement);
+ }
testing_profile_manager_.reset(
new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
@@ -152,6 +168,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));
}
MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() {
@@ -339,7 +359,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");
@@ -368,6 +388,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.
@@ -378,7 +404,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");
@@ -409,9 +435,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");
@@ -448,9 +478,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");
@@ -475,9 +511,106 @@ 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_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_F(AccountReconcilorTest, StartReconcileAddToChrome) {
+TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) {
signin_manager()->SetAuthenticatedUsername("user@gmail.com");
token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
@@ -500,9 +633,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");
@@ -533,9 +674,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");
@@ -560,7 +709,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");
@@ -592,3 +741,7 @@ TEST_F(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) {
GoogleServiceAuthError::AuthErrorNone());
ASSERT_FALSE(reconcilor->is_reconcile_started_);
}
+
+INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled,
+ AccountReconcilorTest,
+ testing::Bool());
« no previous file with comments | « base/test/statistics_delta_reader.h ('k') | chrome/test/base/uma_histogram_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698