| 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" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // We're not taking ownership of the details object, but storing a copy of | 64 // We're not taking ownership of the details object, but storing a copy of |
| 65 // it locally. | 65 // it locally. |
| 66 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( | 66 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( |
| 67 *content::Details<BrowsingDataRemover::NotificationDetails>( | 67 *content::Details<BrowsingDataRemover::NotificationDetails>( |
| 68 details).ptr())); | 68 details).ptr())); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 71 void RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 72 const std::string& key, | 72 const std::string& key, |
| 73 int expected_mask) { | 73 int expected_mask) { |
| 74 scoped_refptr<RemoveBrowsingDataFunction> function = | 74 scoped_refptr<BrowsingDataRemoveFunction> function = |
| 75 new RemoveBrowsingDataFunction(); | 75 new BrowsingDataRemoveFunction(); |
| 76 SCOPED_TRACE(key); | 76 SCOPED_TRACE(key); |
| 77 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( | 77 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( |
| 78 function.get(), | 78 function.get(), |
| 79 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", | 79 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", |
| 80 browser())); | 80 browser())); |
| 81 EXPECT_EQ(expected_mask, GetRemovalMask()); | 81 EXPECT_EQ(expected_mask, GetRemovalMask()); |
| 82 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 82 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( | 85 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( |
| 86 const std::string& protectedStr, | 86 const std::string& protectedStr, |
| 87 int expected_mask) { | 87 int expected_mask) { |
| 88 scoped_refptr<RemoveBrowsingDataFunction> function = | 88 scoped_refptr<BrowsingDataRemoveFunction> function = |
| 89 new RemoveBrowsingDataFunction(); | 89 new BrowsingDataRemoveFunction(); |
| 90 SCOPED_TRACE(protectedStr); | 90 SCOPED_TRACE(protectedStr); |
| 91 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( | 91 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( |
| 92 function.get(), | 92 function.get(), |
| 93 "[{\"originTypes\": " + protectedStr + "}, {\"cookies\": true}]", | 93 "[{\"originTypes\": " + protectedStr + "}, {\"cookies\": true}]", |
| 94 browser())); | 94 browser())); |
| 95 EXPECT_EQ(expected_mask, GetOriginSetMask()); | 95 EXPECT_EQ(expected_mask, GetOriginSetMask()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 template<class ShortcutFunction> | 98 template<class ShortcutFunction> |
| 99 void RunAndCompareRemovalMask(int expected_mask) { | 99 void RunAndCompareRemovalMask(int expected_mask) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; | 112 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
| 113 content::NotificationRegistrar registrar_; | 113 content::NotificationRegistrar registrar_; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { | 118 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { |
| 119 BrowsingDataRemover::set_removing(true); | 119 BrowsingDataRemover::set_removing(true); |
| 120 scoped_refptr<RemoveBrowsingDataFunction> function = | 120 scoped_refptr<BrowsingDataRemoveFunction> function = |
| 121 new RemoveBrowsingDataFunction(); | 121 new BrowsingDataRemoveFunction(); |
| 122 EXPECT_TRUE(MatchPattern( | 122 EXPECT_TRUE(MatchPattern( |
| 123 RunFunctionAndReturnError(function, | 123 RunFunctionAndReturnError(function, |
| 124 kRemoveEverythingArguments, | 124 kRemoveEverythingArguments, |
| 125 browser()), | 125 browser()), |
| 126 extension_browsing_data_api_constants::kOneAtATimeError)); | 126 extension_browsing_data_api_constants::kOneAtATimeError)); |
| 127 BrowsingDataRemover::set_removing(false); | 127 BrowsingDataRemover::set_removing(false); |
| 128 | 128 |
| 129 EXPECT_EQ(base::Time(), GetBeginTime()); | 129 EXPECT_EQ(base::Time(), GetBeginTime()); |
| 130 EXPECT_EQ(-1, GetRemovalMask()); | 130 EXPECT_EQ(-1, GetRemovalMask()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Use-after-free, see http://crbug.com/116522 | 133 // Use-after-free, see http://crbug.com/116522 |
| 134 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, | 134 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, |
| 135 DISABLED_RemoveBrowsingDataAll) { | 135 DISABLED_RemoveBrowsingDataAll) { |
| 136 scoped_refptr<RemoveBrowsingDataFunction> function = | 136 scoped_refptr<BrowsingDataRemoveFunction> function = |
| 137 new RemoveBrowsingDataFunction(); | 137 new BrowsingDataRemoveFunction(); |
| 138 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(function.get(), | 138 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(function.get(), |
| 139 kRemoveEverythingArguments, | 139 kRemoveEverythingArguments, |
| 140 browser())); | 140 browser())); |
| 141 | 141 |
| 142 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime()); | 142 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime()); |
| 143 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | | 143 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | |
| 144 BrowsingDataRemover::REMOVE_CACHE | | 144 BrowsingDataRemover::REMOVE_CACHE | |
| 145 BrowsingDataRemover::REMOVE_DOWNLOADS | | 145 BrowsingDataRemover::REMOVE_DOWNLOADS | |
| 146 BrowsingDataRemover::REMOVE_FORM_DATA | | 146 BrowsingDataRemover::REMOVE_FORM_DATA | |
| 147 BrowsingDataRemover::REMOVE_HISTORY | | 147 BrowsingDataRemover::REMOVE_HISTORY | |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 "serverBoundCertificates", | 200 "serverBoundCertificates", |
| 201 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); | 201 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); |
| 202 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 202 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 203 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); | 203 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); |
| 204 // We can't remove plugin data inside a test profile. | 204 // We can't remove plugin data inside a test profile. |
| 205 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 205 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
| 206 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); | 206 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); |
| 207 } | 207 } |
| 208 | 208 |
| 209 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, ShortcutFunctionRemovalMask) { | 209 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, ShortcutFunctionRemovalMask) { |
| 210 RunAndCompareRemovalMask<RemoveAppCacheFunction>( | 210 RunAndCompareRemovalMask<BrowsingDataRemoveAppcacheFunction>( |
| 211 BrowsingDataRemover::REMOVE_APPCACHE); | 211 BrowsingDataRemover::REMOVE_APPCACHE); |
| 212 RunAndCompareRemovalMask<RemoveCacheFunction>( | 212 RunAndCompareRemovalMask<BrowsingDataRemoveCacheFunction>( |
| 213 BrowsingDataRemover::REMOVE_CACHE); | 213 BrowsingDataRemover::REMOVE_CACHE); |
| 214 RunAndCompareRemovalMask<RemoveCookiesFunction>( | 214 RunAndCompareRemovalMask<BrowsingDataRemoveCookiesFunction>( |
| 215 BrowsingDataRemover::REMOVE_COOKIES | | 215 BrowsingDataRemover::REMOVE_COOKIES | |
| 216 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); | 216 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); |
| 217 RunAndCompareRemovalMask<RemoveDownloadsFunction>( | 217 RunAndCompareRemovalMask<BrowsingDataRemoveDownloadsFunction>( |
| 218 BrowsingDataRemover::REMOVE_DOWNLOADS); | 218 BrowsingDataRemover::REMOVE_DOWNLOADS); |
| 219 RunAndCompareRemovalMask<RemoveFileSystemsFunction>( | 219 RunAndCompareRemovalMask<BrowsingDataRemoveFileSystemsFunction>( |
| 220 BrowsingDataRemover::REMOVE_FILE_SYSTEMS); | 220 BrowsingDataRemover::REMOVE_FILE_SYSTEMS); |
| 221 RunAndCompareRemovalMask<RemoveFormDataFunction>( | 221 RunAndCompareRemovalMask<BrowsingDataRemoveFormDataFunction>( |
| 222 BrowsingDataRemover::REMOVE_FORM_DATA); | 222 BrowsingDataRemover::REMOVE_FORM_DATA); |
| 223 RunAndCompareRemovalMask<RemoveHistoryFunction>( | 223 RunAndCompareRemovalMask<BrowsingDataRemoveHistoryFunction>( |
| 224 BrowsingDataRemover::REMOVE_HISTORY); | 224 BrowsingDataRemover::REMOVE_HISTORY); |
| 225 RunAndCompareRemovalMask<RemoveIndexedDBFunction>( | 225 RunAndCompareRemovalMask<BrowsingDataRemoveIndexedDBFunction>( |
| 226 BrowsingDataRemover::REMOVE_INDEXEDDB); | 226 BrowsingDataRemover::REMOVE_INDEXEDDB); |
| 227 RunAndCompareRemovalMask<RemoveLocalStorageFunction>( | 227 RunAndCompareRemovalMask<BrowsingDataRemoveLocalStorageFunction>( |
| 228 BrowsingDataRemover::REMOVE_LOCAL_STORAGE); | 228 BrowsingDataRemover::REMOVE_LOCAL_STORAGE); |
| 229 // We can't remove plugin data inside a test profile. | 229 // We can't remove plugin data inside a test profile. |
| 230 RunAndCompareRemovalMask<RemovePasswordsFunction>( | 230 RunAndCompareRemovalMask<BrowsingDataRemovePasswordsFunction>( |
| 231 BrowsingDataRemover::REMOVE_PASSWORDS); | 231 BrowsingDataRemover::REMOVE_PASSWORDS); |
| 232 RunAndCompareRemovalMask<RemoveWebSQLFunction>( | 232 RunAndCompareRemovalMask<BrowsingDataRemoveWebSQLFunction>( |
| 233 BrowsingDataRemover::REMOVE_WEBSQL); | 233 BrowsingDataRemover::REMOVE_WEBSQL); |
| 234 } | 234 } |
| 235 | 235 |
| OLD | NEW |