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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // Add all of our data types. | 84 // Add all of our data types. |
85 result.SetBoolean("appsSynced", types.Has(syncer::APPS)); | 85 result.SetBoolean("appsSynced", types.Has(syncer::APPS)); |
86 result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL)); | 86 result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL)); |
87 result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS)); | 87 result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS)); |
88 result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS)); | 88 result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS)); |
89 result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS)); | 89 result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS)); |
90 result.SetBoolean("preferencesSynced", types.Has(syncer::PREFERENCES)); | 90 result.SetBoolean("preferencesSynced", types.Has(syncer::PREFERENCES)); |
91 result.SetBoolean("tabsSynced", types.Has(syncer::PROXY_TABS)); | 91 result.SetBoolean("tabsSynced", types.Has(syncer::PROXY_TABS)); |
92 result.SetBoolean("themesSynced", types.Has(syncer::THEMES)); | 92 result.SetBoolean("themesSynced", types.Has(syncer::THEMES)); |
93 result.SetBoolean("typedUrlsSynced", types.Has(syncer::TYPED_URLS)); | 93 result.SetBoolean("typedUrlsSynced", types.Has(syncer::TYPED_URLS)); |
| 94 result.SetBoolean("wifiCredentialsSynced", |
| 95 types.Has(syncer::WIFI_CREDENTIALS)); |
94 std::string args; | 96 std::string args; |
95 base::JSONWriter::Write(&result, &args); | 97 base::JSONWriter::Write(&result, &args); |
96 return args; | 98 return args; |
97 } | 99 } |
98 | 100 |
99 // Checks whether the passed |dictionary| contains a |key| with the given | 101 // Checks whether the passed |dictionary| contains a |key| with the given |
100 // |expected_value|. If |omit_if_false| is true, then the value should only | 102 // |expected_value|. If |omit_if_false| is true, then the value should only |
101 // be present if |expected_value| is true. | 103 // be present if |expected_value| is true. |
102 void CheckBool(const base::DictionaryValue* dictionary, | 104 void CheckBool(const base::DictionaryValue* dictionary, |
103 const std::string& key, | 105 const std::string& key, |
104 bool expected_value, | 106 bool expected_value, |
105 bool omit_if_false) { | 107 bool omit_if_false) { |
106 if (omit_if_false && !expected_value) { | 108 if (omit_if_false && !expected_value) { |
107 EXPECT_FALSE(dictionary->HasKey(key)) << | 109 EXPECT_FALSE(dictionary->HasKey(key)) << |
108 "Did not expect to find value for " << key; | 110 "Did not expect to find value for " << key; |
109 } else { | 111 } else { |
110 bool actual_value; | 112 bool actual_value; |
111 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) << | 113 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) << |
112 "No value found for " << key; | 114 "No value found for " << key; |
113 EXPECT_EQ(actual_value, expected_value) << | 115 EXPECT_EQ(expected_value, actual_value) << |
114 "Mismatch found for " << key; | 116 "Mismatch found for " << key; |
115 } | 117 } |
116 } | 118 } |
117 | 119 |
118 void CheckBool(const base::DictionaryValue* dictionary, | 120 void CheckBool(const base::DictionaryValue* dictionary, |
119 const std::string& key, | 121 const std::string& key, |
120 bool expected_value) { | 122 bool expected_value) { |
121 return CheckBool(dictionary, key, expected_value, false); | 123 return CheckBool(dictionary, key, expected_value, false); |
122 } | 124 } |
123 | 125 |
124 // Checks to make sure that the values stored in |dictionary| match the values | 126 // Checks to make sure that the values stored in |dictionary| match the values |
125 // expected by the showSyncSetupPage() JS function for a given set of data | 127 // expected by the showSyncSetupPage() JS function for a given set of data |
126 // types. | 128 // types. |
127 void CheckConfigDataTypeArguments(base::DictionaryValue* dictionary, | 129 void CheckConfigDataTypeArguments(base::DictionaryValue* dictionary, |
128 SyncAllDataConfig config, | 130 SyncAllDataConfig config, |
129 syncer::ModelTypeSet types) { | 131 syncer::ModelTypeSet types) { |
130 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA); | 132 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA); |
131 CheckBool(dictionary, "syncNothing", config == SYNC_NOTHING); | 133 CheckBool(dictionary, "syncNothing", config == SYNC_NOTHING); |
132 CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS)); | 134 CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS)); |
133 CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL)); | 135 CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL)); |
134 CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS)); | 136 CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS)); |
135 CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS)); | 137 CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS)); |
136 CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS)); | 138 CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS)); |
137 CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES)); | 139 CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES)); |
138 CheckBool(dictionary, "tabsSynced", types.Has(syncer::PROXY_TABS)); | 140 CheckBool(dictionary, "tabsSynced", types.Has(syncer::PROXY_TABS)); |
139 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); | 141 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); |
140 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); | 142 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); |
| 143 CheckBool(dictionary, "wifiCredentialsSynced", |
| 144 types.Has(syncer::WIFI_CREDENTIALS)); |
141 } | 145 } |
142 | 146 |
143 | 147 |
144 } // namespace | 148 } // namespace |
145 | 149 |
146 // Test instance of WebUI that tracks the data passed to | 150 // Test instance of WebUI that tracks the data passed to |
147 // CallJavascriptFunction(). | 151 // CallJavascriptFunction(). |
148 class TestWebUI : public content::WebUI { | 152 class TestWebUI : public content::WebUI { |
149 public: | 153 public: |
150 ~TestWebUI() override { ClearTrackedCalls(); } | 154 ~TestWebUI() override { ClearTrackedCalls(); } |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 base::DictionaryValue* dictionary; | 915 base::DictionaryValue* dictionary; |
912 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 916 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
913 CheckBool(dictionary, "showSyncEverythingPage", false); | 917 CheckBool(dictionary, "showSyncEverythingPage", false); |
914 CheckBool(dictionary, "syncAllDataTypes", true); | 918 CheckBool(dictionary, "syncAllDataTypes", true); |
915 CheckBool(dictionary, "appsRegistered", true); | 919 CheckBool(dictionary, "appsRegistered", true); |
916 CheckBool(dictionary, "autofillRegistered", true); | 920 CheckBool(dictionary, "autofillRegistered", true); |
917 CheckBool(dictionary, "bookmarksRegistered", true); | 921 CheckBool(dictionary, "bookmarksRegistered", true); |
918 CheckBool(dictionary, "extensionsRegistered", true); | 922 CheckBool(dictionary, "extensionsRegistered", true); |
919 CheckBool(dictionary, "passwordsRegistered", true); | 923 CheckBool(dictionary, "passwordsRegistered", true); |
920 CheckBool(dictionary, "preferencesRegistered", true); | 924 CheckBool(dictionary, "preferencesRegistered", true); |
| 925 CheckBool(dictionary, "wifiCredentialsRegistered", true); |
921 CheckBool(dictionary, "tabsRegistered", true); | 926 CheckBool(dictionary, "tabsRegistered", true); |
922 CheckBool(dictionary, "themesRegistered", true); | 927 CheckBool(dictionary, "themesRegistered", true); |
923 CheckBool(dictionary, "typedUrlsRegistered", true); | 928 CheckBool(dictionary, "typedUrlsRegistered", true); |
924 CheckBool(dictionary, "showPassphrase", false); | 929 CheckBool(dictionary, "showPassphrase", false); |
925 CheckBool(dictionary, "usePassphrase", false); | 930 CheckBool(dictionary, "usePassphrase", false); |
926 CheckBool(dictionary, "passphraseFailed", false); | 931 CheckBool(dictionary, "passphraseFailed", false); |
927 CheckBool(dictionary, "encryptAllData", false); | 932 CheckBool(dictionary, "encryptAllData", false); |
928 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); | 933 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); |
929 } | 934 } |
930 | 935 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 | 1040 |
1036 // This should display the sync setup dialog (not login). | 1041 // This should display the sync setup dialog (not login). |
1037 handler_->OpenSyncSetup(); | 1042 handler_->OpenSyncSetup(); |
1038 | 1043 |
1039 ExpectConfig(); | 1044 ExpectConfig(); |
1040 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1045 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
1041 base::DictionaryValue* dictionary; | 1046 base::DictionaryValue* dictionary; |
1042 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1047 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
1043 CheckBool(dictionary, "encryptAllData", true); | 1048 CheckBool(dictionary, "encryptAllData", true); |
1044 } | 1049 } |
OLD | NEW |