| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 const char kTestCaptchaImageUrl[] = "http://pizzamyheart/image"; | 51 const char kTestCaptchaImageUrl[] = "http://pizzamyheart/image"; |
| 52 const char kTestCaptchaUnlockUrl[] = "http://pizzamyheart/unlock"; | 52 const char kTestCaptchaUnlockUrl[] = "http://pizzamyheart/unlock"; |
| 53 | 53 |
| 54 // Returns a ModelTypeSet with all user selectable types set. | 54 // Returns a ModelTypeSet with all user selectable types set. |
| 55 syncer::ModelTypeSet GetAllTypes() { | 55 syncer::ModelTypeSet GetAllTypes() { |
| 56 return syncer::UserSelectableTypes(); | 56 return syncer::UserSelectableTypes(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 enum SyncAllDataConfig { | 59 enum SyncAllDataConfig { |
| 60 SYNC_ALL_DATA, | 60 SYNC_ALL_DATA, |
| 61 CHOOSE_WHAT_TO_SYNC | 61 CHOOSE_WHAT_TO_SYNC, |
| 62 SYNC_NOTHING |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 enum EncryptAllConfig { | 65 enum EncryptAllConfig { |
| 65 ENCRYPT_ALL_DATA, | 66 ENCRYPT_ALL_DATA, |
| 66 ENCRYPT_PASSWORDS | 67 ENCRYPT_PASSWORDS |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 // Create a json-format string with the key/value pairs appropriate for a call | 70 // 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 // to HandleConfigure(). If |extra_values| is non-null, then the values from |
| 71 // the passed dictionary are added to the json. | 72 // the passed dictionary are added to the json. |
| 72 std::string GetConfiguration(const DictionaryValue* extra_values, | 73 std::string GetConfiguration(const DictionaryValue* extra_values, |
| 73 SyncAllDataConfig sync_all, | 74 SyncAllDataConfig sync_all, |
| 74 syncer::ModelTypeSet types, | 75 syncer::ModelTypeSet types, |
| 75 const std::string& passphrase, | 76 const std::string& passphrase, |
| 76 EncryptAllConfig encrypt_all) { | 77 EncryptAllConfig encrypt_all) { |
| 77 DictionaryValue result; | 78 DictionaryValue result; |
| 78 if (extra_values) | 79 if (extra_values) |
| 79 result.MergeDictionary(extra_values); | 80 result.MergeDictionary(extra_values); |
| 80 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA); | 81 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA); |
| 82 result.SetBoolean("syncNothing", sync_all == SYNC_NOTHING); |
| 81 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA); | 83 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA); |
| 82 result.SetBoolean("usePassphrase", !passphrase.empty()); | 84 result.SetBoolean("usePassphrase", !passphrase.empty()); |
| 83 if (!passphrase.empty()) | 85 if (!passphrase.empty()) |
| 84 result.SetString("passphrase", passphrase); | 86 result.SetString("passphrase", passphrase); |
| 85 // Add all of our data types. | 87 // Add all of our data types. |
| 86 result.SetBoolean("appsSynced", types.Has(syncer::APPS)); | 88 result.SetBoolean("appsSynced", types.Has(syncer::APPS)); |
| 87 result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL)); | 89 result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL)); |
| 88 result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS)); | 90 result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS)); |
| 89 result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS)); | 91 result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS)); |
| 90 result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS)); | 92 result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 CheckBool(dictionary, "editableUser", user_is_editable); | 177 CheckBool(dictionary, "editableUser", user_is_editable); |
| 176 } | 178 } |
| 177 | 179 |
| 178 // Checks to make sure that the values stored in |dictionary| match the values | 180 // Checks to make sure that the values stored in |dictionary| match the values |
| 179 // expected by the showSyncSetupPage() JS function for a given set of data | 181 // expected by the showSyncSetupPage() JS function for a given set of data |
| 180 // types. | 182 // types. |
| 181 void CheckConfigDataTypeArguments(DictionaryValue* dictionary, | 183 void CheckConfigDataTypeArguments(DictionaryValue* dictionary, |
| 182 SyncAllDataConfig config, | 184 SyncAllDataConfig config, |
| 183 syncer::ModelTypeSet types) { | 185 syncer::ModelTypeSet types) { |
| 184 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA); | 186 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA); |
| 187 CheckBool(dictionary, "syncNothing", config == SYNC_NOTHING); |
| 185 CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS)); | 188 CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS)); |
| 186 CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL)); | 189 CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL)); |
| 187 CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS)); | 190 CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS)); |
| 188 CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS)); | 191 CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS)); |
| 189 CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS)); | 192 CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS)); |
| 190 CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES)); | 193 CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES)); |
| 191 CheckBool(dictionary, "tabsSynced", types.Has(syncer::PROXY_TABS)); | 194 CheckBool(dictionary, "tabsSynced", types.Has(syncer::PROXY_TABS)); |
| 192 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); | 195 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); |
| 193 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); | 196 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); |
| 194 } | 197 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 448 |
| 446 TEST_P(SyncSetupHandlerTest, Basic) { | 449 TEST_P(SyncSetupHandlerTest, Basic) { |
| 447 } | 450 } |
| 448 | 451 |
| 449 #if !defined(OS_CHROMEOS) | 452 #if !defined(OS_CHROMEOS) |
| 450 TEST_P(SyncSetupHandlerTest, DisplayBasicLogin) { | 453 TEST_P(SyncSetupHandlerTest, DisplayBasicLogin) { |
| 451 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 454 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 452 .WillRepeatedly(Return(false)); | 455 .WillRepeatedly(Return(false)); |
| 453 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 456 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 454 .WillRepeatedly(Return(false)); | 457 .WillRepeatedly(Return(false)); |
| 458 const GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| 459 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
| 455 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 460 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 456 .WillRepeatedly(Return(false)); | 461 .WillRepeatedly(Return(false)); |
| 457 handler_->HandleStartSignin(NULL); | 462 handler_->HandleStartSignin(NULL); |
| 458 EXPECT_EQ(handler_.get(), | 463 EXPECT_EQ(handler_.get(), |
| 459 LoginUIServiceFactory::GetForProfile( | 464 LoginUIServiceFactory::GetForProfile( |
| 460 profile_.get())->current_login_ui()); | 465 profile_.get())->current_login_ui()); |
| 461 | 466 |
| 462 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 467 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| 463 ASSERT_EQ(1U, web_ui_.call_data().size()); | 468 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 464 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 469 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 .WillRepeatedly(Return(false)); | 931 .WillRepeatedly(Return(false)); |
| 927 SetupInitializedProfileSyncService(); | 932 SetupInitializedProfileSyncService(); |
| 928 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); | 933 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); |
| 929 handler_->HandleConfigure(&list_args); | 934 handler_->HandleConfigure(&list_args); |
| 930 | 935 |
| 931 // Ensure that we navigated to the "done" state since we don't need a | 936 // Ensure that we navigated to the "done" state since we don't need a |
| 932 // passphrase. | 937 // passphrase. |
| 933 ExpectDone(); | 938 ExpectDone(); |
| 934 } | 939 } |
| 935 | 940 |
| 941 TEST_P(SyncSetupHandlerTest, TestSyncNothing) { |
| 942 std::string args = GetConfiguration( |
| 943 NULL, SYNC_NOTHING, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); |
| 944 ListValue list_args; |
| 945 list_args.Append(new StringValue(args)); |
| 946 EXPECT_CALL(*mock_pss_, DisableForUser()); |
| 947 SetupInitializedProfileSyncService(); |
| 948 handler_->HandleConfigure(&list_args); |
| 949 |
| 950 // Ensure that the sync setup dialog was closed. |
| 951 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 952 EXPECT_EQ("OptionsPage.closeOverlay", data.function_name); |
| 953 } |
| 954 |
| 936 TEST_P(SyncSetupHandlerTest, TurnOnEncryptAll) { | 955 TEST_P(SyncSetupHandlerTest, TurnOnEncryptAll) { |
| 937 std::string args = GetConfiguration( | 956 std::string args = GetConfiguration( |
| 938 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); | 957 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); |
| 939 ListValue list_args; | 958 ListValue list_args; |
| 940 list_args.Append(new StringValue(args)); | 959 list_args.Append(new StringValue(args)); |
| 941 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 960 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
| 942 .WillRepeatedly(Return(false)); | 961 .WillRepeatedly(Return(false)); |
| 943 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 962 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 944 .WillRepeatedly(Return(false)); | 963 .WillRepeatedly(Return(false)); |
| 945 SetupInitializedProfileSyncService(); | 964 SetupInitializedProfileSyncService(); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 ExpectConfig(); | 1350 ExpectConfig(); |
| 1332 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1351 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 1333 DictionaryValue* dictionary; | 1352 DictionaryValue* dictionary; |
| 1334 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1353 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 1335 CheckBool(dictionary, "encryptAllData", true); | 1354 CheckBool(dictionary, "encryptAllData", true); |
| 1336 } | 1355 } |
| 1337 | 1356 |
| 1338 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, | 1357 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, |
| 1339 SyncSetupHandlerTest, | 1358 SyncSetupHandlerTest, |
| 1340 Values(true, false)); | 1359 Values(true, false)); |
| OLD | NEW |