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

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

Issue 601643002: Use a distinct source parameter on gaia endpoints for the reconcilor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@uber
Patch Set: Address review comments Created 6 years, 2 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/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "chrome/browser/prefs/pref_service_syncable.h" 13 #include "chrome/browser/prefs/pref_service_syncable.h"
13 #include "chrome/browser/signin/account_reconcilor_factory.h" 14 #include "chrome/browser/signin/account_reconcilor_factory.h"
14 #include "chrome/browser/signin/chrome_signin_client_factory.h" 15 #include "chrome/browser/signin/chrome_signin_client_factory.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/profile_oauth2_token_service_factory.h" 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/browser/signin/test_signin_client_builder.h" 21 #include "chrome/browser/signin/test_signin_client_builder.h"
21 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "chrome/test/base/testing_profile_manager.h" 24 #include "chrome/test/base/testing_profile_manager.h"
24 #include "components/signin/core/browser/account_reconcilor.h" 25 #include "components/signin/core/browser/account_reconcilor.h"
25 #include "components/signin/core/browser/profile_oauth2_token_service.h" 26 #include "components/signin/core/browser/profile_oauth2_token_service.h"
26 #include "components/signin/core/browser/signin_manager.h" 27 #include "components/signin/core/browser/signin_manager.h"
27 #include "components/signin/core/browser/signin_metrics.h" 28 #include "components/signin/core/browser/signin_metrics.h"
28 #include "components/signin/core/common/profile_management_switches.h" 29 #include "components/signin/core/common/profile_management_switches.h"
29 #include "components/signin/core/common/signin_switches.h" 30 #include "components/signin/core/common/signin_switches.h"
30 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "google_apis/gaia/gaia_constants.h"
31 #include "google_apis/gaia/gaia_urls.h" 33 #include "google_apis/gaia/gaia_urls.h"
32 #include "net/url_request/test_url_fetcher_factory.h" 34 #include "net/url_request/test_url_fetcher_factory.h"
33 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
35 37
36 namespace { 38 namespace {
37 39
38 const char kTestEmail[] = "user@gmail.com"; 40 const char kTestEmail[] = "user@gmail.com";
39 41
40 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { 42 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); 94 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status);
93 } 95 }
94 96
95 MockAccountReconcilor* GetMockReconcilor(); 97 MockAccountReconcilor* GetMockReconcilor();
96 98
97 void SimulateMergeSessionCompleted( 99 void SimulateMergeSessionCompleted(
98 MergeSessionHelper::Observer* observer, 100 MergeSessionHelper::Observer* observer,
99 const std::string& account_id, 101 const std::string& account_id,
100 const GoogleServiceAuthError& error); 102 const GoogleServiceAuthError& error);
101 103
104 GURL list_accounts_url() { return list_accounts_url_; }
105
102 private: 106 private:
103 content::TestBrowserThreadBundle bundle_; 107 content::TestBrowserThreadBundle bundle_;
104 TestingProfile* profile_; 108 TestingProfile* profile_;
105 FakeSigninManagerForTesting* signin_manager_; 109 FakeSigninManagerForTesting* signin_manager_;
106 FakeProfileOAuth2TokenService* token_service_; 110 FakeProfileOAuth2TokenService* token_service_;
107 MockAccountReconcilor* mock_reconcilor_; 111 MockAccountReconcilor* mock_reconcilor_;
108 net::FakeURLFetcherFactory url_fetcher_factory_; 112 net::FakeURLFetcherFactory url_fetcher_factory_;
109 scoped_ptr<TestingProfileManager> testing_profile_manager_; 113 scoped_ptr<TestingProfileManager> testing_profile_manager_;
110 base::HistogramTester histogram_tester_; 114 base::HistogramTester histogram_tester_;
115 GURL list_accounts_url_;
111 116
112 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest); 117 DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest);
113 }; 118 };
114 119
115 AccountReconcilorTest::AccountReconcilorTest() 120 AccountReconcilorTest::AccountReconcilorTest()
116 : signin_manager_(NULL), 121 : signin_manager_(NULL),
117 token_service_(NULL), 122 token_service_(NULL),
118 mock_reconcilor_(NULL), 123 mock_reconcilor_(NULL),
119 url_fetcher_factory_(NULL) {} 124 url_fetcher_factory_(NULL) {}
120 125
121 void AccountReconcilorTest::SetUp() { 126 void AccountReconcilorTest::SetUp() {
122 // If it's a non-parameterized test, or we have a parameter of true, set flag. 127 // If it's a non-parameterized test, or we have a parameter of true, set flag.
123 if (!::testing::UnitTest::GetInstance()->current_test_info()->value_param() || 128 if (!::testing::UnitTest::GetInstance()->current_test_info()->value_param() ||
124 GetParam()) { 129 GetParam()) {
125 CommandLine::ForCurrentProcess()->AppendSwitch( 130 CommandLine::ForCurrentProcess()->AppendSwitch(
126 switches::kEnableNewProfileManagement); 131 switches::kEnableNewProfileManagement);
127 } 132 }
128 133
134 list_accounts_url_ = GaiaUrls::GetInstance()->ListAccountsURLWithSource(
135 GaiaConstants::kReconcilorSource);
136
129 testing_profile_manager_.reset( 137 testing_profile_manager_.reset(
130 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 138 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
131 ASSERT_TRUE(testing_profile_manager_.get()->SetUp()); 139 ASSERT_TRUE(testing_profile_manager_.get()->SetUp());
132 140
133 TestingProfile::TestingFactories factories; 141 TestingProfile::TestingFactories factories;
134 factories.push_back(std::make_pair(ChromeSigninClientFactory::GetInstance(), 142 factories.push_back(std::make_pair(ChromeSigninClientFactory::GetInstance(),
135 signin::BuildTestSigninClient)); 143 signin::BuildTestSigninClient));
136 factories.push_back(std::make_pair( 144 factories.push_back(std::make_pair(
137 ProfileOAuth2TokenServiceFactory::GetInstance(), 145 ProfileOAuth2TokenServiceFactory::GetInstance(),
138 BuildFakeProfileOAuth2TokenService)); 146 BuildFakeProfileOAuth2TokenService));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 239 }
232 240
233 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { 241 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) {
234 signin_manager()->SetAuthenticatedUsername(kTestEmail); 242 signin_manager()->SetAuthenticatedUsername(kTestEmail);
235 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); 243 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
236 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(kTestEmail)); 244 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(kTestEmail));
237 AccountReconcilor* reconcilor = 245 AccountReconcilor* reconcilor =
238 AccountReconcilorFactory::GetForProfile(profile()); 246 AccountReconcilorFactory::GetForProfile(profile());
239 ASSERT_TRUE(reconcilor); 247 ASSERT_TRUE(reconcilor);
240 248
241 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 249 SetFakeResponse(list_accounts_url().spec(),
242 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", 250 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]",
243 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 251 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
244 252
245 reconcilor->StartReconcile(); 253 reconcilor->StartReconcile();
246 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 254 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
247 255
248 base::RunLoop().RunUntilIdle(); 256 base::RunLoop().RunUntilIdle();
249 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); 257 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
250 const std::vector<std::pair<std::string, bool> >& accounts = 258 const std::vector<std::pair<std::string, bool> >& accounts =
251 reconcilor->GetGaiaAccountsForTesting(); 259 reconcilor->GetGaiaAccountsForTesting();
252 ASSERT_EQ(1u, accounts.size()); 260 ASSERT_EQ(1u, accounts.size());
253 ASSERT_EQ("user@gmail.com", accounts[0].first); 261 ASSERT_EQ("user@gmail.com", accounts[0].first);
254 } 262 }
255 263
256 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { 264 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) {
257 signin_manager()->SetAuthenticatedUsername(kTestEmail); 265 signin_manager()->SetAuthenticatedUsername(kTestEmail);
258 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); 266 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
259 AccountReconcilor* reconcilor = 267 AccountReconcilor* reconcilor =
260 AccountReconcilorFactory::GetForProfile(profile()); 268 AccountReconcilorFactory::GetForProfile(profile());
261 ASSERT_TRUE(reconcilor); 269 ASSERT_TRUE(reconcilor);
262 270
263 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), "", 271 SetFakeResponse(list_accounts_url().spec(), "",
264 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); 272 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
265 273
266 reconcilor->StartReconcile(); 274 reconcilor->StartReconcile();
267 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 275 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
268 276
269 base::RunLoop().RunUntilIdle(); 277 base::RunLoop().RunUntilIdle();
270 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 278 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
271 } 279 }
272 280
273 TEST_P(AccountReconcilorTest, StartReconcileNoop) { 281 TEST_P(AccountReconcilorTest, StartReconcileNoop) {
274 signin_manager()->SetAuthenticatedUsername(kTestEmail); 282 signin_manager()->SetAuthenticatedUsername(kTestEmail);
275 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); 283 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
276 284
277 AccountReconcilor* reconcilor = 285 AccountReconcilor* reconcilor =
278 AccountReconcilorFactory::GetForProfile(profile()); 286 AccountReconcilorFactory::GetForProfile(profile());
279 ASSERT_TRUE(reconcilor); 287 ASSERT_TRUE(reconcilor);
280 288
281 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 289 SetFakeResponse(list_accounts_url().spec(),
282 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 290 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
283 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 291 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
284 292
285 reconcilor->StartReconcile(); 293 reconcilor->StartReconcile();
286 ASSERT_TRUE(reconcilor->is_reconcile_started_); 294 ASSERT_TRUE(reconcilor->is_reconcile_started_);
287 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 295 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
288 296
289 base::RunLoop().RunUntilIdle(); 297 base::RunLoop().RunUntilIdle();
290 ASSERT_FALSE(reconcilor->is_reconcile_started_); 298 ASSERT_FALSE(reconcilor->is_reconcile_started_);
291 299
(...skipping 14 matching lines...) Expand all
306 // token service, will be considered the same as "dots@gmail.com" as returned 314 // token service, will be considered the same as "dots@gmail.com" as returned
307 // by gaia::ParseListAccountsData(). 315 // by gaia::ParseListAccountsData().
308 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { 316 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) {
309 signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com"); 317 signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com");
310 token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token"); 318 token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token");
311 319
312 AccountReconcilor* reconcilor = 320 AccountReconcilor* reconcilor =
313 AccountReconcilorFactory::GetForProfile(profile()); 321 AccountReconcilorFactory::GetForProfile(profile());
314 ASSERT_TRUE(reconcilor); 322 ASSERT_TRUE(reconcilor);
315 323
316 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 324 SetFakeResponse(list_accounts_url().spec(),
317 "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 325 "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
318 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 326 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
319 327
320 reconcilor->StartReconcile(); 328 reconcilor->StartReconcile();
321 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 329 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
322 330
323 base::RunLoop().RunUntilIdle(); 331 base::RunLoop().RunUntilIdle();
324 ASSERT_FALSE(reconcilor->is_reconcile_started_); 332 ASSERT_FALSE(reconcilor->is_reconcile_started_);
325 333
326 histogram_tester()->ExpectUniqueSample( 334 histogram_tester()->ExpectUniqueSample(
327 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 335 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
328 signin_metrics::ACCOUNTS_SAME, 336 signin_metrics::ACCOUNTS_SAME,
329 1); 337 1);
330 } 338 }
331 339
332 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { 340 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) {
333 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 341 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
334 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 342 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
335 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 343 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
336 344
337 AccountReconcilor* reconcilor = 345 AccountReconcilor* reconcilor =
338 AccountReconcilorFactory::GetForProfile(profile()); 346 AccountReconcilorFactory::GetForProfile(profile());
339 ASSERT_TRUE(reconcilor); 347 ASSERT_TRUE(reconcilor);
340 348
341 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 349 SetFakeResponse(list_accounts_url().spec(),
342 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 350 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
343 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 351 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
344 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 352 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
345 353
346 reconcilor->StartReconcile(); 354 reconcilor->StartReconcile();
347 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); 355 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
348 base::RunLoop().RunUntilIdle(); 356 base::RunLoop().RunUntilIdle();
349 ASSERT_FALSE(reconcilor->is_reconcile_started_); 357 ASSERT_FALSE(reconcilor->is_reconcile_started_);
350 358
351 histogram_tester()->ExpectTotalCount( 359 histogram_tester()->ExpectTotalCount(
352 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); 360 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
353 histogram_tester()->ExpectUniqueSample( 361 histogram_tester()->ExpectUniqueSample(
354 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 362 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
355 signin_metrics::ACCOUNTS_SAME, 363 signin_metrics::ACCOUNTS_SAME,
356 1); 364 1);
357 } 365 }
358 366
359 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { 367 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
360 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 368 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
361 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 369 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
362 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 370 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
363 371
364 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); 372 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
365 373
366 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 374 SetFakeResponse(list_accounts_url().spec(),
367 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 375 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
368 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 376 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
369 377
370 AccountReconcilor* reconcilor = GetMockReconcilor(); 378 AccountReconcilor* reconcilor = GetMockReconcilor();
371 reconcilor->StartReconcile(); 379 reconcilor->StartReconcile();
372 380
373 base::RunLoop().RunUntilIdle(); 381 base::RunLoop().RunUntilIdle();
374 ASSERT_TRUE(reconcilor->is_reconcile_started_); 382 ASSERT_TRUE(reconcilor->is_reconcile_started_);
375 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", 383 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com",
376 GoogleServiceAuthError::AuthErrorNone()); 384 GoogleServiceAuthError::AuthErrorNone());
377 ASSERT_FALSE(reconcilor->is_reconcile_started_); 385 ASSERT_FALSE(reconcilor->is_reconcile_started_);
378 386
379 histogram_tester()->ExpectUniqueSample( 387 histogram_tester()->ExpectUniqueSample(
380 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 388 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
381 signin_metrics::ACCOUNTS_SAME, 389 signin_metrics::ACCOUNTS_SAME,
382 1); 390 1);
383 histogram_tester()->ExpectUniqueSample( 391 histogram_tester()->ExpectUniqueSample(
384 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 392 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
385 histogram_tester()->ExpectUniqueSample( 393 histogram_tester()->ExpectUniqueSample(
386 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); 394 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1);
387 } 395 }
388 396
389 TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) { 397 TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) {
390 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 398 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
391 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 399 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
392 400
393 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); 401 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
394 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); 402 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
395 403
396 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 404 SetFakeResponse(list_accounts_url().spec(),
397 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 405 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
398 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 406 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
399 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 407 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
400 408
401 AccountReconcilor* reconcilor = GetMockReconcilor(); 409 AccountReconcilor* reconcilor = GetMockReconcilor();
402 reconcilor->StartReconcile(); 410 reconcilor->StartReconcile();
403 ASSERT_TRUE(reconcilor->is_reconcile_started_); 411 ASSERT_TRUE(reconcilor->is_reconcile_started_);
404 412
405 base::RunLoop().RunUntilIdle(); 413 base::RunLoop().RunUntilIdle();
406 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 414 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
(...skipping 12 matching lines...) Expand all
419 427
420 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { 428 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
421 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 429 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
422 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 430 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
423 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 431 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
424 432
425 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); 433 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
426 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); 434 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com"));
427 435
428 SetFakeResponse( 436 SetFakeResponse(
429 GaiaUrls::GetInstance()->list_accounts_url().spec(), 437 list_accounts_url().spec(),
430 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 438 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
431 net::HTTP_OK, 439 net::HTTP_OK,
432 net::URLRequestStatus::SUCCESS); 440 net::URLRequestStatus::SUCCESS);
433 441
434 AccountReconcilor* reconcilor = GetMockReconcilor(); 442 AccountReconcilor* reconcilor = GetMockReconcilor();
435 reconcilor->StartReconcile(); 443 reconcilor->StartReconcile();
436 444
437 base::RunLoop().RunUntilIdle(); 445 base::RunLoop().RunUntilIdle();
438 ASSERT_TRUE(reconcilor->is_reconcile_started_); 446 ASSERT_TRUE(reconcilor->is_reconcile_started_);
439 SimulateMergeSessionCompleted( 447 SimulateMergeSessionCompleted(
440 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); 448 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone());
441 ASSERT_FALSE(reconcilor->is_reconcile_started_); 449 ASSERT_FALSE(reconcilor->is_reconcile_started_);
442 450
443 histogram_tester()->ExpectUniqueSample( 451 histogram_tester()->ExpectUniqueSample(
444 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 452 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
445 signin_metrics::ACCOUNTS_SAME, 453 signin_metrics::ACCOUNTS_SAME,
446 1); 454 1);
447 histogram_tester()->ExpectUniqueSample( 455 histogram_tester()->ExpectUniqueSample(
448 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); 456 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
449 histogram_tester()->ExpectUniqueSample( 457 histogram_tester()->ExpectUniqueSample(
450 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); 458 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1);
451 459
452 // Do another pass after I've added a third account to the token service 460 // Do another pass after I've added a third account to the token service
453 461
454 SetFakeResponse( 462 SetFakeResponse(
455 GaiaUrls::GetInstance()->list_accounts_url().spec(), 463 list_accounts_url().spec(),
456 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 464 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
457 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 465 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
458 net::HTTP_OK, 466 net::HTTP_OK,
459 net::URLRequestStatus::SUCCESS); 467 net::URLRequestStatus::SUCCESS);
460 // This will cause the reconcilor to fire. 468 // This will cause the reconcilor to fire.
461 token_service()->UpdateCredentials("third@gmail.com", "refresh_token"); 469 token_service()->UpdateCredentials("third@gmail.com", "refresh_token");
462 470
463 base::RunLoop().RunUntilIdle(); 471 base::RunLoop().RunUntilIdle();
464 472
465 ASSERT_TRUE(reconcilor->is_reconcile_started_); 473 ASSERT_TRUE(reconcilor->is_reconcile_started_);
(...skipping 21 matching lines...) Expand all
487 495
488 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { 496 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
489 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 497 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
490 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 498 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
491 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 499 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
492 500
493 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); 501 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
494 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); 502 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
495 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); 503 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
496 504
497 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 505 SetFakeResponse(list_accounts_url().spec(),
498 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], " 506 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
499 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 507 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
500 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 508 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
501 509
502 AccountReconcilor* reconcilor = GetMockReconcilor(); 510 AccountReconcilor* reconcilor = GetMockReconcilor();
503 reconcilor->StartReconcile(); 511 reconcilor->StartReconcile();
504 512
505 base::RunLoop().RunUntilIdle(); 513 base::RunLoop().RunUntilIdle();
506 ASSERT_TRUE(reconcilor->is_reconcile_started_); 514 ASSERT_TRUE(reconcilor->is_reconcile_started_);
507 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", 515 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com",
(...skipping 14 matching lines...) Expand all
522 } 530 }
523 531
524 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { 532 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) {
525 signin_manager()->SetAuthenticatedUsername(kTestEmail); 533 signin_manager()->SetAuthenticatedUsername(kTestEmail);
526 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); 534 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
527 535
528 AccountReconcilor* reconcilor = 536 AccountReconcilor* reconcilor =
529 AccountReconcilorFactory::GetForProfile(profile()); 537 AccountReconcilorFactory::GetForProfile(profile());
530 ASSERT_TRUE(reconcilor); 538 ASSERT_TRUE(reconcilor);
531 539
532 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 540 SetFakeResponse(list_accounts_url().spec(),
533 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 541 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
534 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 542 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
535 543
536 ASSERT_FALSE(reconcilor->is_reconcile_started_); 544 ASSERT_FALSE(reconcilor->is_reconcile_started_);
537 reconcilor->StartReconcile(); 545 reconcilor->StartReconcile();
538 ASSERT_TRUE(reconcilor->is_reconcile_started_); 546 ASSERT_TRUE(reconcilor->is_reconcile_started_);
539 547
540 base::RunLoop().RunUntilIdle(); 548 base::RunLoop().RunUntilIdle();
541 ASSERT_FALSE(reconcilor->is_reconcile_started_); 549 ASSERT_FALSE(reconcilor->is_reconcile_started_);
542 } 550 }
543 551
544 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { 552 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) {
545 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 553 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
546 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 554 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
547 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 555 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
548 556
549 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); 557 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
550 558
551 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 559 SetFakeResponse(list_accounts_url().spec(),
552 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]," 560 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0],"
553 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 561 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
554 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 562 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
555 563
556 AccountReconcilor* reconcilor = 564 AccountReconcilor* reconcilor =
557 AccountReconcilorFactory::GetForProfile(profile()); 565 AccountReconcilorFactory::GetForProfile(profile());
558 ASSERT_TRUE(reconcilor); 566 ASSERT_TRUE(reconcilor);
559 567
560 ASSERT_FALSE(reconcilor->is_reconcile_started_); 568 ASSERT_FALSE(reconcilor->is_reconcile_started_);
561 reconcilor->StartReconcile(); 569 reconcilor->StartReconcile();
562 ASSERT_TRUE(reconcilor->is_reconcile_started_); 570 ASSERT_TRUE(reconcilor->is_reconcile_started_);
563 571
564 base::RunLoop().RunUntilIdle(); 572 base::RunLoop().RunUntilIdle();
565 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 573 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
566 GoogleServiceAuthError::AuthErrorNone()); 574 GoogleServiceAuthError::AuthErrorNone());
567 ASSERT_FALSE(reconcilor->is_reconcile_started_); 575 ASSERT_FALSE(reconcilor->is_reconcile_started_);
568 } 576 }
569 577
570 TEST_F(AccountReconcilorTest, MergeSessionCompletedWithBogusAccount) { 578 TEST_F(AccountReconcilorTest, MergeSessionCompletedWithBogusAccount) {
571 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 579 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
572 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 580 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
573 581
574 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); 582 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
575 583
576 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 584 SetFakeResponse(list_accounts_url().spec(),
577 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", 585 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]",
578 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 586 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
579 587
580 AccountReconcilor* reconcilor = 588 AccountReconcilor* reconcilor =
581 AccountReconcilorFactory::GetForProfile(profile()); 589 AccountReconcilorFactory::GetForProfile(profile());
582 ASSERT_TRUE(reconcilor); 590 ASSERT_TRUE(reconcilor);
583 591
584 ASSERT_FALSE(reconcilor->is_reconcile_started_); 592 ASSERT_FALSE(reconcilor->is_reconcile_started_);
585 reconcilor->StartReconcile(); 593 reconcilor->StartReconcile();
586 ASSERT_TRUE(reconcilor->is_reconcile_started_); 594 ASSERT_TRUE(reconcilor->is_reconcile_started_);
587 595
588 base::RunLoop().RunUntilIdle(); 596 base::RunLoop().RunUntilIdle();
589 597
590 // If an unknown account id is sent, it should not upset the state. 598 // If an unknown account id is sent, it should not upset the state.
591 SimulateMergeSessionCompleted(reconcilor, "bogus@gmail.com", 599 SimulateMergeSessionCompleted(reconcilor, "bogus@gmail.com",
592 GoogleServiceAuthError::AuthErrorNone()); 600 GoogleServiceAuthError::AuthErrorNone());
593 ASSERT_TRUE(reconcilor->is_reconcile_started_); 601 ASSERT_TRUE(reconcilor->is_reconcile_started_);
594 602
595 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 603 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
596 GoogleServiceAuthError::AuthErrorNone()); 604 GoogleServiceAuthError::AuthErrorNone());
597 ASSERT_FALSE(reconcilor->is_reconcile_started_); 605 ASSERT_FALSE(reconcilor->is_reconcile_started_);
598 } 606 }
599 607
600 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, 608 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled,
601 AccountReconcilorTest, 609 AccountReconcilorTest,
602 testing::Bool()); 610 testing::Bool());
603 611
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698