1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/options/sync_setup_handler.h"
#include <vector>
#include "base/command_line.h"
#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
#include "base/stl_util.h"
#include "base/values.h"
#include "chrome/browser/signin/fake_signin_manager.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync_driver/sync_prefs.h"
#include "content/public/browser/web_ui.h"
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/layout.h"
using ::testing::_;
using ::testing::Mock;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::Values;
typedef GoogleServiceAuthError AuthError;
namespace {
MATCHER_P(ModelTypeSetMatches, value, "") { return arg.Equals(value); }
const char kTestUser[] = "chrome.p13n.test@gmail.com";
// Returns a ModelTypeSet with all user selectable types set.
syncer::ModelTypeSet GetAllTypes() {
return syncer::UserSelectableTypes();
}
enum SyncAllDataConfig {
SYNC_ALL_DATA,
CHOOSE_WHAT_TO_SYNC,
SYNC_NOTHING
};
enum EncryptAllConfig {
ENCRYPT_ALL_DATA,
ENCRYPT_PASSWORDS
};
// Create a json-format string with the key/value pairs appropriate for a call
// to HandleConfigure(). If |extra_values| is non-null, then the values from
// the passed dictionary are added to the json.
std::string GetConfiguration(const base::DictionaryValue* extra_values,
SyncAllDataConfig sync_all,
syncer::ModelTypeSet types,
const std::string& passphrase,
EncryptAllConfig encrypt_all) {
base::DictionaryValue result;
if (extra_values)
result.MergeDictionary(extra_values);
result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA);
result.SetBoolean("syncNothing", sync_all == SYNC_NOTHING);
result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA);
result.SetBoolean("usePassphrase", !passphrase.empty());
if (!passphrase.empty())
result.SetString("passphrase", passphrase);
// Add all of our data types.
result.SetBoolean("appsSynced", types.Has(syncer::APPS));
result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL));
result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS));
result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS));
result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS));
result.SetBoolean("preferencesSynced", types.Has(syncer::PREFERENCES));
result.SetBoolean("tabsSynced", types.Has(syncer::PROXY_TABS));
result.SetBoolean("themesSynced", types.Has(syncer::THEMES));
result.SetBoolean("typedUrlsSynced", types.Has(syncer::TYPED_URLS));
result.SetBoolean("wifiCredentialsSynced",
types.Has(syncer::WIFI_CREDENTIALS));
std::string args;
base::JSONWriter::Write(&result, &args);
return args;
}
// Checks whether the passed |dictionary| contains a |key| with the given
// |expected_value|. If |omit_if_false| is true, then the value should only
// be present if |expected_value| is true.
void CheckBool(const base::DictionaryValue* dictionary,
const std::string& key,
bool expected_value,
bool omit_if_false) {
if (omit_if_false && !expected_value) {
EXPECT_FALSE(dictionary->HasKey(key)) <<
"Did not expect to find value for " << key;
} else {
bool actual_value;
EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) <<
"No value found for " << key;
EXPECT_EQ(expected_value, actual_value) <<
"Mismatch found for " << key;
}
}
void CheckBool(const base::DictionaryValue* dictionary,
const std::string& key,
bool expected_value) {
return CheckBool(dictionary, key, expected_value, false);
}
// Checks to make sure that the values stored in |dictionary| match the values
// expected by the showSyncSetupPage() JS function for a given set of data
// types.
void CheckConfigDataTypeArguments(base::DictionaryValue* dictionary,
SyncAllDataConfig config,
syncer::ModelTypeSet types) {
CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA);
CheckBool(dictionary, "syncNothing", config == SYNC_NOTHING);
CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS));
CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL));
CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS));
CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS));
CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS));
CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES));
CheckBool(dictionary, "tabsSynced", types.Has(syncer::PROXY_TABS));
CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES));
CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS));
CheckBool(dictionary, "wifiCredentialsSynced",
types.Has(syncer::WIFI_CREDENTIALS));
}
} // namespace
// Test instance of WebUI that tracks the data passed to
// CallJavascriptFunction().
class TestWebUI : public content::WebUI {
public:
~TestWebUI() override { ClearTrackedCalls(); }
void ClearTrackedCalls() {
// Manually free the arguments stored in CallData, since there's no good
// way to use a self-freeing reference like scoped_ptr in a std::vector.
for (std::vector<CallData>::iterator i = call_data_.begin();
i != call_data_.end();
++i) {
delete i->arg1;
delete i->arg2;
}
call_data_.clear();
}
void CallJavascriptFunction(const std::string& function_name) override {
call_data_.push_back(CallData());
call_data_.back().function_name = function_name;
}
void CallJavascriptFunction(const std::string& function_name,
const base::Value& arg1) override {
call_data_.push_back(CallData());
call_data_.back().function_name = function_name;
call_data_.back().arg1 = arg1.DeepCopy();
}
void CallJavascriptFunction(const std::string& function_name,
const base::Value& arg1,
const base::Value& arg2) override {
call_data_.push_back(CallData());
call_data_.back().function_name = function_name;
call_data_.back().arg1 = arg1.DeepCopy();
call_data_.back().arg2 = arg2.DeepCopy();
}
content::WebContents* GetWebContents() const override { return NULL; }
content::WebUIController* GetController() const override { return NULL; }
void SetController(content::WebUIController* controller) override {}
float GetDeviceScaleFactor() const override { return 1.0f; }
const base::string16& GetOverriddenTitle() const override {
return temp_string_;
}
void OverrideTitle(const base::string16& title) override {}
ui::PageTransition GetLinkTransitionType() const override {
return ui::PAGE_TRANSITION_LINK;
}
void SetLinkTransitionType(ui::PageTransition type) override {}
int GetBindings() const override { return 0; }
void SetBindings(int bindings) override {}
void OverrideJavaScriptFrame(const std::string& frame_name) override {}
void AddMessageHandler(content::WebUIMessageHandler* handler) override {}
void RegisterMessageCallback(const std::string& message,
const MessageCallback& callback) override {}
void ProcessWebUIMessage(const GURL& source_url,
const std::string& message,
const base::ListValue& args) override {}
void CallJavascriptFunction(const std::string& function_name,
const base::Value& arg1,
const base::Value& arg2,
const base::Value& arg3) override {}
void CallJavascriptFunction(const std::string& function_name,
const base::Value& arg1,
const base::Value& arg2,
const base::Value& arg3,
const base::Value& arg4) override {}
void CallJavascriptFunction(
const std::string& function_name,
const std::vector<const base::Value*>& args) override {}
class CallData {
public:
CallData() : arg1(NULL), arg2(NULL) {}
std::string function_name;
base::Value* arg1;
base::Value* arg2;
};
const std::vector<CallData>& call_data() { return call_data_; }
private:
std::vector<CallData> call_data_;
base::string16 temp_string_;
};
class TestingSyncSetupHandler : public SyncSetupHandler {
public:
TestingSyncSetupHandler(content::WebUI* web_ui, Profile* profile)
: SyncSetupHandler(NULL),
profile_(profile) {
set_web_ui(web_ui);
}
~TestingSyncSetupHandler() override { set_web_ui(NULL); }
void FocusUI() override {}
Profile* GetProfile() const override { return profile_; }
using SyncSetupHandler::is_configuring_sync;
private:
#if !defined(OS_CHROMEOS)
void DisplayGaiaLoginInNewTabOrWindow() override {}
#endif
// Weak pointer to parent profile.
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler);
};
// The boolean parameter indicates whether the test is run with ClientOAuth
// or not. The test parameter is a bool: whether or not to test with/
// /ClientLogin enabled or not.
class SyncSetupHandlerTest : public testing::Test {
public:
SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {}
void SetUp() override {
error_ = GoogleServiceAuthError::AuthErrorNone();
TestingProfile::Builder builder;
builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
FakeSigninManagerBase::Build);
profile_ = builder.Build();
// Sign in the user.
mock_signin_ = static_cast<SigninManagerBase*>(
SigninManagerFactory::GetForProfile(profile_.get()));
std::string username = GetTestUser();
if (!username.empty())
mock_signin_->SetAuthenticatedUsername(username);
mock_pss_ = static_cast<ProfileSyncServiceMock*>(
ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
profile_.get(),
ProfileSyncServiceMock::BuildMockProfileSyncService));
EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault(
Return(syncer::IMPLICIT_PASSPHRASE));
ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault(
Return(base::Time()));
ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault(
Return(base::Time()));
ON_CALL(*mock_pss_, GetRegisteredDataTypes())
.WillByDefault(Return(syncer::ModelTypeSet()));
mock_pss_->Initialize();
handler_.reset(new TestingSyncSetupHandler(&web_ui_, profile_.get()));
}
// Setup the expectations for calls made when displaying the config page.
void SetDefaultExpectationsForConfigPage() {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).
WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()).
WillRepeatedly(Return(GetAllTypes()));
EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()).
WillRepeatedly(Return(GetAllTypes()));
EXPECT_CALL(*mock_pss_, GetActiveDataTypes()).
WillRepeatedly(Return(GetAllTypes()));
EXPECT_CALL(*mock_pss_, EncryptEverythingAllowed()).
WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()).
WillRepeatedly(Return(false));
}
void SetupInitializedProfileSyncService() {
// An initialized ProfileSyncService will have already completed sync setup
// and will have an initialized sync backend.
ASSERT_TRUE(mock_signin_->IsInitialized());
EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(true));
}
void ExpectConfig() {
ASSERT_EQ(1U, web_ui_.call_data().size());
const TestWebUI::CallData& data = web_ui_.call_data()[0];
EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
std::string page;
ASSERT_TRUE(data.arg1->GetAsString(&page));
EXPECT_EQ(page, "configure");
}
void ExpectDone() {
ASSERT_EQ(1U, web_ui_.call_data().size());
const TestWebUI::CallData& data = web_ui_.call_data()[0];
EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
std::string page;
ASSERT_TRUE(data.arg1->GetAsString(&page));
EXPECT_EQ(page, "done");
}
void ExpectSpinnerAndClose() {
// We expect a call to SyncSetupOverlay.showSyncSetupPage.
EXPECT_EQ(1U, web_ui_.call_data().size());
const TestWebUI::CallData& data = web_ui_.call_data()[0];
EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
std::string page;
ASSERT_TRUE(data.arg1->GetAsString(&page));
EXPECT_EQ(page, "spinner");
// Cancelling the spinner dialog will cause CloseSyncSetup().
handler_->CloseSyncSetup();
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
}
// It's difficult to notify sync listeners when using a ProfileSyncServiceMock
// so this helper routine dispatches an OnStateChanged() notification to the
// SyncStartupTracker.
void NotifySyncListeners() {
if (handler_->sync_startup_tracker_)
handler_->sync_startup_tracker_->OnStateChanged();
}
virtual std::string GetTestUser() {
return std::string(kTestUser);
}
content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<Profile> profile_;
ProfileSyncServiceMock* mock_pss_;
GoogleServiceAuthError error_;
SigninManagerBase* mock_signin_;
TestWebUI web_ui_;
scoped_ptr<TestingSyncSetupHandler> handler_;
};
class SyncSetupHandlerFirstSigninTest : public SyncSetupHandlerTest {
std::string GetTestUser() override { return std::string(); }
};
TEST_F(SyncSetupHandlerTest, Basic) {
}
#if !defined(OS_CHROMEOS)
TEST_F(SyncSetupHandlerFirstSigninTest, DisplayBasicLogin) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
// Ensure that the user is not signed in before calling |HandleStartSignin()|.
SigninManager* manager = static_cast<SigninManager*>(mock_signin_);
manager->SignOut(signin_metrics::SIGNOUT_TEST);
handler_->HandleStartSignin(NULL);
// Sync setup hands off control to the gaia login tab.
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
ASSERT_FALSE(handler_->is_configuring_sync());
handler_->CloseSyncSetup();
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
}
TEST_F(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
handler_->HandleShowSetupUI(NULL);
// We expect a call to SyncSetupOverlay.showSyncSetupPage.
ASSERT_EQ(1U, web_ui_.call_data().size());
const TestWebUI::CallData& data = web_ui_.call_data()[0];
EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
ASSERT_FALSE(handler_->is_configuring_sync());
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
}
#endif // !defined(OS_CHROMEOS)
// Verifies that the sync setup is terminated correctly when the
// sync is disabled.
TEST_F(SyncSetupHandlerTest, HandleSetupUIWhenSyncDisabled) {
EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true));
handler_->HandleShowSetupUI(NULL);
// Sync setup is closed when sync is disabled.
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
ASSERT_FALSE(handler_->is_configuring_sync());
}
// Verifies that the handler correctly handles a cancellation when
// it is displaying the spinner to the user.
TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
error_ = GoogleServiceAuthError::AuthErrorNone();
EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
// We're simulating a user setting up sync, which would cause the backend to
// kick off initialization, but not download user data types. The sync
// backend will try to download control data types (e.g encryption info), but
// that won't finish for this test as we're simulating cancelling while the
// spinner is showing.
handler_->HandleShowSetupUI(NULL);
EXPECT_EQ(handler_.get(),
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
ExpectSpinnerAndClose();
}
// Verifies that the handler correctly transitions from showing the spinner
// to showing a configuration page when sync setup completes successfully.
TEST_F(SyncSetupHandlerTest,
DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
error_ = GoogleServiceAuthError::AuthErrorNone();
// Sync backend is stopped initially, and will start up.
EXPECT_CALL(*mock_pss_, backend_initialized())
.WillRepeatedly(Return(false));
SetDefaultExpectationsForConfigPage();
handler_->OpenSyncSetup();
// We expect a call to SyncSetupOverlay.showSyncSetupPage.
EXPECT_EQ(1U, web_ui_.call_data().size());
const TestWebUI::CallData& data0 = web_ui_.call_data()[0];
EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data0.function_name);
std::string page;
ASSERT_TRUE(data0.arg1->GetAsString(&page));
EXPECT_EQ(page, "spinner");
Mock::VerifyAndClearExpectations(mock_pss_);
// Now, act as if the ProfileSyncService has started up.
SetDefaultExpectationsForConfigPage();
EXPECT_CALL(*mock_pss_, backend_initialized())
.WillRepeatedly(Return(true));
error_ = GoogleServiceAuthError::AuthErrorNone();
EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
NotifySyncListeners();
// We expect a second call to SyncSetupOverlay.showSyncSetupPage.
EXPECT_EQ(2U, web_ui_.call_data().size());
const TestWebUI::CallData& data1 = web_ui_.call_data().back();
EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data1.function_name);
ASSERT_TRUE(data1.arg1->GetAsString(&page));
EXPECT_EQ(page, "configure");
base::DictionaryValue* dictionary;
ASSERT_TRUE(data1.arg2->GetAsDictionary(&dictionary));
CheckBool(dictionary, "passphraseFailed", false);
CheckBool(dictionary, "syncAllDataTypes", true);
CheckBool(dictionary, "encryptAllDataAllowed", true);
CheckBool(dictionary, "encryptAllData", false);
CheckBool(dictionary, "usePassphrase", false);
}
// Verifies the case where the user cancels after the sync backend has
// initialized (meaning it already transitioned from the spinner to a proper
// configuration page, tested by
// DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user
// before the user has continued on.
TEST_F(SyncSetupHandlerTest,
DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
error_ = GoogleServiceAuthError::AuthErrorNone();
EXPECT_CALL(*mock_pss_, backend_initialized())
.WillOnce(Return(false))
.WillRepeatedly(Return(true));
SetDefaultExpectationsForConfigPage();
handler_->OpenSyncSetup();
// It's important to tell sync the user cancelled the setup flow before we
// tell it we're through with the setup progress.
testing::InSequence seq;
EXPECT_CALL(*mock_pss_, DisableForUser());
EXPECT_CALL(*mock_pss_, SetSetupInProgress(false));
handler_->CloseSyncSetup();
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
}
TEST_F(SyncSetupHandlerTest,
DisplayConfigureWithBackendDisabledAndSigninFailed) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
error_ = GoogleServiceAuthError::AuthErrorNone();
EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
handler_->OpenSyncSetup();
const TestWebUI::CallData& data = web_ui_.call_data()[0];
EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
std::string page;
ASSERT_TRUE(data.arg1->GetAsString(&page));
EXPECT_EQ(page, "spinner");
Mock::VerifyAndClearExpectations(mock_pss_);
error_ = GoogleServiceAuthError(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
NotifySyncListeners();
// On failure, the dialog will be closed.
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
}
#if !defined(OS_CHROMEOS)
class SyncSetupHandlerNonCrosTest : public SyncSetupHandlerTest {
public:
SyncSetupHandlerNonCrosTest() {}
};
TEST_F(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
// Open the web UI.
handler_->OpenSyncSetup();
ASSERT_FALSE(handler_->is_configuring_sync());
}
// TODO(kochi): We need equivalent tests for ChromeOS.
TEST_F(SyncSetupHandlerNonCrosTest, UnrecoverableErrorInitializingSync) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
// Open the web UI.
handler_->OpenSyncSetup();
ASSERT_FALSE(handler_->is_configuring_sync());
}
TEST_F(SyncSetupHandlerNonCrosTest, GaiaErrorInitializingSync) {
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
.WillRepeatedly(Return(false));
// Open the web UI.
handler_->OpenSyncSetup();
ASSERT_FALSE(handler_->is_configuring_sync());
}
#endif // #if !defined(OS_CHROMEOS)
TEST_F(SyncSetupHandlerTest, TestSyncEverything) {
std::string args = GetConfiguration(
NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
handler_->HandleConfigure(&list_args);
// Ensure that we navigated to the "done" state since we don't need a
// passphrase.
ExpectDone();
}
TEST_F(SyncSetupHandlerTest, TestSyncNothing) {
std::string args = GetConfiguration(
NULL, SYNC_NOTHING, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, DisableForUser());
SetupInitializedProfileSyncService();
handler_->HandleConfigure(&list_args);
// We expect a call to SyncSetupOverlay.showSyncSetupPage.
ASSERT_EQ(1U, web_ui_.call_data().size());
const TestWebUI::CallData& data = web_ui_.call_data()[0];
EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
}
TEST_F(SyncSetupHandlerTest, TurnOnEncryptAll) {
std::string args = GetConfiguration(
NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, EncryptEverythingAllowed())
.WillRepeatedly(Return(true));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_, EnableEncryptEverything());
EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
handler_->HandleConfigure(&list_args);
// Ensure that we navigated to the "done" state since we don't need a
// passphrase.
ExpectDone();
}
TEST_F(SyncSetupHandlerTest, TestPassphraseStillRequired) {
std::string args = GetConfiguration(
NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
SetDefaultExpectationsForConfigPage();
// We should navigate back to the configure page since we need a passphrase.
handler_->HandleConfigure(&list_args);
ExpectConfig();
}
TEST_F(SyncSetupHandlerTest, SuccessfullySetPassphrase) {
base::DictionaryValue dict;
dict.SetBoolean("isGooglePassphrase", true);
std::string args = GetConfiguration(&dict,
SYNC_ALL_DATA,
GetAllTypes(),
"gaiaPassphrase",
ENCRYPT_PASSWORDS);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
// Act as if an encryption passphrase is required the first time, then never
// again after that.
EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase")).
WillOnce(Return(true));
handler_->HandleConfigure(&list_args);
// We should navigate to "done" page since we finished configuring.
ExpectDone();
}
TEST_F(SyncSetupHandlerTest, SelectCustomEncryption) {
base::DictionaryValue dict;
dict.SetBoolean("isGooglePassphrase", false);
std::string args = GetConfiguration(&dict,
SYNC_ALL_DATA,
GetAllTypes(),
"custom_passphrase",
ENCRYPT_PASSWORDS);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
EXPECT_CALL(*mock_pss_,
SetEncryptionPassphrase("custom_passphrase",
ProfileSyncService::EXPLICIT));
handler_->HandleConfigure(&list_args);
// We should navigate to "done" page since we finished configuring.
ExpectDone();
}
TEST_F(SyncSetupHandlerTest, UnsuccessfullySetPassphrase) {
base::DictionaryValue dict;
dict.SetBoolean("isGooglePassphrase", true);
std::string args = GetConfiguration(&dict,
SYNC_ALL_DATA,
GetAllTypes(),
"invalid_passphrase",
ENCRYPT_PASSWORDS);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("invalid_passphrase")).
WillOnce(Return(false));
SetDefaultExpectationsForConfigPage();
// We should navigate back to the configure page since we need a passphrase.
handler_->HandleConfigure(&list_args);
ExpectConfig();
// Make sure we display an error message to the user due to the failed
// passphrase.
const TestWebUI::CallData& data = web_ui_.call_data()[0];
base::DictionaryValue* dictionary;
ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
CheckBool(dictionary, "passphraseFailed", true);
}
// Walks through each user selectable type, and tries to sync just that single
// data type.
TEST_F(SyncSetupHandlerTest, TestSyncIndividualTypes) {
syncer::ModelTypeSet user_selectable_types = GetAllTypes();
syncer::ModelTypeSet::Iterator it;
for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
syncer::ModelTypeSet type_to_set;
type_to_set.Put(it.Get());
std::string args = GetConfiguration(NULL,
CHOOSE_WHAT_TO_SYNC,
type_to_set,
std::string(),
ENCRYPT_PASSWORDS);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_,
OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set)));
handler_->HandleConfigure(&list_args);
ExpectDone();
Mock::VerifyAndClearExpectations(mock_pss_);
web_ui_.ClearTrackedCalls();
}
}
TEST_F(SyncSetupHandlerTest, TestSyncAllManually) {
std::string args = GetConfiguration(NULL,
CHOOSE_WHAT_TO_SYNC,
GetAllTypes(),
std::string(),
ENCRYPT_PASSWORDS);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_,
OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes())));
handler_->HandleConfigure(&list_args);
ExpectDone();
}
TEST_F(SyncSetupHandlerTest, ShowSyncSetup) {
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
// This should display the sync setup dialog (not login).
SetDefaultExpectationsForConfigPage();
handler_->OpenSyncSetup();
ExpectConfig();
}
// We do not display signin on chromeos in the case of auth error.
TEST_F(SyncSetupHandlerTest, ShowSigninOnAuthError) {
// Initialize the system to a signed in state, but with an auth error.
error_ = GoogleServiceAuthError(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
SetupInitializedProfileSyncService();
mock_signin_->SetAuthenticatedUsername(kTestUser);
FakeAuthStatusProvider provider(
SigninErrorControllerFactory::GetForProfile(profile_.get()));
provider.SetAuthError(kTestUser, kTestUser, error_);
EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
#if defined(OS_CHROMEOS)
// On ChromeOS, auth errors are ignored - instead we just try to start the
// sync backend (which will fail due to the auth error). This should only
// happen if the user manually navigates to chrome://settings/syncSetup -
// clicking on the button in the UI will sign the user out rather than
// displaying a spinner. Should be no visible UI on ChromeOS in this case.
EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
#else
// On ChromeOS, this should display the spinner while we try to startup the
// sync backend, and on desktop this displays the login dialog.
handler_->OpenSyncSetup();
// Sync setup is closed when re-auth is in progress.
EXPECT_EQ(NULL,
LoginUIServiceFactory::GetForProfile(
profile_.get())->current_login_ui());
ASSERT_FALSE(handler_->is_configuring_sync());
#endif
}
TEST_F(SyncSetupHandlerTest, ShowSetupSyncEverything) {
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
SetDefaultExpectationsForConfigPage();
// This should display the sync setup dialog (not login).
handler_->OpenSyncSetup();
ExpectConfig();
const TestWebUI::CallData& data = web_ui_.call_data()[0];
base::DictionaryValue* dictionary;
ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
CheckBool(dictionary, "syncAllDataTypes", true);
CheckBool(dictionary, "appsRegistered", true);
CheckBool(dictionary, "autofillRegistered", true);
CheckBool(dictionary, "bookmarksRegistered", true);
CheckBool(dictionary, "extensionsRegistered", true);
CheckBool(dictionary, "passwordsRegistered", true);
CheckBool(dictionary, "preferencesRegistered", true);
CheckBool(dictionary, "wifiCredentialsRegistered", true);
CheckBool(dictionary, "tabsRegistered", true);
CheckBool(dictionary, "themesRegistered", true);
CheckBool(dictionary, "typedUrlsRegistered", true);
CheckBool(dictionary, "showPassphrase", false);
CheckBool(dictionary, "usePassphrase", false);
CheckBool(dictionary, "passphraseFailed", false);
CheckBool(dictionary, "encryptAllData", false);
CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes());
}
TEST_F(SyncSetupHandlerTest, ShowSetupManuallySyncAll) {
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
sync_prefs.SetKeepEverythingSynced(false);
SetDefaultExpectationsForConfigPage();
// This should display the sync setup dialog (not login).
handler_->OpenSyncSetup();
ExpectConfig();
const TestWebUI::CallData& data = web_ui_.call_data()[0];
base::DictionaryValue* dictionary;
ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes());
}
TEST_F(SyncSetupHandlerTest, ShowSetupSyncForAllTypesIndividually) {
syncer::ModelTypeSet user_selectable_types = GetAllTypes();
syncer::ModelTypeSet::Iterator it;
for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
sync_prefs.SetKeepEverythingSynced(false);
SetDefaultExpectationsForConfigPage();
syncer::ModelTypeSet types;
types.Put(it.Get());
EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()).
WillRepeatedly(Return(types));
// This should display the sync setup dialog (not login).
handler_->OpenSyncSetup();
ExpectConfig();
// Close the config overlay.
LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed(
handler_.get());
const TestWebUI::CallData& data = web_ui_.call_data()[0];
base::DictionaryValue* dictionary;
ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types);
Mock::VerifyAndClearExpectations(mock_pss_);
// Clean up so we can loop back to display the dialog again.
web_ui_.ClearTrackedCalls();
}
}
TEST_F(SyncSetupHandlerTest, ShowSetupGaiaPassphraseRequired) {
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
SetDefaultExpectationsForConfigPage();
// This should display the sync setup dialog (not login).
handler_->OpenSyncSetup();
ExpectConfig();
const TestWebUI::CallData& data = web_ui_.call_data()[0];
base::DictionaryValue* dictionary;
ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
CheckBool(dictionary, "showPassphrase", true);
CheckBool(dictionary, "usePassphrase", false);
CheckBool(dictionary, "passphraseFailed", false);
}
TEST_F(SyncSetupHandlerTest, ShowSetupCustomPassphraseRequired) {
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_pss_, GetPassphraseType())
.WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE));
SetupInitializedProfileSyncService();
SetDefaultExpectationsForConfigPage();
// This should display the sync setup dialog (not login).
handler_->OpenSyncSetup();
ExpectConfig();
const TestWebUI::CallData& data = web_ui_.call_data()[0];
base::DictionaryValue* dictionary;
ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
CheckBool(dictionary, "showPassphrase", true);
CheckBool(dictionary, "usePassphrase", true);
CheckBool(dictionary, "passphraseFailed", false);
}
TEST_F(SyncSetupHandlerTest, ShowSetupEncryptAll) {
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
SetDefaultExpectationsForConfigPage();
EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()).
WillRepeatedly(Return(true));
// This should display the sync setup dialog (not login).
handler_->OpenSyncSetup();
ExpectConfig();
const TestWebUI::CallData& data = web_ui_.call_data()[0];
base::DictionaryValue* dictionary;
ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
CheckBool(dictionary, "encryptAllData", true);
}
TEST_F(SyncSetupHandlerTest, ShowSetupEncryptAllDisallowed) {
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
SetDefaultExpectationsForConfigPage();
EXPECT_CALL(*mock_pss_, EncryptEverythingAllowed()).
WillRepeatedly(Return(false));
// This should display the sync setup dialog (not login).
handler_->OpenSyncSetup();
ExpectConfig();
const TestWebUI::CallData& data = web_ui_.call_data()[0];
base::DictionaryValue* dictionary;
ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
CheckBool(dictionary, "encryptAllData", false);
CheckBool(dictionary, "encryptAllDataAllowed", false);
}
TEST_F(SyncSetupHandlerTest, TurnOnEncryptAllDisallowed) {
std::string args = GetConfiguration(
NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA);
base::ListValue list_args;
list_args.Append(new base::StringValue(args));
EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
SetupInitializedProfileSyncService();
EXPECT_CALL(*mock_pss_, EncryptEverythingAllowed()).
WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
handler_->HandleConfigure(&list_args);
// Ensure that we navigated to the "done" state since we don't need a
// passphrase.
ExpectDone();
}
|