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

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

Powered by Google App Engine
This is Rietveld 408576698