OLD | NEW |
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/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 DictionaryValue* dictionary; | 479 DictionaryValue* dictionary; |
480 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 480 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
481 CheckShowSyncSetupArgs( | 481 CheckShowSyncSetupArgs( |
482 dictionary, "", false, GoogleServiceAuthError::NONE, "", true, ""); | 482 dictionary, "", false, GoogleServiceAuthError::NONE, "", true, ""); |
483 handler_->CloseSyncSetup(); | 483 handler_->CloseSyncSetup(); |
484 EXPECT_EQ(NULL, | 484 EXPECT_EQ(NULL, |
485 LoginUIServiceFactory::GetForProfile( | 485 LoginUIServiceFactory::GetForProfile( |
486 profile_.get())->current_login_ui()); | 486 profile_.get())->current_login_ui()); |
487 } | 487 } |
488 | 488 |
| 489 // Verifies that the handler correctly handles a cancellation when |
| 490 // it is displaying the spinner to the user. |
489 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { | 491 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { |
490 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 492 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
491 .WillRepeatedly(Return(true)); | 493 .WillRepeatedly(Return(true)); |
492 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 494 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
493 .WillRepeatedly(Return(true)); | 495 .WillRepeatedly(Return(true)); |
494 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 496 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
495 .WillRepeatedly(Return(false)); | 497 .WillRepeatedly(Return(false)); |
496 error_ = GoogleServiceAuthError::None(); | 498 error_ = GoogleServiceAuthError::None(); |
497 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 499 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
498 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); | 500 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); |
499 | 501 |
| 502 // We're simulating a user setting up sync, which would cause the backend to |
| 503 // kick off initialization, but not download user data types. The sync |
| 504 // backend will try to download control data types (e.g encryption info), but |
| 505 // that won't finish for this test as we're simulating cancelling while the |
| 506 // spinner is showing. |
500 handler_->OpenSyncSetup(false); | 507 handler_->OpenSyncSetup(false); |
501 EXPECT_EQ(handler_.get(), | 508 EXPECT_EQ(handler_.get(), |
502 LoginUIServiceFactory::GetForProfile( | 509 LoginUIServiceFactory::GetForProfile( |
503 profile_.get())->current_login_ui()); | 510 profile_.get())->current_login_ui()); |
504 ASSERT_EQ(1U, web_ui_.call_data().size()); | 511 ASSERT_EQ(1U, web_ui_.call_data().size()); |
505 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 512 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
506 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 513 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
507 std::string page; | 514 std::string page; |
508 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 515 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
509 EXPECT_EQ(page, "spinner"); | 516 EXPECT_EQ(page, "spinner"); |
510 // Cancelling the spinner dialog will cause CloseSyncSetup(). | 517 // Cancelling the spinner dialog will cause CloseSyncSetup(). |
511 handler_->CloseSyncSetup(); | 518 handler_->CloseSyncSetup(); |
512 EXPECT_EQ(NULL, | 519 EXPECT_EQ(NULL, |
513 LoginUIServiceFactory::GetForProfile( | 520 LoginUIServiceFactory::GetForProfile( |
514 profile_.get())->current_login_ui()); | 521 profile_.get())->current_login_ui()); |
515 } | 522 } |
516 | 523 |
| 524 // Verifies that the handler correctly transitions from showing the spinner |
| 525 // to showing a configuration page when signin completes successfully. |
517 TEST_F(SyncSetupHandlerTest, | 526 TEST_F(SyncSetupHandlerTest, |
518 DisplayConfigureWithBackendDisabledAndSigninSuccess) { | 527 DisplayConfigureWithBackendDisabledAndSigninSuccess) { |
519 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 528 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
520 .WillRepeatedly(Return(true)); | 529 .WillRepeatedly(Return(true)); |
521 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 530 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
522 .WillRepeatedly(Return(true)); | 531 .WillRepeatedly(Return(true)); |
523 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 532 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
524 .WillRepeatedly(Return(false)); | 533 .WillRepeatedly(Return(false)); |
525 error_ = GoogleServiceAuthError::None(); | 534 error_ = GoogleServiceAuthError::None(); |
526 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 535 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
(...skipping 23 matching lines...) Expand all Loading... |
550 EXPECT_EQ(page, "configure"); | 559 EXPECT_EQ(page, "configure"); |
551 DictionaryValue* dictionary; | 560 DictionaryValue* dictionary; |
552 ASSERT_TRUE(data1.arg2->GetAsDictionary(&dictionary)); | 561 ASSERT_TRUE(data1.arg2->GetAsDictionary(&dictionary)); |
553 CheckBool(dictionary, "passphraseFailed", false); | 562 CheckBool(dictionary, "passphraseFailed", false); |
554 CheckBool(dictionary, "showSyncEverythingPage", true); | 563 CheckBool(dictionary, "showSyncEverythingPage", true); |
555 CheckBool(dictionary, "syncAllDataTypes", true); | 564 CheckBool(dictionary, "syncAllDataTypes", true); |
556 CheckBool(dictionary, "encryptAllData", false); | 565 CheckBool(dictionary, "encryptAllData", false); |
557 CheckBool(dictionary, "usePassphrase", false); | 566 CheckBool(dictionary, "usePassphrase", false); |
558 } | 567 } |
559 | 568 |
| 569 // Verifies the case where the user cancels after the sync backend has |
| 570 // initialized (meaning it already transitioned from the spinner to a proper |
| 571 // configuration page, tested by |
| 572 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user |
| 573 // before the user has continued on. |
| 574 TEST_F(SyncSetupHandlerTest, |
| 575 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { |
| 576 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 577 .WillRepeatedly(Return(true)); |
| 578 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 579 .WillRepeatedly(Return(true)); |
| 580 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 581 .WillRepeatedly(Return(false)); |
| 582 error_ = GoogleServiceAuthError::None(); |
| 583 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 584 EXPECT_CALL(*mock_pss_, sync_initialized()) |
| 585 .WillOnce(Return(false)) |
| 586 .WillRepeatedly(Return(true)); |
| 587 SetDefaultExpectationsForConfigPage(); |
| 588 handler_->OpenSyncSetup(false); |
| 589 handler_->SigninSuccess(); |
| 590 |
| 591 // It's important to tell sync the user cancelled the setup flow before we |
| 592 // tell it we're through with the setup progress. |
| 593 testing::InSequence seq; |
| 594 EXPECT_CALL(*mock_pss_, DisableForUser()); |
| 595 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); |
| 596 |
| 597 handler_->CloseSyncSetup(); |
| 598 EXPECT_EQ(NULL, |
| 599 LoginUIServiceFactory::GetForProfile( |
| 600 profile_.get())->current_login_ui()); |
| 601 } |
| 602 |
560 TEST_F(SyncSetupHandlerTest, | 603 TEST_F(SyncSetupHandlerTest, |
561 DisplayConfigureWithBackendDisabledAndSigninFalied) { | 604 DisplayConfigureWithBackendDisabledAndSigninFalied) { |
562 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 605 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
563 .WillRepeatedly(Return(true)); | 606 .WillRepeatedly(Return(true)); |
564 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 607 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
565 .WillRepeatedly(Return(true)); | 608 .WillRepeatedly(Return(true)); |
566 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 609 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
567 .WillRepeatedly(Return(false)); | 610 .WillRepeatedly(Return(false)); |
568 error_ = GoogleServiceAuthError::None(); | 611 error_ = GoogleServiceAuthError::None(); |
569 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 612 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 DictionaryValue* dictionary; | 1191 DictionaryValue* dictionary; |
1149 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1192 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
1150 std::string err = l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED); | 1193 std::string err = l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED); |
1151 CheckShowSyncSetupArgs( | 1194 CheckShowSyncSetupArgs( |
1152 dictionary, err, false, GoogleServiceAuthError::NONE, "", true, ""); | 1195 dictionary, err, false, GoogleServiceAuthError::NONE, "", true, ""); |
1153 handler_->CloseSyncSetup(); | 1196 handler_->CloseSyncSetup(); |
1154 EXPECT_EQ(NULL, | 1197 EXPECT_EQ(NULL, |
1155 LoginUIServiceFactory::GetForProfile( | 1198 LoginUIServiceFactory::GetForProfile( |
1156 profile_.get())->current_login_ui()); | 1199 profile_.get())->current_login_ui()); |
1157 } | 1200 } |
OLD | NEW |