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