| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 base::Unretained(&size))); | 108 base::Unretained(&size))); |
| 109 counter.Restart(); | 109 counter.Restart(); |
| 110 run_loop.Run(); | 110 run_loop.Run(); |
| 111 return size; | 111 return size; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void RemoveAndWait(int remove_mask) { | 114 void RemoveAndWait(int remove_mask) { |
| 115 BrowsingDataRemover* remover = | 115 BrowsingDataRemover* remover = |
| 116 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 116 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
| 117 BrowsingDataRemoverCompletionObserver completion_observer(remover); | 117 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
| 118 remover->Remove(BrowsingDataRemover::Period(browsing_data::LAST_HOUR), | 118 remover->RemoveAndReply( |
| 119 remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); | 119 BrowsingDataRemover::Period(browsing_data::LAST_HOUR), remove_mask, |
| 120 BrowsingDataHelper::UNPROTECTED_WEB, &completion_observer); |
| 120 completion_observer.BlockUntilCompletion(); | 121 completion_observer.BlockUntilCompletion(); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void RemoveWithFilterAndWait( | 124 void RemoveWithFilterAndWait( |
| 124 int remove_mask, | 125 int remove_mask, |
| 125 const BrowsingDataFilterBuilder& filter_builder) { | 126 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { |
| 126 BrowsingDataRemover* remover = | 127 BrowsingDataRemover* remover = |
| 127 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 128 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
| 128 BrowsingDataRemoverCompletionObserver completion_observer(remover); | 129 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
| 129 remover->RemoveWithFilter( | 130 remover->RemoveWithFilterAndReply( |
| 130 BrowsingDataRemover::Period(browsing_data::LAST_HOUR), remove_mask, | 131 BrowsingDataRemover::Period(browsing_data::LAST_HOUR), remove_mask, |
| 131 BrowsingDataHelper::UNPROTECTED_WEB, filter_builder); | 132 BrowsingDataHelper::UNPROTECTED_WEB, std::move(filter_builder), |
| 133 &completion_observer); |
| 132 completion_observer.BlockUntilCompletion(); | 134 completion_observer.BlockUntilCompletion(); |
| 133 } | 135 } |
| 134 | 136 |
| 135 private: | 137 private: |
| 136 void OnCacheSizeResult( | 138 void OnCacheSizeResult( |
| 137 base::RunLoop* run_loop, | 139 base::RunLoop* run_loop, |
| 138 browsing_data::BrowsingDataCounter::ResultInt* out_size, | 140 browsing_data::BrowsingDataCounter::ResultInt* out_size, |
| 139 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 141 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
| 140 if (!result->Finished()) | 142 if (!result->Finished()) |
| 141 return; | 143 return; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 ASSERT_FALSE(url::IsSameOriginWith(url1, url2)); | 240 ASSERT_FALSE(url::IsSameOriginWith(url1, url2)); |
| 239 ui_test_utils::NavigateToURL(browser(), url1); | 241 ui_test_utils::NavigateToURL(browser(), url1); |
| 240 ui_test_utils::NavigateToURL(browser(), url2); | 242 ui_test_utils::NavigateToURL(browser(), url2); |
| 241 | 243 |
| 242 // The cache is nonempty, because we created entries by visiting websites. | 244 // The cache is nonempty, because we created entries by visiting websites. |
| 243 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize(); | 245 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize(); |
| 244 EXPECT_GT(original_size, 0); | 246 EXPECT_GT(original_size, 0); |
| 245 | 247 |
| 246 // Partially delete cache data. Delete data for localhost, which is the origin | 248 // Partially delete cache data. Delete data for localhost, which is the origin |
| 247 // of |url1|, but not for |kExampleHost|, which is the origin of |url2|. | 249 // of |url1|, but not for |kExampleHost|, which is the origin of |url2|. |
| 248 OriginFilterBuilder filter_builder(OriginFilterBuilder::WHITELIST); | 250 std::unique_ptr<OriginFilterBuilder> filter_builder( |
| 249 filter_builder.AddOrigin(url::Origin(url1)); | 251 new OriginFilterBuilder(OriginFilterBuilder::WHITELIST)); |
| 250 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, filter_builder); | 252 filter_builder->AddOrigin(url::Origin(url1)); |
| 253 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, |
| 254 std::move(filter_builder)); |
| 251 | 255 |
| 252 // After the partial deletion, the cache should be smaller but still nonempty. | 256 // After the partial deletion, the cache should be smaller but still nonempty. |
| 253 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize(); | 257 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize(); |
| 254 EXPECT_LT(new_size, original_size); | 258 EXPECT_LT(new_size, original_size); |
| 255 | 259 |
| 256 // Another partial deletion with the same filter should have no effect. | 260 // Another partial deletion with the same filter should have no effect. |
| 257 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, filter_builder); | 261 filter_builder.reset(new OriginFilterBuilder(OriginFilterBuilder::WHITELIST)); |
| 262 filter_builder->AddOrigin(url::Origin(url1)); |
| 263 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, |
| 264 std::move(filter_builder)); |
| 258 EXPECT_EQ(new_size, GetCacheSize()); | 265 EXPECT_EQ(new_size, GetCacheSize()); |
| 259 | 266 |
| 260 // Delete the remaining data. | 267 // Delete the remaining data. |
| 261 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); | 268 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); |
| 262 | 269 |
| 263 // The cache is empty. | 270 // The cache is empty. |
| 264 EXPECT_EQ(0, GetCacheSize()); | 271 EXPECT_EQ(0, GetCacheSize()); |
| 265 } | 272 } |
| 266 | 273 |
| 267 // Verify that TransportSecurityState data is cleared for REMOVE_CACHE. | 274 // Verify that TransportSecurityState data is cleared for REMOVE_CACHE. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 287 base::RunLoop run_loop; | 294 base::RunLoop run_loop; |
| 288 BrowserThread::PostTaskAndReply( | 295 BrowserThread::PostTaskAndReply( |
| 289 BrowserThread::IO, FROM_HERE, | 296 BrowserThread::IO, FROM_HERE, |
| 290 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: | 297 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: |
| 291 CheckTransportSecurityState, | 298 CheckTransportSecurityState, |
| 292 this, | 299 this, |
| 293 base::RetainedRef(browser()->profile()->GetRequestContext()), | 300 base::RetainedRef(browser()->profile()->GetRequestContext()), |
| 294 false /* should not be cleared */), | 301 false /* should not be cleared */), |
| 295 run_loop.QuitClosure()); | 302 run_loop.QuitClosure()); |
| 296 } | 303 } |
| OLD | NEW |