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

Side by Side Diff: chrome/browser/ui/webui/options/sync_setup_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 (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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()) 227 EXPECT_CALL(*mock_pss_, GetActiveDataTypes())
228 .WillRepeatedly(Return(GetAllTypes())); 228 .WillRepeatedly(Return(GetAllTypes()));
229 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 229 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
230 .WillRepeatedly(Return(true)); 230 .WillRepeatedly(Return(true));
231 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled()) 231 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled())
232 .WillRepeatedly(Return(false)); 232 .WillRepeatedly(Return(false));
233 } 233 }
234 234
235 void SetupInitializedProfileSyncService() { 235 void SetupInitializedProfileSyncService() {
236 // An initialized ProfileSyncService will have already completed sync setup 236 // An initialized ProfileSyncService will have already completed sync setup
237 // and will have an initialized sync backend. 237 // and will have an initialized sync engine.
238 ASSERT_TRUE(mock_signin_->IsInitialized()); 238 ASSERT_TRUE(mock_signin_->IsInitialized());
239 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) 239 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(true));
240 .WillRepeatedly(Return(true));
241 } 240 }
242 241
243 void ExpectConfig() { 242 void ExpectConfig() {
244 ASSERT_EQ(1U, web_ui_.call_data().size()); 243 ASSERT_EQ(1U, web_ui_.call_data().size());
245 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 244 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
246 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name()); 245 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name());
247 std::string page; 246 std::string page;
248 ASSERT_TRUE(data.arg1()->GetAsString(&page)); 247 ASSERT_TRUE(data.arg1()->GetAsString(&page));
249 EXPECT_EQ(page, "configure"); 248 EXPECT_EQ(page, "configure");
250 } 249 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 350
352 // Sync setup is closed when sync is disabled. 351 // Sync setup is closed when sync is disabled.
353 EXPECT_EQ(NULL, 352 EXPECT_EQ(NULL,
354 LoginUIServiceFactory::GetForProfile( 353 LoginUIServiceFactory::GetForProfile(
355 profile_.get())->current_login_ui()); 354 profile_.get())->current_login_ui());
356 ASSERT_FALSE(handler_->is_configuring_sync()); 355 ASSERT_FALSE(handler_->is_configuring_sync());
357 } 356 }
358 357
359 // Verifies that the handler correctly handles a cancellation when 358 // Verifies that the handler correctly handles a cancellation when
360 // it is displaying the spinner to the user. 359 // it is displaying the spinner to the user.
361 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { 360 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithEngineDisabledAndCancel) {
362 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 361 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
363 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 362 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
364 error_ = GoogleServiceAuthError::AuthErrorNone(); 363 error_ = GoogleServiceAuthError::AuthErrorNone();
365 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 364 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
366 365
367 // We're simulating a user setting up sync, which would cause the backend to 366 // We're simulating a user setting up sync, which would cause the engine to
368 // kick off initialization, but not download user data types. The sync 367 // 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 368 // engine 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 369 // that won't finish for this test as we're simulating cancelling while the
371 // spinner is showing. 370 // spinner is showing.
372 handler_->HandleShowSetupUI(NULL); 371 handler_->HandleShowSetupUI(NULL);
373 372
374 EXPECT_EQ(handler_.get(), 373 EXPECT_EQ(handler_.get(),
375 LoginUIServiceFactory::GetForProfile( 374 LoginUIServiceFactory::GetForProfile(
376 profile_.get())->current_login_ui()); 375 profile_.get())->current_login_ui());
377 376
378 ExpectSpinnerAndClose(); 377 ExpectSpinnerAndClose();
379 } 378 }
380 379
381 // Verifies that the handler correctly transitions from showing the spinner 380 // Verifies that the handler correctly transitions from showing the spinner
382 // to showing a configuration page when sync setup completes successfully. 381 // to showing a configuration page when sync setup completes successfully.
383 TEST_F(SyncSetupHandlerTest, 382 TEST_F(SyncSetupHandlerTest,
384 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { 383 DisplayConfigureWithEngineDisabledAndSyncStartupCompleted) {
385 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 384 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
386 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 385 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
387 error_ = GoogleServiceAuthError::AuthErrorNone(); 386 error_ = GoogleServiceAuthError::AuthErrorNone();
388 // Sync backend is stopped initially, and will start up. 387 // Sync engine is stopped initially, and will start up.
389 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 388 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
390 SetDefaultExpectationsForConfigPage(); 389 SetDefaultExpectationsForConfigPage();
391 390
392 handler_->OpenSyncSetup(false /* creating_supervised_user */); 391 handler_->OpenSyncSetup(false /* creating_supervised_user */);
393 392
394 // We expect a call to SyncSetupOverlay.showSyncSetupPage. 393 // We expect a call to SyncSetupOverlay.showSyncSetupPage.
395 EXPECT_EQ(1U, web_ui_.call_data().size()); 394 EXPECT_EQ(1U, web_ui_.call_data().size());
396 395
397 const content::TestWebUI::CallData& data0 = *web_ui_.call_data()[0]; 396 const content::TestWebUI::CallData& data0 = *web_ui_.call_data()[0];
398 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data0.function_name()); 397 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data0.function_name());
399 std::string page; 398 std::string page;
400 ASSERT_TRUE(data0.arg1()->GetAsString(&page)); 399 ASSERT_TRUE(data0.arg1()->GetAsString(&page));
401 EXPECT_EQ(page, "spinner"); 400 EXPECT_EQ(page, "spinner");
402 401
403 Mock::VerifyAndClearExpectations(mock_pss_); 402 Mock::VerifyAndClearExpectations(mock_pss_);
404 // Now, act as if the ProfileSyncService has started up. 403 // Now, act as if the ProfileSyncService has started up.
405 SetDefaultExpectationsForConfigPage(); 404 SetDefaultExpectationsForConfigPage();
406 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(true)); 405 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(true));
407 error_ = GoogleServiceAuthError::AuthErrorNone(); 406 error_ = GoogleServiceAuthError::AuthErrorNone();
408 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 407 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
409 NotifySyncListeners(); 408 NotifySyncListeners();
410 409
411 // We expect a second call to SyncSetupOverlay.showSyncSetupPage. 410 // We expect a second call to SyncSetupOverlay.showSyncSetupPage.
412 EXPECT_EQ(2U, web_ui_.call_data().size()); 411 EXPECT_EQ(2U, web_ui_.call_data().size());
413 const content::TestWebUI::CallData& data1 = *web_ui_.call_data().back(); 412 const content::TestWebUI::CallData& data1 = *web_ui_.call_data().back();
414 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data1.function_name()); 413 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data1.function_name());
415 ASSERT_TRUE(data1.arg1()->GetAsString(&page)); 414 ASSERT_TRUE(data1.arg1()->GetAsString(&page));
416 EXPECT_EQ(page, "configure"); 415 EXPECT_EQ(page, "configure");
417 const base::DictionaryValue* dictionary = nullptr; 416 const base::DictionaryValue* dictionary = nullptr;
418 ASSERT_TRUE(data1.arg2()->GetAsDictionary(&dictionary)); 417 ASSERT_TRUE(data1.arg2()->GetAsDictionary(&dictionary));
419 CheckBool(dictionary, "passphraseFailed", false); 418 CheckBool(dictionary, "passphraseFailed", false);
420 CheckBool(dictionary, "syncAllDataTypes", true); 419 CheckBool(dictionary, "syncAllDataTypes", true);
421 CheckBool(dictionary, "encryptAllDataAllowed", true); 420 CheckBool(dictionary, "encryptAllDataAllowed", true);
422 CheckBool(dictionary, "encryptAllData", false); 421 CheckBool(dictionary, "encryptAllData", false);
423 CheckBool(dictionary, "usePassphrase", false); 422 CheckBool(dictionary, "usePassphrase", false);
424 } 423 }
425 424
426 // Verifies the case where the user cancels after the sync backend has 425 // Verifies the case where the user cancels after the sync engine has
427 // initialized (meaning it already transitioned from the spinner to a proper 426 // initialized (meaning it already transitioned from the spinner to a proper
428 // configuration page, tested by 427 // configuration page, tested by
429 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user 428 // DisplayConfigureWithEngineDisabledAndSyncStartupCompleted), but before the
430 // before the user has continued on. 429 // user has continued on.
431 TEST_F(SyncSetupHandlerTest, 430 TEST_F(SyncSetupHandlerTest,
432 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { 431 DisplayConfigureWithEngineDisabledAndCancelAfterSigninSuccess) {
433 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 432 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
434 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 433 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
435 error_ = GoogleServiceAuthError::AuthErrorNone(); 434 error_ = GoogleServiceAuthError::AuthErrorNone();
436 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) 435 EXPECT_CALL(*mock_pss_, IsEngineInitialized())
437 .WillOnce(Return(false)) 436 .WillOnce(Return(false))
438 .WillRepeatedly(Return(true)); 437 .WillRepeatedly(Return(true));
439 SetDefaultExpectationsForConfigPage(); 438 SetDefaultExpectationsForConfigPage();
440 handler_->OpenSyncSetup(false /* creating_supervised_user */); 439 handler_->OpenSyncSetup(false /* creating_supervised_user */);
441 440
442 // It's important to tell sync the user cancelled the setup flow before we 441 // It's important to tell sync the user cancelled the setup flow before we
443 // tell it we're through with the setup progress. 442 // tell it we're through with the setup progress.
444 testing::InSequence seq; 443 testing::InSequence seq;
445 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 444 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
446 EXPECT_CALL(*mock_pss_, OnSetupInProgressHandleDestroyed()); 445 EXPECT_CALL(*mock_pss_, OnSetupInProgressHandleDestroyed());
447 446
448 handler_->CloseSyncSetup(); 447 handler_->CloseSyncSetup();
449 EXPECT_EQ(NULL, 448 EXPECT_EQ(NULL,
450 LoginUIServiceFactory::GetForProfile( 449 LoginUIServiceFactory::GetForProfile(
451 profile_.get())->current_login_ui()); 450 profile_.get())->current_login_ui());
452 } 451 }
453 452
454 TEST_F(SyncSetupHandlerTest, 453 TEST_F(SyncSetupHandlerTest,
455 DisplayConfigureWithBackendDisabledAndSigninFailed) { 454 DisplayConfigureWithEngineDisabledAndSigninFailed) {
456 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 455 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
457 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 456 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
458 error_ = GoogleServiceAuthError::AuthErrorNone(); 457 error_ = GoogleServiceAuthError::AuthErrorNone();
459 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 458 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
460 459
461 handler_->OpenSyncSetup(false /* creating_supervised_user */); 460 handler_->OpenSyncSetup(false /* creating_supervised_user */);
462 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 461 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
463 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name()); 462 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name());
464 std::string page; 463 std::string page;
465 ASSERT_TRUE(data.arg1()->GetAsString(&page)); 464 ASSERT_TRUE(data.arg1()->GetAsString(&page));
466 EXPECT_EQ(page, "spinner"); 465 EXPECT_EQ(page, "spinner");
467 Mock::VerifyAndClearExpectations(mock_pss_); 466 Mock::VerifyAndClearExpectations(mock_pss_);
468 error_ = GoogleServiceAuthError( 467 error_ = GoogleServiceAuthError(
469 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 468 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 SetupInitializedProfileSyncService(); 728 SetupInitializedProfileSyncService();
730 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); 729 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
731 FakeAuthStatusProvider provider( 730 FakeAuthStatusProvider provider(
732 SigninErrorControllerFactory::GetForProfile(profile_.get())); 731 SigninErrorControllerFactory::GetForProfile(profile_.get()));
733 provider.SetAuthError(kTestUser, error_); 732 provider.SetAuthError(kTestUser, error_);
734 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 733 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
735 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 734 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
736 .WillRepeatedly(Return(false)); 735 .WillRepeatedly(Return(false));
737 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 736 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
738 .WillRepeatedly(Return(false)); 737 .WillRepeatedly(Return(false));
739 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 738 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
740 739
741 #if defined(OS_CHROMEOS) 740 #if defined(OS_CHROMEOS)
742 // On ChromeOS, auth errors are ignored - instead we just try to start the 741 // On ChromeOS, auth errors are ignored - instead we just try to start the
743 // sync backend (which will fail due to the auth error). This should only 742 // sync engine (which will fail due to the auth error). This should only
744 // happen if the user manually navigates to chrome://settings/syncSetup - 743 // happen if the user manually navigates to chrome://settings/syncSetup -
745 // clicking on the button in the UI will sign the user out rather than 744 // clicking on the button in the UI will sign the user out rather than
746 // displaying a spinner. Should be no visible UI on ChromeOS in this case. 745 // displaying a spinner. Should be no visible UI on ChromeOS in this case.
747 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile( 746 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(
748 profile_.get())->current_login_ui()); 747 profile_.get())->current_login_ui());
749 #else 748 #else
750 749
751 // On ChromeOS, this should display the spinner while we try to startup the 750 // On ChromeOS, this should display the spinner while we try to startup the
752 // sync backend, and on desktop this displays the login dialog. 751 // sync engine, and on desktop this displays the login dialog.
753 handler_->OpenSyncSetup(false /* creating_supervised_user */); 752 handler_->OpenSyncSetup(false /* creating_supervised_user */);
754 753
755 // Sync setup is closed when re-auth is in progress. 754 // Sync setup is closed when re-auth is in progress.
756 EXPECT_EQ(NULL, 755 EXPECT_EQ(NULL,
757 LoginUIServiceFactory::GetForProfile( 756 LoginUIServiceFactory::GetForProfile(
758 profile_.get())->current_login_ui()); 757 profile_.get())->current_login_ui());
759 758
760 ASSERT_FALSE(handler_->is_configuring_sync()); 759 ASSERT_FALSE(handler_->is_configuring_sync());
761 #endif 760 #endif
762 } 761 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 942 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
944 .WillRepeatedly(Return(false)); 943 .WillRepeatedly(Return(false));
945 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 944 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
946 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 945 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
947 handler_->HandleConfigure(&list_args); 946 handler_->HandleConfigure(&list_args);
948 947
949 // Ensure that we navigated to the "done" state since we don't need a 948 // Ensure that we navigated to the "done" state since we don't need a
950 // passphrase. 949 // passphrase.
951 ExpectDone(); 950 ExpectDone();
952 } 951 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/sync_setup_handler.cc ('k') | chrome/browser/ui/webui/settings/people_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698