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, \"webSQL\": true" 42 "}]"; 43 44 45 class ExtensionBrowsingDataTest : public InProcessBrowserTest, 46 public content::NotificationObserver { 47 public: 48 base::Time GetBeginTime() { 49 return called_with_details_->removal_begin; 50 } 51 52 int GetRemovalMask() { 53 return called_with_details_->removal_mask; 54 } 55 56 int GetOriginSetMask() { 57 return called_with_details_->origin_set_mask; 58 } 59 60 protected: 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. 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 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 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 101 void RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 102 const std::string& key, 103 int expected_mask) { 104 RunBrowsingDataRemoveFunctionAndCompareRemovalMask( 105 std::string("{\"") + key + "\": true}", expected_mask); 106 } 107 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> 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 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 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, "webSQL", 232 BrowsingDataRemover::REMOVE_WEBSQL) | 233 GetAsMask(data_to_remove, "serverBoundCertificates", 234 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); 235 EXPECT_EQ(expected_removal_mask, removal_mask); 236 } 237 238 // The kAllowDeletingBrowserHistory pref must be set to false before this 239 // is called. 240 void CheckRemovalPermitted(const std::string& data_types, bool permitted) { 241 scoped_refptr<BrowsingDataRemoveFunction> function = 242 new BrowsingDataRemoveFunction(); 243 std::string args = "[{\"since\": 1}," + data_types + "]"; 244 245 if (permitted) { 246 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( 247 function.get(), args, browser())) << " for " << args; 248 } else { 249 EXPECT_TRUE(MatchPattern( 250 RunFunctionAndReturnError(function.get(), args, browser()), 251 extension_browsing_data_api_constants::kDeleteProhibitedError)) 252 << " for " << args; 253 } 254 } 255 256 private: 257 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; 258 content::NotificationRegistrar registrar_; 259 }; 260 261 } // namespace 262 263 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { 264 BrowsingDataRemover::set_removing(true); 265 scoped_refptr<BrowsingDataRemoveFunction> function = 266 new BrowsingDataRemoveFunction(); 267 EXPECT_TRUE( 268 MatchPattern(RunFunctionAndReturnError( 269 function.get(), kRemoveEverythingArguments, browser()), 270 extension_browsing_data_api_constants::kOneAtATimeError)); 271 BrowsingDataRemover::set_removing(false); 272 273 EXPECT_EQ(base::Time(), GetBeginTime()); 274 EXPECT_EQ(-1, GetRemovalMask()); 275 } 276 277 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemovalProhibited) { 278 PrefService* prefs = browser()->profile()->GetPrefs(); 279 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); 280 281 CheckRemovalPermitted("{\"appcache\": true}", true); 282 CheckRemovalPermitted("{\"cache\": true}", true); 283 CheckRemovalPermitted("{\"cookies\": true}", true); 284 CheckRemovalPermitted("{\"downloads\": true}", false); 285 CheckRemovalPermitted("{\"fileSystems\": true}", true); 286 CheckRemovalPermitted("{\"formData\": true}", true); 287 CheckRemovalPermitted("{\"history\": true}", false); 288 CheckRemovalPermitted("{\"indexedDB\": true}", true); 289 CheckRemovalPermitted("{\"localStorage\": true}", true); 290 CheckRemovalPermitted("{\"serverBoundCertificates\": true}", true); 291 CheckRemovalPermitted("{\"passwords\": true}", true); 292 CheckRemovalPermitted("{\"webSQL\": true}", true); 293 294 // The entire removal is prohibited if any part is. 295 CheckRemovalPermitted("{\"cache\": true, \"history\": true}", false); 296 CheckRemovalPermitted("{\"cookies\": true, \"downloads\": true}", false); 297 298 // If a prohibited type is not selected, the removal is OK. 299 CheckRemovalPermitted("{\"history\": false}", true); 300 CheckRemovalPermitted("{\"downloads\": false}", true); 301 CheckRemovalPermitted("{\"cache\": true, \"history\": false}", true); 302 CheckRemovalPermitted("{\"cookies\": true, \"downloads\": false}", true); 303 } 304 305 // Use-after-free, see http://crbug.com/116522 306 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, 307 DISABLED_RemoveBrowsingDataAll) { 308 scoped_refptr<BrowsingDataRemoveFunction> function = 309 new BrowsingDataRemoveFunction(); 310 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(function.get(), 311 kRemoveEverythingArguments, 312 browser())); 313 314 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime()); 315 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | 316 BrowsingDataRemover::REMOVE_CACHE | 317 BrowsingDataRemover::REMOVE_DOWNLOADS | 318 BrowsingDataRemover::REMOVE_FORM_DATA | 319 BrowsingDataRemover::REMOVE_HISTORY | 320 BrowsingDataRemover::REMOVE_PASSWORDS) & 321 // We can't remove plugin data inside a test profile. 322 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); 323 } 324 325 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataOriginSetMask) { 326 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask("{}", 0); 327 328 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask( 329 "{\"unprotectedWeb\": true}", UNPROTECTED_WEB); 330 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask( 331 "{\"protectedWeb\": true}", PROTECTED_WEB); 332 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask( 333 "{\"extension\": true}", EXTENSION); 334 335 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask( 336 "{\"unprotectedWeb\": true, \"protectedWeb\": true}", 337 UNPROTECTED_WEB | PROTECTED_WEB); 338 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask( 339 "{\"unprotectedWeb\": true, \"extension\": true}", 340 UNPROTECTED_WEB | EXTENSION); 341 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask( 342 "{\"protectedWeb\": true, \"extension\": true}", 343 PROTECTED_WEB | EXTENSION); 344 345 RunBrowsingDataRemoveFunctionAndCompareOriginSetMask( 346 ("{\"unprotectedWeb\": true, \"protectedWeb\": true, " 347 "\"extension\": true}"), 348 UNPROTECTED_WEB | PROTECTED_WEB | EXTENSION); 349 } 350 351 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, 352 FLAKY_BrowsingDataRemovalMask) { 353 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 354 "appcache", BrowsingDataRemover::REMOVE_APPCACHE); 355 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 356 "cache", BrowsingDataRemover::REMOVE_CACHE); 357 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 358 "cookies", BrowsingDataRemover::REMOVE_COOKIES); 359 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 360 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS); 361 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 362 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS); 363 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 364 "formData", BrowsingDataRemover::REMOVE_FORM_DATA); 365 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 366 "history", BrowsingDataRemover::REMOVE_HISTORY); 367 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 368 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB); 369 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 370 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); 371 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 372 "serverBoundCertificates", 373 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); 374 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 375 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); 376 // We can't remove plugin data inside a test profile. 377 RunBrowsingDataRemoveWithKeyAndCompareRemovalMask( 378 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); 379 } 380 381 // Test an arbitrary combination of data types. 382 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, 383 BrowsingDataRemovalMaskCombination) { 384 RunBrowsingDataRemoveFunctionAndCompareRemovalMask( 385 "{\"appcache\": true, \"cookies\": true, \"history\": true}", 386 BrowsingDataRemover::REMOVE_APPCACHE | 387 BrowsingDataRemover::REMOVE_COOKIES | 388 BrowsingDataRemover::REMOVE_HISTORY); 389 } 390 391 // Make sure the remove() function accepts the format produced by settings(). 392 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, 393 BrowsingDataRemovalInputFromSettings) { 394 PrefService* prefs = browser()->profile()->GetPrefs(); 395 prefs->SetBoolean(prefs::kDeleteCache, true); 396 prefs->SetBoolean(prefs::kDeleteBrowsingHistory, true); 397 prefs->SetBoolean(prefs::kDeleteDownloadHistory, true); 398 prefs->SetBoolean(prefs::kDeleteCookies, false); 399 prefs->SetBoolean(prefs::kDeleteFormData, false); 400 prefs->SetBoolean(prefs::kDeleteHostedAppsData, false); 401 prefs->SetBoolean(prefs::kDeletePasswords, false); 402 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled, false); 403 int expected_mask = BrowsingDataRemover::REMOVE_CACHE | 404 BrowsingDataRemover::REMOVE_DOWNLOADS | 405 BrowsingDataRemover::REMOVE_HISTORY; 406 std::string json; 407 // Scoping for the traces. 408 { 409 scoped_refptr<BrowsingDataSettingsFunction> settings_function = 410 new BrowsingDataSettingsFunction(); 411 SCOPED_TRACE("settings_json"); 412 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( 413 settings_function.get(), std::string("[]"), browser())); 414 415 base::DictionaryValue* result; 416 EXPECT_TRUE(result_value->GetAsDictionary(&result)); 417 base::DictionaryValue* data_to_remove; 418 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove)); 419 420 JSONStringValueSerializer serializer(&json); 421 EXPECT_TRUE(serializer.Serialize(*data_to_remove)); 422 } 423 { 424 scoped_refptr<BrowsingDataRemoveFunction> remove_function = 425 new BrowsingDataRemoveFunction(); 426 SCOPED_TRACE("remove_json"); 427 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( 428 remove_function.get(), 429 std::string("[{\"since\": 1},") + json + "]", 430 browser())); 431 EXPECT_EQ(expected_mask, GetRemovalMask()); 432 EXPECT_EQ(UNPROTECTED_WEB, GetOriginSetMask()); 433 } 434 } 435 436 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, ShortcutFunctionRemovalMask) { 437 RunAndCompareRemovalMask<BrowsingDataRemoveAppcacheFunction>( 438 BrowsingDataRemover::REMOVE_APPCACHE); 439 RunAndCompareRemovalMask<BrowsingDataRemoveCacheFunction>( 440 BrowsingDataRemover::REMOVE_CACHE); 441 RunAndCompareRemovalMask<BrowsingDataRemoveCookiesFunction>( 442 BrowsingDataRemover::REMOVE_COOKIES | 443 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); 444 RunAndCompareRemovalMask<BrowsingDataRemoveDownloadsFunction>( 445 BrowsingDataRemover::REMOVE_DOWNLOADS); 446 RunAndCompareRemovalMask<BrowsingDataRemoveFileSystemsFunction>( 447 BrowsingDataRemover::REMOVE_FILE_SYSTEMS); 448 RunAndCompareRemovalMask<BrowsingDataRemoveFormDataFunction>( 449 BrowsingDataRemover::REMOVE_FORM_DATA); 450 RunAndCompareRemovalMask<BrowsingDataRemoveHistoryFunction>( 451 BrowsingDataRemover::REMOVE_HISTORY); 452 RunAndCompareRemovalMask<BrowsingDataRemoveIndexedDBFunction>( 453 BrowsingDataRemover::REMOVE_INDEXEDDB); 454 RunAndCompareRemovalMask<BrowsingDataRemoveLocalStorageFunction>( 455 BrowsingDataRemover::REMOVE_LOCAL_STORAGE); 456 // We can't remove plugin data inside a test profile. 457 RunAndCompareRemovalMask<BrowsingDataRemovePasswordsFunction>( 458 BrowsingDataRemover::REMOVE_PASSWORDS); 459 RunAndCompareRemovalMask<BrowsingDataRemoveWebSQLFunction>( 460 BrowsingDataRemover::REMOVE_WEBSQL); 461 } 462 463 // Test the processing of the 'delete since' preference. 464 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSince) { 465 SetSinceAndVerify(BrowsingDataRemover::EVERYTHING); 466 SetSinceAndVerify(BrowsingDataRemover::LAST_HOUR); 467 SetSinceAndVerify(BrowsingDataRemover::LAST_DAY); 468 SetSinceAndVerify(BrowsingDataRemover::LAST_WEEK); 469 SetSinceAndVerify(BrowsingDataRemover::FOUR_WEEKS); 470 } 471 472 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionEmpty) { 473 SetPrefsAndVerifySettings(0, 0, 0); 474 } 475 476 // Test straightforward settings, mapped 1:1 to data types. 477 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSimple) { 478 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_CACHE, 0, 479 BrowsingDataRemover::REMOVE_CACHE); 480 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_HISTORY, 0, 481 BrowsingDataRemover::REMOVE_HISTORY); 482 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_FORM_DATA, 0, 483 BrowsingDataRemover::REMOVE_FORM_DATA); 484 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_DOWNLOADS, 0, 485 BrowsingDataRemover::REMOVE_DOWNLOADS); 486 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_PASSWORDS, 0, 487 BrowsingDataRemover::REMOVE_PASSWORDS); 488 } 489 490 // Test cookie and app data settings. 491 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSiteData) { 492 int site_data_no_plugins = BrowsingDataRemover::REMOVE_SITE_DATA & 493 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; 494 495 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_COOKIES, 496 UNPROTECTED_WEB, 497 site_data_no_plugins); 498 SetPrefsAndVerifySettings( 499 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY, 500 PROTECTED_WEB, 501 site_data_no_plugins); 502 SetPrefsAndVerifySettings( 503 BrowsingDataRemover::REMOVE_COOKIES | 504 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY, 505 PROTECTED_WEB | UNPROTECTED_WEB, 506 site_data_no_plugins); 507 SetPrefsAndVerifySettings( 508 BrowsingDataRemover::REMOVE_COOKIES | 509 BrowsingDataRemover::REMOVE_PLUGIN_DATA, 510 UNPROTECTED_WEB, 511 BrowsingDataRemover::REMOVE_SITE_DATA); 512 } 513 514 // Test an arbitrary assortment of settings. 515 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionAssorted) { 516 int site_data_no_plugins = BrowsingDataRemover::REMOVE_SITE_DATA & 517 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; 518 519 SetPrefsAndVerifySettings( 520 BrowsingDataRemover::REMOVE_COOKIES | 521 BrowsingDataRemover::REMOVE_HISTORY | 522 BrowsingDataRemover::REMOVE_DOWNLOADS, 523 UNPROTECTED_WEB, 524 site_data_no_plugins | 525 BrowsingDataRemover::REMOVE_HISTORY | 526 BrowsingDataRemover::REMOVE_DOWNLOADS); 527 } 528