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

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

Issue 1075273002: Handle ListAccount fetches from within the GaiaCookieManagerService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a test post rebase Created 5 years, 8 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
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/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/account_tracker_service_factory.h" 14 #include "chrome/browser/signin/account_tracker_service_factory.h"
15 #include "chrome/browser/signin/chrome_signin_client_factory.h" 15 #include "chrome/browser/signin/chrome_signin_client_factory.h"
16 #include "chrome/browser/signin/fake_gaia_cookie_manager_service.h"
16 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 17 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
17 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 18 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
18 #include "chrome/browser/signin/fake_signin_manager.h" 19 #include "chrome/browser/signin/fake_signin_manager.h"
19 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" 20 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 22 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/signin/test_signin_client_builder.h" 23 #include "chrome/browser/signin/test_signin_client_builder.h"
23 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
24 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
25 #include "chrome/test/base/testing_profile_manager.h" 26 #include "chrome/test/base/testing_profile_manager.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_; }
90 AccountTrackerService* account_tracker() { return account_tracker_; } 91 AccountTrackerService* account_tracker() { return account_tracker_; }
92 FakeGaiaCookieManagerService* cookie_manager_service() {
93 return cookie_manager_service_;
94 }
91 base::HistogramTester* histogram_tester() { return &histogram_tester_; } 95 base::HistogramTester* histogram_tester() { return &histogram_tester_; }
92 96
93 void SetFakeResponse(const std::string& url, 97 void SetFakeResponse(const std::string& url,
94 const std::string& data, 98 const std::string& data,
95 net::HttpStatusCode code, 99 net::HttpStatusCode code,
96 net::URLRequestStatus::Status status) { 100 net::URLRequestStatus::Status status) {
97 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); 101 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status);
98 } 102 }
99 103
100 MockAccountReconcilor* GetMockReconcilor(); 104 MockAccountReconcilor* GetMockReconcilor();
101 105
102 std::string ConnectProfileToAccount(const std::string& gaia_id, 106 std::string ConnectProfileToAccount(const std::string& gaia_id,
103 const std::string& username); 107 const std::string& username);
104 108
105 std::string PickAccountIdForAccount(const std::string& gaia_id, 109 std::string PickAccountIdForAccount(const std::string& gaia_id,
106 const std::string& username); 110 const std::string& username);
107 111
108 void SimulateAddAccountToCookieCompleted( 112 void SimulateAddAccountToCookieCompleted(
109 GaiaCookieManagerService::Observer* observer, 113 GaiaCookieManagerService::Observer* observer,
110 const std::string& account_id, 114 const std::string& account_id,
111 const GoogleServiceAuthError& error); 115 const GoogleServiceAuthError& error);
112 116
113 void SimulateCookieContentSettingsChanged( 117 void SimulateCookieContentSettingsChanged(
114 content_settings::Observer* observer, 118 content_settings::Observer* observer,
115 const ContentSettingsPattern& primary_pattern); 119 const ContentSettingsPattern& primary_pattern);
116 120
117 GURL list_accounts_url() { return list_accounts_url_; }
118 GURL get_check_connection_info_url() { 121 GURL get_check_connection_info_url() {
119 return get_check_connection_info_url_; 122 return get_check_connection_info_url_;
120 } 123 }
121 124
122 private: 125 private:
123 content::TestBrowserThreadBundle bundle_; 126 content::TestBrowserThreadBundle bundle_;
124 TestingProfile* profile_; 127 TestingProfile* profile_;
125 FakeSigninManagerForTesting* signin_manager_; 128 FakeSigninManagerForTesting* signin_manager_;
126 FakeProfileOAuth2TokenService* token_service_; 129 FakeProfileOAuth2TokenService* token_service_;
127 TestSigninClient* test_signin_client_; 130 TestSigninClient* test_signin_client_;
128 AccountTrackerService* account_tracker_; 131 AccountTrackerService* account_tracker_;
132 FakeGaiaCookieManagerService* cookie_manager_service_;
129 MockAccountReconcilor* mock_reconcilor_; 133 MockAccountReconcilor* mock_reconcilor_;
130 net::FakeURLFetcherFactory url_fetcher_factory_; 134 net::FakeURLFetcherFactory url_fetcher_factory_;
131 scoped_ptr<TestingProfileManager> testing_profile_manager_; 135 scoped_ptr<TestingProfileManager> testing_profile_manager_;
132 base::HistogramTester histogram_tester_; 136 base::HistogramTester histogram_tester_;
133 GURL list_accounts_url_;
134 GURL get_check_connection_info_url_; 137 GURL get_check_connection_info_url_;
135 138
136 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest); 139 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest);
137 }; 140 };
138 141
139 AccountReconcilorTest::AccountReconcilorTest() 142 AccountReconcilorTest::AccountReconcilorTest()
140 : signin_manager_(NULL), 143 : signin_manager_(NULL),
141 token_service_(NULL), 144 token_service_(NULL),
142 test_signin_client_(NULL), 145 test_signin_client_(NULL),
146 cookie_manager_service_(NULL),
143 mock_reconcilor_(NULL), 147 mock_reconcilor_(NULL),
144 url_fetcher_factory_(NULL) {} 148 url_fetcher_factory_(NULL) {}
145 149
146 void AccountReconcilorTest::SetUp() { 150 void AccountReconcilorTest::SetUp() {
147 // If it's a non-parameterized test, or we have a parameter of true, set flag. 151 // If it's a non-parameterized test, or we have a parameter of true, set flag.
148 if (!::testing::UnitTest::GetInstance()->current_test_info()->value_param() || 152 if (!::testing::UnitTest::GetInstance()->current_test_info()->value_param() ||
149 GetParam()) { 153 GetParam()) {
150 base::CommandLine::ForCurrentProcess()->AppendSwitch( 154 base::CommandLine::ForCurrentProcess()->AppendSwitch(
151 switches::kEnableNewProfileManagement); 155 switches::kEnableNewProfileManagement);
152 } 156 }
153 157
154 list_accounts_url_ = GaiaUrls::GetInstance()->ListAccountsURLWithSource(
155 GaiaConstants::kReconcilorSource);
156 get_check_connection_info_url_ = 158 get_check_connection_info_url_ =
157 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( 159 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource(
158 GaiaConstants::kChromeSource); 160 GaiaConstants::kChromeSource);
159 161
160 // Specific tests may set a response that includes specific accounts.
161 SetFakeResponse(list_accounts_url().spec(), "",
162 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
163
164 testing_profile_manager_.reset( 162 testing_profile_manager_.reset(
165 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 163 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
166 ASSERT_TRUE(testing_profile_manager_.get()->SetUp()); 164 ASSERT_TRUE(testing_profile_manager_.get()->SetUp());
167 165
168 TestingProfile::TestingFactories factories; 166 TestingProfile::TestingFactories factories;
169 factories.push_back(std::make_pair(ChromeSigninClientFactory::GetInstance(), 167 factories.push_back(std::make_pair(ChromeSigninClientFactory::GetInstance(),
170 signin::BuildTestSigninClient)); 168 signin::BuildTestSigninClient));
171 factories.push_back(std::make_pair( 169 factories.push_back(std::make_pair(
172 ProfileOAuth2TokenServiceFactory::GetInstance(), 170 ProfileOAuth2TokenServiceFactory::GetInstance(),
173 BuildFakeProfileOAuth2TokenService)); 171 BuildFakeProfileOAuth2TokenService));
172 factories.push_back(std::make_pair(
173 GaiaCookieManagerServiceFactory::GetInstance(),
174 FakeGaiaCookieManagerService::Build));
174 factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(), 175 factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(),
175 FakeSigninManagerBase::Build)); 176 FakeSigninManagerBase::Build));
176 factories.push_back(std::make_pair(AccountReconcilorFactory::GetInstance(), 177 factories.push_back(std::make_pair(AccountReconcilorFactory::GetInstance(),
177 MockAccountReconcilor::Build)); 178 MockAccountReconcilor::Build));
178 179
179 profile_ = testing_profile_manager_.get()->CreateTestingProfile("name", 180 profile_ = testing_profile_manager_.get()->CreateTestingProfile("name",
180 scoped_ptr<PrefServiceSyncable>(), 181 scoped_ptr<PrefServiceSyncable>(),
181 base::UTF8ToUTF16("name"), 0, std::string(), 182 base::UTF8ToUTF16("name"), 0, std::string(),
182 factories); 183 factories);
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()));
187 188
188 token_service_ = 189 token_service_ =
189 static_cast<FakeProfileOAuth2TokenService*>( 190 static_cast<FakeProfileOAuth2TokenService*>(
190 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); 191 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()));
191 192
192 account_tracker_ = 193 account_tracker_ =
193 AccountTrackerServiceFactory::GetForProfile(profile()); 194 AccountTrackerServiceFactory::GetForProfile(profile());
194 195
195 signin_manager_ = 196 signin_manager_ =
196 static_cast<FakeSigninManagerForTesting*>( 197 static_cast<FakeSigninManagerForTesting*>(
197 SigninManagerFactory::GetForProfile(profile())); 198 SigninManagerFactory::GetForProfile(profile()));
199
200 test_signin_client_ =
201 static_cast<TestSigninClient*>(
202 ChromeSigninClientFactory::GetForProfile(profile()));
203
204 cookie_manager_service_ =
205 static_cast<FakeGaiaCookieManagerService*>(
206 GaiaCookieManagerServiceFactory::GetForProfile(profile()));
207 cookie_manager_service_->Init(&url_fetcher_factory_);
208
209 cookie_manager_service_->SetListAccountsResponseHttpNotFound();
198 } 210 }
199 211
200 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { 212 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() {
201 if (!mock_reconcilor_) { 213 if (!mock_reconcilor_) {
202 mock_reconcilor_ = 214 mock_reconcilor_ =
203 static_cast<MockAccountReconcilor*>( 215 static_cast<MockAccountReconcilor*>(
204 AccountReconcilorFactory::GetForProfile(profile())); 216 AccountReconcilorFactory::GetForProfile(profile()));
205 } 217 }
206 218
207 return mock_reconcilor_; 219 return mock_reconcilor_;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 308
297 AccountReconcilor* reconcilor = 309 AccountReconcilor* reconcilor =
298 AccountReconcilorFactory::GetForProfile(profile()); 310 AccountReconcilorFactory::GetForProfile(profile());
299 ASSERT_TRUE(reconcilor); 311 ASSERT_TRUE(reconcilor);
300 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); 312 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
301 } 313 }
302 314
303 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { 315 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) {
304 const std::string account_id = 316 const std::string account_id =
305 ConnectProfileToAccount("12345", "user@gmail.com"); 317 ConnectProfileToAccount("12345", "user@gmail.com");
318 cookie_manager_service()->SetListAccountsResponseOneAccountWithExpiry(
319 "user@gmail.com", true);
306 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); 320 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
307 321
308 AccountReconcilor* reconcilor = 322 AccountReconcilor* reconcilor =
309 AccountReconcilorFactory::GetForProfile(profile()); 323 AccountReconcilorFactory::GetForProfile(profile());
310 ASSERT_TRUE(reconcilor); 324 ASSERT_TRUE(reconcilor);
311 325
312 SetFakeResponse(list_accounts_url().spec(), 326 reconcilor->StartReconcile();
313 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", 327 base::RunLoop().RunUntilIdle();
314 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
315 328
316 reconcilor->StartReconcile(); 329 std::vector<std::pair<std::string, bool> > accounts;
317 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 330 ASSERT_TRUE(cookie_manager_service()->ListAccounts(&accounts));
318
319 base::RunLoop().RunUntilIdle();
320 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
321 const std::vector<std::pair<std::string, bool> >& accounts =
322 reconcilor->GetGaiaAccountsForTesting();
323 ASSERT_EQ(1u, accounts.size()); 331 ASSERT_EQ(1u, accounts.size());
324 ASSERT_EQ(account_id, accounts[0].first); 332 ASSERT_EQ(account_id, accounts[0].first);
325 } 333 }
326 334
327 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { 335 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) {
328 ConnectProfileToAccount("12345", "user@gmail.com"); 336 ConnectProfileToAccount("12345", "user@gmail.com");
337 cookie_manager_service()->SetListAccountsResponseHttpNotFound();
338
329 AccountReconcilor* reconcilor = 339 AccountReconcilor* reconcilor =
330 AccountReconcilorFactory::GetForProfile(profile()); 340 AccountReconcilorFactory::GetForProfile(profile());
331 ASSERT_TRUE(reconcilor); 341 ASSERT_TRUE(reconcilor);
332 342
333 SetFakeResponse(list_accounts_url().spec(), "", 343 reconcilor->StartReconcile();
334 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); 344 base::RunLoop().RunUntilIdle();
335 345
336 reconcilor->StartReconcile(); 346 std::vector<std::pair<std::string, bool> > accounts;
337 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 347 ASSERT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
338 348 ASSERT_EQ(0u, accounts.size());
339 base::RunLoop().RunUntilIdle();
340 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
341 } 349 }
342 350
343 TEST_P(AccountReconcilorTest, StartReconcileNoop) { 351 TEST_P(AccountReconcilorTest, StartReconcileNoop) {
344 const std::string account_id = 352 const std::string account_id =
345 ConnectProfileToAccount("12345", "user@gmail.com"); 353 ConnectProfileToAccount("12345", "user@gmail.com");
346 354
347 AccountReconcilor* reconcilor = 355 AccountReconcilor* reconcilor =
348 AccountReconcilorFactory::GetForProfile(profile()); 356 AccountReconcilorFactory::GetForProfile(profile());
349 ASSERT_TRUE(reconcilor); 357 ASSERT_TRUE(reconcilor);
350 358
351 SetFakeResponse(list_accounts_url().spec(), 359 cookie_manager_service()->SetListAccountsResponseOneAccount("user@gmail.com");
352 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
353 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
354 360
355 reconcilor->StartReconcile(); 361 reconcilor->StartReconcile();
356 ASSERT_TRUE(reconcilor->is_reconcile_started_); 362 ASSERT_TRUE(reconcilor->is_reconcile_started_);
357 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
358 363
359 base::RunLoop().RunUntilIdle(); 364 base::RunLoop().RunUntilIdle();
360 ASSERT_FALSE(reconcilor->is_reconcile_started_); 365 ASSERT_FALSE(reconcilor->is_reconcile_started_);
361 366
362 histogram_tester()->ExpectTotalCount( 367 histogram_tester()->ExpectTotalCount(
363 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); 368 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
364 histogram_tester()->ExpectUniqueSample( 369 histogram_tester()->ExpectUniqueSample(
365 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 370 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
366 signin_metrics::ACCOUNTS_SAME, 371 signin_metrics::ACCOUNTS_SAME,
367 1); 372 1);
368 } 373 }
369 374
370 TEST_P(AccountReconcilorTest, StartReconcileCookiesDisabled) { 375 TEST_P(AccountReconcilorTest, StartReconcileCookiesDisabled) {
371 const std::string account_id = 376 const std::string account_id =
372 ConnectProfileToAccount("12345", "user@gmail.com"); 377 ConnectProfileToAccount("12345", "user@gmail.com");
373 token_service()->UpdateCredentials(account_id, "refresh_token"); 378 token_service()->UpdateCredentials(account_id, "refresh_token");
374 test_signin_client()->set_are_signin_cookies_allowed(false); 379 test_signin_client()->set_are_signin_cookies_allowed(false);
375 380
376 AccountReconcilor* reconcilor = 381 AccountReconcilor* reconcilor =
377 AccountReconcilorFactory::GetForProfile(profile()); 382 AccountReconcilorFactory::GetForProfile(profile());
378 ASSERT_TRUE(reconcilor); 383 ASSERT_TRUE(reconcilor);
379 384
380 reconcilor->StartReconcile(); 385 reconcilor->StartReconcile();
381 ASSERT_FALSE(reconcilor->is_reconcile_started_); 386 ASSERT_FALSE(reconcilor->is_reconcile_started_);
382 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
383 387
384 base::RunLoop().RunUntilIdle(); 388 base::RunLoop().RunUntilIdle();
389 std::vector<std::pair<std::string, bool> > accounts;
390 // This will be the first call to ListAccounts.
391 ASSERT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
385 ASSERT_FALSE(reconcilor->is_reconcile_started_); 392 ASSERT_FALSE(reconcilor->is_reconcile_started_);
386 } 393 }
387 394
388 TEST_P(AccountReconcilorTest, StartReconcileContentSettings) { 395 TEST_P(AccountReconcilorTest, StartReconcileContentSettings) {
389 const std::string account_id = 396 const std::string account_id =
390 ConnectProfileToAccount("12345", "user@gmail.com"); 397 ConnectProfileToAccount("12345", "user@gmail.com");
391 token_service()->UpdateCredentials(account_id, "refresh_token"); 398 token_service()->UpdateCredentials(account_id, "refresh_token");
392 399
393 AccountReconcilor* reconcilor = 400 AccountReconcilor* reconcilor =
394 AccountReconcilorFactory::GetForProfile(profile()); 401 AccountReconcilorFactory::GetForProfile(profile());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 // token service, will be considered the same as "dots@gmail.com" as returned 468 // token service, will be considered the same as "dots@gmail.com" as returned
462 // by gaia::ParseListAccountsData(). 469 // by gaia::ParseListAccountsData().
463 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { 470 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) {
464 if (account_tracker()->GetMigrationState() != 471 if (account_tracker()->GetMigrationState() !=
465 AccountTrackerService::MIGRATION_NOT_STARTED) { 472 AccountTrackerService::MIGRATION_NOT_STARTED) {
466 return; 473 return;
467 } 474 }
468 475
469 const std::string account_id = 476 const std::string account_id =
470 ConnectProfileToAccount("12345", "Dot.S@gmail.com"); 477 ConnectProfileToAccount("12345", "Dot.S@gmail.com");
478 cookie_manager_service()->SetListAccountsResponseOneAccount(
479 "dot.s@gmail.com");
471 AccountReconcilor* reconcilor = 480 AccountReconcilor* reconcilor =
472 AccountReconcilorFactory::GetForProfile(profile()); 481 AccountReconcilorFactory::GetForProfile(profile());
473 ASSERT_TRUE(reconcilor); 482 ASSERT_TRUE(reconcilor);
474 483
475 SetFakeResponse(list_accounts_url().spec(),
476 "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
477 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
478
479 reconcilor->StartReconcile(); 484 reconcilor->StartReconcile();
480 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
481
482 base::RunLoop().RunUntilIdle(); 485 base::RunLoop().RunUntilIdle();
483 ASSERT_FALSE(reconcilor->is_reconcile_started_); 486 ASSERT_FALSE(reconcilor->is_reconcile_started_);
484 487
485 histogram_tester()->ExpectUniqueSample( 488 histogram_tester()->ExpectUniqueSample(
486 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 489 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
487 signin_metrics::ACCOUNTS_SAME, 490 signin_metrics::ACCOUNTS_SAME,
488 1); 491 1);
489 } 492 }
490 493
491 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { 494 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) {
492 const std::string account_id = 495 const std::string account_id =
493 ConnectProfileToAccount("12345", "user@gmail.com"); 496 ConnectProfileToAccount("12345", "user@gmail.com");
494 const std::string account_id2 = 497 const std::string account_id2 =
495 PickAccountIdForAccount("67890", "other@gmail.com"); 498 PickAccountIdForAccount("67890", "other@gmail.com");
499 cookie_manager_service()->SetListAccountsResponseTwoAccounts(
500 "user@gmail.com", "other@gmail.com");
496 token_service()->UpdateCredentials(account_id2, "refresh_token"); 501 token_service()->UpdateCredentials(account_id2, "refresh_token");
497 502
498 AccountReconcilor* reconcilor = 503 AccountReconcilor* reconcilor =
499 AccountReconcilorFactory::GetForProfile(profile()); 504 AccountReconcilorFactory::GetForProfile(profile());
500 ASSERT_TRUE(reconcilor); 505 ASSERT_TRUE(reconcilor);
501 506
502 SetFakeResponse(list_accounts_url().spec(),
503 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
504 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
505 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
506
507 reconcilor->StartReconcile(); 507 reconcilor->StartReconcile();
508 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
509 base::RunLoop().RunUntilIdle(); 508 base::RunLoop().RunUntilIdle();
510 ASSERT_FALSE(reconcilor->is_reconcile_started_); 509 ASSERT_FALSE(reconcilor->is_reconcile_started_);
511 510
512 histogram_tester()->ExpectTotalCount( 511 histogram_tester()->ExpectTotalCount(
513 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); 512 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
514 histogram_tester()->ExpectUniqueSample( 513 histogram_tester()->ExpectUniqueSample(
515 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 514 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
516 signin_metrics::ACCOUNTS_SAME, 515 signin_metrics::ACCOUNTS_SAME,
517 1); 516 1);
518 } 517 }
519 518
520 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { 519 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
521 const std::string account_id = 520 const std::string account_id =
522 ConnectProfileToAccount("12345", "user@gmail.com"); 521 ConnectProfileToAccount("12345", "user@gmail.com");
523 token_service()->UpdateCredentials(account_id, "refresh_token"); 522 token_service()->UpdateCredentials(account_id, "refresh_token");
523 cookie_manager_service()->SetListAccountsResponseOneAccount(
524 "user@gmail.com");
524 525
525 const std::string account_id2 = 526 const std::string account_id2 =
526 PickAccountIdForAccount("67890", "other@gmail.com"); 527 PickAccountIdForAccount("67890", "other@gmail.com");
527 token_service()->UpdateCredentials(account_id2, "refresh_token"); 528 token_service()->UpdateCredentials(account_id2, "refresh_token");
528 529
529 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2)); 530 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2));
530 531
531 SetFakeResponse(list_accounts_url().spec(),
532 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
533 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
534
535 AccountReconcilor* reconcilor = GetMockReconcilor(); 532 AccountReconcilor* reconcilor = GetMockReconcilor();
536 reconcilor->StartReconcile(); 533 reconcilor->StartReconcile();
537 534
538 base::RunLoop().RunUntilIdle(); 535 base::RunLoop().RunUntilIdle();
539 ASSERT_TRUE(reconcilor->is_reconcile_started_); 536 ASSERT_TRUE(reconcilor->is_reconcile_started_);
540 SimulateAddAccountToCookieCompleted(reconcilor, account_id2, 537 SimulateAddAccountToCookieCompleted(reconcilor, account_id2,
541 GoogleServiceAuthError::AuthErrorNone()); 538 GoogleServiceAuthError::AuthErrorNone());
542 ASSERT_FALSE(reconcilor->is_reconcile_started_); 539 ASSERT_FALSE(reconcilor->is_reconcile_started_);
543 540
544 histogram_tester()->ExpectUniqueSample( 541 histogram_tester()->ExpectUniqueSample(
545 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 542 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
546 signin_metrics::ACCOUNTS_SAME, 543 signin_metrics::ACCOUNTS_SAME,
547 1); 544 1);
548 histogram_tester()->ExpectUniqueSample( 545 histogram_tester()->ExpectUniqueSample(
549 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 546 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
550 histogram_tester()->ExpectUniqueSample( 547 histogram_tester()->ExpectUniqueSample(
551 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); 548 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1);
552 } 549 }
553 550
554 TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) { 551 TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) {
555 const std::string account_id = 552 const std::string account_id =
556 ConnectProfileToAccount("12345", "user@gmail.com"); 553 ConnectProfileToAccount("12345", "user@gmail.com");
557 token_service()->UpdateCredentials(account_id, "refresh_token"); 554 token_service()->UpdateCredentials(account_id, "refresh_token");
555 cookie_manager_service()->SetListAccountsResponseTwoAccounts(
556 "user@gmail.com", "other@gmail.com");
558 557
559 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); 558 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
560 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); 559 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
561 560
562 SetFakeResponse(list_accounts_url().spec(),
563 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
564 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
565 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
566
567 AccountReconcilor* reconcilor = GetMockReconcilor(); 561 AccountReconcilor* reconcilor = GetMockReconcilor();
568 reconcilor->StartReconcile(); 562 reconcilor->StartReconcile();
569 ASSERT_TRUE(reconcilor->is_reconcile_started_); 563 ASSERT_TRUE(reconcilor->is_reconcile_started_);
570 564
571 base::RunLoop().RunUntilIdle(); 565 base::RunLoop().RunUntilIdle();
572 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", 566 SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com",
573 GoogleServiceAuthError::AuthErrorNone()); 567 GoogleServiceAuthError::AuthErrorNone());
574 ASSERT_FALSE(reconcilor->is_reconcile_started_); 568 ASSERT_FALSE(reconcilor->is_reconcile_started_);
575 569
576 histogram_tester()->ExpectUniqueSample( 570 histogram_tester()->ExpectUniqueSample(
577 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 571 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
578 signin_metrics::ACCOUNTS_SAME, 572 signin_metrics::ACCOUNTS_SAME,
579 1); 573 1);
580 histogram_tester()->ExpectUniqueSample( 574 histogram_tester()->ExpectUniqueSample(
581 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); 575 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1);
582 histogram_tester()->ExpectUniqueSample( 576 histogram_tester()->ExpectUniqueSample(
583 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 1, 1); 577 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 1, 1);
584 } 578 }
585 579
586 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { 580 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
587 const std::string account_id = 581 const std::string account_id =
588 ConnectProfileToAccount("12345", "user@gmail.com"); 582 ConnectProfileToAccount("12345", "user@gmail.com");
589 const std::string account_id2 = 583 const std::string account_id2 =
590 PickAccountIdForAccount("67890", "other@gmail.com"); 584 PickAccountIdForAccount("67890", "other@gmail.com");
591 const std::string account_id3 = 585 const std::string account_id3 =
592 PickAccountIdForAccount("34567", "third@gmail.com"); 586 PickAccountIdForAccount("34567", "third@gmail.com");
593 587
588 cookie_manager_service()->SetListAccountsResponseOneAccount(
589 "user@gmail.com");
594 token_service()->UpdateCredentials(account_id2, "refresh_token"); 590 token_service()->UpdateCredentials(account_id2, "refresh_token");
595 591
596 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2)); 592 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2));
597 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id3)); 593 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id3));
598 594
599 SetFakeResponse(
600 list_accounts_url().spec(),
601 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
602 net::HTTP_OK,
603 net::URLRequestStatus::SUCCESS);
604
605 AccountReconcilor* reconcilor = GetMockReconcilor(); 595 AccountReconcilor* reconcilor = GetMockReconcilor();
606 reconcilor->StartReconcile(); 596 reconcilor->StartReconcile();
607 597
608 base::RunLoop().RunUntilIdle(); 598 base::RunLoop().RunUntilIdle();
609 ASSERT_TRUE(reconcilor->is_reconcile_started_); 599 ASSERT_TRUE(reconcilor->is_reconcile_started_);
610 SimulateAddAccountToCookieCompleted( 600 SimulateAddAccountToCookieCompleted(
611 reconcilor, account_id2, GoogleServiceAuthError::AuthErrorNone()); 601 reconcilor, account_id2, GoogleServiceAuthError::AuthErrorNone());
612 ASSERT_FALSE(reconcilor->is_reconcile_started_); 602 ASSERT_FALSE(reconcilor->is_reconcile_started_);
613 603
614 histogram_tester()->ExpectUniqueSample( 604 histogram_tester()->ExpectUniqueSample(
615 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 605 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
616 signin_metrics::ACCOUNTS_SAME, 606 signin_metrics::ACCOUNTS_SAME,
617 1); 607 1);
618 histogram_tester()->ExpectUniqueSample( 608 histogram_tester()->ExpectUniqueSample(
619 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 609 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
620 histogram_tester()->ExpectUniqueSample( 610 histogram_tester()->ExpectUniqueSample(
621 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); 611 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1);
622 612
623 // Do another pass after I've added a third account to the token service 613 // Do another pass after I've added a third account to the token service
614 cookie_manager_service()->SetListAccountsResponseTwoAccounts(
615 "user@gmail.com", "other@gmail.com");
616 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false);
624 617
625 SetFakeResponse(
626 list_accounts_url().spec(),
627 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
628 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
629 net::HTTP_OK,
630 net::URLRequestStatus::SUCCESS);
631 // This will cause the reconcilor to fire. 618 // This will cause the reconcilor to fire.
632 token_service()->UpdateCredentials(account_id3, "refresh_token"); 619 token_service()->UpdateCredentials(account_id3, "refresh_token");
633 base::RunLoop().RunUntilIdle(); 620 base::RunLoop().RunUntilIdle();
634 621
635 ASSERT_TRUE(reconcilor->is_reconcile_started_); 622 ASSERT_TRUE(reconcilor->is_reconcile_started_);
636 SimulateAddAccountToCookieCompleted( 623 SimulateAddAccountToCookieCompleted(
637 reconcilor, account_id3, GoogleServiceAuthError::AuthErrorNone()); 624 reconcilor, account_id3, GoogleServiceAuthError::AuthErrorNone());
638 ASSERT_FALSE(reconcilor->is_reconcile_started_); 625 ASSERT_FALSE(reconcilor->is_reconcile_started_);
639 626
640 histogram_tester()->ExpectUniqueSample( 627 histogram_tester()->ExpectUniqueSample(
(...skipping 14 matching lines...) Expand all
655 "Signin.Reconciler.RemovedFromCookieJar.SubsequentRun", 0, 1); 642 "Signin.Reconciler.RemovedFromCookieJar.SubsequentRun", 0, 1);
656 } 643 }
657 644
658 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { 645 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
659 const std::string account_id = 646 const std::string account_id =
660 ConnectProfileToAccount("12345", "user@gmail.com"); 647 ConnectProfileToAccount("12345", "user@gmail.com");
661 const std::string account_id2 = 648 const std::string account_id2 =
662 PickAccountIdForAccount("67890", "other@gmail.com"); 649 PickAccountIdForAccount("67890", "other@gmail.com");
663 650
664 token_service()->UpdateCredentials(account_id2, "refresh_token"); 651 token_service()->UpdateCredentials(account_id2, "refresh_token");
652 cookie_manager_service()->SetListAccountsResponseTwoAccounts(
653 "other@gmail.com", "user@gmail.com");
665 654
666 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); 655 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
667 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); 656 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
668 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2)); 657 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2));
669 658
670 SetFakeResponse(list_accounts_url().spec(),
671 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
672 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
673 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
674
675 AccountReconcilor* reconcilor = GetMockReconcilor(); 659 AccountReconcilor* reconcilor = GetMockReconcilor();
676 reconcilor->StartReconcile(); 660 reconcilor->StartReconcile();
677 661
678 base::RunLoop().RunUntilIdle(); 662 base::RunLoop().RunUntilIdle();
679 ASSERT_TRUE(reconcilor->is_reconcile_started_); 663 ASSERT_TRUE(reconcilor->is_reconcile_started_);
680 SimulateAddAccountToCookieCompleted(reconcilor, account_id2, 664 SimulateAddAccountToCookieCompleted(reconcilor, account_id2,
681 GoogleServiceAuthError::AuthErrorNone()); 665 GoogleServiceAuthError::AuthErrorNone());
682 ASSERT_TRUE(reconcilor->is_reconcile_started_); 666 ASSERT_TRUE(reconcilor->is_reconcile_started_);
683 SimulateAddAccountToCookieCompleted(reconcilor, account_id, 667 SimulateAddAccountToCookieCompleted(reconcilor, account_id,
684 GoogleServiceAuthError::AuthErrorNone()); 668 GoogleServiceAuthError::AuthErrorNone());
685 ASSERT_FALSE(reconcilor->is_reconcile_started_); 669 ASSERT_FALSE(reconcilor->is_reconcile_started_);
686 670
687 histogram_tester()->ExpectUniqueSample( 671 histogram_tester()->ExpectUniqueSample(
688 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 672 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
689 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT, 673 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT,
690 1); 674 1);
691 histogram_tester()->ExpectUniqueSample( 675 histogram_tester()->ExpectUniqueSample(
692 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); 676 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1);
693 histogram_tester()->ExpectUniqueSample( 677 histogram_tester()->ExpectUniqueSample(
694 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); 678 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1);
695 } 679 }
696 680
697 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { 681 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) {
698 const std::string account_id = 682 const std::string account_id =
699 ConnectProfileToAccount("12345", "user@gmail.com"); 683 ConnectProfileToAccount("12345", "user@gmail.com");
684 cookie_manager_service()->SetListAccountsResponseOneAccount(
685 "user@gmail.com");
700 686
701 AccountReconcilor* reconcilor = 687 AccountReconcilor* reconcilor =
702 AccountReconcilorFactory::GetForProfile(profile()); 688 AccountReconcilorFactory::GetForProfile(profile());
703 ASSERT_TRUE(reconcilor); 689 ASSERT_TRUE(reconcilor);
704 690
705 SetFakeResponse(list_accounts_url().spec(),
706 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
707 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
708
709 ASSERT_FALSE(reconcilor->is_reconcile_started_); 691 ASSERT_FALSE(reconcilor->is_reconcile_started_);
710 reconcilor->StartReconcile(); 692 reconcilor->StartReconcile();
711 ASSERT_TRUE(reconcilor->is_reconcile_started_); 693 ASSERT_TRUE(reconcilor->is_reconcile_started_);
712 694
713 base::RunLoop().RunUntilIdle(); 695 base::RunLoop().RunUntilIdle();
714 ASSERT_FALSE(reconcilor->is_reconcile_started_); 696 ASSERT_FALSE(reconcilor->is_reconcile_started_);
715 } 697 }
716 698
717 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { 699 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) {
718 const std::string account_id = 700 const std::string account_id =
719 ConnectProfileToAccount("12345", "user@gmail.com"); 701 ConnectProfileToAccount("12345", "user@gmail.com");
720 const std::string account_id2 = 702 const std::string account_id2 =
721 PickAccountIdForAccount("67890", "other@gmail.com"); 703 PickAccountIdForAccount("67890", "other@gmail.com");
722 token_service()->UpdateCredentials(account_id2, "refresh_token"); 704 token_service()->UpdateCredentials(account_id2, "refresh_token");
705 cookie_manager_service()->SetListAccountsResponseTwoAccountsWithExpiry(
706 "user@gmail.com", true, "other@gmail.com", false);
723 707
724 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); 708 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
725 709
726 SetFakeResponse(list_accounts_url().spec(),
727 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0],"
728 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
729 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
730
731 AccountReconcilor* reconcilor = 710 AccountReconcilor* reconcilor =
732 AccountReconcilorFactory::GetForProfile(profile()); 711 AccountReconcilorFactory::GetForProfile(profile());
733 ASSERT_TRUE(reconcilor); 712 ASSERT_TRUE(reconcilor);
734 713
735 ASSERT_FALSE(reconcilor->is_reconcile_started_); 714 ASSERT_FALSE(reconcilor->is_reconcile_started_);
736 reconcilor->StartReconcile(); 715 reconcilor->StartReconcile();
737 ASSERT_TRUE(reconcilor->is_reconcile_started_); 716 ASSERT_TRUE(reconcilor->is_reconcile_started_);
738 717
739 base::RunLoop().RunUntilIdle(); 718 base::RunLoop().RunUntilIdle();
740 SimulateAddAccountToCookieCompleted(reconcilor, account_id, 719 SimulateAddAccountToCookieCompleted(reconcilor, account_id,
741 GoogleServiceAuthError::AuthErrorNone()); 720 GoogleServiceAuthError::AuthErrorNone());
742 ASSERT_FALSE(reconcilor->is_reconcile_started_); 721 ASSERT_FALSE(reconcilor->is_reconcile_started_);
743 } 722 }
744 723
745 TEST_F(AccountReconcilorTest, AddAccountToCookieCompletedWithBogusAccount) { 724 TEST_F(AccountReconcilorTest, AddAccountToCookieCompletedWithBogusAccount) {
746 const std::string account_id = 725 const std::string account_id =
747 ConnectProfileToAccount("12345", "user@gmail.com"); 726 ConnectProfileToAccount("12345", "user@gmail.com");
727 cookie_manager_service()->SetListAccountsResponseOneAccountWithExpiry(
728 "user@gmail.com", true);
748 729
749 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); 730 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
750 731
751 SetFakeResponse(list_accounts_url().spec(),
752 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]",
753 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
754
755 AccountReconcilor* reconcilor = 732 AccountReconcilor* reconcilor =
756 AccountReconcilorFactory::GetForProfile(profile()); 733 AccountReconcilorFactory::GetForProfile(profile());
757 ASSERT_TRUE(reconcilor); 734 ASSERT_TRUE(reconcilor);
758 735
759 ASSERT_FALSE(reconcilor->is_reconcile_started_); 736 ASSERT_FALSE(reconcilor->is_reconcile_started_);
760 reconcilor->StartReconcile(); 737 reconcilor->StartReconcile();
761 ASSERT_TRUE(reconcilor->is_reconcile_started_); 738 ASSERT_TRUE(reconcilor->is_reconcile_started_);
762 739
763 base::RunLoop().RunUntilIdle(); 740 base::RunLoop().RunUntilIdle();
764 741
765 // If an unknown account id is sent, it should not upset the state. 742 // If an unknown account id is sent, it should not upset the state.
766 SimulateAddAccountToCookieCompleted(reconcilor, "bogus_account_id", 743 SimulateAddAccountToCookieCompleted(reconcilor, "bogus_account_id",
767 GoogleServiceAuthError::AuthErrorNone()); 744 GoogleServiceAuthError::AuthErrorNone());
768 ASSERT_TRUE(reconcilor->is_reconcile_started_); 745 ASSERT_TRUE(reconcilor->is_reconcile_started_);
769 746
770 SimulateAddAccountToCookieCompleted(reconcilor, account_id, 747 SimulateAddAccountToCookieCompleted(reconcilor, account_id,
771 GoogleServiceAuthError::AuthErrorNone()); 748 GoogleServiceAuthError::AuthErrorNone());
772 ASSERT_FALSE(reconcilor->is_reconcile_started_); 749 ASSERT_FALSE(reconcilor->is_reconcile_started_);
773 } 750 }
774 751
775 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, 752 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled,
776 AccountReconcilorTest, 753 AccountReconcilorTest,
777 testing::Bool()); 754 testing::Bool());
OLDNEW
« no previous file with comments | « chrome/browser/signin/about_signin_internals_factory.cc ('k') | chrome/browser/signin/chrome_signin_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698