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/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 EncryptAllConfig encrypt_all) { | 80 EncryptAllConfig encrypt_all) { |
81 DictionaryValue result; | 81 DictionaryValue result; |
82 if (extra_values) | 82 if (extra_values) |
83 result.MergeDictionary(extra_values); | 83 result.MergeDictionary(extra_values); |
84 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA); | 84 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA); |
85 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA); | 85 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA); |
86 result.SetBoolean("usePassphrase", !passphrase.empty()); | 86 result.SetBoolean("usePassphrase", !passphrase.empty()); |
87 if (!passphrase.empty()) | 87 if (!passphrase.empty()) |
88 result.SetString("passphrase", passphrase); | 88 result.SetString("passphrase", passphrase); |
89 // Add all of our data types. | 89 // Add all of our data types. |
90 result.SetBoolean("sync_apps", types.Has(syncable::APPS)); | 90 result.SetBoolean("appsSynced", types.Has(syncable::APPS)); |
91 result.SetBoolean("sync_autofill", types.Has(syncable::AUTOFILL)); | 91 result.SetBoolean("autofillSynced", types.Has(syncable::AUTOFILL)); |
92 result.SetBoolean("sync_bookmarks", types.Has(syncable::BOOKMARKS)); | 92 result.SetBoolean("bookmarksSynced", types.Has(syncable::BOOKMARKS)); |
93 result.SetBoolean("sync_extensions", types.Has(syncable::EXTENSIONS)); | 93 result.SetBoolean("extensionsSynced", types.Has(syncable::EXTENSIONS)); |
94 result.SetBoolean("sync_passwords", types.Has(syncable::PASSWORDS)); | 94 result.SetBoolean("passwordsSynced", types.Has(syncable::PASSWORDS)); |
95 result.SetBoolean("sync_preferences", types.Has(syncable::PREFERENCES)); | 95 result.SetBoolean("preferencesSynced", types.Has(syncable::PREFERENCES)); |
96 result.SetBoolean("sync_sessions", types.Has(syncable::SESSIONS)); | 96 result.SetBoolean("sessionsSynced", types.Has(syncable::SESSIONS)); |
97 result.SetBoolean("sync_themes", types.Has(syncable::THEMES)); | 97 result.SetBoolean("themesSynced", types.Has(syncable::THEMES)); |
98 result.SetBoolean("sync_typed_urls", types.Has(syncable::TYPED_URLS)); | 98 result.SetBoolean("typedUrlsSynced", types.Has(syncable::TYPED_URLS)); |
99 std::string args; | 99 std::string args; |
100 base::JSONWriter::Write(&result, &args); | 100 base::JSONWriter::Write(&result, &args); |
101 return args; | 101 return args; |
102 } | 102 } |
103 | 103 |
104 void CheckInt(const DictionaryValue* dictionary, | 104 void CheckInt(const DictionaryValue* dictionary, |
105 const std::string& key, | 105 const std::string& key, |
106 int expected_value) { | 106 int expected_value) { |
107 int actual_value; | 107 int actual_value; |
108 EXPECT_TRUE(dictionary->GetInteger(key, &actual_value)) << | 108 EXPECT_TRUE(dictionary->GetInteger(key, &actual_value)) << |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // named values set: | 164 // named values set: |
165 // error_message: custom error message to display. | 165 // error_message: custom error message to display. |
166 // fatalError: true if there was a fatal error while logging in. | 166 // fatalError: true if there was a fatal error while logging in. |
167 // error: GoogleServiceAuthError from previous login attempt (0 if none). | 167 // error: GoogleServiceAuthError from previous login attempt (0 if none). |
168 // user: The email the user most recently entered. | 168 // user: The email the user most recently entered. |
169 // editable_user: Whether the username field should be editable. | 169 // editable_user: Whether the username field should be editable. |
170 // captchaUrl: The captcha image to display to the user (empty if none). | 170 // captchaUrl: The captcha image to display to the user (empty if none). |
171 // | 171 // |
172 // The code below validates these arguments. | 172 // The code below validates these arguments. |
173 | 173 |
174 CheckString(dictionary, "error_message", error_message, true); | 174 CheckString(dictionary, "errorMessage", error_message, true); |
175 CheckString(dictionary, "user", user, false); | 175 CheckString(dictionary, "user", user, false); |
176 CheckString(dictionary, "captchaUrl", captcha_url, false); | 176 CheckString(dictionary, "captchaUrl", captcha_url, false); |
177 CheckInt(dictionary, "error", error); | 177 CheckInt(dictionary, "error", error); |
178 CheckBool(dictionary, "fatalError", fatal_error, true); | 178 CheckBool(dictionary, "fatalError", fatal_error, true); |
179 CheckBool(dictionary, "editable_user", user_is_editable); | 179 CheckBool(dictionary, "editableUser", user_is_editable); |
180 } | 180 } |
181 | 181 |
182 // Checks to make sure that the values stored in |dictionary| match the values | 182 // Checks to make sure that the values stored in |dictionary| match the values |
183 // expected by the showSyncSetupPage() JS function for a given set of data | 183 // expected by the showSyncSetupPage() JS function for a given set of data |
184 // types. | 184 // types. |
185 void CheckConfigDataTypeArguments(DictionaryValue* dictionary, | 185 void CheckConfigDataTypeArguments(DictionaryValue* dictionary, |
186 SyncAllDataConfig config, | 186 SyncAllDataConfig config, |
187 syncable::ModelTypeSet types) { | 187 syncable::ModelTypeSet types) { |
188 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA); | 188 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA); |
189 CheckBool(dictionary, "sync_apps", types.Has(syncable::APPS)); | 189 CheckBool(dictionary, "appsSynced", types.Has(syncable::APPS)); |
190 CheckBool(dictionary, "sync_autofill", types.Has(syncable::AUTOFILL)); | 190 CheckBool(dictionary, "autofillSynced", types.Has(syncable::AUTOFILL)); |
191 CheckBool(dictionary, "sync_bookmarks", types.Has(syncable::BOOKMARKS)); | 191 CheckBool(dictionary, "bookmarksSynced", types.Has(syncable::BOOKMARKS)); |
192 CheckBool(dictionary, "sync_extensions", types.Has(syncable::EXTENSIONS)); | 192 CheckBool(dictionary, "extensionsSynced", types.Has(syncable::EXTENSIONS)); |
193 CheckBool(dictionary, "sync_passwords", types.Has(syncable::PASSWORDS)); | 193 CheckBool(dictionary, "passwordsSynced", types.Has(syncable::PASSWORDS)); |
194 CheckBool(dictionary, "sync_preferences", types.Has(syncable::PREFERENCES)); | 194 CheckBool(dictionary, "preferencesSynced", types.Has(syncable::PREFERENCES)); |
195 CheckBool(dictionary, "sync_sessions", types.Has(syncable::SESSIONS)); | 195 CheckBool(dictionary, "sessionsSynced", types.Has(syncable::SESSIONS)); |
196 CheckBool(dictionary, "sync_themes", types.Has(syncable::THEMES)); | 196 CheckBool(dictionary, "themesSynced", types.Has(syncable::THEMES)); |
197 CheckBool(dictionary, "sync_typed_urls", types.Has(syncable::TYPED_URLS)); | 197 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncable::TYPED_URLS)); |
198 } | 198 } |
199 | 199 |
200 | 200 |
201 } // namespace | 201 } // namespace |
202 | 202 |
203 // Test instance of MockWebUI that tracks the data passed to | 203 // Test instance of MockWebUI that tracks the data passed to |
204 // CallJavascriptFunction(). | 204 // CallJavascriptFunction(). |
205 class TestWebUI : public content::MockWebUI { | 205 class TestWebUI : public content::MockWebUI { |
206 public: | 206 public: |
207 virtual ~TestWebUI() { | 207 virtual ~TestWebUI() { |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 642 |
643 ExpectConfig(); | 643 ExpectConfig(); |
644 } | 644 } |
645 | 645 |
646 TEST_F(SyncSetupHandlerTest, SuccessfullySetPassphrase) { | 646 TEST_F(SyncSetupHandlerTest, SuccessfullySetPassphrase) { |
647 DictionaryValue dict; | 647 DictionaryValue dict; |
648 dict.SetBoolean("isGooglePassphrase", true); | 648 dict.SetBoolean("isGooglePassphrase", true); |
649 std::string args = GetConfiguration(&dict, | 649 std::string args = GetConfiguration(&dict, |
650 SYNC_ALL_DATA, | 650 SYNC_ALL_DATA, |
651 GetAllTypes(), | 651 GetAllTypes(), |
652 "gaia_passphrase", | 652 "gaiaPassphrase", |
653 ENCRYPT_PASSWORDS); | 653 ENCRYPT_PASSWORDS); |
654 ListValue list_args; | 654 ListValue list_args; |
655 list_args.Append(new StringValue(args)); | 655 list_args.Append(new StringValue(args)); |
656 // Act as if an encryption passphrase is required the first time, then never | 656 // Act as if an encryption passphrase is required the first time, then never |
657 // again after that. | 657 // again after that. |
658 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true)); | 658 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true)); |
659 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 659 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
660 .WillRepeatedly(Return(false)); | 660 .WillRepeatedly(Return(false)); |
661 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 661 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
662 .WillRepeatedly(Return(false)); | 662 .WillRepeatedly(Return(false)); |
663 SetupInitializedProfileSyncService(); | 663 SetupInitializedProfileSyncService(); |
664 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); | 664 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); |
665 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaia_passphrase")). | 665 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase")). |
666 WillOnce(Return(true)); | 666 WillOnce(Return(true)); |
667 | 667 |
668 handler_->HandleConfigure(&list_args); | 668 handler_->HandleConfigure(&list_args); |
669 // We should navigate to "done" page since we finished configuring. | 669 // We should navigate to "done" page since we finished configuring. |
670 ExpectDone(); | 670 ExpectDone(); |
671 } | 671 } |
672 | 672 |
673 TEST_F(SyncSetupHandlerTest, SelectCustomEncryption) { | 673 TEST_F(SyncSetupHandlerTest, SelectCustomEncryption) { |
674 DictionaryValue dict; | 674 DictionaryValue dict; |
675 dict.SetBoolean("isGooglePassphrase", false); | 675 dict.SetBoolean("isGooglePassphrase", false); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 // We should navigate back to the configure page since we need a passphrase. | 722 // We should navigate back to the configure page since we need a passphrase. |
723 handler_->HandleConfigure(&list_args); | 723 handler_->HandleConfigure(&list_args); |
724 | 724 |
725 ExpectConfig(); | 725 ExpectConfig(); |
726 | 726 |
727 // Make sure we display an error message to the user due to the failed | 727 // Make sure we display an error message to the user due to the failed |
728 // passphrase. | 728 // passphrase. |
729 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 729 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
730 DictionaryValue* dictionary; | 730 DictionaryValue* dictionary; |
731 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 731 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
732 CheckBool(dictionary, "passphrase_failed", true); | 732 CheckBool(dictionary, "passphraseFailed", true); |
733 } | 733 } |
734 | 734 |
735 // Walks through each user selectable type, and tries to sync just that single | 735 // Walks through each user selectable type, and tries to sync just that single |
736 // data type. | 736 // data type. |
737 TEST_F(SyncSetupHandlerTest, TestSyncIndividualTypes) { | 737 TEST_F(SyncSetupHandlerTest, TestSyncIndividualTypes) { |
738 for (size_t i = 0; i < arraysize(kUserSelectableTypes); ++i) { | 738 for (size_t i = 0; i < arraysize(kUserSelectableTypes); ++i) { |
739 syncable::ModelTypeSet type_to_set; | 739 syncable::ModelTypeSet type_to_set; |
740 type_to_set.Put(kUserSelectableTypes[i]); | 740 type_to_set.Put(kUserSelectableTypes[i]); |
741 std::string args = GetConfiguration( | 741 std::string args = GetConfiguration( |
742 NULL, CHOOSE_WHAT_TO_SYNC, type_to_set, "", ENCRYPT_PASSWORDS); | 742 NULL, CHOOSE_WHAT_TO_SYNC, type_to_set, "", ENCRYPT_PASSWORDS); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 SetDefaultExpectationsForConfigPage(); | 834 SetDefaultExpectationsForConfigPage(); |
835 // This should display the sync setup dialog (not login). | 835 // This should display the sync setup dialog (not login). |
836 handler_->OpenSyncSetup(false); | 836 handler_->OpenSyncSetup(false); |
837 | 837 |
838 ExpectConfig(); | 838 ExpectConfig(); |
839 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 839 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
840 DictionaryValue* dictionary; | 840 DictionaryValue* dictionary; |
841 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 841 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
842 CheckBool(dictionary, "showSyncEverythingPage", false); | 842 CheckBool(dictionary, "showSyncEverythingPage", false); |
843 CheckBool(dictionary, "syncAllDataTypes", true); | 843 CheckBool(dictionary, "syncAllDataTypes", true); |
844 CheckBool(dictionary, "apps_registered", true); | 844 CheckBool(dictionary, "appsRegistered", true); |
845 CheckBool(dictionary, "autofill_registered", true); | 845 CheckBool(dictionary, "autofillRegistered", true); |
846 CheckBool(dictionary, "bookmarks_registered", true); | 846 CheckBool(dictionary, "bookmarksRegistered", true); |
847 CheckBool(dictionary, "extensions_registered", true); | 847 CheckBool(dictionary, "extensionsRegistered", true); |
848 CheckBool(dictionary, "passwords_registered", true); | 848 CheckBool(dictionary, "passwordsRegistered", true); |
849 CheckBool(dictionary, "preferences_registered", true); | 849 CheckBool(dictionary, "preferencesRegistered", true); |
850 CheckBool(dictionary, "sessions_registered", true); | 850 CheckBool(dictionary, "sessionsRegistered", true); |
851 CheckBool(dictionary, "themes_registered", true); | 851 CheckBool(dictionary, "themesRegistered", true); |
852 CheckBool(dictionary, "typed_urls_registered", true); | 852 CheckBool(dictionary, "typedUrlsRegistered", true); |
853 CheckBool(dictionary, "show_passphrase", false); | 853 CheckBool(dictionary, "showPassphrase", false); |
854 CheckBool(dictionary, "usePassphrase", false); | 854 CheckBool(dictionary, "usePassphrase", false); |
855 CheckBool(dictionary, "passphrase_failed", false); | 855 CheckBool(dictionary, "passphraseFailed", false); |
856 CheckBool(dictionary, "encryptAllData", false); | 856 CheckBool(dictionary, "encryptAllData", false); |
857 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); | 857 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); |
858 } | 858 } |
859 | 859 |
860 TEST_F(SyncSetupHandlerTest, ShowSetupManuallySyncAll) { | 860 TEST_F(SyncSetupHandlerTest, ShowSetupManuallySyncAll) { |
861 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 861 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
862 .WillRepeatedly(Return(false)); | 862 .WillRepeatedly(Return(false)); |
863 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 863 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
864 .WillRepeatedly(Return(false)); | 864 .WillRepeatedly(Return(false)); |
865 SetupInitializedProfileSyncService(); | 865 SetupInitializedProfileSyncService(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 SetupInitializedProfileSyncService(); | 916 SetupInitializedProfileSyncService(); |
917 SetDefaultExpectationsForConfigPage(); | 917 SetDefaultExpectationsForConfigPage(); |
918 | 918 |
919 // This should display the sync setup dialog (not login). | 919 // This should display the sync setup dialog (not login). |
920 handler_->OpenSyncSetup(false); | 920 handler_->OpenSyncSetup(false); |
921 | 921 |
922 ExpectConfig(); | 922 ExpectConfig(); |
923 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 923 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
924 DictionaryValue* dictionary; | 924 DictionaryValue* dictionary; |
925 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 925 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
926 CheckBool(dictionary, "show_passphrase", true); | 926 CheckBool(dictionary, "showPassphrase", true); |
927 CheckBool(dictionary, "usePassphrase", false); | 927 CheckBool(dictionary, "usePassphrase", false); |
928 CheckBool(dictionary, "passphrase_failed", false); | 928 CheckBool(dictionary, "passphraseFailed", false); |
929 } | 929 } |
930 | 930 |
931 TEST_F(SyncSetupHandlerTest, ShowSetupCustomPassphraseRequired) { | 931 TEST_F(SyncSetupHandlerTest, ShowSetupCustomPassphraseRequired) { |
932 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 932 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
933 .WillRepeatedly(Return(true)); | 933 .WillRepeatedly(Return(true)); |
934 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 934 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
935 .WillRepeatedly(Return(true)); | 935 .WillRepeatedly(Return(true)); |
936 SetupInitializedProfileSyncService(); | 936 SetupInitializedProfileSyncService(); |
937 SetDefaultExpectationsForConfigPage(); | 937 SetDefaultExpectationsForConfigPage(); |
938 | 938 |
939 // This should display the sync setup dialog (not login). | 939 // This should display the sync setup dialog (not login). |
940 handler_->OpenSyncSetup(false); | 940 handler_->OpenSyncSetup(false); |
941 | 941 |
942 ExpectConfig(); | 942 ExpectConfig(); |
943 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 943 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
944 DictionaryValue* dictionary; | 944 DictionaryValue* dictionary; |
945 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 945 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
946 CheckBool(dictionary, "show_passphrase", true); | 946 CheckBool(dictionary, "showPassphrase", true); |
947 CheckBool(dictionary, "usePassphrase", true); | 947 CheckBool(dictionary, "usePassphrase", true); |
948 CheckBool(dictionary, "passphrase_failed", false); | 948 CheckBool(dictionary, "passphraseFailed", false); |
949 } | 949 } |
950 | 950 |
951 TEST_F(SyncSetupHandlerTest, ShowSetupEncryptAll) { | 951 TEST_F(SyncSetupHandlerTest, ShowSetupEncryptAll) { |
952 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 952 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
953 .WillRepeatedly(Return(false)); | 953 .WillRepeatedly(Return(false)); |
954 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 954 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
955 .WillRepeatedly(Return(false)); | 955 .WillRepeatedly(Return(false)); |
956 SetupInitializedProfileSyncService(); | 956 SetupInitializedProfileSyncService(); |
957 SetDefaultExpectationsForConfigPage(); | 957 SetDefaultExpectationsForConfigPage(); |
958 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). | 958 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). |
959 WillRepeatedly(Return(true)); | 959 WillRepeatedly(Return(true)); |
960 | 960 |
961 // This should display the sync setup dialog (not login). | 961 // This should display the sync setup dialog (not login). |
962 handler_->OpenSyncSetup(false); | 962 handler_->OpenSyncSetup(false); |
963 | 963 |
964 ExpectConfig(); | 964 ExpectConfig(); |
965 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 965 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
966 DictionaryValue* dictionary; | 966 DictionaryValue* dictionary; |
967 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 967 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
968 CheckBool(dictionary, "encryptAllData", true); | 968 CheckBool(dictionary, "encryptAllData", true); |
969 } | 969 } |
OLD | NEW |