Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / browsing_data / browsing_data_test.cc
blob3c9e58a439218f93a623662abf2f8ddccd59e042
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.
5 #include <string>
7 #include "base/json/json_string_value_serializer.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/strings/pattern.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/values.h"
15 #include "chrome/browser/browsing_data/browsing_data_helper.h"
16 #include "chrome/browser/browsing_data/browsing_data_remover.h"
17 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h"
18 #include "chrome/browser/extensions/extension_function_test_utils.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/in_process_browser_test.h"
24 using extension_function_test_utils::RunFunctionAndReturnError;
25 using extension_function_test_utils::RunFunctionAndReturnSingleResult;
27 namespace {
29 enum OriginTypeMask {
30 UNPROTECTED_WEB = BrowsingDataHelper::UNPROTECTED_WEB,
31 PROTECTED_WEB = BrowsingDataHelper::PROTECTED_WEB,
32 EXTENSION = BrowsingDataHelper::EXTENSION
35 const char kRemoveEverythingArguments[] =
36 "[{\"since\": 1000}, {"
37 "\"appcache\": true, \"cache\": true, \"cookies\": true, "
38 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, "
39 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, "
40 "\"serverBoundCertificates\": true, \"passwords\": true, "
41 "\"pluginData\": true, \"serviceWorkers\": true, \"cacheStorage\": true, "
42 "\"webSQL\": true"
43 "}]";
45 class ExtensionBrowsingDataTest : public InProcessBrowserTest {
46 public:
47 base::Time GetBeginTime() {
48 return called_with_details_->removal_begin;
51 int GetRemovalMask() {
52 return called_with_details_->removal_mask;
55 int GetOriginTypeMask() {
56 return called_with_details_->origin_type_mask;
59 protected:
60 void SetUpOnMainThread() override {
61 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
62 callback_subscription_ =
63 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
64 base::Bind(&ExtensionBrowsingDataTest::NotifyWithDetails,
65 base::Unretained(this)));
68 // Callback for browsing data removal events.
69 void NotifyWithDetails(
70 const BrowsingDataRemover::NotificationDetails& details) {
71 // We're not taking ownership of the details object, but storing a copy of
72 // it locally.
73 called_with_details_.reset(
74 new BrowsingDataRemover::NotificationDetails(details));
77 int GetAsMask(const base::DictionaryValue* dict, std::string path,
78 int mask_value) {
79 bool result;
80 EXPECT_TRUE(dict->GetBoolean(path, &result)) << "for " << path;
81 return result ? mask_value : 0;
84 void RunBrowsingDataRemoveFunctionAndCompareRemovalMask(
85 const std::string& data_types,
86 int expected_mask) {
87 scoped_refptr<BrowsingDataRemoveFunction> function =
88 new BrowsingDataRemoveFunction();
89 SCOPED_TRACE(data_types);
90 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
91 function.get(),
92 std::string("[{\"since\": 1},") + data_types + "]",
93 browser()));
94 EXPECT_EQ(expected_mask, GetRemovalMask());
95 EXPECT_EQ(UNPROTECTED_WEB, GetOriginTypeMask());
98 void RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
99 const std::string& key,
100 int expected_mask) {
101 RunBrowsingDataRemoveFunctionAndCompareRemovalMask(
102 std::string("{\"") + key + "\": true}", expected_mask);
105 void RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask(
106 const std::string& protectedStr,
107 int expected_mask) {
108 scoped_refptr<BrowsingDataRemoveFunction> function =
109 new BrowsingDataRemoveFunction();
110 SCOPED_TRACE(protectedStr);
111 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
112 function.get(),
113 "[{\"originTypes\": " + protectedStr + "}, {\"cookies\": true}]",
114 browser()));
115 EXPECT_EQ(expected_mask, GetOriginTypeMask());
118 template<class ShortcutFunction>
119 void RunAndCompareRemovalMask(int expected_mask) {
120 scoped_refptr<ShortcutFunction> function =
121 new ShortcutFunction();
122 SCOPED_TRACE(ShortcutFunction::function_name());
123 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
124 function.get(),
125 std::string("[{\"since\": 1}]"),
126 browser()));
127 EXPECT_EQ(expected_mask, GetRemovalMask());
128 EXPECT_EQ(UNPROTECTED_WEB, GetOriginTypeMask());
131 void SetSinceAndVerify(BrowsingDataRemover::TimePeriod since_pref) {
132 PrefService* prefs = browser()->profile()->GetPrefs();
133 prefs->SetInteger(prefs::kDeleteTimePeriod, since_pref);
135 scoped_refptr<BrowsingDataSettingsFunction> function =
136 new BrowsingDataSettingsFunction();
137 SCOPED_TRACE("settings");
138 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult(
139 function.get(), std::string("[]"), browser()));
141 base::DictionaryValue* result;
142 EXPECT_TRUE(result_value->GetAsDictionary(&result));
143 base::DictionaryValue* options;
144 EXPECT_TRUE(result->GetDictionary("options", &options));
145 double since;
146 EXPECT_TRUE(options->GetDouble("since", &since));
148 double expected_since = 0;
149 if (since_pref != BrowsingDataRemover::EVERYTHING) {
150 base::Time time =
151 BrowsingDataRemover::CalculateBeginDeleteTime(since_pref);
152 expected_since = time.ToJsTime();
154 // Even a synchronous function takes nonzero time, but the difference
155 // between when the function was called and now should be well under a
156 // second, so we'll make sure the requested start time is within 10 seconds.
157 // Since the smallest selectable period is an hour, that should be
158 // sufficient.
159 EXPECT_LE(expected_since, since + 10.0 * 1000.0);
162 void SetPrefsAndVerifySettings(int data_type_flags,
163 int expected_origin_type_mask,
164 int expected_removal_mask) {
165 PrefService* prefs = browser()->profile()->GetPrefs();
166 prefs->SetBoolean(prefs::kDeleteCache,
167 !!(data_type_flags & BrowsingDataRemover::REMOVE_CACHE));
168 prefs->SetBoolean(prefs::kDeleteCookies,
169 !!(data_type_flags & BrowsingDataRemover::REMOVE_COOKIES));
170 prefs->SetBoolean(prefs::kDeleteBrowsingHistory,
171 !!(data_type_flags & BrowsingDataRemover::REMOVE_HISTORY));
172 prefs->SetBoolean(prefs::kDeleteFormData,
173 !!(data_type_flags & BrowsingDataRemover::REMOVE_FORM_DATA));
174 prefs->SetBoolean(prefs::kDeleteDownloadHistory,
175 !!(data_type_flags & BrowsingDataRemover::REMOVE_DOWNLOADS));
176 prefs->SetBoolean(prefs::kDeleteHostedAppsData,
177 !!(data_type_flags &
178 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY));
179 prefs->SetBoolean(prefs::kDeletePasswords,
180 !!(data_type_flags & BrowsingDataRemover::REMOVE_PASSWORDS));
181 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled,
182 !!(data_type_flags & BrowsingDataRemover::REMOVE_PLUGIN_DATA));
184 scoped_refptr<BrowsingDataSettingsFunction> function =
185 new BrowsingDataSettingsFunction();
186 SCOPED_TRACE("settings");
187 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult(
188 function.get(), std::string("[]"), browser()));
190 base::DictionaryValue* result;
191 EXPECT_TRUE(result_value->GetAsDictionary(&result));
193 base::DictionaryValue* options;
194 EXPECT_TRUE(result->GetDictionary("options", &options));
195 base::DictionaryValue* origin_types;
196 EXPECT_TRUE(options->GetDictionary("originTypes", &origin_types));
197 int origin_type_mask = GetAsMask(origin_types, "unprotectedWeb",
198 UNPROTECTED_WEB) |
199 GetAsMask(origin_types, "protectedWeb",
200 PROTECTED_WEB) |
201 GetAsMask(origin_types, "extension", EXTENSION);
202 EXPECT_EQ(expected_origin_type_mask, origin_type_mask);
204 base::DictionaryValue* data_to_remove;
205 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove));
206 int removal_mask =
207 GetAsMask(data_to_remove, "appcache",
208 BrowsingDataRemover::REMOVE_APPCACHE) |
209 GetAsMask(data_to_remove, "cache", BrowsingDataRemover::REMOVE_CACHE) |
210 GetAsMask(data_to_remove, "cookies",
211 BrowsingDataRemover::REMOVE_COOKIES |
212 BrowsingDataRemover::REMOVE_WEBRTC_IDENTITY) |
213 GetAsMask(data_to_remove, "downloads",
214 BrowsingDataRemover::REMOVE_DOWNLOADS) |
215 GetAsMask(data_to_remove, "fileSystems",
216 BrowsingDataRemover::REMOVE_FILE_SYSTEMS) |
217 GetAsMask(data_to_remove, "formData",
218 BrowsingDataRemover::REMOVE_FORM_DATA) |
219 GetAsMask(data_to_remove, "history",
220 BrowsingDataRemover::REMOVE_HISTORY) |
221 GetAsMask(data_to_remove, "indexedDB",
222 BrowsingDataRemover::REMOVE_INDEXEDDB) |
223 GetAsMask(data_to_remove, "localStorage",
224 BrowsingDataRemover::REMOVE_LOCAL_STORAGE) |
225 GetAsMask(data_to_remove, "pluginData",
226 BrowsingDataRemover::REMOVE_PLUGIN_DATA) |
227 GetAsMask(data_to_remove, "passwords",
228 BrowsingDataRemover::REMOVE_PASSWORDS) |
229 GetAsMask(data_to_remove, "serviceWorkers",
230 BrowsingDataRemover::REMOVE_SERVICE_WORKERS) |
231 GetAsMask(data_to_remove, "cacheStorage",
232 BrowsingDataRemover::REMOVE_CACHE_STORAGE) |
233 GetAsMask(data_to_remove, "webSQL",
234 BrowsingDataRemover::REMOVE_WEBSQL) |
235 GetAsMask(data_to_remove, "serverBoundCertificates",
236 BrowsingDataRemover::REMOVE_CHANNEL_IDS);
237 EXPECT_EQ(expected_removal_mask, removal_mask);
240 // The kAllowDeletingBrowserHistory pref must be set to false before this
241 // is called.
242 void CheckRemovalPermitted(const std::string& data_types, bool permitted) {
243 scoped_refptr<BrowsingDataRemoveFunction> function =
244 new BrowsingDataRemoveFunction();
245 std::string args = "[{\"since\": 1}," + data_types + "]";
247 if (permitted) {
248 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
249 function.get(), args, browser())) << " for " << args;
250 } else {
251 EXPECT_TRUE(base::MatchPattern(
252 RunFunctionAndReturnError(function.get(), args, browser()),
253 extension_browsing_data_api_constants::kDeleteProhibitedError))
254 << " for " << args;
258 private:
259 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
261 BrowsingDataRemover::CallbackSubscription callback_subscription_;
265 } // namespace
267 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) {
268 BrowsingDataRemover::set_removing(true);
269 scoped_refptr<BrowsingDataRemoveFunction> function =
270 new BrowsingDataRemoveFunction();
271 EXPECT_TRUE(base::MatchPattern(
272 RunFunctionAndReturnError(function.get(), kRemoveEverythingArguments,
273 browser()),
274 extension_browsing_data_api_constants::kOneAtATimeError));
275 BrowsingDataRemover::set_removing(false);
277 EXPECT_EQ(base::Time(), GetBeginTime());
278 EXPECT_EQ(-1, GetRemovalMask());
281 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemovalProhibited) {
282 PrefService* prefs = browser()->profile()->GetPrefs();
283 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
285 CheckRemovalPermitted("{\"appcache\": true}", true);
286 CheckRemovalPermitted("{\"cache\": true}", true);
287 CheckRemovalPermitted("{\"cookies\": true}", true);
288 CheckRemovalPermitted("{\"downloads\": true}", false);
289 CheckRemovalPermitted("{\"fileSystems\": true}", true);
290 CheckRemovalPermitted("{\"formData\": true}", true);
291 CheckRemovalPermitted("{\"history\": true}", false);
292 CheckRemovalPermitted("{\"indexedDB\": true}", true);
293 CheckRemovalPermitted("{\"localStorage\": true}", true);
294 CheckRemovalPermitted("{\"serverBoundCertificates\": true}", true);
295 CheckRemovalPermitted("{\"passwords\": true}", true);
296 CheckRemovalPermitted("{\"serviceWorkers\": true}", true);
297 CheckRemovalPermitted("{\"cacheStorage\": true}", true);
298 CheckRemovalPermitted("{\"webSQL\": true}", true);
300 // The entire removal is prohibited if any part is.
301 CheckRemovalPermitted("{\"cache\": true, \"history\": true}", false);
302 CheckRemovalPermitted("{\"cookies\": true, \"downloads\": true}", false);
304 // If a prohibited type is not selected, the removal is OK.
305 CheckRemovalPermitted("{\"history\": false}", true);
306 CheckRemovalPermitted("{\"downloads\": false}", true);
307 CheckRemovalPermitted("{\"cache\": true, \"history\": false}", true);
308 CheckRemovalPermitted("{\"cookies\": true, \"downloads\": false}", true);
311 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemoveBrowsingDataAll) {
312 scoped_refptr<BrowsingDataRemoveFunction> function =
313 new BrowsingDataRemoveFunction();
314 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(function.get(),
315 kRemoveEverythingArguments,
316 browser()));
318 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime());
319 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA |
320 BrowsingDataRemover::REMOVE_CACHE |
321 BrowsingDataRemover::REMOVE_DOWNLOADS |
322 BrowsingDataRemover::REMOVE_FORM_DATA |
323 BrowsingDataRemover::REMOVE_HISTORY |
324 BrowsingDataRemover::REMOVE_PASSWORDS) &
325 // TODO(benwells): implement clearing of site usage data via the browsing
326 // data API. https://crbug.com/500801.
327 ~BrowsingDataRemover::REMOVE_SITE_USAGE_DATA &
328 // We can't remove plugin data inside a test profile.
329 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
332 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataOriginTypeMask) {
333 RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask("{}", 0);
335 RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask(
336 "{\"unprotectedWeb\": true}", UNPROTECTED_WEB);
337 RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask(
338 "{\"protectedWeb\": true}", PROTECTED_WEB);
339 RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask(
340 "{\"extension\": true}", EXTENSION);
342 RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask(
343 "{\"unprotectedWeb\": true, \"protectedWeb\": true}",
344 UNPROTECTED_WEB | PROTECTED_WEB);
345 RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask(
346 "{\"unprotectedWeb\": true, \"extension\": true}",
347 UNPROTECTED_WEB | EXTENSION);
348 RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask(
349 "{\"protectedWeb\": true, \"extension\": true}",
350 PROTECTED_WEB | EXTENSION);
352 RunBrowsingDataRemoveFunctionAndCompareOriginTypeMask(
353 ("{\"unprotectedWeb\": true, \"protectedWeb\": true, "
354 "\"extension\": true}"),
355 UNPROTECTED_WEB | PROTECTED_WEB | EXTENSION);
358 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,
359 BrowsingDataRemovalMask) {
360 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
361 "appcache", BrowsingDataRemover::REMOVE_APPCACHE);
362 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
363 "cache", BrowsingDataRemover::REMOVE_CACHE);
364 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
365 "cookies", BrowsingDataRemover::REMOVE_COOKIES |
366 BrowsingDataRemover::REMOVE_WEBRTC_IDENTITY);
367 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
368 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS);
369 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
370 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS);
371 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
372 "formData", BrowsingDataRemover::REMOVE_FORM_DATA);
373 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
374 "history", BrowsingDataRemover::REMOVE_HISTORY);
375 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
376 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB);
377 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
378 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE);
379 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
380 "serverBoundCertificates",
381 BrowsingDataRemover::REMOVE_CHANNEL_IDS);
382 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
383 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS);
384 // We can't remove plugin data inside a test profile.
385 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
386 "serviceWorkers", BrowsingDataRemover::REMOVE_SERVICE_WORKERS);
387 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
388 "cacheStorage", BrowsingDataRemover::REMOVE_CACHE_STORAGE);
389 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
390 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL);
393 // Test an arbitrary combination of data types.
394 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,
395 BrowsingDataRemovalMaskCombination) {
396 RunBrowsingDataRemoveFunctionAndCompareRemovalMask(
397 "{\"appcache\": true, \"cookies\": true, \"history\": true}",
398 BrowsingDataRemover::REMOVE_APPCACHE |
399 BrowsingDataRemover::REMOVE_COOKIES |
400 BrowsingDataRemover::REMOVE_WEBRTC_IDENTITY |
401 BrowsingDataRemover::REMOVE_HISTORY);
404 // Make sure the remove() function accepts the format produced by settings().
405 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,
406 BrowsingDataRemovalInputFromSettings) {
407 PrefService* prefs = browser()->profile()->GetPrefs();
408 prefs->SetBoolean(prefs::kDeleteCache, true);
409 prefs->SetBoolean(prefs::kDeleteBrowsingHistory, true);
410 prefs->SetBoolean(prefs::kDeleteDownloadHistory, true);
411 prefs->SetBoolean(prefs::kDeleteCookies, false);
412 prefs->SetBoolean(prefs::kDeleteFormData, false);
413 prefs->SetBoolean(prefs::kDeleteHostedAppsData, false);
414 prefs->SetBoolean(prefs::kDeletePasswords, false);
415 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled, false);
416 int expected_mask = BrowsingDataRemover::REMOVE_CACHE |
417 BrowsingDataRemover::REMOVE_DOWNLOADS |
418 BrowsingDataRemover::REMOVE_HISTORY;
419 std::string json;
420 // Scoping for the traces.
422 scoped_refptr<BrowsingDataSettingsFunction> settings_function =
423 new BrowsingDataSettingsFunction();
424 SCOPED_TRACE("settings_json");
425 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult(
426 settings_function.get(), std::string("[]"), browser()));
428 base::DictionaryValue* result;
429 EXPECT_TRUE(result_value->GetAsDictionary(&result));
430 base::DictionaryValue* data_to_remove;
431 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove));
433 JSONStringValueSerializer serializer(&json);
434 EXPECT_TRUE(serializer.Serialize(*data_to_remove));
437 scoped_refptr<BrowsingDataRemoveFunction> remove_function =
438 new BrowsingDataRemoveFunction();
439 SCOPED_TRACE("remove_json");
440 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
441 remove_function.get(),
442 std::string("[{\"since\": 1},") + json + "]",
443 browser()));
444 EXPECT_EQ(expected_mask, GetRemovalMask());
445 EXPECT_EQ(UNPROTECTED_WEB, GetOriginTypeMask());
449 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, ShortcutFunctionRemovalMask) {
450 RunAndCompareRemovalMask<BrowsingDataRemoveAppcacheFunction>(
451 BrowsingDataRemover::REMOVE_APPCACHE);
452 RunAndCompareRemovalMask<BrowsingDataRemoveCacheFunction>(
453 BrowsingDataRemover::REMOVE_CACHE);
454 RunAndCompareRemovalMask<BrowsingDataRemoveCookiesFunction>(
455 BrowsingDataRemover::REMOVE_COOKIES |
456 BrowsingDataRemover::REMOVE_CHANNEL_IDS |
457 BrowsingDataRemover::REMOVE_WEBRTC_IDENTITY);
458 RunAndCompareRemovalMask<BrowsingDataRemoveDownloadsFunction>(
459 BrowsingDataRemover::REMOVE_DOWNLOADS);
460 RunAndCompareRemovalMask<BrowsingDataRemoveFileSystemsFunction>(
461 BrowsingDataRemover::REMOVE_FILE_SYSTEMS);
462 RunAndCompareRemovalMask<BrowsingDataRemoveFormDataFunction>(
463 BrowsingDataRemover::REMOVE_FORM_DATA);
464 RunAndCompareRemovalMask<BrowsingDataRemoveHistoryFunction>(
465 BrowsingDataRemover::REMOVE_HISTORY);
466 RunAndCompareRemovalMask<BrowsingDataRemoveIndexedDBFunction>(
467 BrowsingDataRemover::REMOVE_INDEXEDDB);
468 RunAndCompareRemovalMask<BrowsingDataRemoveLocalStorageFunction>(
469 BrowsingDataRemover::REMOVE_LOCAL_STORAGE);
470 // We can't remove plugin data inside a test profile.
471 RunAndCompareRemovalMask<BrowsingDataRemovePasswordsFunction>(
472 BrowsingDataRemover::REMOVE_PASSWORDS);
473 RunAndCompareRemovalMask<BrowsingDataRemoveServiceWorkersFunction>(
474 BrowsingDataRemover::REMOVE_SERVICE_WORKERS);
475 RunAndCompareRemovalMask<BrowsingDataRemoveWebSQLFunction>(
476 BrowsingDataRemover::REMOVE_WEBSQL);
479 // Test the processing of the 'delete since' preference.
480 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSince) {
481 SetSinceAndVerify(BrowsingDataRemover::EVERYTHING);
482 SetSinceAndVerify(BrowsingDataRemover::LAST_HOUR);
483 SetSinceAndVerify(BrowsingDataRemover::LAST_DAY);
484 SetSinceAndVerify(BrowsingDataRemover::LAST_WEEK);
485 SetSinceAndVerify(BrowsingDataRemover::FOUR_WEEKS);
488 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionEmpty) {
489 SetPrefsAndVerifySettings(0, 0, 0);
492 // Test straightforward settings, mapped 1:1 to data types.
493 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSimple) {
494 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_CACHE, 0,
495 BrowsingDataRemover::REMOVE_CACHE);
496 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_HISTORY, 0,
497 BrowsingDataRemover::REMOVE_HISTORY);
498 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_FORM_DATA, 0,
499 BrowsingDataRemover::REMOVE_FORM_DATA);
500 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_DOWNLOADS, 0,
501 BrowsingDataRemover::REMOVE_DOWNLOADS);
502 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_PASSWORDS, 0,
503 BrowsingDataRemover::REMOVE_PASSWORDS);
506 // Test cookie and app data settings.
507 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSiteData) {
508 int site_data_no_usage = BrowsingDataRemover::REMOVE_SITE_DATA &
509 ~BrowsingDataRemover::REMOVE_SITE_USAGE_DATA;
510 int site_data_no_plugins = site_data_no_usage &
511 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
513 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_COOKIES,
514 UNPROTECTED_WEB,
515 site_data_no_plugins);
516 SetPrefsAndVerifySettings(
517 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY,
518 PROTECTED_WEB,
519 site_data_no_plugins);
520 SetPrefsAndVerifySettings(
521 BrowsingDataRemover::REMOVE_COOKIES |
522 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY,
523 PROTECTED_WEB | UNPROTECTED_WEB,
524 site_data_no_plugins);
525 SetPrefsAndVerifySettings(
526 BrowsingDataRemover::REMOVE_COOKIES |
527 BrowsingDataRemover::REMOVE_PLUGIN_DATA,
528 UNPROTECTED_WEB,
529 site_data_no_usage);
532 // Test an arbitrary assortment of settings.
533 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionAssorted) {
534 int site_data_no_plugins = BrowsingDataRemover::REMOVE_SITE_DATA &
535 ~BrowsingDataRemover::REMOVE_SITE_USAGE_DATA &
536 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
538 SetPrefsAndVerifySettings(
539 BrowsingDataRemover::REMOVE_COOKIES |
540 BrowsingDataRemover::REMOVE_HISTORY |
541 BrowsingDataRemover::REMOVE_DOWNLOADS,
542 UNPROTECTED_WEB,
543 site_data_no_plugins |
544 BrowsingDataRemover::REMOVE_HISTORY |
545 BrowsingDataRemover::REMOVE_DOWNLOADS);