| 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/test/histogram_tester.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/prefs/pref_service_syncable.h" | 12 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 13 #include "chrome/browser/signin/account_reconcilor_factory.h" | 13 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 14 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 14 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 15 #include "chrome/browser/signin/fake_gaia_cookie_manager_service.h" |
| 15 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 16 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 16 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 17 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 17 #include "chrome/browser/signin/fake_signin_manager.h" | 18 #include "chrome/browser/signin/fake_signin_manager.h" |
| 18 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" | 19 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" |
| 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 20 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/signin/test_signin_client_builder.h" | 22 #include "chrome/browser/signin/test_signin_client_builder.h" |
| 22 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
| 24 #include "chrome/test/base/testing_profile_manager.h" | 25 #include "chrome/test/base/testing_profile_manager.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 81 |
| 81 class AccountReconcilorTest : public ::testing::TestWithParam<bool> { | 82 class AccountReconcilorTest : public ::testing::TestWithParam<bool> { |
| 82 public: | 83 public: |
| 83 AccountReconcilorTest(); | 84 AccountReconcilorTest(); |
| 84 void SetUp() override; | 85 void SetUp() override; |
| 85 | 86 |
| 86 TestingProfile* profile() { return profile_; } | 87 TestingProfile* profile() { return profile_; } |
| 87 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } | 88 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } |
| 88 FakeProfileOAuth2TokenService* token_service() { return token_service_; } | 89 FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
| 89 TestSigninClient* test_signin_client() { return test_signin_client_; } | 90 TestSigninClient* test_signin_client() { return test_signin_client_; } |
| 91 FakeGaiaCookieManagerService* cookie_manager_service() { |
| 92 return cookie_manager_service_; |
| 93 } |
| 90 base::HistogramTester* histogram_tester() { return &histogram_tester_; } | 94 base::HistogramTester* histogram_tester() { return &histogram_tester_; } |
| 91 | 95 |
| 92 void SetFakeResponse(const std::string& url, | 96 void SetFakeResponse(const std::string& url, |
| 93 const std::string& data, | 97 const std::string& data, |
| 94 net::HttpStatusCode code, | 98 net::HttpStatusCode code, |
| 95 net::URLRequestStatus::Status status) { | 99 net::URLRequestStatus::Status status) { |
| 96 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); | 100 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); |
| 97 } | 101 } |
| 98 | 102 |
| 99 MockAccountReconcilor* GetMockReconcilor(); | 103 MockAccountReconcilor* GetMockReconcilor(); |
| 100 | 104 |
| 101 void SimulateAddAccountToCookieCompleted( | 105 void SimulateAddAccountToCookieCompleted( |
| 102 GaiaCookieManagerService::Observer* observer, | 106 GaiaCookieManagerService::Observer* observer, |
| 103 const std::string& account_id, | 107 const std::string& account_id, |
| 104 const GoogleServiceAuthError& error); | 108 const GoogleServiceAuthError& error); |
| 105 | 109 |
| 106 void SimulateCookieContentSettingsChanged( | 110 void SimulateCookieContentSettingsChanged( |
| 107 content_settings::Observer* observer, | 111 content_settings::Observer* observer, |
| 108 const ContentSettingsPattern& primary_pattern); | 112 const ContentSettingsPattern& primary_pattern); |
| 109 | 113 |
| 110 GURL list_accounts_url() { return list_accounts_url_; } | |
| 111 GURL get_check_connection_info_url() { | 114 GURL get_check_connection_info_url() { |
| 112 return get_check_connection_info_url_; | 115 return get_check_connection_info_url_; |
| 113 } | 116 } |
| 114 | 117 |
| 115 private: | 118 private: |
| 116 content::TestBrowserThreadBundle bundle_; | 119 content::TestBrowserThreadBundle bundle_; |
| 117 TestingProfile* profile_; | 120 TestingProfile* profile_; |
| 118 FakeSigninManagerForTesting* signin_manager_; | 121 FakeSigninManagerForTesting* signin_manager_; |
| 119 FakeProfileOAuth2TokenService* token_service_; | 122 FakeProfileOAuth2TokenService* token_service_; |
| 120 TestSigninClient* test_signin_client_; | 123 TestSigninClient* test_signin_client_; |
| 124 FakeGaiaCookieManagerService* cookie_manager_service_; |
| 121 MockAccountReconcilor* mock_reconcilor_; | 125 MockAccountReconcilor* mock_reconcilor_; |
| 122 net::FakeURLFetcherFactory url_fetcher_factory_; | 126 net::FakeURLFetcherFactory url_fetcher_factory_; |
| 123 scoped_ptr<TestingProfileManager> testing_profile_manager_; | 127 scoped_ptr<TestingProfileManager> testing_profile_manager_; |
| 124 base::HistogramTester histogram_tester_; | 128 base::HistogramTester histogram_tester_; |
| 125 GURL list_accounts_url_; | |
| 126 GURL get_check_connection_info_url_; | 129 GURL get_check_connection_info_url_; |
| 127 | 130 |
| 128 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest); | 131 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest); |
| 129 }; | 132 }; |
| 130 | 133 |
| 131 AccountReconcilorTest::AccountReconcilorTest() | 134 AccountReconcilorTest::AccountReconcilorTest() |
| 132 : signin_manager_(NULL), | 135 : signin_manager_(NULL), |
| 133 token_service_(NULL), | 136 token_service_(NULL), |
| 134 test_signin_client_(NULL), | 137 test_signin_client_(NULL), |
| 138 cookie_manager_service_(NULL), |
| 135 mock_reconcilor_(NULL), | 139 mock_reconcilor_(NULL), |
| 136 url_fetcher_factory_(NULL) {} | 140 url_fetcher_factory_(NULL) {} |
| 137 | 141 |
| 138 void AccountReconcilorTest::SetUp() { | 142 void AccountReconcilorTest::SetUp() { |
| 139 // If it's a non-parameterized test, or we have a parameter of true, set flag. | 143 // If it's a non-parameterized test, or we have a parameter of true, set flag. |
| 140 if (!::testing::UnitTest::GetInstance()->current_test_info()->value_param() || | 144 if (!::testing::UnitTest::GetInstance()->current_test_info()->value_param() || |
| 141 GetParam()) { | 145 GetParam()) { |
| 142 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 146 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 143 switches::kEnableNewProfileManagement); | 147 switches::kEnableNewProfileManagement); |
| 144 } | 148 } |
| 145 | 149 |
| 146 list_accounts_url_ = GaiaUrls::GetInstance()->ListAccountsURLWithSource( | |
| 147 GaiaConstants::kReconcilorSource); | |
| 148 get_check_connection_info_url_ = | 150 get_check_connection_info_url_ = |
| 149 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( | 151 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( |
| 150 GaiaConstants::kChromeSource); | 152 GaiaConstants::kChromeSource); |
| 151 | 153 |
| 152 // Specific tests may set a response that includes specific accounts. | |
| 153 SetFakeResponse(list_accounts_url().spec(), "", | |
| 154 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); | |
| 155 | |
| 156 testing_profile_manager_.reset( | 154 testing_profile_manager_.reset( |
| 157 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 155 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 158 ASSERT_TRUE(testing_profile_manager_.get()->SetUp()); | 156 ASSERT_TRUE(testing_profile_manager_.get()->SetUp()); |
| 159 | 157 |
| 160 TestingProfile::TestingFactories factories; | 158 TestingProfile::TestingFactories factories; |
| 161 factories.push_back(std::make_pair(ChromeSigninClientFactory::GetInstance(), | 159 factories.push_back(std::make_pair(ChromeSigninClientFactory::GetInstance(), |
| 162 signin::BuildTestSigninClient)); | 160 signin::BuildTestSigninClient)); |
| 163 factories.push_back(std::make_pair( | 161 factories.push_back(std::make_pair( |
| 164 ProfileOAuth2TokenServiceFactory::GetInstance(), | 162 ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 165 BuildFakeProfileOAuth2TokenService)); | 163 BuildFakeProfileOAuth2TokenService)); |
| 164 factories.push_back(std::make_pair( |
| 165 GaiaCookieManagerServiceFactory::GetInstance(), |
| 166 FakeGaiaCookieManagerService::Build)); |
| 166 factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(), | 167 factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(), |
| 167 FakeSigninManagerBase::Build)); | 168 FakeSigninManagerBase::Build)); |
| 168 factories.push_back(std::make_pair(AccountReconcilorFactory::GetInstance(), | 169 factories.push_back(std::make_pair(AccountReconcilorFactory::GetInstance(), |
| 169 MockAccountReconcilor::Build)); | 170 MockAccountReconcilor::Build)); |
| 170 | 171 |
| 171 profile_ = testing_profile_manager_.get()->CreateTestingProfile("name", | 172 profile_ = testing_profile_manager_.get()->CreateTestingProfile("name", |
| 172 scoped_ptr<PrefServiceSyncable>(), | 173 scoped_ptr<PrefServiceSyncable>(), |
| 173 base::UTF8ToUTF16("name"), 0, std::string(), | 174 base::UTF8ToUTF16("name"), 0, std::string(), |
| 174 factories); | 175 factories); |
| 175 | 176 |
| 176 signin_manager_ = | 177 signin_manager_ = |
| 177 static_cast<FakeSigninManagerForTesting*>( | 178 static_cast<FakeSigninManagerForTesting*>( |
| 178 SigninManagerFactory::GetForProfile(profile())); | 179 SigninManagerFactory::GetForProfile(profile())); |
| 179 | 180 |
| 180 token_service_ = | 181 token_service_ = |
| 181 static_cast<FakeProfileOAuth2TokenService*>( | 182 static_cast<FakeProfileOAuth2TokenService*>( |
| 182 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); | 183 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); |
| 183 | 184 |
| 184 test_signin_client_ = | 185 test_signin_client_ = |
| 185 static_cast<TestSigninClient*>( | 186 static_cast<TestSigninClient*>( |
| 186 ChromeSigninClientFactory::GetForProfile(profile())); | 187 ChromeSigninClientFactory::GetForProfile(profile())); |
| 188 |
| 189 cookie_manager_service_ = |
| 190 static_cast<FakeGaiaCookieManagerService*>( |
| 191 GaiaCookieManagerServiceFactory::GetForProfile(profile())); |
| 192 cookie_manager_service_->Init(&url_fetcher_factory_); |
| 193 |
| 194 cookie_manager_service_->SetListAccountsResponseHttpNotFound(); |
| 187 } | 195 } |
| 188 | 196 |
| 189 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { | 197 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { |
| 190 if (!mock_reconcilor_) { | 198 if (!mock_reconcilor_) { |
| 191 mock_reconcilor_ = | 199 mock_reconcilor_ = |
| 192 static_cast<MockAccountReconcilor*>( | 200 static_cast<MockAccountReconcilor*>( |
| 193 AccountReconcilorFactory::GetForProfile(profile())); | 201 AccountReconcilorFactory::GetForProfile(profile())); |
| 194 } | 202 } |
| 195 | 203 |
| 196 return mock_reconcilor_; | 204 return mock_reconcilor_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 274 |
| 267 AccountReconcilor* reconcilor = | 275 AccountReconcilor* reconcilor = |
| 268 AccountReconcilorFactory::GetForProfile(profile()); | 276 AccountReconcilorFactory::GetForProfile(profile()); |
| 269 ASSERT_TRUE(reconcilor); | 277 ASSERT_TRUE(reconcilor); |
| 270 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); | 278 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); |
| 271 } | 279 } |
| 272 | 280 |
| 273 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { | 281 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { |
| 274 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 282 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 275 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 283 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 284 cookie_manager_service()->SetListAccountsResponseOneAccountWithExpiry( |
| 285 kTestEmail, true); |
| 276 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(kTestEmail)); | 286 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(kTestEmail)); |
| 287 |
| 277 AccountReconcilor* reconcilor = | 288 AccountReconcilor* reconcilor = |
| 278 AccountReconcilorFactory::GetForProfile(profile()); | 289 AccountReconcilorFactory::GetForProfile(profile()); |
| 279 ASSERT_TRUE(reconcilor); | 290 ASSERT_TRUE(reconcilor); |
| 280 | 291 |
| 281 SetFakeResponse(list_accounts_url().spec(), | 292 reconcilor->StartReconcile(); |
| 282 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", | 293 base::RunLoop().RunUntilIdle(); |
| 283 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 284 | 294 |
| 285 reconcilor->StartReconcile(); | 295 std::vector<std::pair<std::string, bool> > accounts; |
| 286 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 296 ASSERT_TRUE(cookie_manager_service()->ListAccounts(&accounts)); |
| 287 | |
| 288 base::RunLoop().RunUntilIdle(); | |
| 289 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); | |
| 290 const std::vector<std::pair<std::string, bool> >& accounts = | |
| 291 reconcilor->GetGaiaAccountsForTesting(); | |
| 292 ASSERT_EQ(1u, accounts.size()); | 297 ASSERT_EQ(1u, accounts.size()); |
| 293 ASSERT_EQ("user@gmail.com", accounts[0].first); | 298 ASSERT_EQ("user@gmail.com", accounts[0].first); |
| 294 } | 299 } |
| 295 | 300 |
| 296 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { | 301 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { |
| 297 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 302 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 298 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 303 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 304 cookie_manager_service()->SetListAccountsResponseHttpNotFound(); |
| 305 |
| 299 AccountReconcilor* reconcilor = | 306 AccountReconcilor* reconcilor = |
| 300 AccountReconcilorFactory::GetForProfile(profile()); | 307 AccountReconcilorFactory::GetForProfile(profile()); |
| 301 ASSERT_TRUE(reconcilor); | 308 ASSERT_TRUE(reconcilor); |
| 302 | 309 |
| 303 SetFakeResponse(list_accounts_url().spec(), "", | 310 reconcilor->StartReconcile(); |
| 304 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); | 311 base::RunLoop().RunUntilIdle(); |
| 305 | 312 |
| 306 reconcilor->StartReconcile(); | 313 std::vector<std::pair<std::string, bool> > accounts; |
| 307 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 314 ASSERT_FALSE(cookie_manager_service()->ListAccounts(&accounts)); |
| 308 | 315 ASSERT_EQ(0u, accounts.size()); |
| 309 base::RunLoop().RunUntilIdle(); | |
| 310 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | |
| 311 } | 316 } |
| 312 | 317 |
| 313 TEST_P(AccountReconcilorTest, StartReconcileNoop) { | 318 TEST_P(AccountReconcilorTest, StartReconcileNoop) { |
| 314 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 319 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 315 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 320 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 316 | 321 |
| 317 AccountReconcilor* reconcilor = | 322 AccountReconcilor* reconcilor = |
| 318 AccountReconcilorFactory::GetForProfile(profile()); | 323 AccountReconcilorFactory::GetForProfile(profile()); |
| 319 ASSERT_TRUE(reconcilor); | 324 ASSERT_TRUE(reconcilor); |
| 320 | 325 |
| 321 SetFakeResponse(list_accounts_url().spec(), | 326 cookie_manager_service()->SetListAccountsResponseOneAccount(kTestEmail); |
| 322 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 323 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 324 | 327 |
| 325 reconcilor->StartReconcile(); | 328 reconcilor->StartReconcile(); |
| 326 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 329 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 327 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | |
| 328 | 330 |
| 329 base::RunLoop().RunUntilIdle(); | 331 base::RunLoop().RunUntilIdle(); |
| 330 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 332 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 331 | 333 |
| 332 histogram_tester()->ExpectTotalCount( | 334 histogram_tester()->ExpectTotalCount( |
| 333 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); | 335 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); |
| 334 histogram_tester()->ExpectUniqueSample( | 336 histogram_tester()->ExpectUniqueSample( |
| 335 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 337 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 336 signin_metrics::ACCOUNTS_SAME, | 338 signin_metrics::ACCOUNTS_SAME, |
| 337 1); | 339 1); |
| 338 } | 340 } |
| 339 | 341 |
| 340 TEST_P(AccountReconcilorTest, StartReconcileCookiesDisabled) { | 342 TEST_P(AccountReconcilorTest, StartReconcileCookiesDisabled) { |
| 341 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 343 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 342 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 344 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 343 test_signin_client()->set_are_signin_cookies_allowed(false); | 345 test_signin_client()->set_are_signin_cookies_allowed(false); |
| 344 | 346 |
| 345 AccountReconcilor* reconcilor = | 347 AccountReconcilor* reconcilor = |
| 346 AccountReconcilorFactory::GetForProfile(profile()); | 348 AccountReconcilorFactory::GetForProfile(profile()); |
| 347 ASSERT_TRUE(reconcilor); | 349 ASSERT_TRUE(reconcilor); |
| 348 | 350 |
| 349 reconcilor->StartReconcile(); | 351 reconcilor->StartReconcile(); |
| 350 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 352 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 351 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | |
| 352 | 353 |
| 353 base::RunLoop().RunUntilIdle(); | 354 base::RunLoop().RunUntilIdle(); |
| 355 std::vector<std::pair<std::string, bool> > accounts; |
| 356 // This will be the first call to ListAccounts. |
| 357 ASSERT_FALSE(cookie_manager_service()->ListAccounts(&accounts)); |
| 354 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 358 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 355 } | 359 } |
| 356 | 360 |
| 357 TEST_P(AccountReconcilorTest, StartReconcileContentSettings) { | 361 TEST_P(AccountReconcilorTest, StartReconcileContentSettings) { |
| 358 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 362 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 359 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 363 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 360 | 364 |
| 361 AccountReconcilor* reconcilor = | 365 AccountReconcilor* reconcilor = |
| 362 AccountReconcilorFactory::GetForProfile(profile()); | 366 AccountReconcilorFactory::GetForProfile(profile()); |
| 363 ASSERT_TRUE(reconcilor); | 367 ASSERT_TRUE(reconcilor); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 // The signin manager and token service use the gaia "email" property, which | 425 // The signin manager and token service use the gaia "email" property, which |
| 422 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() | 426 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() |
| 423 // however uses gaia "displayEmail" which does not preserve case, and then | 427 // however uses gaia "displayEmail" which does not preserve case, and then |
| 424 // passes the string through gaia::CanonicalizeEmail() which removes dots. This | 428 // passes the string through gaia::CanonicalizeEmail() which removes dots. This |
| 425 // tests makes sure that an email like "Dot.S@hmail.com", as seen by the | 429 // tests makes sure that an email like "Dot.S@hmail.com", as seen by the |
| 426 // token service, will be considered the same as "dots@gmail.com" as returned | 430 // token service, will be considered the same as "dots@gmail.com" as returned |
| 427 // by gaia::ParseListAccountsData(). | 431 // by gaia::ParseListAccountsData(). |
| 428 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { | 432 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { |
| 429 signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com"); | 433 signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com"); |
| 430 token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token"); | 434 token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token"); |
| 435 cookie_manager_service()->SetListAccountsResponseOneAccount( |
| 436 "dot.s@gmail.com"); |
| 431 | 437 |
| 432 AccountReconcilor* reconcilor = | 438 AccountReconcilor* reconcilor = |
| 433 AccountReconcilorFactory::GetForProfile(profile()); | 439 AccountReconcilorFactory::GetForProfile(profile()); |
| 434 ASSERT_TRUE(reconcilor); | 440 ASSERT_TRUE(reconcilor); |
| 435 | 441 |
| 436 SetFakeResponse(list_accounts_url().spec(), | |
| 437 "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 438 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 439 | |
| 440 reconcilor->StartReconcile(); | 442 reconcilor->StartReconcile(); |
| 441 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | |
| 442 | |
| 443 base::RunLoop().RunUntilIdle(); | 443 base::RunLoop().RunUntilIdle(); |
| 444 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 444 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 445 | 445 |
| 446 histogram_tester()->ExpectUniqueSample( | 446 histogram_tester()->ExpectUniqueSample( |
| 447 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 447 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 448 signin_metrics::ACCOUNTS_SAME, | 448 signin_metrics::ACCOUNTS_SAME, |
| 449 1); | 449 1); |
| 450 } | 450 } |
| 451 | 451 |
| 452 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { | 452 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { |
| 453 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 453 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 454 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 454 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 455 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 455 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 456 cookie_manager_service()->SetListAccountsResponseTwoAccounts( |
| 457 "user@gmail.com", "other@gmail.com"); |
| 456 | 458 |
| 457 AccountReconcilor* reconcilor = | 459 AccountReconcilor* reconcilor = |
| 458 AccountReconcilorFactory::GetForProfile(profile()); | 460 AccountReconcilorFactory::GetForProfile(profile()); |
| 459 ASSERT_TRUE(reconcilor); | 461 ASSERT_TRUE(reconcilor); |
| 460 | 462 |
| 461 SetFakeResponse(list_accounts_url().spec(), | |
| 462 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | |
| 463 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 464 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 465 | |
| 466 reconcilor->StartReconcile(); | 463 reconcilor->StartReconcile(); |
| 467 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | |
| 468 base::RunLoop().RunUntilIdle(); | 464 base::RunLoop().RunUntilIdle(); |
| 469 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 465 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 470 | 466 |
| 471 histogram_tester()->ExpectTotalCount( | 467 histogram_tester()->ExpectTotalCount( |
| 472 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); | 468 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); |
| 473 histogram_tester()->ExpectUniqueSample( | 469 histogram_tester()->ExpectUniqueSample( |
| 474 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 470 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 475 signin_metrics::ACCOUNTS_SAME, | 471 signin_metrics::ACCOUNTS_SAME, |
| 476 1); | 472 1); |
| 477 } | 473 } |
| 478 | 474 |
| 479 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { | 475 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { |
| 480 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 476 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 481 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 477 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 482 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 478 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 479 cookie_manager_service()->SetListAccountsResponseOneAccount( |
| 480 "user@gmail.com"); |
| 483 | 481 |
| 484 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 482 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
| 485 | 483 |
| 486 SetFakeResponse(list_accounts_url().spec(), | |
| 487 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 488 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 489 | |
| 490 AccountReconcilor* reconcilor = GetMockReconcilor(); | 484 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 491 reconcilor->StartReconcile(); | 485 reconcilor->StartReconcile(); |
| 492 | 486 |
| 493 base::RunLoop().RunUntilIdle(); | 487 base::RunLoop().RunUntilIdle(); |
| 494 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 488 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 495 SimulateAddAccountToCookieCompleted(reconcilor, "other@gmail.com", | 489 SimulateAddAccountToCookieCompleted(reconcilor, "other@gmail.com", |
| 496 GoogleServiceAuthError::AuthErrorNone()); | 490 GoogleServiceAuthError::AuthErrorNone()); |
| 497 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 491 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 498 | 492 |
| 499 histogram_tester()->ExpectUniqueSample( | 493 histogram_tester()->ExpectUniqueSample( |
| 500 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 494 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 501 signin_metrics::ACCOUNTS_SAME, | 495 signin_metrics::ACCOUNTS_SAME, |
| 502 1); | 496 1); |
| 503 histogram_tester()->ExpectUniqueSample( | 497 histogram_tester()->ExpectUniqueSample( |
| 504 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); | 498 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
| 505 histogram_tester()->ExpectUniqueSample( | 499 histogram_tester()->ExpectUniqueSample( |
| 506 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); | 500 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); |
| 507 } | 501 } |
| 508 | 502 |
| 509 TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) { | 503 TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) { |
| 510 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 504 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 511 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 505 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 506 cookie_manager_service()->SetListAccountsResponseTwoAccounts( |
| 507 "user@gmail.com", "other@gmail.com"); |
| 512 | 508 |
| 513 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); | 509 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); |
| 514 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 510 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
| 515 | 511 |
| 516 SetFakeResponse(list_accounts_url().spec(), | |
| 517 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | |
| 518 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 519 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 520 | |
| 521 AccountReconcilor* reconcilor = GetMockReconcilor(); | 512 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 522 reconcilor->StartReconcile(); | 513 reconcilor->StartReconcile(); |
| 523 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 514 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 524 | 515 |
| 525 base::RunLoop().RunUntilIdle(); | 516 base::RunLoop().RunUntilIdle(); |
| 526 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", | 517 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", |
| 527 GoogleServiceAuthError::AuthErrorNone()); | 518 GoogleServiceAuthError::AuthErrorNone()); |
| 528 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 519 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 529 | 520 |
| 530 histogram_tester()->ExpectUniqueSample( | 521 histogram_tester()->ExpectUniqueSample( |
| 531 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 522 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 532 signin_metrics::ACCOUNTS_SAME, | 523 signin_metrics::ACCOUNTS_SAME, |
| 533 1); | 524 1); |
| 534 histogram_tester()->ExpectUniqueSample( | 525 histogram_tester()->ExpectUniqueSample( |
| 535 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); | 526 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); |
| 536 histogram_tester()->ExpectUniqueSample( | 527 histogram_tester()->ExpectUniqueSample( |
| 537 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 1, 1); | 528 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 1, 1); |
| 538 } | 529 } |
| 539 | 530 |
| 540 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { | 531 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { |
| 541 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 532 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 542 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 533 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 543 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 534 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 535 cookie_manager_service()->SetListAccountsResponseOneAccount( |
| 536 "user@gmail.com"); |
| 544 | 537 |
| 545 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 538 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
| 546 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); | 539 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); |
| 547 | 540 |
| 548 SetFakeResponse( | |
| 549 list_accounts_url().spec(), | |
| 550 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 551 net::HTTP_OK, | |
| 552 net::URLRequestStatus::SUCCESS); | |
| 553 | |
| 554 AccountReconcilor* reconcilor = GetMockReconcilor(); | 541 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 555 reconcilor->StartReconcile(); | 542 reconcilor->StartReconcile(); |
| 556 | 543 |
| 557 base::RunLoop().RunUntilIdle(); | 544 base::RunLoop().RunUntilIdle(); |
| 558 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 545 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 559 SimulateAddAccountToCookieCompleted( | 546 SimulateAddAccountToCookieCompleted( |
| 560 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); | 547 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); |
| 561 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 548 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 562 | 549 |
| 563 histogram_tester()->ExpectUniqueSample( | 550 histogram_tester()->ExpectUniqueSample( |
| 564 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 551 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 565 signin_metrics::ACCOUNTS_SAME, | 552 signin_metrics::ACCOUNTS_SAME, |
| 566 1); | 553 1); |
| 567 histogram_tester()->ExpectUniqueSample( | 554 histogram_tester()->ExpectUniqueSample( |
| 568 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); | 555 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
| 569 histogram_tester()->ExpectUniqueSample( | 556 histogram_tester()->ExpectUniqueSample( |
| 570 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); | 557 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); |
| 571 | 558 |
| 572 // Do another pass after I've added a third account to the token service | 559 // Do another pass after I've added a third account to the token service |
| 560 cookie_manager_service()->SetListAccountsResponseTwoAccounts( |
| 561 "user@gmail.com", "other@gmail.com"); |
| 562 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false); |
| 573 | 563 |
| 574 SetFakeResponse( | |
| 575 list_accounts_url().spec(), | |
| 576 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | |
| 577 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 578 net::HTTP_OK, | |
| 579 net::URLRequestStatus::SUCCESS); | |
| 580 // This will cause the reconcilor to fire. | 564 // This will cause the reconcilor to fire. |
| 581 token_service()->UpdateCredentials("third@gmail.com", "refresh_token"); | 565 token_service()->UpdateCredentials("third@gmail.com", "refresh_token"); |
| 582 | 566 |
| 583 base::RunLoop().RunUntilIdle(); | 567 base::RunLoop().RunUntilIdle(); |
| 584 | 568 |
| 585 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 569 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 586 SimulateAddAccountToCookieCompleted( | 570 SimulateAddAccountToCookieCompleted( |
| 587 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); | 571 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); |
| 588 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 572 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 589 | 573 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 602 histogram_tester()->ExpectUniqueSample( | 586 histogram_tester()->ExpectUniqueSample( |
| 603 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); | 587 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); |
| 604 histogram_tester()->ExpectUniqueSample( | 588 histogram_tester()->ExpectUniqueSample( |
| 605 "Signin.Reconciler.RemovedFromCookieJar.SubsequentRun", 0, 1); | 589 "Signin.Reconciler.RemovedFromCookieJar.SubsequentRun", 0, 1); |
| 606 } | 590 } |
| 607 | 591 |
| 608 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { | 592 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { |
| 609 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 593 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 610 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 594 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 611 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 595 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 596 cookie_manager_service()->SetListAccountsResponseTwoAccounts( |
| 597 "other@gmail.com", "user@gmail.com"); |
| 612 | 598 |
| 613 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); | 599 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); |
| 614 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 600 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
| 615 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 601 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
| 616 | 602 |
| 617 SetFakeResponse(list_accounts_url().spec(), | |
| 618 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | |
| 619 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 620 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 621 | |
| 622 AccountReconcilor* reconcilor = GetMockReconcilor(); | 603 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 623 reconcilor->StartReconcile(); | 604 reconcilor->StartReconcile(); |
| 624 | 605 |
| 625 base::RunLoop().RunUntilIdle(); | 606 base::RunLoop().RunUntilIdle(); |
| 626 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 607 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 627 SimulateAddAccountToCookieCompleted(reconcilor, "other@gmail.com", | 608 SimulateAddAccountToCookieCompleted(reconcilor, "other@gmail.com", |
| 628 GoogleServiceAuthError::AuthErrorNone()); | 609 GoogleServiceAuthError::AuthErrorNone()); |
| 629 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 610 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 630 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", | 611 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", |
| 631 GoogleServiceAuthError::AuthErrorNone()); | 612 GoogleServiceAuthError::AuthErrorNone()); |
| 632 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 613 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 633 | 614 |
| 634 histogram_tester()->ExpectUniqueSample( | 615 histogram_tester()->ExpectUniqueSample( |
| 635 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 616 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 636 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT, | 617 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT, |
| 637 1); | 618 1); |
| 638 histogram_tester()->ExpectUniqueSample( | 619 histogram_tester()->ExpectUniqueSample( |
| 639 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); | 620 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); |
| 640 histogram_tester()->ExpectUniqueSample( | 621 histogram_tester()->ExpectUniqueSample( |
| 641 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); | 622 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); |
| 642 } | 623 } |
| 643 | 624 |
| 644 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { | 625 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { |
| 645 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 626 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 646 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 627 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 628 cookie_manager_service()->SetListAccountsResponseOneAccount( |
| 629 "user@gmail.com"); |
| 647 | 630 |
| 648 AccountReconcilor* reconcilor = | 631 AccountReconcilor* reconcilor = |
| 649 AccountReconcilorFactory::GetForProfile(profile()); | 632 AccountReconcilorFactory::GetForProfile(profile()); |
| 650 ASSERT_TRUE(reconcilor); | 633 ASSERT_TRUE(reconcilor); |
| 651 | 634 |
| 652 SetFakeResponse(list_accounts_url().spec(), | |
| 653 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 654 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 655 | |
| 656 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 635 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 657 reconcilor->StartReconcile(); | 636 reconcilor->StartReconcile(); |
| 658 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 637 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 659 | 638 |
| 660 base::RunLoop().RunUntilIdle(); | 639 base::RunLoop().RunUntilIdle(); |
| 661 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 640 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 662 } | 641 } |
| 663 | 642 |
| 664 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { | 643 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { |
| 665 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 644 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 666 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 645 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 667 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 646 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 647 cookie_manager_service()->SetListAccountsResponseTwoAccountsWithExpiry( |
| 648 "user@gmail.com", true, "other@gmail.com", false); |
| 668 | 649 |
| 669 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 650 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
| 670 | 651 |
| 671 SetFakeResponse(list_accounts_url().spec(), | |
| 672 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]," | |
| 673 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
| 674 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 675 | |
| 676 AccountReconcilor* reconcilor = | 652 AccountReconcilor* reconcilor = |
| 677 AccountReconcilorFactory::GetForProfile(profile()); | 653 AccountReconcilorFactory::GetForProfile(profile()); |
| 678 ASSERT_TRUE(reconcilor); | 654 ASSERT_TRUE(reconcilor); |
| 679 | 655 |
| 680 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 656 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 681 reconcilor->StartReconcile(); | 657 reconcilor->StartReconcile(); |
| 682 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 658 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 683 | 659 |
| 684 base::RunLoop().RunUntilIdle(); | 660 base::RunLoop().RunUntilIdle(); |
| 685 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", | 661 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", |
| 686 GoogleServiceAuthError::AuthErrorNone()); | 662 GoogleServiceAuthError::AuthErrorNone()); |
| 687 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 663 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 688 } | 664 } |
| 689 | 665 |
| 690 TEST_F(AccountReconcilorTest, AddAccountToCookieCompletedWithBogusAccount) { | 666 TEST_F(AccountReconcilorTest, AddAccountToCookieCompletedWithBogusAccount) { |
| 691 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 667 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 692 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 668 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 669 cookie_manager_service()->SetListAccountsResponseOneAccountWithExpiry( |
| 670 "user@gmail.com", true); |
| 693 | 671 |
| 694 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 672 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
| 695 | 673 |
| 696 SetFakeResponse(list_accounts_url().spec(), | |
| 697 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", | |
| 698 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 699 | |
| 700 AccountReconcilor* reconcilor = | 674 AccountReconcilor* reconcilor = |
| 701 AccountReconcilorFactory::GetForProfile(profile()); | 675 AccountReconcilorFactory::GetForProfile(profile()); |
| 702 ASSERT_TRUE(reconcilor); | 676 ASSERT_TRUE(reconcilor); |
| 703 | 677 |
| 704 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 678 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 705 reconcilor->StartReconcile(); | 679 reconcilor->StartReconcile(); |
| 706 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 680 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 707 | 681 |
| 708 base::RunLoop().RunUntilIdle(); | 682 base::RunLoop().RunUntilIdle(); |
| 709 | 683 |
| 710 // If an unknown account id is sent, it should not upset the state. | 684 // If an unknown account id is sent, it should not upset the state. |
| 711 SimulateAddAccountToCookieCompleted(reconcilor, "bogus@gmail.com", | 685 SimulateAddAccountToCookieCompleted(reconcilor, "bogus@gmail.com", |
| 712 GoogleServiceAuthError::AuthErrorNone()); | 686 GoogleServiceAuthError::AuthErrorNone()); |
| 713 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 687 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 714 | 688 |
| 715 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", | 689 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", |
| 716 GoogleServiceAuthError::AuthErrorNone()); | 690 GoogleServiceAuthError::AuthErrorNone()); |
| 717 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 691 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 718 } | 692 } |
| 719 | 693 |
| 720 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, | 694 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, |
| 721 AccountReconcilorTest, | 695 AccountReconcilorTest, |
| 722 testing::Bool()); | 696 testing::Bool()); |
| OLD | NEW |