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.
4
5 #include <string>
6
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/string_util.h"
12 #include "base/strings/stringprintf.h"
13 #include "base/values.h"
14 #include "chrome/browser/browsing_data/browsing_data_helper.h"
15 #include "chrome/browser/browsing_data/browsing_data_remover.h"
16 #include "chrome/browser/chrome_notification_types.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"
23 #include "content/public/browser/notification_service.h"
24
25 using extension_function_test_utils::RunFunctionAndReturnError;
26 using extension_function_test_utils::RunFunctionAndReturnSingleResult;
27
28 namespace {
29
30 enum OriginSetMask {
31 UNPROTECTED_WEB = BrowsingDataHelper::UNPROTECTED_WEB,
32 PROTECTED_WEB = BrowsingDataHelper::PROTECTED_WEB,
33 EXTENSION = BrowsingDataHelper::EXTENSION
34 };
35
36 const char kRemoveEverythingArguments[] = "[{\"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, \"webSQL\": true"
42 "}]";
43
44
45 class ExtensionBrowsingDataTest : public InProcessBrowserTest,
46 public content::NotificationObserver {
47 public:
GetBeginTime()48 base::Time GetBeginTime() {
49 return called_with_details_->removal_begin;
50 }
51
GetRemovalMask()52 int GetRemovalMask() {
53 return called_with_details_->removal_mask;
54 }
55
GetOriginSetMask()56 int GetOriginSetMask() {
57 return called_with_details_->origin_set_mask;
58 }
59
60 protected:
SetUpOnMainThread()61 virtual void SetUpOnMainThread() OVERRIDE {
62 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
63 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
64 content::Source<Profile>(browser()->profile()));
65 }
66
67 // content::NotificationObserver implementation.
Observe(int type,const content::NotificationSource & source,const content::NotificationDetails & details)68 virtual void Observe(int type,
69 const content::NotificationSource& source,
70 const content::NotificationDetails& details) OVERRIDE {
71 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
72
73 // We're not taking ownership of the details object, but storing a copy of
74 // it locally.
75 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
76 *content::Details<BrowsingDataRemover::NotificationDetails>(
77 details).ptr()));
78 }
79
GetAsMask(const base::DictionaryValue * dict,std::string path,int mask_value)80 int GetAsMask(const base::DictionaryValue* dict, std::string path,
81 int mask_value) {
82 bool result;
83 EXPECT_TRUE(dict->GetBoolean(path, &result)) << "for " << path;
84 return result ? mask_value : 0;
85 }
86
RunBrowsingDataRemoveFunctionAndCompareRemovalMask(const std::string & data_types,int expected_mask)87 void RunBrowsingDataRemoveFunctionAndCompareRemovalMask(
88 const std::string& data_types,
89 int expected_mask) {
90 scoped_refptr<BrowsingDataRemoveFunction> function =
91 new BrowsingDataRemoveFunction();
92 SCOPED_TRACE(data_types);
93 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
94 function.get(),
95 std::string("[{\"since\": 1},") + data_types + "]",
96 browser()));
97 EXPECT_EQ(expected_mask, GetRemovalMask());
98 EXPECT_EQ(UNPROTECTED_WEB, GetOriginSetMask());
99 }
100
RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(const std::string & key,int expected_mask)101 void RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
102 const std::string& key,
103 int expected_mask) {
104 RunBrowsingDataRemoveFunctionAndCompareRemovalMask(
105 std::string("{\"") + key + "\": true}", expected_mask);
106 }
107
RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(const std::string & protectedStr,int expected_mask)108 void RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(
109 const std::string& protectedStr,
110 int expected_mask) {
111 scoped_refptr<BrowsingDataRemoveFunction> function =
112 new BrowsingDataRemoveFunction();
113 SCOPED_TRACE(protectedStr);
114 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
115 function.get(),
116 "[{\"originTypes\": " + protectedStr + "}, {\"cookies\": true}]",
117 browser()));
118 EXPECT_EQ(expected_mask, GetOriginSetMask());
119 }
120
121 template<class ShortcutFunction>
RunAndCompareRemovalMask(int expected_mask)122 void RunAndCompareRemovalMask(int expected_mask) {
123 scoped_refptr<ShortcutFunction> function =
124 new ShortcutFunction();
125 SCOPED_TRACE(ShortcutFunction::function_name());
126 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
127 function.get(),
128 std::string("[{\"since\": 1}]"),
129 browser()));
130 EXPECT_EQ(expected_mask, GetRemovalMask());
131 EXPECT_EQ(UNPROTECTED_WEB, GetOriginSetMask());
132 }
133
SetSinceAndVerify(BrowsingDataRemover::TimePeriod since_pref)134 void SetSinceAndVerify(BrowsingDataRemover::TimePeriod since_pref) {
135 PrefService* prefs = browser()->profile()->GetPrefs();
136 prefs->SetInteger(prefs::kDeleteTimePeriod, since_pref);
137
138 scoped_refptr<BrowsingDataSettingsFunction> function =
139 new BrowsingDataSettingsFunction();
140 SCOPED_TRACE("settings");
141 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult(
142 function.get(), std::string("[]"), browser()));
143
144 base::DictionaryValue* result;
145 EXPECT_TRUE(result_value->GetAsDictionary(&result));
146 base::DictionaryValue* options;
147 EXPECT_TRUE(result->GetDictionary("options", &options));
148 double since;
149 EXPECT_TRUE(options->GetDouble("since", &since));
150
151 double expected_since = 0;
152 if (since_pref != BrowsingDataRemover::EVERYTHING) {
153 base::Time time =
154 BrowsingDataRemover::CalculateBeginDeleteTime(since_pref);
155 expected_since = time.ToJsTime();
156 }
157 // Even a synchronous function takes nonzero time, but the difference
158 // between when the function was called and now should be well under a
159 // second, so we'll make sure the requested start time is within 10 seconds.
160 // Since the smallest selectable period is an hour, that should be
161 // sufficient.
162 EXPECT_LE(expected_since, since + 10.0 * 1000.0);
163 }
164
SetPrefsAndVerifySettings(int data_type_flags,int expected_origin_set_mask,int expected_removal_mask)165 void SetPrefsAndVerifySettings(int data_type_flags,
166 int expected_origin_set_mask,
167 int expected_removal_mask) {
168 PrefService* prefs = browser()->profile()->GetPrefs();
169 prefs->SetBoolean(prefs::kDeleteCache,
170 !!(data_type_flags & BrowsingDataRemover::REMOVE_CACHE));
171 prefs->SetBoolean(prefs::kDeleteCookies,
172 !!(data_type_flags & BrowsingDataRemover::REMOVE_COOKIES));
173 prefs->SetBoolean(prefs::kDeleteBrowsingHistory,
174 !!(data_type_flags & BrowsingDataRemover::REMOVE_HISTORY));
175 prefs->SetBoolean(prefs::kDeleteFormData,
176 !!(data_type_flags & BrowsingDataRemover::REMOVE_FORM_DATA));
177 prefs->SetBoolean(prefs::kDeleteDownloadHistory,
178 !!(data_type_flags & BrowsingDataRemover::REMOVE_DOWNLOADS));
179 prefs->SetBoolean(prefs::kDeleteHostedAppsData,
180 !!(data_type_flags &
181 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY));
182 prefs->SetBoolean(prefs::kDeletePasswords,
183 !!(data_type_flags & BrowsingDataRemover::REMOVE_PASSWORDS));
184 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled,
185 !!(data_type_flags & BrowsingDataRemover::REMOVE_PLUGIN_DATA));
186
187 scoped_refptr<BrowsingDataSettingsFunction> function =
188 new BrowsingDataSettingsFunction();
189 SCOPED_TRACE("settings");
190 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult(
191 function.get(), std::string("[]"), browser()));
192
193 base::DictionaryValue* result;
194 EXPECT_TRUE(result_value->GetAsDictionary(&result));
195
196 base::DictionaryValue* options;
197 EXPECT_TRUE(result->GetDictionary("options", &options));
198 base::DictionaryValue* origin_types;
199 EXPECT_TRUE(options->GetDictionary("originTypes", &origin_types));
200 int origin_set_mask = GetAsMask(origin_types, "unprotectedWeb",
201 UNPROTECTED_WEB) |
202 GetAsMask(origin_types, "protectedWeb",
203 PROTECTED_WEB) |
204 GetAsMask(origin_types, "extension", EXTENSION);
205 EXPECT_EQ(expected_origin_set_mask, origin_set_mask);
206
207 base::DictionaryValue* data_to_remove;
208 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove));
209 int removal_mask = GetAsMask(data_to_remove, "appcache",
210 BrowsingDataRemover::REMOVE_APPCACHE) |
211 GetAsMask(data_to_remove, "cache",
212 BrowsingDataRemover::REMOVE_CACHE) |
213 GetAsMask(data_to_remove, "cookies",
214 BrowsingDataRemover::REMOVE_COOKIES) |
215 GetAsMask(data_to_remove, "downloads",
216 BrowsingDataRemover::REMOVE_DOWNLOADS) |
217 GetAsMask(data_to_remove, "fileSystems",
218 BrowsingDataRemover::REMOVE_FILE_SYSTEMS) |
219 GetAsMask(data_to_remove, "formData",
220 BrowsingDataRemover::REMOVE_FORM_DATA) |
221 GetAsMask(data_to_remove, "history",
222 BrowsingDataRemover::REMOVE_HISTORY) |
223 GetAsMask(data_to_remove, "indexedDB",
224 BrowsingDataRemover::REMOVE_INDEXEDDB) |
225 GetAsMask(data_to_remove, "localStorage",
226 BrowsingDataRemover::REMOVE_LOCAL_STORAGE) |
227 GetAsMask(data_to_remove, "pluginData",
228 BrowsingDataRemover::REMOVE_PLUGIN_DATA) |
229 GetAsMask(data_to_remove, "passwords",
230 BrowsingDataRemover::REMOVE_PASSWORDS) |
231 GetAsMask(data_to_remove, "serviceWorkers",
232 BrowsingDataRemover::REMOVE_SERVICE_WORKERS) |
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);
238 }
239
240 // The kAllowDeletingBrowserHistory pref must be set to false before this
241 // is called.
CheckRemovalPermitted(const std::string & data_types,bool permitted)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 + "]";
246
247 if (permitted) {
248 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
249 function.get(), args, browser())) << " for " << args;
250 } else {
251 EXPECT_TRUE(MatchPattern(
252 RunFunctionAndReturnError(function.get(), args, browser()),
253 extension_browsing_data_api_constants::kDeleteProhibitedError))
254 << " for " << args;
255 }
256 }
257
258 private:
259 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
260 content::NotificationRegistrar registrar_;
261 };
262
263 } // namespace
264
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,OneAtATime)265 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) {
266 BrowsingDataRemover::set_removing(true);
267 scoped_refptr<BrowsingDataRemoveFunction> function =
268 new BrowsingDataRemoveFunction();
269 EXPECT_TRUE(
270 MatchPattern(RunFunctionAndReturnError(
271 function.get(), kRemoveEverythingArguments, browser()),
272 extension_browsing_data_api_constants::kOneAtATimeError));
273 BrowsingDataRemover::set_removing(false);
274
275 EXPECT_EQ(base::Time(), GetBeginTime());
276 EXPECT_EQ(-1, GetRemovalMask());
277 }
278
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,RemovalProhibited)279 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemovalProhibited) {
280 PrefService* prefs = browser()->profile()->GetPrefs();
281 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
282
283 CheckRemovalPermitted("{\"appcache\": true}", true);
284 CheckRemovalPermitted("{\"cache\": true}", true);
285 CheckRemovalPermitted("{\"cookies\": true}", true);
286 CheckRemovalPermitted("{\"downloads\": true}", false);
287 CheckRemovalPermitted("{\"fileSystems\": true}", true);
288 CheckRemovalPermitted("{\"formData\": true}", true);
289 CheckRemovalPermitted("{\"history\": true}", false);
290 CheckRemovalPermitted("{\"indexedDB\": true}", true);
291 CheckRemovalPermitted("{\"localStorage\": true}", true);
292 CheckRemovalPermitted("{\"serverBoundCertificates\": true}", true);
293 CheckRemovalPermitted("{\"passwords\": true}", true);
294 CheckRemovalPermitted("{\"serviceWorkers\": true}", true);
295 CheckRemovalPermitted("{\"webSQL\": true}", true);
296
297 // The entire removal is prohibited if any part is.
298 CheckRemovalPermitted("{\"cache\": true, \"history\": true}", false);
299 CheckRemovalPermitted("{\"cookies\": true, \"downloads\": true}", false);
300
301 // If a prohibited type is not selected, the removal is OK.
302 CheckRemovalPermitted("{\"history\": false}", true);
303 CheckRemovalPermitted("{\"downloads\": false}", true);
304 CheckRemovalPermitted("{\"cache\": true, \"history\": false}", true);
305 CheckRemovalPermitted("{\"cookies\": true, \"downloads\": false}", true);
306 }
307
308 // Use-after-free, see http://crbug.com/116522
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,DISABLED_RemoveBrowsingDataAll)309 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,
310 DISABLED_RemoveBrowsingDataAll) {
311 scoped_refptr<BrowsingDataRemoveFunction> function =
312 new BrowsingDataRemoveFunction();
313 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(function.get(),
314 kRemoveEverythingArguments,
315 browser()));
316
317 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime());
318 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA |
319 BrowsingDataRemover::REMOVE_CACHE |
320 BrowsingDataRemover::REMOVE_DOWNLOADS |
321 BrowsingDataRemover::REMOVE_FORM_DATA |
322 BrowsingDataRemover::REMOVE_HISTORY |
323 BrowsingDataRemover::REMOVE_PASSWORDS) &
324 // We can't remove plugin data inside a test profile.
325 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
326 }
327
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,BrowsingDataOriginSetMask)328 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataOriginSetMask) {
329 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask("{}", 0);
330
331 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(
332 "{\"unprotectedWeb\": true}", UNPROTECTED_WEB);
333 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(
334 "{\"protectedWeb\": true}", PROTECTED_WEB);
335 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(
336 "{\"extension\": true}", EXTENSION);
337
338 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(
339 "{\"unprotectedWeb\": true, \"protectedWeb\": true}",
340 UNPROTECTED_WEB | PROTECTED_WEB);
341 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(
342 "{\"unprotectedWeb\": true, \"extension\": true}",
343 UNPROTECTED_WEB | EXTENSION);
344 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(
345 "{\"protectedWeb\": true, \"extension\": true}",
346 PROTECTED_WEB | EXTENSION);
347
348 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask(
349 ("{\"unprotectedWeb\": true, \"protectedWeb\": true, "
350 "\"extension\": true}"),
351 UNPROTECTED_WEB | PROTECTED_WEB | EXTENSION);
352 }
353
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,BrowsingDataRemovalMask)354 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,
355 BrowsingDataRemovalMask) {
356 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
357 "appcache", BrowsingDataRemover::REMOVE_APPCACHE);
358 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
359 "cache", BrowsingDataRemover::REMOVE_CACHE);
360 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
361 "cookies", BrowsingDataRemover::REMOVE_COOKIES);
362 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
363 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS);
364 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
365 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS);
366 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
367 "formData", BrowsingDataRemover::REMOVE_FORM_DATA);
368 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
369 "history", BrowsingDataRemover::REMOVE_HISTORY);
370 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
371 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB);
372 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
373 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE);
374 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
375 "serverBoundCertificates",
376 BrowsingDataRemover::REMOVE_CHANNEL_IDS);
377 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
378 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS);
379 // We can't remove plugin data inside a test profile.
380 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
381 "serviceWorkers", BrowsingDataRemover::REMOVE_SERVICE_WORKERS);
382 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask(
383 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL);
384 }
385
386 // Test an arbitrary combination of data types.
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,BrowsingDataRemovalMaskCombination)387 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,
388 BrowsingDataRemovalMaskCombination) {
389 RunBrowsingDataRemoveFunctionAndCompareRemovalMask(
390 "{\"appcache\": true, \"cookies\": true, \"history\": true}",
391 BrowsingDataRemover::REMOVE_APPCACHE |
392 BrowsingDataRemover::REMOVE_COOKIES |
393 BrowsingDataRemover::REMOVE_HISTORY);
394 }
395
396 // Make sure the remove() function accepts the format produced by settings().
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,BrowsingDataRemovalInputFromSettings)397 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,
398 BrowsingDataRemovalInputFromSettings) {
399 PrefService* prefs = browser()->profile()->GetPrefs();
400 prefs->SetBoolean(prefs::kDeleteCache, true);
401 prefs->SetBoolean(prefs::kDeleteBrowsingHistory, true);
402 prefs->SetBoolean(prefs::kDeleteDownloadHistory, true);
403 prefs->SetBoolean(prefs::kDeleteCookies, false);
404 prefs->SetBoolean(prefs::kDeleteFormData, false);
405 prefs->SetBoolean(prefs::kDeleteHostedAppsData, false);
406 prefs->SetBoolean(prefs::kDeletePasswords, false);
407 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled, false);
408 int expected_mask = BrowsingDataRemover::REMOVE_CACHE |
409 BrowsingDataRemover::REMOVE_DOWNLOADS |
410 BrowsingDataRemover::REMOVE_HISTORY;
411 std::string json;
412 // Scoping for the traces.
413 {
414 scoped_refptr<BrowsingDataSettingsFunction> settings_function =
415 new BrowsingDataSettingsFunction();
416 SCOPED_TRACE("settings_json");
417 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult(
418 settings_function.get(), std::string("[]"), browser()));
419
420 base::DictionaryValue* result;
421 EXPECT_TRUE(result_value->GetAsDictionary(&result));
422 base::DictionaryValue* data_to_remove;
423 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove));
424
425 JSONStringValueSerializer serializer(&json);
426 EXPECT_TRUE(serializer.Serialize(*data_to_remove));
427 }
428 {
429 scoped_refptr<BrowsingDataRemoveFunction> remove_function =
430 new BrowsingDataRemoveFunction();
431 SCOPED_TRACE("remove_json");
432 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(
433 remove_function.get(),
434 std::string("[{\"since\": 1},") + json + "]",
435 browser()));
436 EXPECT_EQ(expected_mask, GetRemovalMask());
437 EXPECT_EQ(UNPROTECTED_WEB, GetOriginSetMask());
438 }
439 }
440
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,ShortcutFunctionRemovalMask)441 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, ShortcutFunctionRemovalMask) {
442 RunAndCompareRemovalMask<BrowsingDataRemoveAppcacheFunction>(
443 BrowsingDataRemover::REMOVE_APPCACHE);
444 RunAndCompareRemovalMask<BrowsingDataRemoveCacheFunction>(
445 BrowsingDataRemover::REMOVE_CACHE);
446 RunAndCompareRemovalMask<BrowsingDataRemoveCookiesFunction>(
447 BrowsingDataRemover::REMOVE_COOKIES |
448 BrowsingDataRemover::REMOVE_CHANNEL_IDS);
449 RunAndCompareRemovalMask<BrowsingDataRemoveDownloadsFunction>(
450 BrowsingDataRemover::REMOVE_DOWNLOADS);
451 RunAndCompareRemovalMask<BrowsingDataRemoveFileSystemsFunction>(
452 BrowsingDataRemover::REMOVE_FILE_SYSTEMS);
453 RunAndCompareRemovalMask<BrowsingDataRemoveFormDataFunction>(
454 BrowsingDataRemover::REMOVE_FORM_DATA);
455 RunAndCompareRemovalMask<BrowsingDataRemoveHistoryFunction>(
456 BrowsingDataRemover::REMOVE_HISTORY);
457 RunAndCompareRemovalMask<BrowsingDataRemoveIndexedDBFunction>(
458 BrowsingDataRemover::REMOVE_INDEXEDDB);
459 RunAndCompareRemovalMask<BrowsingDataRemoveLocalStorageFunction>(
460 BrowsingDataRemover::REMOVE_LOCAL_STORAGE);
461 // We can't remove plugin data inside a test profile.
462 RunAndCompareRemovalMask<BrowsingDataRemovePasswordsFunction>(
463 BrowsingDataRemover::REMOVE_PASSWORDS);
464 RunAndCompareRemovalMask<BrowsingDataRemoveServiceWorkersFunction>(
465 BrowsingDataRemover::REMOVE_SERVICE_WORKERS);
466 RunAndCompareRemovalMask<BrowsingDataRemoveWebSQLFunction>(
467 BrowsingDataRemover::REMOVE_WEBSQL);
468 }
469
470 // Test the processing of the 'delete since' preference.
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,SettingsFunctionSince)471 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSince) {
472 SetSinceAndVerify(BrowsingDataRemover::EVERYTHING);
473 SetSinceAndVerify(BrowsingDataRemover::LAST_HOUR);
474 SetSinceAndVerify(BrowsingDataRemover::LAST_DAY);
475 SetSinceAndVerify(BrowsingDataRemover::LAST_WEEK);
476 SetSinceAndVerify(BrowsingDataRemover::FOUR_WEEKS);
477 }
478
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,SettingsFunctionEmpty)479 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionEmpty) {
480 SetPrefsAndVerifySettings(0, 0, 0);
481 }
482
483 // Test straightforward settings, mapped 1:1 to data types.
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,SettingsFunctionSimple)484 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSimple) {
485 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_CACHE, 0,
486 BrowsingDataRemover::REMOVE_CACHE);
487 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_HISTORY, 0,
488 BrowsingDataRemover::REMOVE_HISTORY);
489 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_FORM_DATA, 0,
490 BrowsingDataRemover::REMOVE_FORM_DATA);
491 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_DOWNLOADS, 0,
492 BrowsingDataRemover::REMOVE_DOWNLOADS);
493 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_PASSWORDS, 0,
494 BrowsingDataRemover::REMOVE_PASSWORDS);
495 }
496
497 // Test cookie and app data settings.
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,SettingsFunctionSiteData)498 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSiteData) {
499 int site_data_no_plugins = BrowsingDataRemover::REMOVE_SITE_DATA &
500 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
501
502 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_COOKIES,
503 UNPROTECTED_WEB,
504 site_data_no_plugins);
505 SetPrefsAndVerifySettings(
506 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY,
507 PROTECTED_WEB,
508 site_data_no_plugins);
509 SetPrefsAndVerifySettings(
510 BrowsingDataRemover::REMOVE_COOKIES |
511 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY,
512 PROTECTED_WEB | UNPROTECTED_WEB,
513 site_data_no_plugins);
514 SetPrefsAndVerifySettings(
515 BrowsingDataRemover::REMOVE_COOKIES |
516 BrowsingDataRemover::REMOVE_PLUGIN_DATA,
517 UNPROTECTED_WEB,
518 BrowsingDataRemover::REMOVE_SITE_DATA);
519 }
520
521 // Test an arbitrary assortment of settings.
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest,SettingsFunctionAssorted)522 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionAssorted) {
523 int site_data_no_plugins = BrowsingDataRemover::REMOVE_SITE_DATA &
524 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
525
526 SetPrefsAndVerifySettings(
527 BrowsingDataRemover::REMOVE_COOKIES |
528 BrowsingDataRemover::REMOVE_HISTORY |
529 BrowsingDataRemover::REMOVE_DOWNLOADS,
530 UNPROTECTED_WEB,
531 site_data_no_plugins |
532 BrowsingDataRemover::REMOVE_HISTORY |
533 BrowsingDataRemover::REMOVE_DOWNLOADS);
534 }
535