| 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "chrome/browser/signin/account_reconcilor.h" | 8 #include "chrome/browser/signin/account_reconcilor.h" |
| 9 #include "chrome/browser/signin/account_reconcilor_factory.h" | 9 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" | 11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" |
| 12 #include "chrome/browser/signin/fake_signin_manager.h" | 12 #include "chrome/browser/signin/fake_signin_manager.h" |
| 13 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 13 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 15 #include "chrome/browser/signin/signin_manager.h" | 15 #include "chrome/browser/signin/signin_manager.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "google_apis/gaia/gaia_urls.h" |
| 19 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const char kTestEmail[] = "user@gmail.com"; | 26 const char kTestEmail[] = "user@gmail.com"; |
| 26 | 27 |
| 27 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { | 28 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { |
| 28 public: | 29 public: |
| 29 static BrowserContextKeyedService* Build(content::BrowserContext* profile); | 30 static BrowserContextKeyedService* Build(content::BrowserContext* profile); |
| 30 | 31 |
| 31 explicit MockAccountReconcilor(Profile* profile); | 32 explicit MockAccountReconcilor(Profile* profile); |
| 32 virtual ~MockAccountReconcilor() {} | 33 virtual ~MockAccountReconcilor() {} |
| 33 | 34 |
| 34 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id)); | 35 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id)); |
| 35 MOCK_METHOD1(StartRemoveAction, void(const std::string& account_id)); | 36 MOCK_METHOD1(StartRemoveAction, void(const std::string& account_id)); |
| 36 MOCK_METHOD3(FinishRemoveAction, | 37 MOCK_METHOD3( |
| 37 void(const std::string& account_id, | 38 FinishRemoveAction, |
| 38 const GoogleServiceAuthError& error, | 39 void(const std::string& account_id, |
| 39 const std::vector<std::string>& accounts)); | 40 const GoogleServiceAuthError& error, |
| 41 const std::vector<std::pair<std::string, bool> >& accounts)); |
| 40 MOCK_METHOD2(PerformAddToChromeAction, void(const std::string& account_id, | 42 MOCK_METHOD2(PerformAddToChromeAction, void(const std::string& account_id, |
| 41 int session_index)); | 43 int session_index)); |
| 42 MOCK_METHOD0(PerformLogoutAllAccountsAction, void()); | 44 MOCK_METHOD0(PerformLogoutAllAccountsAction, void()); |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 // static | 47 // static |
| 46 BrowserContextKeyedService* MockAccountReconcilor::Build( | 48 BrowserContextKeyedService* MockAccountReconcilor::Build( |
| 47 content::BrowserContext* profile) { | 49 content::BrowserContext* profile) { |
| 48 return new MockAccountReconcilor(static_cast<Profile*>(profile)); | 50 return new MockAccountReconcilor(static_cast<Profile*>(profile)); |
| 49 } | 51 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); | 200 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); |
| 199 } | 201 } |
| 200 | 202 |
| 201 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { | 203 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { |
| 202 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 204 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 203 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 205 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 204 AccountReconcilor* reconcilor = | 206 AccountReconcilor* reconcilor = |
| 205 AccountReconcilorFactory::GetForProfile(profile()); | 207 AccountReconcilorFactory::GetForProfile(profile()); |
| 206 ASSERT_TRUE(reconcilor); | 208 ASSERT_TRUE(reconcilor); |
| 207 | 209 |
| 208 SetFakeResponse("https://accounts.google.com/ListAccounts", | 210 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 209 "[\"foo\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0]]]", | 211 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", |
| 210 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 212 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 211 | 213 |
| 212 reconcilor->StartReconcile(); | 214 reconcilor->StartReconcile(); |
| 213 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 215 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
| 214 | 216 |
| 215 base::RunLoop().RunUntilIdle(); | 217 base::RunLoop().RunUntilIdle(); |
| 216 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); | 218 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); |
| 217 const std::vector<std::string>& accounts = | 219 const std::vector<std::pair<std::string, bool> >& accounts = |
| 218 reconcilor->GetGaiaAccountsForTesting(); | 220 reconcilor->GetGaiaAccountsForTesting(); |
| 219 ASSERT_EQ(1u, accounts.size()); | 221 ASSERT_EQ(1u, accounts.size()); |
| 220 ASSERT_EQ("user@gmail.com", accounts[0]); | 222 ASSERT_EQ("user@gmail.com", accounts[0].first); |
| 221 } | 223 } |
| 222 | 224 |
| 223 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { | 225 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { |
| 224 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 226 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 225 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 227 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 226 AccountReconcilor* reconcilor = | 228 AccountReconcilor* reconcilor = |
| 227 AccountReconcilorFactory::GetForProfile(profile()); | 229 AccountReconcilorFactory::GetForProfile(profile()); |
| 228 ASSERT_TRUE(reconcilor); | 230 ASSERT_TRUE(reconcilor); |
| 229 | 231 |
| 230 SetFakeResponse("https://accounts.google.com/ListAccounts", "", | 232 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), "", |
| 231 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); | 233 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); |
| 232 | 234 |
| 233 reconcilor->StartReconcile(); | 235 reconcilor->StartReconcile(); |
| 234 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 236 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
| 235 | 237 |
| 236 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
| 237 ASSERT_EQ(0u, reconcilor->GetGaiaAccountsForTesting().size()); | 239 ASSERT_EQ(0u, reconcilor->GetGaiaAccountsForTesting().size()); |
| 238 } | 240 } |
| 239 | 241 |
| 240 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokens) { | 242 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokens) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 304 } |
| 303 | 305 |
| 304 TEST_F(AccountReconcilorTest, StartReconcileNoop) { | 306 TEST_F(AccountReconcilorTest, StartReconcileNoop) { |
| 305 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 307 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 306 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 308 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 307 | 309 |
| 308 AccountReconcilor* reconcilor = | 310 AccountReconcilor* reconcilor = |
| 309 AccountReconcilorFactory::GetForProfile(profile()); | 311 AccountReconcilorFactory::GetForProfile(profile()); |
| 310 ASSERT_TRUE(reconcilor); | 312 ASSERT_TRUE(reconcilor); |
| 311 | 313 |
| 312 SetFakeResponse("https://accounts.google.com/ListAccounts", | 314 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 313 "[\"foo\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0]]]", | 315 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 314 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 316 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 315 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | 317 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", |
| 316 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 318 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 317 | 319 |
| 318 reconcilor->StartReconcile(); | 320 reconcilor->StartReconcile(); |
| 319 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 321 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
| 320 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | 322 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); |
| 321 | 323 |
| 322 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
| 323 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); | 325 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 334 | 336 |
| 335 TEST_F(AccountReconcilorTest, StartReconcileNoopMultiple) { | 337 TEST_F(AccountReconcilorTest, StartReconcileNoopMultiple) { |
| 336 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 338 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 337 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 339 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 338 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 340 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 339 | 341 |
| 340 AccountReconcilor* reconcilor = | 342 AccountReconcilor* reconcilor = |
| 341 AccountReconcilorFactory::GetForProfile(profile()); | 343 AccountReconcilorFactory::GetForProfile(profile()); |
| 342 ASSERT_TRUE(reconcilor); | 344 ASSERT_TRUE(reconcilor); |
| 343 | 345 |
| 344 SetFakeResponse("https://accounts.google.com/ListAccounts", | 346 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 345 "[\"foo\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0], " | 347 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
| 346 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0]]]", | 348 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 347 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 349 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 348 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | 350 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", |
| 349 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 351 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 350 | 352 |
| 351 reconcilor->StartReconcile(); | 353 reconcilor->StartReconcile(); |
| 352 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 354 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
| 353 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | 355 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); |
| 354 | 356 |
| 355 base::RunLoop().RunUntilIdle(); | 357 base::RunLoop().RunUntilIdle(); |
| 356 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); | 358 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 371 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 373 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 372 } | 374 } |
| 373 | 375 |
| 374 TEST_F(AccountReconcilorTest, StartReconcileAddToCookie) { | 376 TEST_F(AccountReconcilorTest, StartReconcileAddToCookie) { |
| 375 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 377 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 376 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 378 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 377 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 379 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 378 | 380 |
| 379 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 381 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
| 380 | 382 |
| 381 SetFakeResponse("https://accounts.google.com/ListAccounts", | 383 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 382 "[\"foo\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0]]]", | 384 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 383 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 385 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 384 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | 386 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", |
| 385 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 387 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 386 | 388 |
| 387 AccountReconcilor* reconcilor = GetMockReconcilor(); | 389 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 388 reconcilor->StartReconcile(); | 390 reconcilor->StartReconcile(); |
| 389 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", | 391 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", |
| 390 base::Time::Now() + base::TimeDelta::FromHours(1)); | 392 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 391 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | 393 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 392 base::Time::Now() + base::TimeDelta::FromHours(1)); | 394 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 393 | 395 |
| 394 base::RunLoop().RunUntilIdle(); | 396 base::RunLoop().RunUntilIdle(); |
| 395 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 397 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 396 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", | 398 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", |
| 397 GoogleServiceAuthError::AuthErrorNone()); | 399 GoogleServiceAuthError::AuthErrorNone()); |
| 398 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 400 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 399 } | 401 } |
| 400 | 402 |
| 401 TEST_F(AccountReconcilorTest, StartReconcileAddToChrome) { | 403 TEST_F(AccountReconcilorTest, StartReconcileAddToChrome) { |
| 402 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 404 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 403 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 405 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 404 | 406 |
| 405 EXPECT_CALL(*GetMockReconcilor(), | 407 EXPECT_CALL(*GetMockReconcilor(), |
| 406 PerformAddToChromeAction("other@gmail.com", 1)); | 408 PerformAddToChromeAction("other@gmail.com", 1)); |
| 407 | 409 |
| 408 SetFakeResponse("https://accounts.google.com/ListAccounts", | 410 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 409 "[\"foo\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0], " | 411 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
| 410 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0]]]", | 412 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 411 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 413 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 412 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | 414 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", |
| 413 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 415 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 414 | 416 |
| 415 AccountReconcilor* reconcilor = GetMockReconcilor(); | 417 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 416 reconcilor->StartReconcile(); | 418 reconcilor->StartReconcile(); |
| 417 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | 419 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 418 base::Time::Now() + base::TimeDelta::FromHours(1)); | 420 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 419 | 421 |
| 420 base::RunLoop().RunUntilIdle(); | 422 base::RunLoop().RunUntilIdle(); |
| 421 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 423 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 422 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", ""); | 424 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", ""); |
| 423 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 425 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 424 } | 426 } |
| 425 | 427 |
| 426 TEST_F(AccountReconcilorTest, StartReconcileBadPrimary) { | 428 TEST_F(AccountReconcilorTest, StartReconcileBadPrimary) { |
| 427 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 429 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 428 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 430 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 429 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 431 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 430 | 432 |
| 431 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); | 433 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); |
| 432 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 434 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
| 433 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 435 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
| 434 | 436 |
| 435 SetFakeResponse("https://accounts.google.com/ListAccounts", | 437 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 436 "[\"foo\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0], " | 438 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
| 437 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0]]]", | 439 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 438 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 440 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 439 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | 441 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", |
| 440 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 442 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 441 | 443 |
| 442 AccountReconcilor* reconcilor = GetMockReconcilor(); | 444 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 443 reconcilor->StartReconcile(); | 445 reconcilor->StartReconcile(); |
| 444 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", | 446 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", |
| 445 base::Time::Now() + base::TimeDelta::FromHours(1)); | 447 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 446 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | 448 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 447 base::Time::Now() + base::TimeDelta::FromHours(1)); | 449 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 448 | 450 |
| 449 base::RunLoop().RunUntilIdle(); | 451 base::RunLoop().RunUntilIdle(); |
| 450 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 452 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 451 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", | 453 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", |
| 452 GoogleServiceAuthError::AuthErrorNone()); | 454 GoogleServiceAuthError::AuthErrorNone()); |
| 453 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 455 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 454 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", | 456 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
| 455 GoogleServiceAuthError::AuthErrorNone()); | 457 GoogleServiceAuthError::AuthErrorNone()); |
| 456 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 458 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 457 } | 459 } |
| 458 | 460 |
| 459 TEST_F(AccountReconcilorTest, StartReconcileOnlyOnce) { | 461 TEST_F(AccountReconcilorTest, StartReconcileOnlyOnce) { |
| 460 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 462 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
| 461 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 463 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 462 | 464 |
| 463 AccountReconcilor* reconcilor = | 465 AccountReconcilor* reconcilor = |
| 464 AccountReconcilorFactory::GetForProfile(profile()); | 466 AccountReconcilorFactory::GetForProfile(profile()); |
| 465 ASSERT_TRUE(reconcilor); | 467 ASSERT_TRUE(reconcilor); |
| 466 | 468 |
| 467 SetFakeResponse("https://accounts.google.com/ListAccounts", | 469 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 468 "[\"foo\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0]]]", | 470 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 469 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 471 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 470 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | 472 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", |
| 471 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 473 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 472 | 474 |
| 473 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 475 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 474 reconcilor->StartReconcile(); | 476 reconcilor->StartReconcile(); |
| 475 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 477 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 476 | 478 |
| 477 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | 479 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 478 base::Time::Now() + base::TimeDelta::FromHours(1)); | 480 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 479 | 481 |
| 480 base::RunLoop().RunUntilIdle(); | 482 base::RunLoop().RunUntilIdle(); |
| 481 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 483 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 482 } | 484 } |
| 485 |
| 486 TEST_F(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { |
| 487 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 488 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 489 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
| 490 |
| 491 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
| 492 |
| 493 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 494 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]," |
| 495 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
| 496 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 497 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", |
| 498 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 499 |
| 500 AccountReconcilor* reconcilor = |
| 501 AccountReconcilorFactory::GetForProfile(profile()); |
| 502 ASSERT_TRUE(reconcilor); |
| 503 |
| 504 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 505 reconcilor->StartReconcile(); |
| 506 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 507 |
| 508 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", |
| 509 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 510 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", |
| 511 base::Time::Now() + base::TimeDelta::FromHours(1)); |
| 512 |
| 513 base::RunLoop().RunUntilIdle(); |
| 514 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
| 515 GoogleServiceAuthError::AuthErrorNone()); |
| 516 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 517 } |
| OLD | NEW |