| 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 "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" | 5 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browsing_data_helper.h" |
| 14 #include "chrome/browser/browsing_data_remover.h" | 15 #include "chrome/browser/browsing_data_remover.h" |
| 15 #include "chrome/browser/extensions/extension_function_test_utils.h" | 16 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 21 | 22 |
| 22 using extension_function_test_utils::RunFunctionAndReturnError; | 23 using extension_function_test_utils::RunFunctionAndReturnError; |
| 23 using extension_function_test_utils::RunFunctionAndReturnResult; | 24 using extension_function_test_utils::RunFunctionAndReturnResult; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kRemoveEverythingArguments[] = "[{\"since\": 1000}, {" | 28 const char kRemoveEverythingArguments[] = "[{\"since\": 1000}, {" |
| 28 "\"appcache\": true, \"cache\": true, \"cookies\": true, " | 29 "\"appcache\": true, \"cache\": true, \"cookies\": true, " |
| 29 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " | 30 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " |
| 30 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " | 31 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " |
| 31 "\"serverBoundCerts\": true, \"passwords\": true, \"pluginData\": true, " | 32 "\"serverBoundCerts\": true, \"passwords\": true, \"pluginData\": true, " |
| 32 "\"webSQL\": true" | 33 "\"webSQL\": true" |
| 33 "}]"; | 34 "}]"; |
| 34 | 35 |
| 36 const char kRemoveEverythingProtectedArguments[] = "[{" |
| 37 "\"since\": 1000," |
| 38 "\"origin_types\": [\"unprotected_web\", \"protected_web\"]" |
| 39 "},{" |
| 40 "\"appcache\": true, \"cache\": true, \"cookies\": true, " |
| 41 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " |
| 42 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " |
| 43 "\"serverBoundCerts\": true, \"passwords\": true, \"pluginData\": true, " |
| 44 "\"webSQL\": true" |
| 45 "}]"; |
| 46 |
| 47 |
| 35 class ExtensionBrowsingDataTest : public InProcessBrowserTest, | 48 class ExtensionBrowsingDataTest : public InProcessBrowserTest, |
| 36 public content::NotificationObserver { | 49 public content::NotificationObserver { |
| 37 public: | 50 public: |
| 38 base::Time GetBeginTime() { | 51 base::Time GetBeginTime() { |
| 39 return called_with_details_->removal_begin; | 52 return called_with_details_->removal_begin; |
| 40 } | 53 } |
| 41 | 54 |
| 42 int GetRemovalMask() { | 55 int GetRemovalMask() { |
| 43 return called_with_details_->removal_mask; | 56 return called_with_details_->removal_mask; |
| 44 } | 57 } |
| 45 | 58 |
| 59 int GetOriginSetMask() { |
| 60 return called_with_details_->origin_set_mask; |
| 61 } |
| 62 |
| 46 protected: | 63 protected: |
| 47 virtual void SetUpOnMainThread() { | 64 virtual void SetUpOnMainThread() { |
| 48 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 65 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 49 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, | 66 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, |
| 50 content::Source<Profile>(browser()->profile())); | 67 content::Source<Profile>(browser()->profile())); |
| 51 } | 68 } |
| 52 | 69 |
| 53 virtual void TearDownOnMainThread() { | 70 virtual void TearDownOnMainThread() { |
| 54 registrar_.RemoveAll(); | 71 registrar_.RemoveAll(); |
| 55 } | 72 } |
| 56 | 73 |
| 57 // content::NotificationObserver implementation. | 74 // content::NotificationObserver implementation. |
| 58 virtual void Observe(int type, | 75 virtual void Observe(int type, |
| 59 const content::NotificationSource& source, | 76 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) OVERRIDE { | 77 const content::NotificationDetails& details) OVERRIDE { |
| 61 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); | 78 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); |
| 62 | 79 |
| 63 // We're not taking ownership of the details object, but storing a copy of | 80 // We're not taking ownership of the details object, but storing a copy of |
| 64 // it locally. | 81 // it locally. |
| 65 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( | 82 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( |
| 66 *content::Details<BrowsingDataRemover::NotificationDetails>( | 83 *content::Details<BrowsingDataRemover::NotificationDetails>( |
| 67 details).ptr())); | 84 details).ptr())); |
| 68 } | 85 } |
| 69 | 86 |
| 70 void RunRemoveBrowsingDataFunctionAndCompareMask(const std::string& key, | 87 void RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 71 int expected_mask) { | 88 const std::string& key, |
| 89 int expected_mask) { |
| 72 SCOPED_TRACE(key); | 90 SCOPED_TRACE(key); |
| 73 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(), | 91 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(), |
| 74 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", browser())); | 92 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", browser())); |
| 75 EXPECT_EQ(expected_mask, GetRemovalMask()); | 93 EXPECT_EQ(expected_mask, GetRemovalMask()); |
| 76 } | 94 } |
| 77 | 95 |
| 96 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( |
| 97 const std::string& protectedStr, |
| 98 int expected_mask) { |
| 99 SCOPED_TRACE(protectedStr); |
| 100 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(), |
| 101 "[{\"origin_types\": " + protectedStr + "}, {\"cookies\": true}]", |
| 102 browser())); |
| 103 EXPECT_EQ(expected_mask, GetOriginSetMask()); |
| 104 } |
| 105 |
| 78 private: | 106 private: |
| 79 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; | 107 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
| 80 content::NotificationRegistrar registrar_; | 108 content::NotificationRegistrar registrar_; |
| 81 }; | 109 }; |
| 82 | 110 |
| 83 } // namespace | 111 } // namespace |
| 84 | 112 |
| 85 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { | 113 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { |
| 86 BrowsingDataRemover::set_removing(true); | 114 BrowsingDataRemover::set_removing(true); |
| 87 EXPECT_TRUE(MatchPattern( | 115 EXPECT_TRUE(MatchPattern( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 106 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | | 134 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | |
| 107 BrowsingDataRemover::REMOVE_CACHE | | 135 BrowsingDataRemover::REMOVE_CACHE | |
| 108 BrowsingDataRemover::REMOVE_DOWNLOADS | | 136 BrowsingDataRemover::REMOVE_DOWNLOADS | |
| 109 BrowsingDataRemover::REMOVE_FORM_DATA | | 137 BrowsingDataRemover::REMOVE_FORM_DATA | |
| 110 BrowsingDataRemover::REMOVE_HISTORY | | 138 BrowsingDataRemover::REMOVE_HISTORY | |
| 111 BrowsingDataRemover::REMOVE_PASSWORDS) & | 139 BrowsingDataRemover::REMOVE_PASSWORDS) & |
| 112 // We can't remove plugin data inside a test profile. | 140 // We can't remove plugin data inside a test profile. |
| 113 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); | 141 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
| 114 } | 142 } |
| 115 | 143 |
| 116 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemoveBrowsingDataMask) { | 144 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataOriginSetMask) { |
| 117 RunRemoveBrowsingDataFunctionAndCompareMask( | 145 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( |
| 146 "[\"unprotected_web\"]", BrowsingDataHelper::UNPROTECTED_WEB); |
| 147 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( |
| 148 "[\"protected_web\"]", BrowsingDataHelper::PROTECTED_WEB); |
| 149 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( |
| 150 "[\"unprotected_web\", \"protected_web\"]", |
| 151 BrowsingDataHelper::UNPROTECTED_WEB | BrowsingDataHelper::PROTECTED_WEB); |
| 152 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( |
| 153 "[\"protected_web\", \"unprotected_web\"]", |
| 154 BrowsingDataHelper::UNPROTECTED_WEB | BrowsingDataHelper::PROTECTED_WEB); |
| 155 } |
| 156 |
| 157 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataRemovalMask) { |
| 158 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 118 "appcache", BrowsingDataRemover::REMOVE_APPCACHE); | 159 "appcache", BrowsingDataRemover::REMOVE_APPCACHE); |
| 119 RunRemoveBrowsingDataFunctionAndCompareMask( | 160 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 120 "cache", BrowsingDataRemover::REMOVE_CACHE); | 161 "cache", BrowsingDataRemover::REMOVE_CACHE); |
| 121 RunRemoveBrowsingDataFunctionAndCompareMask( | 162 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 122 "cookies", BrowsingDataRemover::REMOVE_COOKIES); | 163 "cookies", BrowsingDataRemover::REMOVE_COOKIES); |
| 123 RunRemoveBrowsingDataFunctionAndCompareMask( | 164 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 124 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS); | 165 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS); |
| 125 RunRemoveBrowsingDataFunctionAndCompareMask( | 166 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 126 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS); | 167 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS); |
| 127 RunRemoveBrowsingDataFunctionAndCompareMask( | 168 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 128 "formData", BrowsingDataRemover::REMOVE_FORM_DATA); | 169 "formData", BrowsingDataRemover::REMOVE_FORM_DATA); |
| 129 RunRemoveBrowsingDataFunctionAndCompareMask( | 170 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 130 "history", BrowsingDataRemover::REMOVE_HISTORY); | 171 "history", BrowsingDataRemover::REMOVE_HISTORY); |
| 131 RunRemoveBrowsingDataFunctionAndCompareMask( | 172 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 132 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB); | 173 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB); |
| 133 RunRemoveBrowsingDataFunctionAndCompareMask( | 174 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 134 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); | 175 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); |
| 135 RunRemoveBrowsingDataFunctionAndCompareMask( | 176 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 136 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); | 177 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); |
| 137 RunRemoveBrowsingDataFunctionAndCompareMask( | 178 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 138 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); | 179 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); |
| 139 // We can't remove plugin data inside a test profile. | 180 // We can't remove plugin data inside a test profile. |
| 140 RunRemoveBrowsingDataFunctionAndCompareMask( | 181 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 141 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); | 182 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); |
| 142 } | 183 } |
| OLD | NEW |