| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 // Note that this file only tests the basic behavior of the cache counter, as in | 5 // Note that this file only tests the basic behavior of the cache counter, as in |
| 6 // when it counts and when not, when result is nonzero and when not. It does not | 6 // when it counts and when not, when result is nonzero and when not. It does not |
| 7 // test whether the result of the counting is correct. This is the | 7 // test whether the result of the counting is correct. This is the |
| 8 // responsibility of a lower layer, and is tested in | 8 // responsibility of a lower layer, and is tested in |
| 9 // DiskCacheBackendTest.CalculateSizeOfAllEntries in net_unittests. | 9 // DiskCacheBackendTest.CalculateSizeOfAllEntries in net_unittests. |
| 10 | 10 |
| 11 #include "chrome/browser/browsing_data/cache_counter.h" | 11 #include "chrome/browser/browsing_data/cache_counter.h" |
| 12 | 12 |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "components/browsing_data/content/storage_partition_http_cache_data_rem
over.h" | |
| 19 #include "components/browsing_data/core/browsing_data_utils.h" | 18 #include "components/browsing_data/core/browsing_data_utils.h" |
| 20 #include "components/browsing_data/core/pref_names.h" | 19 #include "components/browsing_data/core/pref_names.h" |
| 21 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
| 22 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
| 22 #include "content/public/browser/storage_partition_http_cache_data_remover.h" |
| 23 #include "net/disk_cache/disk_cache.h" | 23 #include "net/disk_cache/disk_cache.h" |
| 24 #include "net/http/http_cache.h" | 24 #include "net/http/http_cache.h" |
| 25 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 26 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 27 | 27 |
| 28 using content::BrowserContext; | 28 using content::BrowserContext; |
| 29 using content::BrowserThread; | 29 using content::BrowserThread; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // Tests that after dooming a nonempty cache, the result is zero. | 210 // Tests that after dooming a nonempty cache, the result is zero. |
| 211 IN_PROC_BROWSER_TEST_F(CacheCounterTest, AfterDoom) { | 211 IN_PROC_BROWSER_TEST_F(CacheCounterTest, AfterDoom) { |
| 212 CreateCacheEntry(); | 212 CreateCacheEntry(); |
| 213 | 213 |
| 214 Profile* profile = browser()->profile(); | 214 Profile* profile = browser()->profile(); |
| 215 CacheCounter counter(profile); | 215 CacheCounter counter(profile); |
| 216 counter.Init( | 216 counter.Init( |
| 217 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, | 217 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 218 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 218 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
| 219 | 219 |
| 220 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( | 220 content::StoragePartitionHttpCacheDataRemover::CreateForRange( |
| 221 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()), | 221 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()), |
| 222 base::Time(), | 222 base::Time(), base::Time::Max()) |
| 223 base::Time::Max())->Remove( | 223 ->Remove(base::Bind(&CacheCounter::Restart, base::Unretained(&counter))); |
| 224 base::Bind(&CacheCounter::Restart, | |
| 225 base::Unretained(&counter))); | |
| 226 | 224 |
| 227 WaitForIOThread(); | 225 WaitForIOThread(); |
| 228 EXPECT_EQ(0u, GetResult()); | 226 EXPECT_EQ(0u, GetResult()); |
| 229 } | 227 } |
| 230 | 228 |
| 231 // Tests that the counter starts counting automatically when the deletion | 229 // Tests that the counter starts counting automatically when the deletion |
| 232 // pref changes to true. | 230 // pref changes to true. |
| 233 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefChanged) { | 231 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefChanged) { |
| 234 SetCacheDeletionPref(false); | 232 SetCacheDeletionPref(false); |
| 235 | 233 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 WaitForIOThread(); | 268 WaitForIOThread(); |
| 271 EXPECT_EQ(result, GetResult()); | 269 EXPECT_EQ(result, GetResult()); |
| 272 | 270 |
| 273 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); | 271 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); |
| 274 WaitForIOThread(); | 272 WaitForIOThread(); |
| 275 EXPECT_EQ(result, GetResult()); | 273 EXPECT_EQ(result, GetResult()); |
| 276 EXPECT_FALSE(IsUpperLimit()); | 274 EXPECT_FALSE(IsUpperLimit()); |
| 277 } | 275 } |
| 278 | 276 |
| 279 } // namespace | 277 } // namespace |
| OLD | NEW |