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