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

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

Issue 2551023006: [Sync] SyncEngine 1.5: Fix all backend references in PSS. (Closed)
Patch Set: Fix Android. Created 4 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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()) 223 EXPECT_CALL(*mock_pss_, GetActiveDataTypes())
224 .WillRepeatedly(Return(GetAllTypes())); 224 .WillRepeatedly(Return(GetAllTypes()));
225 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 225 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
226 .WillRepeatedly(Return(true)); 226 .WillRepeatedly(Return(true));
227 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled()) 227 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled())
228 .WillRepeatedly(Return(false)); 228 .WillRepeatedly(Return(false));
229 } 229 }
230 230
231 void SetupInitializedProfileSyncService() { 231 void SetupInitializedProfileSyncService() {
232 // An initialized ProfileSyncService will have already completed sync setup 232 // An initialized ProfileSyncService will have already completed sync setup
233 // and will have an initialized sync backend. 233 // and will have an initialized sync engine.
234 ASSERT_TRUE(mock_signin_->IsInitialized()); 234 ASSERT_TRUE(mock_signin_->IsInitialized());
235 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) 235 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(true));
236 .WillRepeatedly(Return(true));
237 } 236 }
238 237
239 void ExpectPageStatusResponse(const std::string& expected_status) { 238 void ExpectPageStatusResponse(const std::string& expected_status) {
240 auto& data = *web_ui_.call_data().back(); 239 auto& data = *web_ui_.call_data().back();
241 EXPECT_EQ("cr.webUIResponse", data.function_name()); 240 EXPECT_EQ("cr.webUIResponse", data.function_name());
242 std::string callback_id; 241 std::string callback_id;
243 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); 242 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id));
244 EXPECT_EQ(kTestCallbackId, callback_id); 243 EXPECT_EQ(kTestCallbackId, callback_id);
245 bool success = false; 244 bool success = false;
246 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); 245 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 358
360 // Sync setup is closed when sync is disabled. 359 // Sync setup is closed when sync is disabled.
361 EXPECT_EQ(NULL, 360 EXPECT_EQ(NULL,
362 LoginUIServiceFactory::GetForProfile( 361 LoginUIServiceFactory::GetForProfile(
363 profile_)->current_login_ui()); 362 profile_)->current_login_ui());
364 ASSERT_FALSE(handler_->is_configuring_sync()); 363 ASSERT_FALSE(handler_->is_configuring_sync());
365 } 364 }
366 365
367 // Verifies that the handler correctly handles a cancellation when 366 // Verifies that the handler correctly handles a cancellation when
368 // it is displaying the spinner to the user. 367 // it is displaying the spinner to the user.
369 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { 368 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndCancel) {
370 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 369 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
371 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 370 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
372 error_ = GoogleServiceAuthError::AuthErrorNone(); 371 error_ = GoogleServiceAuthError::AuthErrorNone();
373 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 372 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
374 373
375 // We're simulating a user setting up sync, which would cause the backend to 374 // We're simulating a user setting up sync, which would cause the engine to
376 // kick off initialization, but not download user data types. The sync 375 // kick off initialization, but not download user data types. The sync
377 // backend will try to download control data types (e.g encryption info), but 376 // engine will try to download control data types (e.g encryption info), but
378 // that won't finish for this test as we're simulating cancelling while the 377 // that won't finish for this test as we're simulating cancelling while the
379 // spinner is showing. 378 // spinner is showing.
380 handler_->HandleShowSetupUI(NULL); 379 handler_->HandleShowSetupUI(NULL);
381 380
382 EXPECT_EQ(handler_.get(), 381 EXPECT_EQ(handler_.get(),
383 LoginUIServiceFactory::GetForProfile( 382 LoginUIServiceFactory::GetForProfile(
384 profile_)->current_login_ui()); 383 profile_)->current_login_ui());
385 384
386 ExpectSpinnerAndClose(); 385 ExpectSpinnerAndClose();
387 } 386 }
388 387
389 // Verifies that the handler correctly transitions from showing the spinner 388 // Verifies that the handler correctly transitions from showing the spinner
390 // to showing a configuration page when sync setup completes successfully. 389 // to showing a configuration page when sync setup completes successfully.
391 TEST_F(PeopleHandlerTest, 390 TEST_F(PeopleHandlerTest,
392 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { 391 DisplayConfigureWithEngineDisabledAndSyncStartupCompleted) {
393 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 392 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
394 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 393 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
395 error_ = GoogleServiceAuthError::AuthErrorNone(); 394 error_ = GoogleServiceAuthError::AuthErrorNone();
396 // Sync backend is stopped initially, and will start up. 395 // Sync engine is stopped initially, and will start up.
397 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 396 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
398 SetDefaultExpectationsForConfigPage(); 397 SetDefaultExpectationsForConfigPage();
399 398
400 handler_->OpenSyncSetup(false /* creating_supervised_user */); 399 handler_->OpenSyncSetup(false /* creating_supervised_user */);
401 400
402 EXPECT_EQ(1U, web_ui_.call_data().size()); 401 EXPECT_EQ(1U, web_ui_.call_data().size());
403 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus); 402 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus);
404 403
405 Mock::VerifyAndClearExpectations(mock_pss_); 404 Mock::VerifyAndClearExpectations(mock_pss_);
406 // Now, act as if the ProfileSyncService has started up. 405 // Now, act as if the ProfileSyncService has started up.
407 SetDefaultExpectationsForConfigPage(); 406 SetDefaultExpectationsForConfigPage();
408 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(true)); 407 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(true));
409 error_ = GoogleServiceAuthError::AuthErrorNone(); 408 error_ = GoogleServiceAuthError::AuthErrorNone();
410 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 409 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
411 handler_->SyncStartupCompleted(); 410 handler_->SyncStartupCompleted();
412 411
413 EXPECT_EQ(2U, web_ui_.call_data().size()); 412 EXPECT_EQ(2U, web_ui_.call_data().size());
414 413
415 const base::DictionaryValue* dictionary = ExpectSyncPrefsChanged(); 414 const base::DictionaryValue* dictionary = ExpectSyncPrefsChanged();
416 CheckBool(dictionary, "syncAllDataTypes", true); 415 CheckBool(dictionary, "syncAllDataTypes", true);
417 CheckBool(dictionary, "encryptAllDataAllowed", true); 416 CheckBool(dictionary, "encryptAllDataAllowed", true);
418 CheckBool(dictionary, "encryptAllData", false); 417 CheckBool(dictionary, "encryptAllData", false);
419 CheckBool(dictionary, "passphraseRequired", false); 418 CheckBool(dictionary, "passphraseRequired", false);
420 } 419 }
421 420
422 // Verifies the case where the user cancels after the sync backend has 421 // Verifies the case where the user cancels after the sync engine has
423 // initialized (meaning it already transitioned from the spinner to a proper 422 // initialized (meaning it already transitioned from the spinner to a proper
424 // configuration page, tested by 423 // configuration page, tested by
425 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user 424 // DisplayConfigureWithEngineDisabledAndSyncStartupCompleted), but before the
426 // before the user has continued on. 425 // user has continued on.
427 TEST_F(PeopleHandlerTest, 426 TEST_F(PeopleHandlerTest,
428 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { 427 DisplayConfigureWithEngineDisabledAndCancelAfterSigninSuccess) {
429 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 428 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
430 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 429 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
431 error_ = GoogleServiceAuthError::AuthErrorNone(); 430 error_ = GoogleServiceAuthError::AuthErrorNone();
432 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) 431 EXPECT_CALL(*mock_pss_, IsEngineInitialized())
433 .WillOnce(Return(false)) 432 .WillOnce(Return(false))
434 .WillRepeatedly(Return(true)); 433 .WillRepeatedly(Return(true));
435 SetDefaultExpectationsForConfigPage(); 434 SetDefaultExpectationsForConfigPage();
436 handler_->OpenSyncSetup(false /* creating_supervised_user */); 435 handler_->OpenSyncSetup(false /* creating_supervised_user */);
437 436
438 // It's important to tell sync the user cancelled the setup flow before we 437 // It's important to tell sync the user cancelled the setup flow before we
439 // tell it we're through with the setup progress. 438 // tell it we're through with the setup progress.
440 testing::InSequence seq; 439 testing::InSequence seq;
441 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 440 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
442 EXPECT_CALL(*mock_pss_, OnSetupInProgressHandleDestroyed()); 441 EXPECT_CALL(*mock_pss_, OnSetupInProgressHandleDestroyed());
443 442
444 handler_->CloseSyncSetup(); 443 handler_->CloseSyncSetup();
445 EXPECT_EQ(NULL, 444 EXPECT_EQ(NULL,
446 LoginUIServiceFactory::GetForProfile( 445 LoginUIServiceFactory::GetForProfile(
447 profile_)->current_login_ui()); 446 profile_)->current_login_ui());
448 } 447 }
449 448
450 TEST_F(PeopleHandlerTest, 449 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndSigninFailed) {
451 DisplayConfigureWithBackendDisabledAndSigninFailed) {
452 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 450 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
453 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 451 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
454 error_ = GoogleServiceAuthError::AuthErrorNone(); 452 error_ = GoogleServiceAuthError::AuthErrorNone();
455 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 453 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
456 454
457 handler_->OpenSyncSetup(false /* creating_supervised_user */); 455 handler_->OpenSyncSetup(false /* creating_supervised_user */);
458 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus); 456 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus);
459 Mock::VerifyAndClearExpectations(mock_pss_); 457 Mock::VerifyAndClearExpectations(mock_pss_);
460 error_ = GoogleServiceAuthError( 458 error_ = GoogleServiceAuthError(
461 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 459 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
462 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 460 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
463 NotifySyncListeners(); 461 NotifySyncListeners();
464 462
465 // On failure, the dialog will be closed. 463 // On failure, the dialog will be closed.
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 SetupInitializedProfileSyncService(); 712 SetupInitializedProfileSyncService();
715 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); 713 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
716 FakeAuthStatusProvider provider( 714 FakeAuthStatusProvider provider(
717 SigninErrorControllerFactory::GetForProfile(profile_)); 715 SigninErrorControllerFactory::GetForProfile(profile_));
718 provider.SetAuthError(kTestUser, error_); 716 provider.SetAuthError(kTestUser, error_);
719 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 717 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
720 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 718 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
721 .WillRepeatedly(Return(false)); 719 .WillRepeatedly(Return(false));
722 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 720 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
723 .WillRepeatedly(Return(false)); 721 .WillRepeatedly(Return(false));
724 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 722 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
725 723
726 #if defined(OS_CHROMEOS) 724 #if defined(OS_CHROMEOS)
727 // On ChromeOS, auth errors are ignored - instead we just try to start the 725 // On ChromeOS, auth errors are ignored - instead we just try to start the
728 // sync backend (which will fail due to the auth error). This should only 726 // sync engine (which will fail due to the auth error). This should only
729 // happen if the user manually navigates to chrome://settings/syncSetup - 727 // happen if the user manually navigates to chrome://settings/syncSetup -
730 // clicking on the button in the UI will sign the user out rather than 728 // clicking on the button in the UI will sign the user out rather than
731 // displaying a spinner. Should be no visible UI on ChromeOS in this case. 729 // displaying a spinner. Should be no visible UI on ChromeOS in this case.
732 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile( 730 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(
733 profile_)->current_login_ui()); 731 profile_)->current_login_ui());
734 #else 732 #else
735 733
736 // On ChromeOS, this should display the spinner while we try to startup the 734 // On ChromeOS, this should display the spinner while we try to startup the
737 // sync backend, and on desktop this displays the login dialog. 735 // sync engine, and on desktop this displays the login dialog.
738 handler_->OpenSyncSetup(false /* creating_supervised_user */); 736 handler_->OpenSyncSetup(false /* creating_supervised_user */);
739 737
740 // Sync setup is closed when re-auth is in progress. 738 // Sync setup is closed when re-auth is in progress.
741 EXPECT_EQ(NULL, 739 EXPECT_EQ(NULL,
742 LoginUIServiceFactory::GetForProfile( 740 LoginUIServiceFactory::GetForProfile(
743 profile_)->current_login_ui()); 741 profile_)->current_login_ui());
744 742
745 ASSERT_FALSE(handler_->is_configuring_sync()); 743 ASSERT_FALSE(handler_->is_configuring_sync());
746 #endif 744 #endif
747 } 745 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 SetupInitializedProfileSyncService(); 901 SetupInitializedProfileSyncService();
904 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 902 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
905 .WillRepeatedly(Return(false)); 903 .WillRepeatedly(Return(false));
906 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 904 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
907 handler_->HandleSetEncryption(&list_args); 905 handler_->HandleSetEncryption(&list_args);
908 906
909 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 907 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
910 } 908 }
911 909
912 } // namespace settings 910 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698