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

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

Issue 379283002: Rework UMAHistogramHelper and StatisticsDeltaReader into [Chrome]HistogramTester. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Prefer base histogram_tester. ChromeHistogramTester with RunMessageLoop for NaCl Created 6 years, 5 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 | Annotate | Revision Log
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/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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } // namespace 82 } // namespace
90 83
91 class AccountReconcilorTest : public ::testing::TestWithParam<bool> { 84 class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
92 public: 85 public:
93 AccountReconcilorTest(); 86 AccountReconcilorTest();
94 virtual void SetUp() OVERRIDE; 87 virtual void SetUp() OVERRIDE;
95 88
96 TestingProfile* profile() { return profile_; } 89 TestingProfile* profile() { return profile_; }
97 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } 90 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; }
98 FakeProfileOAuth2TokenService* token_service() { return token_service_; } 91 FakeProfileOAuth2TokenService* token_service() { return token_service_; }
99 UMAHistogramHelper* histogram_helper() { return &histogram_helper_; } 92 base::HistogramTester* histogram_tester() { return &histogram_tester_; }
100 93
101 void SetFakeResponse(const std::string& url, 94 void SetFakeResponse(const std::string& url,
102 const std::string& data, 95 const std::string& data,
103 net::HttpStatusCode code, 96 net::HttpStatusCode code,
104 net::URLRequestStatus::Status status) { 97 net::URLRequestStatus::Status status) {
105 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); 98 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status);
106 } 99 }
107 100
108 MockAccountReconcilor* GetMockReconcilor(); 101 MockAccountReconcilor* GetMockReconcilor();
109 102
110 void SimulateMergeSessionCompleted( 103 void SimulateMergeSessionCompleted(
111 MergeSessionHelper::Observer* observer, 104 MergeSessionHelper::Observer* observer,
112 const std::string& account_id, 105 const std::string& account_id,
113 const GoogleServiceAuthError& error); 106 const GoogleServiceAuthError& error);
114 107
115 void SimulateRefreshTokenFetched( 108 void SimulateRefreshTokenFetched(
116 AccountReconcilor* reconcilor, 109 AccountReconcilor* reconcilor,
117 const std::string& account_id, 110 const std::string& account_id,
118 const std::string& refresh_token); 111 const std::string& refresh_token);
119 112
120 private: 113 private:
121 content::TestBrowserThreadBundle bundle_; 114 content::TestBrowserThreadBundle bundle_;
122 TestingProfile* profile_; 115 TestingProfile* profile_;
123 FakeSigninManagerForTesting* signin_manager_; 116 FakeSigninManagerForTesting* signin_manager_;
124 FakeProfileOAuth2TokenService* token_service_; 117 FakeProfileOAuth2TokenService* token_service_;
125 MockAccountReconcilor* mock_reconcilor_; 118 MockAccountReconcilor* mock_reconcilor_;
126 net::FakeURLFetcherFactory url_fetcher_factory_; 119 net::FakeURLFetcherFactory url_fetcher_factory_;
127 scoped_ptr<TestingProfileManager> testing_profile_manager_; 120 scoped_ptr<TestingProfileManager> testing_profile_manager_;
128 UMAHistogramHelper histogram_helper_; 121 base::HistogramTester histogram_tester_;
129 122
130 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest); 123 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest);
131 }; 124 };
132 125
133 AccountReconcilorTest::AccountReconcilorTest() 126 AccountReconcilorTest::AccountReconcilorTest()
134 : signin_manager_(NULL), 127 : signin_manager_(NULL),
135 token_service_(NULL), 128 token_service_(NULL),
136 mock_reconcilor_(NULL), 129 mock_reconcilor_(NULL),
137 url_fetcher_factory_(NULL) {} 130 url_fetcher_factory_(NULL) {}
138 131
(...skipping 25 matching lines...) Expand all
164 base::UTF8ToUTF16("name"), 0, std::string(), 157 base::UTF8ToUTF16("name"), 0, std::string(),
165 factories); 158 factories);
166 159
167 signin_manager_ = 160 signin_manager_ =
168 static_cast<FakeSigninManagerForTesting*>( 161 static_cast<FakeSigninManagerForTesting*>(
169 SigninManagerFactory::GetForProfile(profile())); 162 SigninManagerFactory::GetForProfile(profile()));
170 163
171 token_service_ = 164 token_service_ =
172 static_cast<FakeProfileOAuth2TokenService*>( 165 static_cast<FakeProfileOAuth2TokenService*>(
173 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); 166 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()));
174
175 // Take a new snapshot of the concerned histograms before each test
176 histogram_helper_.PrepareSnapshot(kHistogramsToSnapshot,
177 arraysize(kHistogramsToSnapshot));
178 } 167 }
179 168
180 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { 169 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() {
181 if (!mock_reconcilor_) { 170 if (!mock_reconcilor_) {
182 mock_reconcilor_ = 171 mock_reconcilor_ =
183 static_cast<MockAccountReconcilor*>( 172 static_cast<MockAccountReconcilor*>(
184 AccountReconcilorFactory::GetForProfile(profile())); 173 AccountReconcilorFactory::GetForProfile(profile()));
185 } 174 }
186 175
187 return mock_reconcilor_; 176 return mock_reconcilor_;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size()); 374 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size());
386 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); 375 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
387 376
388 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", 377 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
389 base::Time::Now() + base::TimeDelta::FromHours(1)); 378 base::Time::Now() + base::TimeDelta::FromHours(1));
390 379
391 base::RunLoop().RunUntilIdle(); 380 base::RunLoop().RunUntilIdle();
392 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); 381 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
393 ASSERT_FALSE(reconcilor->is_reconcile_started_); 382 ASSERT_FALSE(reconcilor->is_reconcile_started_);
394 383
395 histogram_helper()->Fetch(); 384 histogram_tester()->ExpectTotalCount(
396 histogram_helper()->ExpectTotalCount(
397 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); 385 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
398 histogram_helper()->ExpectUniqueSample( 386 histogram_tester()->ExpectUniqueSample(
399 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 387 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
400 signin_metrics::ACCOUNTS_SAME, 388 signin_metrics::ACCOUNTS_SAME,
401 1); 389 1);
402 } 390 }
403 391
404 // This is test is needed until chrome changes to use gaia obfuscated id. 392 // This is test is needed until chrome changes to use gaia obfuscated id.
405 // The signin manager and token service use the gaia "email" property, which 393 // The signin manager and token service use the gaia "email" property, which
406 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() 394 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData()
407 // however uses gaia "displayEmail" which does not preserve case, and then 395 // however uses gaia "displayEmail" which does not preserve case, and then
408 // passes the string through gaia::CanonicalizeEmail() which removes dots. This 396 // passes the string through gaia::CanonicalizeEmail() which removes dots. This
(...skipping 25 matching lines...) Expand all
434 reconcilor->GetGaiaAccountsForTesting()[0].first.c_str()); 422 reconcilor->GetGaiaAccountsForTesting()[0].first.c_str());
435 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); 423 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
436 424
437 token_service()->IssueAllTokensForAccount("Dot.S@gmail.com", "access_token", 425 token_service()->IssueAllTokensForAccount("Dot.S@gmail.com", "access_token",
438 base::Time::Now() + base::TimeDelta::FromHours(1)); 426 base::Time::Now() + base::TimeDelta::FromHours(1));
439 427
440 base::RunLoop().RunUntilIdle(); 428 base::RunLoop().RunUntilIdle();
441 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); 429 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
442 ASSERT_FALSE(reconcilor->is_reconcile_started_); 430 ASSERT_FALSE(reconcilor->is_reconcile_started_);
443 431
444 histogram_helper()->Fetch(); 432 histogram_tester()->ExpectUniqueSample(
445 histogram_helper()->ExpectUniqueSample(
446 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 433 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
447 signin_metrics::ACCOUNTS_SAME, 434 signin_metrics::ACCOUNTS_SAME,
448 1); 435 1);
449 } 436 }
450 437
451 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { 438 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) {
452 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 439 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
453 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 440 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
454 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 441 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
455 442
(...skipping 23 matching lines...) Expand all
479 base::RunLoop().RunUntilIdle(); 466 base::RunLoop().RunUntilIdle();
480 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); 467 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
481 468
482 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", 469 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
483 base::Time::Now() + base::TimeDelta::FromHours(1)); 470 base::Time::Now() + base::TimeDelta::FromHours(1));
484 471
485 base::RunLoop().RunUntilIdle(); 472 base::RunLoop().RunUntilIdle();
486 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); 473 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
487 ASSERT_FALSE(reconcilor->is_reconcile_started_); 474 ASSERT_FALSE(reconcilor->is_reconcile_started_);
488 475
489 histogram_helper()->Fetch(); 476 histogram_tester()->ExpectTotalCount(
490 histogram_helper()->ExpectTotalCount(
491 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); 477 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
492 histogram_helper()->ExpectUniqueSample( 478 histogram_tester()->ExpectUniqueSample(
493 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 479 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
494 signin_metrics::ACCOUNTS_SAME, 480 signin_metrics::ACCOUNTS_SAME,
495 1); 481 1);
496 } 482 }
497 483
498 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { 484 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
499 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 485 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
500 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 486 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
501 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 487 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
502 488
(...skipping 11 matching lines...) Expand all
514 base::Time::Now() + base::TimeDelta::FromHours(1)); 500 base::Time::Now() + base::TimeDelta::FromHours(1));
515 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", 501 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
516 base::Time::Now() + base::TimeDelta::FromHours(1)); 502 base::Time::Now() + base::TimeDelta::FromHours(1));
517 503
518 base::RunLoop().RunUntilIdle(); 504 base::RunLoop().RunUntilIdle();
519 ASSERT_TRUE(reconcilor->is_reconcile_started_); 505 ASSERT_TRUE(reconcilor->is_reconcile_started_);
520 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", 506 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com",
521 GoogleServiceAuthError::AuthErrorNone()); 507 GoogleServiceAuthError::AuthErrorNone());
522 ASSERT_FALSE(reconcilor->is_reconcile_started_); 508 ASSERT_FALSE(reconcilor->is_reconcile_started_);
523 509
524 histogram_helper()->Fetch(); 510 histogram_tester()->ExpectUniqueSample(
525 histogram_helper()->ExpectUniqueSample(
526 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 511 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
527 signin_metrics::ACCOUNTS_SAME, 512 signin_metrics::ACCOUNTS_SAME,
528 1); 513 1);
529 histogram_helper()->ExpectUniqueSample( 514 histogram_tester()->ExpectUniqueSample(
530 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 515 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
531 histogram_helper()->ExpectUniqueSample( 516 histogram_tester()->ExpectUniqueSample(
532 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); 517 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
533 } 518 }
534 519
535 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { 520 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
536 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 521 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
537 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 522 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
538 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 523 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
539 524
540 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); 525 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
541 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); 526 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com"));
(...skipping 18 matching lines...) Expand all
560 "user@gmail.com", 545 "user@gmail.com",
561 "access_token", 546 "access_token",
562 base::Time::Now() + base::TimeDelta::FromHours(1)); 547 base::Time::Now() + base::TimeDelta::FromHours(1));
563 548
564 base::RunLoop().RunUntilIdle(); 549 base::RunLoop().RunUntilIdle();
565 ASSERT_TRUE(reconcilor->is_reconcile_started_); 550 ASSERT_TRUE(reconcilor->is_reconcile_started_);
566 SimulateMergeSessionCompleted( 551 SimulateMergeSessionCompleted(
567 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); 552 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone());
568 ASSERT_FALSE(reconcilor->is_reconcile_started_); 553 ASSERT_FALSE(reconcilor->is_reconcile_started_);
569 554
570 histogram_helper()->Fetch(); 555 histogram_tester()->ExpectUniqueSample(
571 histogram_helper()->ExpectUniqueSample(
572 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 556 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
573 signin_metrics::ACCOUNTS_SAME, 557 signin_metrics::ACCOUNTS_SAME,
574 1); 558 1);
575 histogram_helper()->ExpectUniqueSample( 559 histogram_tester()->ExpectUniqueSample(
576 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 560 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
577 histogram_helper()->ExpectUniqueSample( 561 histogram_tester()->ExpectUniqueSample(
578 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); 562 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
579 563
580 // Do another pass after I've added a third account to the token service 564 // Do another pass after I've added a third account to the token service
581 565
582 SetFakeResponse( 566 SetFakeResponse(
583 GaiaUrls::GetInstance()->list_accounts_url().spec(), 567 GaiaUrls::GetInstance()->list_accounts_url().spec(),
584 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 568 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
585 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 569 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
586 net::HTTP_OK, 570 net::HTTP_OK,
587 net::URLRequestStatus::SUCCESS); 571 net::URLRequestStatus::SUCCESS);
(...skipping 13 matching lines...) Expand all
601 "access_token", 585 "access_token",
602 base::Time::Now() + base::TimeDelta::FromHours(1)); 586 base::Time::Now() + base::TimeDelta::FromHours(1));
603 587
604 base::RunLoop().RunUntilIdle(); 588 base::RunLoop().RunUntilIdle();
605 589
606 ASSERT_TRUE(reconcilor->is_reconcile_started_); 590 ASSERT_TRUE(reconcilor->is_reconcile_started_);
607 SimulateMergeSessionCompleted( 591 SimulateMergeSessionCompleted(
608 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); 592 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone());
609 ASSERT_FALSE(reconcilor->is_reconcile_started_); 593 ASSERT_FALSE(reconcilor->is_reconcile_started_);
610 594
611 histogram_helper()->Fetch(); 595 histogram_tester()->ExpectUniqueSample(
612 histogram_helper()->ExpectUniqueSample(
613 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 596 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
614 signin_metrics::ACCOUNTS_SAME, 597 signin_metrics::ACCOUNTS_SAME,
615 1); 598 1);
616 histogram_helper()->ExpectUniqueSample( 599 histogram_tester()->ExpectUniqueSample(
617 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 600 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
618 histogram_helper()->ExpectUniqueSample( 601 histogram_tester()->ExpectUniqueSample(
619 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); 602 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
620 histogram_helper()->ExpectUniqueSample( 603 histogram_tester()->ExpectUniqueSample(
621 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", 604 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun",
622 signin_metrics::ACCOUNTS_SAME, 605 signin_metrics::ACCOUNTS_SAME,
623 1); 606 1);
624 histogram_helper()->ExpectUniqueSample( 607 histogram_tester()->ExpectUniqueSample(
625 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); 608 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1);
626 histogram_helper()->ExpectUniqueSample( 609 histogram_tester()->ExpectUniqueSample(
627 "Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1); 610 "Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1);
628 } 611 }
629 612
630 TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) { 613 TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) {
631 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 614 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
632 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 615 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
633 616
634 EXPECT_CALL(*GetMockReconcilor(), 617 EXPECT_CALL(*GetMockReconcilor(),
635 PerformAddToChromeAction("other@gmail.com", 1, "")); 618 PerformAddToChromeAction("other@gmail.com", 1, ""));
636 619
637 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 620 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
638 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 621 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
639 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 622 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
640 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 623 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
641 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", 624 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
642 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); 625 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
643 626
644 AccountReconcilor* reconcilor = GetMockReconcilor(); 627 AccountReconcilor* reconcilor = GetMockReconcilor();
645 reconcilor->StartReconcile(); 628 reconcilor->StartReconcile();
646 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", 629 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
647 base::Time::Now() + base::TimeDelta::FromHours(1)); 630 base::Time::Now() + base::TimeDelta::FromHours(1));
648 631
649 base::RunLoop().RunUntilIdle(); 632 base::RunLoop().RunUntilIdle();
650 ASSERT_TRUE(reconcilor->is_reconcile_started_); 633 ASSERT_TRUE(reconcilor->is_reconcile_started_);
651 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", ""); 634 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", "");
652 ASSERT_FALSE(reconcilor->is_reconcile_started_); 635 ASSERT_FALSE(reconcilor->is_reconcile_started_);
653 636
654 histogram_helper()->Fetch(); 637 histogram_tester()->ExpectUniqueSample(
655 histogram_helper()->ExpectUniqueSample(
656 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 638 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
657 signin_metrics::ACCOUNTS_SAME, 639 signin_metrics::ACCOUNTS_SAME,
658 1); 640 1);
659 histogram_helper()->ExpectUniqueSample( 641 histogram_tester()->ExpectUniqueSample(
660 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); 642 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1);
661 histogram_helper()->ExpectUniqueSample( 643 histogram_tester()->ExpectUniqueSample(
662 "Signin.Reconciler.AddedToChrome.FirstRun", 1, 1); 644 "Signin.Reconciler.AddedToChrome.FirstRun", 1, 1);
663 } 645 }
664 646
665 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { 647 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
666 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 648 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
667 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 649 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
668 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 650 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
669 651
670 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); 652 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
671 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); 653 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
(...skipping 15 matching lines...) Expand all
687 669
688 base::RunLoop().RunUntilIdle(); 670 base::RunLoop().RunUntilIdle();
689 ASSERT_TRUE(reconcilor->is_reconcile_started_); 671 ASSERT_TRUE(reconcilor->is_reconcile_started_);
690 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", 672 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com",
691 GoogleServiceAuthError::AuthErrorNone()); 673 GoogleServiceAuthError::AuthErrorNone());
692 ASSERT_TRUE(reconcilor->is_reconcile_started_); 674 ASSERT_TRUE(reconcilor->is_reconcile_started_);
693 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 675 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
694 GoogleServiceAuthError::AuthErrorNone()); 676 GoogleServiceAuthError::AuthErrorNone());
695 ASSERT_FALSE(reconcilor->is_reconcile_started_); 677 ASSERT_FALSE(reconcilor->is_reconcile_started_);
696 678
697 histogram_helper()->Fetch(); 679 histogram_tester()->ExpectUniqueSample(
698 histogram_helper()->ExpectUniqueSample(
699 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 680 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
700 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT, 681 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT,
701 1); 682 1);
702 histogram_helper()->ExpectUniqueSample( 683 histogram_tester()->ExpectUniqueSample(
703 "Signin.Reconciler.AddedToCookieJar.FirstRun", 2, 1); 684 "Signin.Reconciler.AddedToCookieJar.FirstRun", 2, 1);
704 histogram_helper()->ExpectUniqueSample( 685 histogram_tester()->ExpectUniqueSample(
705 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); 686 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
706 } 687 }
707 688
708 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { 689 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) {
709 signin_manager()->SetAuthenticatedUsername(kTestEmail); 690 signin_manager()->SetAuthenticatedUsername(kTestEmail);
710 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); 691 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
711 692
712 AccountReconcilor* reconcilor = 693 AccountReconcilor* reconcilor =
713 AccountReconcilorFactory::GetForProfile(profile()); 694 AccountReconcilorFactory::GetForProfile(profile());
714 ASSERT_TRUE(reconcilor); 695 ASSERT_TRUE(reconcilor);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 775
795 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 776 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
796 GoogleServiceAuthError::AuthErrorNone()); 777 GoogleServiceAuthError::AuthErrorNone());
797 ASSERT_FALSE(reconcilor->is_reconcile_started_); 778 ASSERT_FALSE(reconcilor->is_reconcile_started_);
798 } 779 }
799 780
800 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, 781 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled,
801 AccountReconcilorTest, 782 AccountReconcilorTest,
802 testing::Bool()); 783 testing::Bool());
803 784
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698