Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: chrome/browser/ui/webui/settings/people_handler_unittest.cc

Issue 1549443002: [Sync] Remove PSS::IsOAuthRefreshTokenAvailable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/ui/webui/settings/people_handler.h" 5 #include "chrome/browser/ui/webui/settings/people_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest { 295 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest {
296 std::string GetTestUser() override { return std::string(); } 296 std::string GetTestUser() override { return std::string(); }
297 }; 297 };
298 298
299 TEST_F(PeopleHandlerTest, Basic) { 299 TEST_F(PeopleHandlerTest, Basic) {
300 } 300 }
301 301
302 #if !defined(OS_CHROMEOS) 302 #if !defined(OS_CHROMEOS)
303 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) { 303 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) {
304 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 304 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
305 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
306 .WillRepeatedly(Return(false));
307 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 305 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
308 .WillRepeatedly(Return(false)); 306 .WillRepeatedly(Return(false));
309 // Ensure that the user is not signed in before calling |HandleStartSignin()|. 307 // Ensure that the user is not signed in before calling |HandleStartSignin()|.
310 SigninManager* manager = static_cast<SigninManager*>(mock_signin_); 308 SigninManager* manager = static_cast<SigninManager*>(mock_signin_);
311 manager->SignOut(signin_metrics::SIGNOUT_TEST); 309 manager->SignOut(signin_metrics::SIGNOUT_TEST);
312 handler_->HandleStartSignin(NULL); 310 handler_->HandleStartSignin(NULL);
313 311
314 // Sync setup hands off control to the gaia login tab. 312 // Sync setup hands off control to the gaia login tab.
315 EXPECT_EQ(NULL, 313 EXPECT_EQ(NULL,
316 LoginUIServiceFactory::GetForProfile( 314 LoginUIServiceFactory::GetForProfile(
317 profile_.get())->current_login_ui()); 315 profile_.get())->current_login_ui());
318 316
319 ASSERT_FALSE(handler_->is_configuring_sync()); 317 ASSERT_FALSE(handler_->is_configuring_sync());
320 318
321 handler_->CloseSyncSetup(); 319 handler_->CloseSyncSetup();
322 EXPECT_EQ(NULL, 320 EXPECT_EQ(NULL,
323 LoginUIServiceFactory::GetForProfile( 321 LoginUIServiceFactory::GetForProfile(
324 profile_.get())->current_login_ui()); 322 profile_.get())->current_login_ui());
325 } 323 }
326 324
327 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) { 325 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) {
328 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 326 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
329 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
330 .WillRepeatedly(Return(false));
331 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 327 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
332 .WillRepeatedly(Return(false)); 328 .WillRepeatedly(Return(false));
333 handler_->HandleShowSetupUI(NULL); 329 handler_->HandleShowSetupUI(NULL);
334 330
335 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. 331 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage.
336 ASSERT_EQ(1U, web_ui_.call_data().size()); 332 ASSERT_EQ(1U, web_ui_.call_data().size());
337 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 333 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
338 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 334 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
339 335
340 ASSERT_FALSE(handler_->is_configuring_sync()); 336 ASSERT_FALSE(handler_->is_configuring_sync());
(...skipping 13 matching lines...) Expand all
354 EXPECT_EQ(NULL, 350 EXPECT_EQ(NULL,
355 LoginUIServiceFactory::GetForProfile( 351 LoginUIServiceFactory::GetForProfile(
356 profile_.get())->current_login_ui()); 352 profile_.get())->current_login_ui());
357 ASSERT_FALSE(handler_->is_configuring_sync()); 353 ASSERT_FALSE(handler_->is_configuring_sync());
358 } 354 }
359 355
360 // Verifies that the handler correctly handles a cancellation when 356 // Verifies that the handler correctly handles a cancellation when
361 // it is displaying the spinner to the user. 357 // it is displaying the spinner to the user.
362 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { 358 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) {
363 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 359 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
364 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
365 .WillRepeatedly(Return(true));
366 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 360 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
367 .WillRepeatedly(Return(false)); 361 .WillRepeatedly(Return(false));
368 error_ = GoogleServiceAuthError::AuthErrorNone(); 362 error_ = GoogleServiceAuthError::AuthErrorNone();
369 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 363 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
370 364
371 // We're simulating a user setting up sync, which would cause the backend to 365 // We're simulating a user setting up sync, which would cause the backend to
372 // kick off initialization, but not download user data types. The sync 366 // kick off initialization, but not download user data types. The sync
373 // backend will try to download control data types (e.g encryption info), but 367 // backend will try to download control data types (e.g encryption info), but
374 // that won't finish for this test as we're simulating cancelling while the 368 // that won't finish for this test as we're simulating cancelling while the
375 // spinner is showing. 369 // spinner is showing.
376 handler_->HandleShowSetupUI(NULL); 370 handler_->HandleShowSetupUI(NULL);
377 371
378 EXPECT_EQ(handler_.get(), 372 EXPECT_EQ(handler_.get(),
379 LoginUIServiceFactory::GetForProfile( 373 LoginUIServiceFactory::GetForProfile(
380 profile_.get())->current_login_ui()); 374 profile_.get())->current_login_ui());
381 375
382 ExpectSpinnerAndClose(); 376 ExpectSpinnerAndClose();
383 } 377 }
384 378
385 // Verifies that the handler correctly transitions from showing the spinner 379 // Verifies that the handler correctly transitions from showing the spinner
386 // to showing a configuration page when sync setup completes successfully. 380 // to showing a configuration page when sync setup completes successfully.
387 TEST_F(PeopleHandlerTest, 381 TEST_F(PeopleHandlerTest,
388 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { 382 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) {
389 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 383 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
390 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
391 .WillRepeatedly(Return(true));
392 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 384 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
393 .WillRepeatedly(Return(false)); 385 .WillRepeatedly(Return(false));
394 error_ = GoogleServiceAuthError::AuthErrorNone(); 386 error_ = GoogleServiceAuthError::AuthErrorNone();
395 // Sync backend is stopped initially, and will start up. 387 // Sync backend is stopped initially, and will start up.
396 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 388 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
397 SetDefaultExpectationsForConfigPage(); 389 SetDefaultExpectationsForConfigPage();
398 390
399 handler_->OpenSyncSetup(nullptr); 391 handler_->OpenSyncSetup(nullptr);
400 392
401 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. 393 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage.
(...skipping 29 matching lines...) Expand all
431 } 423 }
432 424
433 // Verifies the case where the user cancels after the sync backend has 425 // Verifies the case where the user cancels after the sync backend has
434 // initialized (meaning it already transitioned from the spinner to a proper 426 // initialized (meaning it already transitioned from the spinner to a proper
435 // configuration page, tested by 427 // configuration page, tested by
436 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user 428 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user
437 // before the user has continued on. 429 // before the user has continued on.
438 TEST_F(PeopleHandlerTest, 430 TEST_F(PeopleHandlerTest,
439 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { 431 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) {
440 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 432 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
441 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
442 .WillRepeatedly(Return(true));
443 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 433 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
444 .WillRepeatedly(Return(false)); 434 .WillRepeatedly(Return(false));
445 error_ = GoogleServiceAuthError::AuthErrorNone(); 435 error_ = GoogleServiceAuthError::AuthErrorNone();
446 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) 436 EXPECT_CALL(*mock_pss_, IsBackendInitialized())
447 .WillOnce(Return(false)) 437 .WillOnce(Return(false))
448 .WillRepeatedly(Return(true)); 438 .WillRepeatedly(Return(true));
449 SetDefaultExpectationsForConfigPage(); 439 SetDefaultExpectationsForConfigPage();
450 handler_->OpenSyncSetup(nullptr); 440 handler_->OpenSyncSetup(nullptr);
451 441
452 // It's important to tell sync the user cancelled the setup flow before we 442 // It's important to tell sync the user cancelled the setup flow before we
453 // tell it we're through with the setup progress. 443 // tell it we're through with the setup progress.
454 testing::InSequence seq; 444 testing::InSequence seq;
455 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 445 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
456 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); 446 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false));
457 447
458 handler_->CloseSyncSetup(); 448 handler_->CloseSyncSetup();
459 EXPECT_EQ(NULL, 449 EXPECT_EQ(NULL,
460 LoginUIServiceFactory::GetForProfile( 450 LoginUIServiceFactory::GetForProfile(
461 profile_.get())->current_login_ui()); 451 profile_.get())->current_login_ui());
462 } 452 }
463 453
464 TEST_F(PeopleHandlerTest, 454 TEST_F(PeopleHandlerTest,
465 DisplayConfigureWithBackendDisabledAndSigninFailed) { 455 DisplayConfigureWithBackendDisabledAndSigninFailed) {
466 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 456 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
467 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
468 .WillRepeatedly(Return(true));
469 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 457 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
470 .WillRepeatedly(Return(false)); 458 .WillRepeatedly(Return(false));
471 error_ = GoogleServiceAuthError::AuthErrorNone(); 459 error_ = GoogleServiceAuthError::AuthErrorNone();
472 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 460 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
473 461
474 handler_->OpenSyncSetup(nullptr); 462 handler_->OpenSyncSetup(nullptr);
475 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 463 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
476 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 464 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
477 std::string page; 465 std::string page;
478 ASSERT_TRUE(data.arg1()->GetAsString(&page)); 466 ASSERT_TRUE(data.arg1()->GetAsString(&page));
(...skipping 12 matching lines...) Expand all
491 479
492 #if !defined(OS_CHROMEOS) 480 #if !defined(OS_CHROMEOS)
493 481
494 class PeopleHandlerNonCrosTest : public PeopleHandlerTest { 482 class PeopleHandlerNonCrosTest : public PeopleHandlerTest {
495 public: 483 public:
496 PeopleHandlerNonCrosTest() {} 484 PeopleHandlerNonCrosTest() {}
497 }; 485 };
498 486
499 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) { 487 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) {
500 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 488 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
501 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
502 .WillRepeatedly(Return(false));
503 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) 489 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
504 .WillRepeatedly(Return(false)); 490 .WillRepeatedly(Return(false));
505 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 491 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
506 .WillRepeatedly(Return(false)); 492 .WillRepeatedly(Return(false));
507 // Open the web UI. 493 // Open the web UI.
508 handler_->OpenSyncSetup(nullptr); 494 handler_->OpenSyncSetup(nullptr);
509 495
510 ASSERT_FALSE(handler_->is_configuring_sync()); 496 ASSERT_FALSE(handler_->is_configuring_sync());
511 } 497 }
512 498
513 // TODO(kochi): We need equivalent tests for ChromeOS. 499 // TODO(kochi): We need equivalent tests for ChromeOS.
514 TEST_F(PeopleHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { 500 TEST_F(PeopleHandlerNonCrosTest, UnrecoverableErrorInitializingSync) {
515 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 501 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
516 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
517 .WillRepeatedly(Return(false));
518 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 502 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
519 .WillRepeatedly(Return(false)); 503 .WillRepeatedly(Return(false));
520 // Open the web UI. 504 // Open the web UI.
521 handler_->OpenSyncSetup(nullptr); 505 handler_->OpenSyncSetup(nullptr);
522 506
523 ASSERT_FALSE(handler_->is_configuring_sync()); 507 ASSERT_FALSE(handler_->is_configuring_sync());
524 } 508 }
525 509
526 TEST_F(PeopleHandlerNonCrosTest, GaiaErrorInitializingSync) { 510 TEST_F(PeopleHandlerNonCrosTest, GaiaErrorInitializingSync) {
527 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 511 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
528 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
529 .WillRepeatedly(Return(false));
530 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 512 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
531 .WillRepeatedly(Return(false)); 513 .WillRepeatedly(Return(false));
532 // Open the web UI. 514 // Open the web UI.
533 handler_->OpenSyncSetup(nullptr); 515 handler_->OpenSyncSetup(nullptr);
534 516
535 ASSERT_FALSE(handler_->is_configuring_sync()); 517 ASSERT_FALSE(handler_->is_configuring_sync());
536 } 518 }
537 519
538 #endif // #if !defined(OS_CHROMEOS) 520 #endif // #if !defined(OS_CHROMEOS)
539 521
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 // Initialize the system to a signed in state, but with an auth error. 751 // Initialize the system to a signed in state, but with an auth error.
770 error_ = GoogleServiceAuthError( 752 error_ = GoogleServiceAuthError(
771 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 753 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
772 754
773 SetupInitializedProfileSyncService(); 755 SetupInitializedProfileSyncService();
774 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); 756 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
775 FakeAuthStatusProvider provider( 757 FakeAuthStatusProvider provider(
776 SigninErrorControllerFactory::GetForProfile(profile_.get())); 758 SigninErrorControllerFactory::GetForProfile(profile_.get()));
777 provider.SetAuthError(kTestUser, error_); 759 provider.SetAuthError(kTestUser, error_);
778 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 760 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
779 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
780 .WillRepeatedly(Return(true));
781 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 761 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
782 .WillRepeatedly(Return(false)); 762 .WillRepeatedly(Return(false));
783 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 763 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
784 .WillRepeatedly(Return(false)); 764 .WillRepeatedly(Return(false));
785 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 765 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
786 766
787 #if defined(OS_CHROMEOS) 767 #if defined(OS_CHROMEOS)
788 // On ChromeOS, auth errors are ignored - instead we just try to start the 768 // On ChromeOS, auth errors are ignored - instead we just try to start the
789 // sync backend (which will fail due to the auth error). This should only 769 // sync backend (which will fail due to the auth error). This should only
790 // happen if the user manually navigates to chrome://settings/syncSetup - 770 // happen if the user manually navigates to chrome://settings/syncSetup -
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 970 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
991 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 971 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
992 handler_->HandleConfigure(&list_args); 972 handler_->HandleConfigure(&list_args);
993 973
994 // Ensure that we navigated to the "done" state since we don't need a 974 // Ensure that we navigated to the "done" state since we don't need a
995 // passphrase. 975 // passphrase.
996 ExpectDone(); 976 ExpectDone();
997 } 977 }
998 978
999 } // namespace settings 979 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/sync_setup_handler_unittest.cc ('k') | components/browser_sync/browser/profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698