| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 272 |
| 273 CacheCounter counter(browser_state()); | 273 CacheCounter counter(browser_state()); |
| 274 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, | 274 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, |
| 275 base::Unretained(this))); | 275 base::Unretained(this))); |
| 276 SetCacheDeletionPref(true); | 276 SetCacheDeletionPref(true); |
| 277 | 277 |
| 278 WaitForIOThread(); | 278 WaitForIOThread(); |
| 279 EXPECT_EQ(0u, GetResult()); | 279 EXPECT_EQ(0u, GetResult()); |
| 280 } | 280 } |
| 281 | 281 |
| 282 // Tests that the counter does not count if the deletion preference is false. | |
| 283 TEST_F(CacheCounterTest, PrefIsFalse) { | |
| 284 SetCacheDeletionPref(false); | |
| 285 | |
| 286 CacheCounter counter(browser_state()); | |
| 287 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, | |
| 288 base::Unretained(this))); | |
| 289 counter.Restart(); | |
| 290 | |
| 291 EXPECT_FALSE(counter.pending()); | |
| 292 } | |
| 293 | |
| 294 // Tests that the counting is restarted when the time period changes. Currently, | 282 // Tests that the counting is restarted when the time period changes. Currently, |
| 295 // the results should be the same for every period. This is because the counter | 283 // the results should be the same for every period. This is because the counter |
| 296 // always counts the size of the entire cache, and it is up to the UI | 284 // always counts the size of the entire cache, and it is up to the UI |
| 297 // to interpret it as exact value or upper bound. | 285 // to interpret it as exact value or upper bound. |
| 298 TEST_F(CacheCounterTest, PeriodChanged) { | 286 TEST_F(CacheCounterTest, PeriodChanged) { |
| 299 CreateCacheEntry(); | 287 CreateCacheEntry(); |
| 300 | 288 |
| 301 CacheCounter counter(browser_state()); | 289 CacheCounter counter(browser_state()); |
| 302 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, | 290 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, |
| 303 base::Unretained(this))); | 291 base::Unretained(this))); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 317 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 305 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |
| 318 WaitForIOThread(); | 306 WaitForIOThread(); |
| 319 EXPECT_EQ(result, GetResult()); | 307 EXPECT_EQ(result, GetResult()); |
| 320 | 308 |
| 321 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 309 SetDeletionPeriodPref(browsing_data::ALL_TIME); |
| 322 WaitForIOThread(); | 310 WaitForIOThread(); |
| 323 EXPECT_EQ(result, GetResult()); | 311 EXPECT_EQ(result, GetResult()); |
| 324 } | 312 } |
| 325 | 313 |
| 326 } // namespace | 314 } // namespace |
| OLD | NEW |