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

Powered by Google App Engine
This is Rietveld 408576698