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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 using extension_function_test_utils::RunFunctionAndReturnSingleResult; | 25 using extension_function_test_utils::RunFunctionAndReturnSingleResult; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 enum OriginTypeMask { | 29 enum OriginTypeMask { |
30 UNPROTECTED_WEB = BrowsingDataHelper::UNPROTECTED_WEB, | 30 UNPROTECTED_WEB = BrowsingDataHelper::UNPROTECTED_WEB, |
31 PROTECTED_WEB = BrowsingDataHelper::PROTECTED_WEB, | 31 PROTECTED_WEB = BrowsingDataHelper::PROTECTED_WEB, |
32 EXTENSION = BrowsingDataHelper::EXTENSION | 32 EXTENSION = BrowsingDataHelper::EXTENSION |
33 }; | 33 }; |
34 | 34 |
35 const char kRemoveEverythingArguments[] = "[{\"since\": 1000}, {" | 35 const char kRemoveEverythingArguments[] = |
| 36 "[{\"since\": 1000}, {" |
36 "\"appcache\": true, \"cache\": true, \"cookies\": true, " | 37 "\"appcache\": true, \"cache\": true, \"cookies\": true, " |
37 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " | 38 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " |
38 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " | 39 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " |
39 "\"serverBoundCertificates\": true, \"passwords\": true, " | 40 "\"serverBoundCertificates\": true, \"passwords\": true, " |
40 "\"pluginData\": true, \"serviceWorkers\": true, \"webSQL\": true" | 41 "\"pluginData\": true, \"serviceWorkers\": true, \"cacheStorage\": true, " |
| 42 "\"webSQL\": true" |
41 "}]"; | 43 "}]"; |
42 | 44 |
43 | |
44 class ExtensionBrowsingDataTest : public InProcessBrowserTest { | 45 class ExtensionBrowsingDataTest : public InProcessBrowserTest { |
45 public: | 46 public: |
46 base::Time GetBeginTime() { | 47 base::Time GetBeginTime() { |
47 return called_with_details_->removal_begin; | 48 return called_with_details_->removal_begin; |
48 } | 49 } |
49 | 50 |
50 int GetRemovalMask() { | 51 int GetRemovalMask() { |
51 return called_with_details_->removal_mask; | 52 return called_with_details_->removal_mask; |
52 } | 53 } |
53 | 54 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 EXPECT_TRUE(options->GetDictionary("originTypes", &origin_types)); | 196 EXPECT_TRUE(options->GetDictionary("originTypes", &origin_types)); |
196 int origin_type_mask = GetAsMask(origin_types, "unprotectedWeb", | 197 int origin_type_mask = GetAsMask(origin_types, "unprotectedWeb", |
197 UNPROTECTED_WEB) | | 198 UNPROTECTED_WEB) | |
198 GetAsMask(origin_types, "protectedWeb", | 199 GetAsMask(origin_types, "protectedWeb", |
199 PROTECTED_WEB) | | 200 PROTECTED_WEB) | |
200 GetAsMask(origin_types, "extension", EXTENSION); | 201 GetAsMask(origin_types, "extension", EXTENSION); |
201 EXPECT_EQ(expected_origin_type_mask, origin_type_mask); | 202 EXPECT_EQ(expected_origin_type_mask, origin_type_mask); |
202 | 203 |
203 base::DictionaryValue* data_to_remove; | 204 base::DictionaryValue* data_to_remove; |
204 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove)); | 205 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove)); |
205 int removal_mask = GetAsMask(data_to_remove, "appcache", | 206 int removal_mask = |
206 BrowsingDataRemover::REMOVE_APPCACHE) | | 207 GetAsMask(data_to_remove, "appcache", |
207 GetAsMask(data_to_remove, "cache", | 208 BrowsingDataRemover::REMOVE_APPCACHE) | |
208 BrowsingDataRemover::REMOVE_CACHE) | | 209 GetAsMask(data_to_remove, "cache", BrowsingDataRemover::REMOVE_CACHE) | |
209 GetAsMask(data_to_remove, "cookies", | 210 GetAsMask(data_to_remove, "cookies", |
210 BrowsingDataRemover::REMOVE_COOKIES | | 211 BrowsingDataRemover::REMOVE_COOKIES | |
211 BrowsingDataRemover::REMOVE_WEBRTC_IDENTITY) | | 212 BrowsingDataRemover::REMOVE_WEBRTC_IDENTITY) | |
212 GetAsMask(data_to_remove, "downloads", | 213 GetAsMask(data_to_remove, "downloads", |
213 BrowsingDataRemover::REMOVE_DOWNLOADS) | | 214 BrowsingDataRemover::REMOVE_DOWNLOADS) | |
214 GetAsMask(data_to_remove, "fileSystems", | 215 GetAsMask(data_to_remove, "fileSystems", |
215 BrowsingDataRemover::REMOVE_FILE_SYSTEMS) | | 216 BrowsingDataRemover::REMOVE_FILE_SYSTEMS) | |
216 GetAsMask(data_to_remove, "formData", | 217 GetAsMask(data_to_remove, "formData", |
217 BrowsingDataRemover::REMOVE_FORM_DATA) | | 218 BrowsingDataRemover::REMOVE_FORM_DATA) | |
218 GetAsMask(data_to_remove, "history", | 219 GetAsMask(data_to_remove, "history", |
219 BrowsingDataRemover::REMOVE_HISTORY) | | 220 BrowsingDataRemover::REMOVE_HISTORY) | |
220 GetAsMask(data_to_remove, "indexedDB", | 221 GetAsMask(data_to_remove, "indexedDB", |
221 BrowsingDataRemover::REMOVE_INDEXEDDB) | | 222 BrowsingDataRemover::REMOVE_INDEXEDDB) | |
222 GetAsMask(data_to_remove, "localStorage", | 223 GetAsMask(data_to_remove, "localStorage", |
223 BrowsingDataRemover::REMOVE_LOCAL_STORAGE) | | 224 BrowsingDataRemover::REMOVE_LOCAL_STORAGE) | |
224 GetAsMask(data_to_remove, "pluginData", | 225 GetAsMask(data_to_remove, "pluginData", |
225 BrowsingDataRemover::REMOVE_PLUGIN_DATA) | | 226 BrowsingDataRemover::REMOVE_PLUGIN_DATA) | |
226 GetAsMask(data_to_remove, "passwords", | 227 GetAsMask(data_to_remove, "passwords", |
227 BrowsingDataRemover::REMOVE_PASSWORDS) | | 228 BrowsingDataRemover::REMOVE_PASSWORDS) | |
228 GetAsMask(data_to_remove, "serviceWorkers", | 229 GetAsMask(data_to_remove, "serviceWorkers", |
229 BrowsingDataRemover::REMOVE_SERVICE_WORKERS) | | 230 BrowsingDataRemover::REMOVE_SERVICE_WORKERS) | |
230 GetAsMask(data_to_remove, "webSQL", | 231 GetAsMask(data_to_remove, "cacheStorage", |
231 BrowsingDataRemover::REMOVE_WEBSQL) | | 232 BrowsingDataRemover::REMOVE_CACHE_STORAGE) | |
232 GetAsMask(data_to_remove, "serverBoundCertificates", | 233 GetAsMask(data_to_remove, "webSQL", |
233 BrowsingDataRemover::REMOVE_CHANNEL_IDS); | 234 BrowsingDataRemover::REMOVE_WEBSQL) | |
| 235 GetAsMask(data_to_remove, "serverBoundCertificates", |
| 236 BrowsingDataRemover::REMOVE_CHANNEL_IDS); |
234 EXPECT_EQ(expected_removal_mask, removal_mask); | 237 EXPECT_EQ(expected_removal_mask, removal_mask); |
235 } | 238 } |
236 | 239 |
237 // The kAllowDeletingBrowserHistory pref must be set to false before this | 240 // The kAllowDeletingBrowserHistory pref must be set to false before this |
238 // is called. | 241 // is called. |
239 void CheckRemovalPermitted(const std::string& data_types, bool permitted) { | 242 void CheckRemovalPermitted(const std::string& data_types, bool permitted) { |
240 scoped_refptr<BrowsingDataRemoveFunction> function = | 243 scoped_refptr<BrowsingDataRemoveFunction> function = |
241 new BrowsingDataRemoveFunction(); | 244 new BrowsingDataRemoveFunction(); |
242 std::string args = "[{\"since\": 1}," + data_types + "]"; | 245 std::string args = "[{\"since\": 1}," + data_types + "]"; |
243 | 246 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 CheckRemovalPermitted("{\"cookies\": true}", true); | 287 CheckRemovalPermitted("{\"cookies\": true}", true); |
285 CheckRemovalPermitted("{\"downloads\": true}", false); | 288 CheckRemovalPermitted("{\"downloads\": true}", false); |
286 CheckRemovalPermitted("{\"fileSystems\": true}", true); | 289 CheckRemovalPermitted("{\"fileSystems\": true}", true); |
287 CheckRemovalPermitted("{\"formData\": true}", true); | 290 CheckRemovalPermitted("{\"formData\": true}", true); |
288 CheckRemovalPermitted("{\"history\": true}", false); | 291 CheckRemovalPermitted("{\"history\": true}", false); |
289 CheckRemovalPermitted("{\"indexedDB\": true}", true); | 292 CheckRemovalPermitted("{\"indexedDB\": true}", true); |
290 CheckRemovalPermitted("{\"localStorage\": true}", true); | 293 CheckRemovalPermitted("{\"localStorage\": true}", true); |
291 CheckRemovalPermitted("{\"serverBoundCertificates\": true}", true); | 294 CheckRemovalPermitted("{\"serverBoundCertificates\": true}", true); |
292 CheckRemovalPermitted("{\"passwords\": true}", true); | 295 CheckRemovalPermitted("{\"passwords\": true}", true); |
293 CheckRemovalPermitted("{\"serviceWorkers\": true}", true); | 296 CheckRemovalPermitted("{\"serviceWorkers\": true}", true); |
| 297 CheckRemovalPermitted("{\"cacheStorage\": true}", true); |
294 CheckRemovalPermitted("{\"webSQL\": true}", true); | 298 CheckRemovalPermitted("{\"webSQL\": true}", true); |
295 | 299 |
296 // The entire removal is prohibited if any part is. | 300 // The entire removal is prohibited if any part is. |
297 CheckRemovalPermitted("{\"cache\": true, \"history\": true}", false); | 301 CheckRemovalPermitted("{\"cache\": true, \"history\": true}", false); |
298 CheckRemovalPermitted("{\"cookies\": true, \"downloads\": true}", false); | 302 CheckRemovalPermitted("{\"cookies\": true, \"downloads\": true}", false); |
299 | 303 |
300 // If a prohibited type is not selected, the removal is OK. | 304 // If a prohibited type is not selected, the removal is OK. |
301 CheckRemovalPermitted("{\"history\": false}", true); | 305 CheckRemovalPermitted("{\"history\": false}", true); |
302 CheckRemovalPermitted("{\"downloads\": false}", true); | 306 CheckRemovalPermitted("{\"downloads\": false}", true); |
303 CheckRemovalPermitted("{\"cache\": true, \"history\": false}", true); | 307 CheckRemovalPermitted("{\"cache\": true, \"history\": false}", true); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); | 378 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); |
375 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( | 379 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( |
376 "serverBoundCertificates", | 380 "serverBoundCertificates", |
377 BrowsingDataRemover::REMOVE_CHANNEL_IDS); | 381 BrowsingDataRemover::REMOVE_CHANNEL_IDS); |
378 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( | 382 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( |
379 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); | 383 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); |
380 // We can't remove plugin data inside a test profile. | 384 // We can't remove plugin data inside a test profile. |
381 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( | 385 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( |
382 "serviceWorkers", BrowsingDataRemover::REMOVE_SERVICE_WORKERS); | 386 "serviceWorkers", BrowsingDataRemover::REMOVE_SERVICE_WORKERS); |
383 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( | 387 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( |
| 388 "cacheStorage", BrowsingDataRemover::REMOVE_CACHE_STORAGE); |
| 389 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( |
384 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); | 390 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); |
385 } | 391 } |
386 | 392 |
387 // Test an arbitrary combination of data types. | 393 // Test an arbitrary combination of data types. |
388 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, | 394 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, |
389 BrowsingDataRemovalMaskCombination) { | 395 BrowsingDataRemovalMaskCombination) { |
390 RunBrowsingDataRemoveFunctionAndCompareRemovalMask( | 396 RunBrowsingDataRemoveFunctionAndCompareRemovalMask( |
391 "{\"appcache\": true, \"cookies\": true, \"history\": true}", | 397 "{\"appcache\": true, \"cookies\": true, \"history\": true}", |
392 BrowsingDataRemover::REMOVE_APPCACHE | | 398 BrowsingDataRemover::REMOVE_APPCACHE | |
393 BrowsingDataRemover::REMOVE_COOKIES | | 399 BrowsingDataRemover::REMOVE_COOKIES | |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 537 |
532 SetPrefsAndVerifySettings( | 538 SetPrefsAndVerifySettings( |
533 BrowsingDataRemover::REMOVE_COOKIES | | 539 BrowsingDataRemover::REMOVE_COOKIES | |
534 BrowsingDataRemover::REMOVE_HISTORY | | 540 BrowsingDataRemover::REMOVE_HISTORY | |
535 BrowsingDataRemover::REMOVE_DOWNLOADS, | 541 BrowsingDataRemover::REMOVE_DOWNLOADS, |
536 UNPROTECTED_WEB, | 542 UNPROTECTED_WEB, |
537 site_data_no_plugins | | 543 site_data_no_plugins | |
538 BrowsingDataRemover::REMOVE_HISTORY | | 544 BrowsingDataRemover::REMOVE_HISTORY | |
539 BrowsingDataRemover::REMOVE_DOWNLOADS); | 545 BrowsingDataRemover::REMOVE_DOWNLOADS); |
540 } | 546 } |
OLD | NEW |