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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 MockAccountReconcilor(ProfileOAuth2TokenService* token_service, | 44 MockAccountReconcilor(ProfileOAuth2TokenService* token_service, |
45 SigninManagerBase* signin_manager, | 45 SigninManagerBase* signin_manager, |
46 SigninClient* client); | 46 SigninClient* client); |
47 virtual ~MockAccountReconcilor() {} | 47 virtual ~MockAccountReconcilor() {} |
48 | 48 |
49 virtual void StartFetchingExternalCcResult() OVERRIDE { | 49 virtual void StartFetchingExternalCcResult() OVERRIDE { |
50 // Don't do this in tests. | 50 // Don't do this in tests. |
51 } | 51 } |
52 | 52 |
53 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id)); | 53 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id)); |
54 MOCK_METHOD1(PerformStartRemoveAction, void(const std::string& account_id)); | |
55 MOCK_METHOD3( | |
56 PerformFinishRemoveAction, | |
57 void(const std::string& account_id, | |
58 const GoogleServiceAuthError& error, | |
59 const std::vector<std::pair<std::string, bool> >& accounts)); | |
60 MOCK_METHOD3(PerformAddToChromeAction, | |
61 void(const std::string& account_id, | |
62 int session_index, | |
63 const std::string& signin_scoped_device_id)); | |
64 MOCK_METHOD0(PerformLogoutAllAccountsAction, void()); | 54 MOCK_METHOD0(PerformLogoutAllAccountsAction, void()); |
65 }; | 55 }; |
66 | 56 |
67 // static | 57 // static |
68 KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) { | 58 KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) { |
69 Profile* profile = Profile::FromBrowserContext(context); | 59 Profile* profile = Profile::FromBrowserContext(context); |
70 AccountReconcilor* reconcilor = new MockAccountReconcilor( | 60 AccountReconcilor* reconcilor = new MockAccountReconcilor( |
71 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 61 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
72 SigninManagerFactory::GetForProfile(profile), | 62 SigninManagerFactory::GetForProfile(profile), |
73 ChromeSigninClientFactory::GetForProfile(profile)); | 63 ChromeSigninClientFactory::GetForProfile(profile)); |
(...skipping 28 matching lines...) Expand all Loading... |
102 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); | 92 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); |
103 } | 93 } |
104 | 94 |
105 MockAccountReconcilor* GetMockReconcilor(); | 95 MockAccountReconcilor* GetMockReconcilor(); |
106 | 96 |
107 void SimulateMergeSessionCompleted( | 97 void SimulateMergeSessionCompleted( |
108 MergeSessionHelper::Observer* observer, | 98 MergeSessionHelper::Observer* observer, |
109 const std::string& account_id, | 99 const std::string& account_id, |
110 const GoogleServiceAuthError& error); | 100 const GoogleServiceAuthError& error); |
111 | 101 |
112 void SimulateRefreshTokenFetched( | |
113 AccountReconcilor* reconcilor, | |
114 const std::string& account_id, | |
115 const std::string& refresh_token); | |
116 | |
117 private: | 102 private: |
118 content::TestBrowserThreadBundle bundle_; | 103 content::TestBrowserThreadBundle bundle_; |
119 TestingProfile* profile_; | 104 TestingProfile* profile_; |
120 FakeSigninManagerForTesting* signin_manager_; | 105 FakeSigninManagerForTesting* signin_manager_; |
121 FakeProfileOAuth2TokenService* token_service_; | 106 FakeProfileOAuth2TokenService* token_service_; |
122 MockAccountReconcilor* mock_reconcilor_; | 107 MockAccountReconcilor* mock_reconcilor_; |
123 net::FakeURLFetcherFactory url_fetcher_factory_; | 108 net::FakeURLFetcherFactory url_fetcher_factory_; |
124 scoped_ptr<TestingProfileManager> testing_profile_manager_; | 109 scoped_ptr<TestingProfileManager> testing_profile_manager_; |
125 base::HistogramTester histogram_tester_; | 110 base::HistogramTester histogram_tester_; |
126 | 111 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 return mock_reconcilor_; | 165 return mock_reconcilor_; |
181 } | 166 } |
182 | 167 |
183 void AccountReconcilorTest::SimulateMergeSessionCompleted( | 168 void AccountReconcilorTest::SimulateMergeSessionCompleted( |
184 MergeSessionHelper::Observer* observer, | 169 MergeSessionHelper::Observer* observer, |
185 const std::string& account_id, | 170 const std::string& account_id, |
186 const GoogleServiceAuthError& error) { | 171 const GoogleServiceAuthError& error) { |
187 observer->MergeSessionCompleted(account_id, error); | 172 observer->MergeSessionCompleted(account_id, error); |
188 } | 173 } |
189 | 174 |
190 void AccountReconcilorTest::SimulateRefreshTokenFetched( | |
191 AccountReconcilor* reconcilor, | |
192 const std::string& account_id, | |
193 const std::string& refresh_token) { | |
194 reconcilor->HandleRefreshTokenFetched(account_id, refresh_token); | |
195 } | |
196 | |
197 TEST_F(AccountReconcilorTest, Basic) { | 175 TEST_F(AccountReconcilorTest, Basic) { |
198 AccountReconcilor* reconcilor = | 176 AccountReconcilor* reconcilor = |
199 AccountReconcilorFactory::GetForProfile(profile()); | 177 AccountReconcilorFactory::GetForProfile(profile()); |
200 ASSERT_TRUE(reconcilor); | 178 ASSERT_TRUE(reconcilor); |
201 ASSERT_EQ(token_service(), reconcilor->token_service()); | 179 ASSERT_EQ(token_service(), reconcilor->token_service()); |
202 } | 180 } |
203 | 181 |
204 #if !defined(OS_CHROMEOS) | 182 #if !defined(OS_CHROMEOS) |
205 | 183 |
206 // This method requires the use of the |TestSigninClient| to be created from the | 184 // This method requires the use of the |TestSigninClient| to be created from the |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 226 |
249 AccountReconcilor* reconcilor = | 227 AccountReconcilor* reconcilor = |
250 AccountReconcilorFactory::GetForProfile(profile()); | 228 AccountReconcilorFactory::GetForProfile(profile()); |
251 ASSERT_TRUE(reconcilor); | 229 ASSERT_TRUE(reconcilor); |
252 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); | 230 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); |
253 } | 231 } |
254 | 232 |
255 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { | 233 TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { |
256 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 234 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
257 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 235 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
| 236 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(kTestEmail)); |
258 AccountReconcilor* reconcilor = | 237 AccountReconcilor* reconcilor = |
259 AccountReconcilorFactory::GetForProfile(profile()); | 238 AccountReconcilorFactory::GetForProfile(profile()); |
260 ASSERT_TRUE(reconcilor); | 239 ASSERT_TRUE(reconcilor); |
261 | 240 |
262 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 241 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
263 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", | 242 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", |
264 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 243 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
265 | 244 |
266 reconcilor->StartReconcile(); | 245 reconcilor->StartReconcile(); |
267 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 246 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
(...skipping 13 matching lines...) Expand all Loading... |
281 AccountReconcilorFactory::GetForProfile(profile()); | 260 AccountReconcilorFactory::GetForProfile(profile()); |
282 ASSERT_TRUE(reconcilor); | 261 ASSERT_TRUE(reconcilor); |
283 | 262 |
284 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), "", | 263 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), "", |
285 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); | 264 net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); |
286 | 265 |
287 reconcilor->StartReconcile(); | 266 reconcilor->StartReconcile(); |
288 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 267 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
289 | 268 |
290 base::RunLoop().RunUntilIdle(); | 269 base::RunLoop().RunUntilIdle(); |
291 ASSERT_EQ(0u, reconcilor->GetGaiaAccountsForTesting().size()); | 270 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
292 } | |
293 | |
294 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokens) { | |
295 signin_manager()->SetAuthenticatedUsername(kTestEmail); | |
296 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | |
297 | |
298 AccountReconcilor* reconcilor = | |
299 AccountReconcilorFactory::GetForProfile(profile()); | |
300 ASSERT_TRUE(reconcilor); | |
301 | |
302 reconcilor->ValidateAccountsFromTokenService(); | |
303 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
304 | |
305 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
306 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
307 token_service()->IssueTokenForAllPendingRequests("access_token", | |
308 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
309 | |
310 base::RunLoop().RunUntilIdle(); | |
311 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | |
312 ASSERT_EQ(1u, reconcilor->GetValidChromeAccountsForTesting().size()); | |
313 ASSERT_EQ(0u, reconcilor->GetInvalidChromeAccountsForTesting().size()); | |
314 } | |
315 | |
316 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedUserInfo) { | |
317 signin_manager()->SetAuthenticatedUsername(kTestEmail); | |
318 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | |
319 | |
320 AccountReconcilor* reconcilor = | |
321 AccountReconcilorFactory::GetForProfile(profile()); | |
322 ASSERT_TRUE(reconcilor); | |
323 | |
324 reconcilor->ValidateAccountsFromTokenService(); | |
325 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
326 | |
327 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
328 "", net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); | |
329 token_service()->IssueTokenForAllPendingRequests("access_token", | |
330 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
331 | |
332 base::RunLoop().RunUntilIdle(); | |
333 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | |
334 ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size()); | |
335 ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size()); | |
336 } | |
337 | |
338 TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedTokenRequest) { | |
339 signin_manager()->SetAuthenticatedUsername(kTestEmail); | |
340 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | |
341 | |
342 AccountReconcilor* reconcilor = | |
343 AccountReconcilorFactory::GetForProfile(profile()); | |
344 ASSERT_TRUE(reconcilor); | |
345 | |
346 reconcilor->ValidateAccountsFromTokenService(); | |
347 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
348 | |
349 token_service()->IssueErrorForAllPendingRequests( | |
350 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | |
351 | |
352 base::RunLoop().RunUntilIdle(); | |
353 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | |
354 ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size()); | |
355 ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size()); | |
356 } | 271 } |
357 | 272 |
358 TEST_P(AccountReconcilorTest, StartReconcileNoop) { | 273 TEST_P(AccountReconcilorTest, StartReconcileNoop) { |
359 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 274 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
360 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 275 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
361 | 276 |
362 AccountReconcilor* reconcilor = | 277 AccountReconcilor* reconcilor = |
363 AccountReconcilorFactory::GetForProfile(profile()); | 278 AccountReconcilorFactory::GetForProfile(profile()); |
364 ASSERT_TRUE(reconcilor); | 279 ASSERT_TRUE(reconcilor); |
365 | 280 |
366 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 281 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
367 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 282 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
368 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 283 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
369 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
370 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
371 | 284 |
372 reconcilor->StartReconcile(); | 285 reconcilor->StartReconcile(); |
| 286 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
373 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 287 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
374 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
375 | 288 |
376 base::RunLoop().RunUntilIdle(); | 289 base::RunLoop().RunUntilIdle(); |
377 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); | |
378 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size()); | |
379 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
380 | |
381 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | |
382 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
383 | |
384 base::RunLoop().RunUntilIdle(); | |
385 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | |
386 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 290 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
387 | 291 |
388 histogram_tester()->ExpectTotalCount( | 292 histogram_tester()->ExpectTotalCount( |
389 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); | 293 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); |
390 histogram_tester()->ExpectUniqueSample( | 294 histogram_tester()->ExpectUniqueSample( |
391 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 295 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
392 signin_metrics::ACCOUNTS_SAME, | 296 signin_metrics::ACCOUNTS_SAME, |
393 1); | 297 1); |
394 } | 298 } |
395 | 299 |
396 // This is test is needed until chrome changes to use gaia obfuscated id. | 300 // This is test is needed until chrome changes to use gaia obfuscated id. |
397 // The signin manager and token service use the gaia "email" property, which | 301 // The signin manager and token service use the gaia "email" property, which |
398 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() | 302 // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() |
399 // however uses gaia "displayEmail" which does not preserve case, and then | 303 // however uses gaia "displayEmail" which does not preserve case, and then |
400 // passes the string through gaia::CanonicalizeEmail() which removes dots. This | 304 // passes the string through gaia::CanonicalizeEmail() which removes dots. This |
401 // tests makes sure that an email like "Dot.S@hmail.com", as seen by the | 305 // tests makes sure that an email like "Dot.S@hmail.com", as seen by the |
402 // token service, will be considered the same as "dots@gmail.com" as returned | 306 // token service, will be considered the same as "dots@gmail.com" as returned |
403 // by gaia::ParseListAccountsData(). | 307 // by gaia::ParseListAccountsData(). |
404 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { | 308 TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { |
405 signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com"); | 309 signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com"); |
406 token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token"); | 310 token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token"); |
407 | 311 |
408 AccountReconcilor* reconcilor = | 312 AccountReconcilor* reconcilor = |
409 AccountReconcilorFactory::GetForProfile(profile()); | 313 AccountReconcilorFactory::GetForProfile(profile()); |
410 ASSERT_TRUE(reconcilor); | 314 ASSERT_TRUE(reconcilor); |
411 | 315 |
412 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 316 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
413 "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 317 "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
414 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 318 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
415 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
416 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
417 | 319 |
418 reconcilor->StartReconcile(); | 320 reconcilor->StartReconcile(); |
419 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 321 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
420 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
421 | 322 |
422 base::RunLoop().RunUntilIdle(); | 323 base::RunLoop().RunUntilIdle(); |
423 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); | |
424 ASSERT_EQ(1u, reconcilor->GetGaiaAccountsForTesting().size()); | |
425 ASSERT_STREQ("dots@gmail.com", | |
426 reconcilor->GetGaiaAccountsForTesting()[0].first.c_str()); | |
427 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
428 | |
429 token_service()->IssueAllTokensForAccount("Dot.S@gmail.com", "access_token", | |
430 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
431 | |
432 base::RunLoop().RunUntilIdle(); | |
433 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | |
434 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 324 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
435 | 325 |
436 histogram_tester()->ExpectUniqueSample( | 326 histogram_tester()->ExpectUniqueSample( |
437 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 327 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
438 signin_metrics::ACCOUNTS_SAME, | 328 signin_metrics::ACCOUNTS_SAME, |
439 1); | 329 1); |
440 } | 330 } |
441 | 331 |
442 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { | 332 TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { |
443 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 333 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
444 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 334 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
445 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 335 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
446 | 336 |
447 AccountReconcilor* reconcilor = | 337 AccountReconcilor* reconcilor = |
448 AccountReconcilorFactory::GetForProfile(profile()); | 338 AccountReconcilorFactory::GetForProfile(profile()); |
449 ASSERT_TRUE(reconcilor); | 339 ASSERT_TRUE(reconcilor); |
450 | 340 |
451 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 341 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
452 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | 342 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
453 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 343 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
454 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 344 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
455 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
456 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
457 | 345 |
458 reconcilor->StartReconcile(); | 346 reconcilor->StartReconcile(); |
459 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); | 347 ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); |
460 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
461 | |
462 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
463 ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); | |
464 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
465 ASSERT_EQ(2u, reconcilor->GetGaiaAccountsForTesting().size()); | |
466 | |
467 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", | |
468 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
469 | |
470 base::RunLoop().RunUntilIdle(); | |
471 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); | |
472 | |
473 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | |
474 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
475 | |
476 base::RunLoop().RunUntilIdle(); | |
477 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); | |
478 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 349 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
479 | 350 |
480 histogram_tester()->ExpectTotalCount( | 351 histogram_tester()->ExpectTotalCount( |
481 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); | 352 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1); |
482 histogram_tester()->ExpectUniqueSample( | 353 histogram_tester()->ExpectUniqueSample( |
483 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 354 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
484 signin_metrics::ACCOUNTS_SAME, | 355 signin_metrics::ACCOUNTS_SAME, |
485 1); | 356 1); |
486 } | 357 } |
487 | 358 |
488 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { | 359 TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { |
489 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 360 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
490 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 361 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
491 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 362 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
492 | 363 |
493 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 364 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
494 | 365 |
495 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 366 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
496 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 367 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
497 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 368 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
498 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
499 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
500 | 369 |
501 AccountReconcilor* reconcilor = GetMockReconcilor(); | 370 AccountReconcilor* reconcilor = GetMockReconcilor(); |
502 reconcilor->StartReconcile(); | 371 reconcilor->StartReconcile(); |
503 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", | |
504 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
505 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | |
506 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
507 | 372 |
508 base::RunLoop().RunUntilIdle(); | 373 base::RunLoop().RunUntilIdle(); |
509 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 374 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
510 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", | 375 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", |
511 GoogleServiceAuthError::AuthErrorNone()); | 376 GoogleServiceAuthError::AuthErrorNone()); |
512 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 377 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
513 | 378 |
514 histogram_tester()->ExpectUniqueSample( | 379 histogram_tester()->ExpectUniqueSample( |
515 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 380 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
516 signin_metrics::ACCOUNTS_SAME, | 381 signin_metrics::ACCOUNTS_SAME, |
517 1); | 382 1); |
518 histogram_tester()->ExpectUniqueSample( | 383 histogram_tester()->ExpectUniqueSample( |
519 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); | 384 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
520 histogram_tester()->ExpectUniqueSample( | 385 histogram_tester()->ExpectUniqueSample( |
521 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); | 386 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); |
| 387 } |
| 388 |
| 389 TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) { |
| 390 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
| 391 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
| 392 |
| 393 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); |
| 394 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
| 395 |
| 396 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
| 397 "[\"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]]]", |
| 399 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 400 |
| 401 AccountReconcilor* reconcilor = GetMockReconcilor(); |
| 402 reconcilor->StartReconcile(); |
| 403 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
| 404 |
| 405 base::RunLoop().RunUntilIdle(); |
| 406 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
| 407 GoogleServiceAuthError::AuthErrorNone()); |
| 408 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
| 409 |
| 410 histogram_tester()->ExpectUniqueSample( |
| 411 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
| 412 signin_metrics::ACCOUNTS_SAME, |
| 413 1); |
| 414 histogram_tester()->ExpectUniqueSample( |
| 415 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); |
| 416 histogram_tester()->ExpectUniqueSample( |
| 417 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 1, 1); |
522 } | 418 } |
523 | 419 |
524 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { | 420 TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { |
525 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 421 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
526 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 422 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
527 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 423 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
528 | 424 |
529 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 425 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
530 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); | 426 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); |
531 | 427 |
532 SetFakeResponse( | 428 SetFakeResponse( |
533 GaiaUrls::GetInstance()->list_accounts_url().spec(), | 429 GaiaUrls::GetInstance()->list_accounts_url().spec(), |
534 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 430 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
535 net::HTTP_OK, | 431 net::HTTP_OK, |
536 net::URLRequestStatus::SUCCESS); | 432 net::URLRequestStatus::SUCCESS); |
537 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
538 "{\"id\":\"foo\"}", | |
539 net::HTTP_OK, | |
540 net::URLRequestStatus::SUCCESS); | |
541 | 433 |
542 AccountReconcilor* reconcilor = GetMockReconcilor(); | 434 AccountReconcilor* reconcilor = GetMockReconcilor(); |
543 reconcilor->StartReconcile(); | 435 reconcilor->StartReconcile(); |
544 token_service()->IssueAllTokensForAccount( | |
545 "other@gmail.com", | |
546 "access_token", | |
547 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
548 token_service()->IssueAllTokensForAccount( | |
549 "user@gmail.com", | |
550 "access_token", | |
551 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
552 | 436 |
553 base::RunLoop().RunUntilIdle(); | 437 base::RunLoop().RunUntilIdle(); |
554 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 438 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
555 SimulateMergeSessionCompleted( | 439 SimulateMergeSessionCompleted( |
556 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); | 440 reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); |
557 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 441 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
558 | 442 |
559 histogram_tester()->ExpectUniqueSample( | 443 histogram_tester()->ExpectUniqueSample( |
560 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 444 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
561 signin_metrics::ACCOUNTS_SAME, | 445 signin_metrics::ACCOUNTS_SAME, |
562 1); | 446 1); |
563 histogram_tester()->ExpectUniqueSample( | 447 histogram_tester()->ExpectUniqueSample( |
564 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); | 448 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
565 histogram_tester()->ExpectUniqueSample( | 449 histogram_tester()->ExpectUniqueSample( |
566 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); | 450 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); |
567 | 451 |
568 // Do another pass after I've added a third account to the token service | 452 // Do another pass after I've added a third account to the token service |
569 | 453 |
570 SetFakeResponse( | 454 SetFakeResponse( |
571 GaiaUrls::GetInstance()->list_accounts_url().spec(), | 455 GaiaUrls::GetInstance()->list_accounts_url().spec(), |
572 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | 456 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
573 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 457 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
574 net::HTTP_OK, | 458 net::HTTP_OK, |
575 net::URLRequestStatus::SUCCESS); | 459 net::URLRequestStatus::SUCCESS); |
576 // This will cause the reconcilor to fire. | 460 // This will cause the reconcilor to fire. |
577 token_service()->UpdateCredentials("third@gmail.com", "refresh_token"); | 461 token_service()->UpdateCredentials("third@gmail.com", "refresh_token"); |
578 | 462 |
579 token_service()->IssueAllTokensForAccount( | |
580 "other@gmail.com", | |
581 "access_token", | |
582 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
583 token_service()->IssueAllTokensForAccount( | |
584 "user@gmail.com", | |
585 "access_token", | |
586 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
587 token_service()->IssueAllTokensForAccount( | |
588 "third@gmail.com", | |
589 "access_token", | |
590 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
591 | |
592 base::RunLoop().RunUntilIdle(); | 463 base::RunLoop().RunUntilIdle(); |
593 | 464 |
594 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 465 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
595 SimulateMergeSessionCompleted( | 466 SimulateMergeSessionCompleted( |
596 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); | 467 reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); |
597 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 468 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
598 | 469 |
599 histogram_tester()->ExpectUniqueSample( | 470 histogram_tester()->ExpectUniqueSample( |
600 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 471 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
601 signin_metrics::ACCOUNTS_SAME, | 472 signin_metrics::ACCOUNTS_SAME, |
602 1); | 473 1); |
603 histogram_tester()->ExpectUniqueSample( | 474 histogram_tester()->ExpectUniqueSample( |
604 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); | 475 "Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1); |
605 histogram_tester()->ExpectUniqueSample( | 476 histogram_tester()->ExpectUniqueSample( |
606 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); | 477 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); |
607 histogram_tester()->ExpectUniqueSample( | 478 histogram_tester()->ExpectUniqueSample( |
608 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", | 479 "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun", |
609 signin_metrics::ACCOUNTS_SAME, | 480 signin_metrics::ACCOUNTS_SAME, |
610 1); | 481 1); |
611 histogram_tester()->ExpectUniqueSample( | 482 histogram_tester()->ExpectUniqueSample( |
612 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); | 483 "Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1); |
613 histogram_tester()->ExpectUniqueSample( | 484 histogram_tester()->ExpectUniqueSample( |
614 "Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1); | 485 "Signin.Reconciler.RemovedFromCookieJar.SubsequentRun", 0, 1); |
615 } | |
616 | |
617 TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) { | |
618 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | |
619 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | |
620 | |
621 EXPECT_CALL(*GetMockReconcilor(), | |
622 PerformAddToChromeAction("other@gmail.com", 1, "")); | |
623 | |
624 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | |
625 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | |
626 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | |
627 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
628 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
629 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
630 | |
631 AccountReconcilor* reconcilor = GetMockReconcilor(); | |
632 reconcilor->StartReconcile(); | |
633 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | |
634 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
635 | |
636 base::RunLoop().RunUntilIdle(); | |
637 ASSERT_TRUE(reconcilor->is_reconcile_started_); | |
638 SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", ""); | |
639 ASSERT_FALSE(reconcilor->is_reconcile_started_); | |
640 | |
641 histogram_tester()->ExpectUniqueSample( | |
642 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | |
643 signin_metrics::ACCOUNTS_SAME, | |
644 1); | |
645 histogram_tester()->ExpectUniqueSample( | |
646 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); | |
647 histogram_tester()->ExpectUniqueSample( | |
648 "Signin.Reconciler.AddedToChrome.FirstRun", 1, 1); | |
649 } | 486 } |
650 | 487 |
651 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { | 488 TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { |
652 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 489 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
653 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 490 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
654 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 491 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
655 | 492 |
656 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); | 493 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); |
657 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 494 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
658 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); | 495 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); |
659 | 496 |
660 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 497 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
661 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], " | 498 "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], " |
662 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 499 "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
663 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 500 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
664 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
665 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
666 | 501 |
667 AccountReconcilor* reconcilor = GetMockReconcilor(); | 502 AccountReconcilor* reconcilor = GetMockReconcilor(); |
668 reconcilor->StartReconcile(); | 503 reconcilor->StartReconcile(); |
669 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", | |
670 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
671 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | |
672 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
673 | 504 |
674 base::RunLoop().RunUntilIdle(); | 505 base::RunLoop().RunUntilIdle(); |
675 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 506 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
676 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", | 507 SimulateMergeSessionCompleted(reconcilor, "other@gmail.com", |
677 GoogleServiceAuthError::AuthErrorNone()); | 508 GoogleServiceAuthError::AuthErrorNone()); |
678 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 509 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
679 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", | 510 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
680 GoogleServiceAuthError::AuthErrorNone()); | 511 GoogleServiceAuthError::AuthErrorNone()); |
681 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 512 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
682 | 513 |
683 histogram_tester()->ExpectUniqueSample( | 514 histogram_tester()->ExpectUniqueSample( |
684 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", | 515 "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", |
685 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT, | 516 signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT, |
686 1); | 517 1); |
687 histogram_tester()->ExpectUniqueSample( | 518 histogram_tester()->ExpectUniqueSample( |
688 "Signin.Reconciler.AddedToCookieJar.FirstRun", 2, 1); | 519 "Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1); |
689 histogram_tester()->ExpectUniqueSample( | 520 histogram_tester()->ExpectUniqueSample( |
690 "Signin.Reconciler.AddedToChrome.FirstRun", 0, 1); | 521 "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1); |
691 } | 522 } |
692 | 523 |
693 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { | 524 TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { |
694 signin_manager()->SetAuthenticatedUsername(kTestEmail); | 525 signin_manager()->SetAuthenticatedUsername(kTestEmail); |
695 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); | 526 token_service()->UpdateCredentials(kTestEmail, "refresh_token"); |
696 | 527 |
697 AccountReconcilor* reconcilor = | 528 AccountReconcilor* reconcilor = |
698 AccountReconcilorFactory::GetForProfile(profile()); | 529 AccountReconcilorFactory::GetForProfile(profile()); |
699 ASSERT_TRUE(reconcilor); | 530 ASSERT_TRUE(reconcilor); |
700 | 531 |
701 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 532 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
702 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 533 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
703 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 534 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
704 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
705 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
706 | 535 |
707 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 536 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
708 reconcilor->StartReconcile(); | 537 reconcilor->StartReconcile(); |
709 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 538 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
710 | 539 |
711 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | |
712 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
713 | |
714 base::RunLoop().RunUntilIdle(); | 540 base::RunLoop().RunUntilIdle(); |
715 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 541 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
716 } | 542 } |
717 | 543 |
718 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { | 544 TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { |
719 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 545 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
720 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 546 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
721 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); | 547 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); |
722 | 548 |
723 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 549 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
724 | 550 |
725 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 551 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
726 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]," | 552 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]," |
727 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", | 553 "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", |
728 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 554 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
729 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
730 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
731 | 555 |
732 AccountReconcilor* reconcilor = | 556 AccountReconcilor* reconcilor = |
733 AccountReconcilorFactory::GetForProfile(profile()); | 557 AccountReconcilorFactory::GetForProfile(profile()); |
734 ASSERT_TRUE(reconcilor); | 558 ASSERT_TRUE(reconcilor); |
735 | 559 |
736 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 560 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
737 reconcilor->StartReconcile(); | 561 reconcilor->StartReconcile(); |
738 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 562 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
739 | 563 |
740 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | |
741 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
742 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", | |
743 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
744 | |
745 base::RunLoop().RunUntilIdle(); | 564 base::RunLoop().RunUntilIdle(); |
746 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", | 565 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
747 GoogleServiceAuthError::AuthErrorNone()); | 566 GoogleServiceAuthError::AuthErrorNone()); |
748 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 567 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
749 } | 568 } |
750 | 569 |
751 TEST_F(AccountReconcilorTest, MergeSessionCompletedWithBogusAccount) { | 570 TEST_F(AccountReconcilorTest, MergeSessionCompletedWithBogusAccount) { |
752 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); | 571 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); |
753 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); | 572 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); |
754 | 573 |
755 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); | 574 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); |
756 | 575 |
757 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), | 576 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), |
758 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", | 577 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", |
759 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 578 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
760 SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", | |
761 "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
762 | 579 |
763 AccountReconcilor* reconcilor = | 580 AccountReconcilor* reconcilor = |
764 AccountReconcilorFactory::GetForProfile(profile()); | 581 AccountReconcilorFactory::GetForProfile(profile()); |
765 ASSERT_TRUE(reconcilor); | 582 ASSERT_TRUE(reconcilor); |
766 | 583 |
767 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 584 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
768 reconcilor->StartReconcile(); | 585 reconcilor->StartReconcile(); |
769 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 586 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
770 | 587 |
771 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", | |
772 base::Time::Now() + base::TimeDelta::FromHours(1)); | |
773 base::RunLoop().RunUntilIdle(); | 588 base::RunLoop().RunUntilIdle(); |
774 | 589 |
775 // If an unknown account id is sent, it should not upset the state. | 590 // If an unknown account id is sent, it should not upset the state. |
776 SimulateMergeSessionCompleted(reconcilor, "bogus@gmail.com", | 591 SimulateMergeSessionCompleted(reconcilor, "bogus@gmail.com", |
777 GoogleServiceAuthError::AuthErrorNone()); | 592 GoogleServiceAuthError::AuthErrorNone()); |
778 ASSERT_TRUE(reconcilor->is_reconcile_started_); | 593 ASSERT_TRUE(reconcilor->is_reconcile_started_); |
779 | 594 |
780 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", | 595 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", |
781 GoogleServiceAuthError::AuthErrorNone()); | 596 GoogleServiceAuthError::AuthErrorNone()); |
782 ASSERT_FALSE(reconcilor->is_reconcile_started_); | 597 ASSERT_FALSE(reconcilor->is_reconcile_started_); |
783 } | 598 } |
784 | 599 |
785 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, | 600 INSTANTIATE_TEST_CASE_P(AccountReconcilorMaybeEnabled, |
786 AccountReconcilorTest, | 601 AccountReconcilorTest, |
787 testing::Bool()); | 602 testing::Bool()); |
788 | 603 |
OLD | NEW |