| 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/strings/pattern.h" | 10 #include "base/strings/pattern.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 14 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 15 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 17 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" | 17 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" |
| 18 #include "chrome/browser/extensions/extension_function_test_utils.h" | 18 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 23 #include "components/browsing_data/pref_names.h" |
| 23 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
| 24 | 25 |
| 25 using extension_function_test_utils::RunFunctionAndReturnError; | 26 using extension_function_test_utils::RunFunctionAndReturnError; |
| 26 using extension_function_test_utils::RunFunctionAndReturnSingleResult; | 27 using extension_function_test_utils::RunFunctionAndReturnSingleResult; |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 enum OriginTypeMask { | 31 enum OriginTypeMask { |
| 31 UNPROTECTED_WEB = BrowsingDataHelper::UNPROTECTED_WEB, | 32 UNPROTECTED_WEB = BrowsingDataHelper::UNPROTECTED_WEB, |
| 32 PROTECTED_WEB = BrowsingDataHelper::PROTECTED_WEB, | 33 PROTECTED_WEB = BrowsingDataHelper::PROTECTED_WEB, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 new ShortcutFunction(); | 123 new ShortcutFunction(); |
| 123 SCOPED_TRACE(ShortcutFunction::function_name()); | 124 SCOPED_TRACE(ShortcutFunction::function_name()); |
| 124 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( | 125 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( |
| 125 function.get(), | 126 function.get(), |
| 126 std::string("[{\"since\": 1}]"), | 127 std::string("[{\"since\": 1}]"), |
| 127 browser())); | 128 browser())); |
| 128 EXPECT_EQ(expected_mask, GetRemovalMask()); | 129 EXPECT_EQ(expected_mask, GetRemovalMask()); |
| 129 EXPECT_EQ(UNPROTECTED_WEB, GetOriginTypeMask()); | 130 EXPECT_EQ(UNPROTECTED_WEB, GetOriginTypeMask()); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void SetSinceAndVerify(BrowsingDataRemover::TimePeriod since_pref) { | 133 void SetSinceAndVerify(browsing_data::TimePeriod since_pref) { |
| 133 PrefService* prefs = browser()->profile()->GetPrefs(); | 134 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 134 prefs->SetInteger(prefs::kDeleteTimePeriod, since_pref); | 135 prefs->SetInteger(browsing_data::prefs::kDeleteTimePeriod, since_pref); |
| 135 | 136 |
| 136 scoped_refptr<BrowsingDataSettingsFunction> function = | 137 scoped_refptr<BrowsingDataSettingsFunction> function = |
| 137 new BrowsingDataSettingsFunction(); | 138 new BrowsingDataSettingsFunction(); |
| 138 SCOPED_TRACE("settings"); | 139 SCOPED_TRACE("settings"); |
| 139 std::unique_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( | 140 std::unique_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( |
| 140 function.get(), std::string("[]"), browser())); | 141 function.get(), std::string("[]"), browser())); |
| 141 | 142 |
| 142 base::DictionaryValue* result; | 143 base::DictionaryValue* result; |
| 143 EXPECT_TRUE(result_value->GetAsDictionary(&result)); | 144 EXPECT_TRUE(result_value->GetAsDictionary(&result)); |
| 144 base::DictionaryValue* options; | 145 base::DictionaryValue* options; |
| 145 EXPECT_TRUE(result->GetDictionary("options", &options)); | 146 EXPECT_TRUE(result->GetDictionary("options", &options)); |
| 146 double since; | 147 double since; |
| 147 EXPECT_TRUE(options->GetDouble("since", &since)); | 148 EXPECT_TRUE(options->GetDouble("since", &since)); |
| 148 | 149 |
| 149 double expected_since = 0; | 150 double expected_since = 0; |
| 150 if (since_pref != BrowsingDataRemover::EVERYTHING) { | 151 if (since_pref != browsing_data::EVERYTHING) { |
| 151 base::Time time = | 152 base::Time time = CalculateBeginDeleteTime(since_pref); |
| 152 BrowsingDataRemover::CalculateBeginDeleteTime(since_pref); | |
| 153 expected_since = time.ToJsTime(); | 153 expected_since = time.ToJsTime(); |
| 154 } | 154 } |
| 155 // Even a synchronous function takes nonzero time, but the difference | 155 // Even a synchronous function takes nonzero time, but the difference |
| 156 // between when the function was called and now should be well under a | 156 // between when the function was called and now should be well under a |
| 157 // second, so we'll make sure the requested start time is within 10 seconds. | 157 // second, so we'll make sure the requested start time is within 10 seconds. |
| 158 // Since the smallest selectable period is an hour, that should be | 158 // Since the smallest selectable period is an hour, that should be |
| 159 // sufficient. | 159 // sufficient. |
| 160 EXPECT_LE(expected_since, since + 10.0 * 1000.0); | 160 EXPECT_LE(expected_since, since + 10.0 * 1000.0); |
| 161 } | 161 } |
| 162 | 162 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 RunAndCompareRemovalMask<BrowsingDataRemovePasswordsFunction>( | 474 RunAndCompareRemovalMask<BrowsingDataRemovePasswordsFunction>( |
| 475 BrowsingDataRemover::REMOVE_PASSWORDS); | 475 BrowsingDataRemover::REMOVE_PASSWORDS); |
| 476 RunAndCompareRemovalMask<BrowsingDataRemoveServiceWorkersFunction>( | 476 RunAndCompareRemovalMask<BrowsingDataRemoveServiceWorkersFunction>( |
| 477 BrowsingDataRemover::REMOVE_SERVICE_WORKERS); | 477 BrowsingDataRemover::REMOVE_SERVICE_WORKERS); |
| 478 RunAndCompareRemovalMask<BrowsingDataRemoveWebSQLFunction>( | 478 RunAndCompareRemovalMask<BrowsingDataRemoveWebSQLFunction>( |
| 479 BrowsingDataRemover::REMOVE_WEBSQL); | 479 BrowsingDataRemover::REMOVE_WEBSQL); |
| 480 } | 480 } |
| 481 | 481 |
| 482 // Test the processing of the 'delete since' preference. | 482 // Test the processing of the 'delete since' preference. |
| 483 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSince) { | 483 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSince) { |
| 484 SetSinceAndVerify(BrowsingDataRemover::EVERYTHING); | 484 SetSinceAndVerify(browsing_data::EVERYTHING); |
| 485 SetSinceAndVerify(BrowsingDataRemover::LAST_HOUR); | 485 SetSinceAndVerify(browsing_data::LAST_HOUR); |
| 486 SetSinceAndVerify(BrowsingDataRemover::LAST_DAY); | 486 SetSinceAndVerify(browsing_data::LAST_DAY); |
| 487 SetSinceAndVerify(BrowsingDataRemover::LAST_WEEK); | 487 SetSinceAndVerify(browsing_data::LAST_WEEK); |
| 488 SetSinceAndVerify(BrowsingDataRemover::FOUR_WEEKS); | 488 SetSinceAndVerify(browsing_data::FOUR_WEEKS); |
| 489 } | 489 } |
| 490 | 490 |
| 491 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionEmpty) { | 491 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionEmpty) { |
| 492 SetPrefsAndVerifySettings(0, 0, 0); | 492 SetPrefsAndVerifySettings(0, 0, 0); |
| 493 } | 493 } |
| 494 | 494 |
| 495 // Test straightforward settings, mapped 1:1 to data types. | 495 // Test straightforward settings, mapped 1:1 to data types. |
| 496 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSimple) { | 496 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSimple) { |
| 497 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_CACHE, 0, | 497 SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_CACHE, 0, |
| 498 BrowsingDataRemover::REMOVE_CACHE); | 498 BrowsingDataRemover::REMOVE_CACHE); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 540 |
| 541 SetPrefsAndVerifySettings( | 541 SetPrefsAndVerifySettings( |
| 542 BrowsingDataRemover::REMOVE_COOKIES | | 542 BrowsingDataRemover::REMOVE_COOKIES | |
| 543 BrowsingDataRemover::REMOVE_HISTORY | | 543 BrowsingDataRemover::REMOVE_HISTORY | |
| 544 BrowsingDataRemover::REMOVE_DOWNLOADS, | 544 BrowsingDataRemover::REMOVE_DOWNLOADS, |
| 545 UNPROTECTED_WEB, | 545 UNPROTECTED_WEB, |
| 546 site_data_no_plugins | | 546 site_data_no_plugins | |
| 547 BrowsingDataRemover::REMOVE_HISTORY | | 547 BrowsingDataRemover::REMOVE_HISTORY | |
| 548 BrowsingDataRemover::REMOVE_DOWNLOADS); | 548 BrowsingDataRemover::REMOVE_DOWNLOADS); |
| 549 } | 549 } |
| OLD | NEW |