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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/run_loop.h"
7 #include "base/time/time.h"
8 #include "chrome/browser/signin/account_reconcilor.h"
9 #include "chrome/browser/signin/account_reconcilor_factory.h"
10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h"
12 #include "chrome/browser/signin/fake_signin_manager.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager.h"
16 #include "chrome/browser/signin/signin_manager_factory.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "google_apis/gaia/gaia_urls.h"
20 #include "net/url_request/test_url_fetcher_factory.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
26 const char kTestEmail[] = "user@gmail.com";
28 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> {
30 static BrowserContextKeyedService* Build(content::BrowserContext* profile);
32 explicit MockAccountReconcilor(Profile* profile);
33 virtual ~MockAccountReconcilor() {}
35 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id));
36 MOCK_METHOD1(StartRemoveAction, void(const std::string& account_id));
39 void(const std::string& account_id,
40 const GoogleServiceAuthError& error,
41 const std::vector<std::pair<std::string, bool> >& accounts));
42 MOCK_METHOD2(PerformAddToChromeAction, void(const std::string& account_id,
44 MOCK_METHOD0(PerformLogoutAllAccountsAction, void());
48 BrowserContextKeyedService* MockAccountReconcilor::Build(
49 content::BrowserContext* profile) {
50 return new MockAccountReconcilor(static_cast<Profile*>(profile));
53 MockAccountReconcilor::MockAccountReconcilor(Profile* profile)
54 : testing::StrictMock<AccountReconcilor>(profile) {
59 class AccountReconcilorTest : public testing::Test {
61 AccountReconcilorTest();
62 virtual void SetUp() OVERRIDE;
63 virtual void TearDown() OVERRIDE;
65 TestingProfile* profile() { return profile_.get(); }
66 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; }
67 FakeProfileOAuth2TokenService* token_service() { return token_service_; }
69 void SetFakeResponse(const std::string& url,
70 const std::string& data,
71 net::HttpStatusCode code,
72 net::URLRequestStatus::Status status) {
73 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status);
76 MockAccountReconcilor* GetMockReconcilor();
78 void SimulateMergeSessionCompleted(
79 MergeSessionHelper::Observer* observer,
80 const std::string& account_id,
81 const GoogleServiceAuthError& error);
83 void SimulateRefreshTokenFetched(
84 AccountReconcilor* reconcilor,
85 const std::string& account_id,
86 const std::string& refresh_token);
89 content::TestBrowserThreadBundle bundle_;
90 scoped_ptr<TestingProfile> profile_;
91 FakeSigninManagerForTesting* signin_manager_;
92 FakeProfileOAuth2TokenService* token_service_;
93 MockAccountReconcilor* mock_reconcilor_;
94 net::FakeURLFetcherFactory url_fetcher_factory_;
97 AccountReconcilorTest::AccountReconcilorTest()
98 : signin_manager_(NULL),
100 mock_reconcilor_(NULL),
101 url_fetcher_factory_(NULL) {}
103 void AccountReconcilorTest::SetUp() {
104 TestingProfile::Builder builder;
105 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
106 FakeProfileOAuth2TokenServiceWrapper::Build);
107 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
108 FakeSigninManagerBase::Build);
109 builder.AddTestingFactory(AccountReconcilorFactory::GetInstance(),
110 MockAccountReconcilor::Build);
111 profile_ = builder.Build();
114 static_cast<FakeSigninManagerForTesting*>(
115 SigninManagerFactory::GetForProfile(profile()));
118 static_cast<FakeProfileOAuth2TokenService*>(
119 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()));
122 void AccountReconcilorTest::TearDown() {
123 // Destroy the profile before all threads are torn down.
127 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() {
128 if (!mock_reconcilor_) {
130 static_cast<MockAccountReconcilor*>(
131 AccountReconcilorFactory::GetForProfile(profile()));
134 return mock_reconcilor_;
137 void AccountReconcilorTest::SimulateMergeSessionCompleted(
138 MergeSessionHelper::Observer* observer,
139 const std::string& account_id,
140 const GoogleServiceAuthError& error) {
141 observer->MergeSessionCompleted(account_id, error);
144 void AccountReconcilorTest::SimulateRefreshTokenFetched(
145 AccountReconcilor* reconcilor,
146 const std::string& account_id,
147 const std::string& refresh_token) {
148 reconcilor->HandleRefreshTokenFetched(account_id, refresh_token);
151 TEST_F(AccountReconcilorTest, Basic) {
152 AccountReconcilor* reconcilor =
153 AccountReconcilorFactory::GetForProfile(profile());
154 ASSERT_TRUE(reconcilor);
155 ASSERT_EQ(profile(), reconcilor->profile());
158 #if !defined(OS_CHROMEOS)
160 TEST_F(AccountReconcilorTest, SigninManagerRegistration) {
161 AccountReconcilor* reconcilor =
162 AccountReconcilorFactory::GetForProfile(profile());
163 ASSERT_TRUE(reconcilor);
164 ASSERT_FALSE(reconcilor->IsPeriodicReconciliationRunning());
165 ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService());
167 signin_manager()->OnExternalSigninCompleted(kTestEmail);
168 ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning());
169 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
171 signin_manager()->SignOut();
172 ASSERT_FALSE(reconcilor->IsPeriodicReconciliationRunning());
173 ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService());
176 TEST_F(AccountReconcilorTest, Reauth) {
177 signin_manager()->SetAuthenticatedUsername(kTestEmail);
179 AccountReconcilor* reconcilor =
180 AccountReconcilorFactory::GetForProfile(profile());
181 ASSERT_TRUE(reconcilor);
182 ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning());
183 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
185 // Simulate reauth. The state of the reconcilor should not change.
186 signin_manager()->OnExternalSigninCompleted(kTestEmail);
187 ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning());
188 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
191 #endif // !defined(OS_CHROMEOS)
193 TEST_F(AccountReconcilorTest, ProfileAlreadyConnected) {
194 signin_manager()->SetAuthenticatedUsername(kTestEmail);
196 AccountReconcilor* reconcilor =
197 AccountReconcilorFactory::GetForProfile(profile());
198 ASSERT_TRUE(reconcilor);
199 ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning());
200 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
203 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) {
204 signin_manager()->SetAuthenticatedUsername(kTestEmail);
205 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
206 AccountReconcilor* reconcilor =
207 AccountReconcilorFactory::GetForProfile(profile());
208 ASSERT_TRUE(reconcilor);
210 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
211 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]",
212 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
214 reconcilor->StartReconcile();
215 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
217 base::RunLoop().RunUntilIdle();
218 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
219 const std::vector<std::pair<std::string, bool> >& accounts =
220 reconcilor->GetGaiaAccountsForTesting();
221 ASSERT_EQ(1u, accounts.size());
222 ASSERT_EQ("user@gmail.com", accounts[0].first);
225 TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) {
226 signin_manager()->SetAuthenticatedUsername(kTestEmail);
227 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
228 AccountReconcilor* reconcilor =
229 AccountReconcilorFactory::GetForProfile(profile());
230 ASSERT_TRUE(reconcilor);
232 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), "",
233 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
235 reconcilor->StartReconcile();
236 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
238 base::RunLoop().RunUntilIdle();
239 ASSERT_EQ(0u, reconcilor->GetGaiaAccountsForTesting().size());
242 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokens) {
243 signin_manager()->SetAuthenticatedUsername(kTestEmail);
244 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
246 AccountReconcilor* reconcilor =
247 AccountReconcilorFactory::GetForProfile(profile());
248 ASSERT_TRUE(reconcilor);
250 reconcilor->ValidateAccountsFromTokenService();
251 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
253 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
254 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
255 token_service()->IssueTokenForAllPendingRequests("access_token",
256 base::Time::Now() + base::TimeDelta::FromHours(1));
258 base::RunLoop().RunUntilIdle();
259 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
260 ASSERT_EQ(1u, reconcilor->GetValidChromeAccountsForTesting().size());
261 ASSERT_EQ(0u, reconcilor->GetInvalidChromeAccountsForTesting().size());
264 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedUserInfo) {
265 signin_manager()->SetAuthenticatedUsername(kTestEmail);
266 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
268 AccountReconcilor* reconcilor =
269 AccountReconcilorFactory::GetForProfile(profile());
270 ASSERT_TRUE(reconcilor);
272 reconcilor->ValidateAccountsFromTokenService();
273 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
275 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
276 "", net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
277 token_service()->IssueTokenForAllPendingRequests("access_token",
278 base::Time::Now() + base::TimeDelta::FromHours(1));
280 base::RunLoop().RunUntilIdle();
281 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
282 ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size());
283 ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size());
286 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedTokenRequest) {
287 signin_manager()->SetAuthenticatedUsername(kTestEmail);
288 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
290 AccountReconcilor* reconcilor =
291 AccountReconcilorFactory::GetForProfile(profile());
292 ASSERT_TRUE(reconcilor);
294 reconcilor->ValidateAccountsFromTokenService();
295 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
297 token_service()->IssueErrorForAllPendingRequests(
298 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
300 base::RunLoop().RunUntilIdle();
301 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
302 ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size());
303 ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size());
306 TEST_F(AccountReconcilorTest, StartReconcileNoop) {
307 signin_manager()->SetAuthenticatedUsername(kTestEmail);
308 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
310 AccountReconcilor* reconcilor =
311 AccountReconcilorFactory::GetForProfile(profile());
312 ASSERT_TRUE(reconcilor);
314 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
315 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
316 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
317 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
318 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
320 reconcilor->StartReconcile();
321 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
322 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
324 base::RunLoop().RunUntilIdle();
325 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
326 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size());
327 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
329 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
330 base::Time::Now() + base::TimeDelta::FromHours(1));
332 base::RunLoop().RunUntilIdle();
333 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
334 ASSERT_FALSE(reconcilor->is_reconcile_started_);
337 TEST_F(AccountReconcilorTest, StartReconcileNoopMultiple) {
338 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
339 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
340 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
342 AccountReconcilor* reconcilor =
343 AccountReconcilorFactory::GetForProfile(profile());
344 ASSERT_TRUE(reconcilor);
346 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
347 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
348 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
349 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
350 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
351 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
353 reconcilor->StartReconcile();
354 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
355 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
357 base::RunLoop().RunUntilIdle();
358 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
359 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
360 ASSERT_EQ(2u, reconcilor->GetGaiaAccountsForTesting().size());
362 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
363 base::Time::Now() + base::TimeDelta::FromHours(1));
365 base::RunLoop().RunUntilIdle();
366 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
368 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
369 base::Time::Now() + base::TimeDelta::FromHours(1));
371 base::RunLoop().RunUntilIdle();
372 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
373 ASSERT_FALSE(reconcilor->is_reconcile_started_);
376 TEST_F(AccountReconcilorTest, StartReconcileAddToCookie) {
377 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
378 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
379 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
381 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
383 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
384 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
385 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
386 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
387 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
389 AccountReconcilor* reconcilor = GetMockReconcilor();
390 reconcilor->StartReconcile();
391 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
392 base::Time::Now() + base::TimeDelta::FromHours(1));
393 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
394 base::Time::Now() + base::TimeDelta::FromHours(1));
396 base::RunLoop().RunUntilIdle();
397 ASSERT_TRUE(reconcilor->is_reconcile_started_);
398 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com",
399 GoogleServiceAuthError::AuthErrorNone());
400 ASSERT_FALSE(reconcilor->is_reconcile_started_);
403 TEST_F(AccountReconcilorTest, StartReconcileAddToChrome) {
404 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
405 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
407 EXPECT_CALL(*GetMockReconcilor(),
408 PerformAddToChromeAction("other@gmail.com", 1));
410 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
411 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
412 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
413 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
414 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
415 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
417 AccountReconcilor* reconcilor = GetMockReconcilor();
418 reconcilor->StartReconcile();
419 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
420 base::Time::Now() + base::TimeDelta::FromHours(1));
422 base::RunLoop().RunUntilIdle();
423 ASSERT_TRUE(reconcilor->is_reconcile_started_);
424 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", "");
425 ASSERT_FALSE(reconcilor->is_reconcile_started_);
428 TEST_F(AccountReconcilorTest, StartReconcileBadPrimary) {
429 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
430 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
431 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
433 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
434 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
435 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
437 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
438 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
439 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
440 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
441 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
442 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
444 AccountReconcilor* reconcilor = GetMockReconcilor();
445 reconcilor->StartReconcile();
446 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
447 base::Time::Now() + base::TimeDelta::FromHours(1));
448 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
449 base::Time::Now() + base::TimeDelta::FromHours(1));
451 base::RunLoop().RunUntilIdle();
452 ASSERT_TRUE(reconcilor->is_reconcile_started_);
453 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com",
454 GoogleServiceAuthError::AuthErrorNone());
455 ASSERT_TRUE(reconcilor->is_reconcile_started_);
456 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
457 GoogleServiceAuthError::AuthErrorNone());
458 ASSERT_FALSE(reconcilor->is_reconcile_started_);
461 TEST_F(AccountReconcilorTest, StartReconcileOnlyOnce) {
462 signin_manager()->SetAuthenticatedUsername(kTestEmail);
463 token_service()->UpdateCredentials(kTestEmail, "refresh_token");
465 AccountReconcilor* reconcilor =
466 AccountReconcilorFactory::GetForProfile(profile());
467 ASSERT_TRUE(reconcilor);
469 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
470 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
471 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
472 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
473 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
475 ASSERT_FALSE(reconcilor->is_reconcile_started_);
476 reconcilor->StartReconcile();
477 ASSERT_TRUE(reconcilor->is_reconcile_started_);
479 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
480 base::Time::Now() + base::TimeDelta::FromHours(1));
482 base::RunLoop().RunUntilIdle();
483 ASSERT_FALSE(reconcilor->is_reconcile_started_);
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");
491 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
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);
500 AccountReconcilor* reconcilor =
501 AccountReconcilorFactory::GetForProfile(profile());
502 ASSERT_TRUE(reconcilor);
504 ASSERT_FALSE(reconcilor->is_reconcile_started_);
505 reconcilor->StartReconcile();
506 ASSERT_TRUE(reconcilor->is_reconcile_started_);
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));
513 base::RunLoop().RunUntilIdle();
514 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
515 GoogleServiceAuthError::AuthErrorNone());
516 ASSERT_FALSE(reconcilor->is_reconcile_started_);