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