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 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 Profile* profile = browser()->profile(); | 250 Profile* profile = browser()->profile(); |
251 CacheCounter counter(profile); | 251 CacheCounter counter(profile); |
252 counter.Init( | 252 counter.Init( |
253 profile->GetPrefs(), | 253 profile->GetPrefs(), |
254 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 254 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
255 counter.Restart(); | 255 counter.Restart(); |
256 | 256 |
257 EXPECT_FALSE(counter.Pending()); | 257 EXPECT_FALSE(counter.Pending()); |
258 } | 258 } |
259 | 259 |
260 // Tests that the counting is restarted when the time period changes. Currently, | 260 // Tests that the counting is restarted when the time period changes. |
261 // the results should be the same for every period. This is because the counter | |
262 // always counts the size of the entire cache, and it is up to the UI | |
263 // to interpret it as exact value or upper bound. | |
264 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PeriodChanged) { | 261 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PeriodChanged) { |
265 CreateCacheEntry(); | 262 CreateCacheEntry(); |
266 | 263 |
267 Profile* profile = browser()->profile(); | 264 Profile* profile = browser()->profile(); |
268 CacheCounter counter(profile); | 265 CacheCounter counter(profile); |
269 counter.Init( | 266 counter.Init( |
270 profile->GetPrefs(), | 267 profile->GetPrefs(), |
271 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 268 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
272 | 269 |
273 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 270 SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
274 WaitForIOThread(); | 271 WaitForIOThread(); |
275 browsing_data::BrowsingDataCounter::ResultInt result = GetResult(); | 272 browsing_data::BrowsingDataCounter::ResultInt result = GetResult(); |
276 EXPECT_TRUE(IsUpperLimit()); | 273 EXPECT_FALSE(IsUpperLimit()); |
277 | 274 |
278 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 275 SetDeletionPeriodPref(browsing_data::LAST_DAY); |
279 WaitForIOThread(); | 276 WaitForIOThread(); |
280 EXPECT_EQ(result, GetResult()); | 277 EXPECT_EQ(result, GetResult()); |
281 EXPECT_TRUE(IsUpperLimit()); | 278 EXPECT_FALSE(IsUpperLimit()); |
282 | 279 |
283 SetDeletionPeriodPref(browsing_data::LAST_WEEK); | 280 SetDeletionPeriodPref(browsing_data::LAST_WEEK); |
284 WaitForIOThread(); | 281 WaitForIOThread(); |
285 EXPECT_EQ(result, GetResult()); | 282 EXPECT_EQ(result, GetResult()); |
286 EXPECT_TRUE(IsUpperLimit()); | 283 EXPECT_FALSE(IsUpperLimit()); |
287 | 284 |
288 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 285 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |
289 WaitForIOThread(); | 286 WaitForIOThread(); |
290 EXPECT_EQ(result, GetResult()); | 287 EXPECT_EQ(result, GetResult()); |
291 EXPECT_TRUE(IsUpperLimit()); | 288 EXPECT_FALSE(IsUpperLimit()); |
292 | 289 |
293 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 290 SetDeletionPeriodPref(browsing_data::ALL_TIME); |
294 WaitForIOThread(); | 291 WaitForIOThread(); |
295 EXPECT_EQ(result, GetResult()); | 292 EXPECT_EQ(result, GetResult()); |
296 EXPECT_FALSE(IsUpperLimit()); | 293 EXPECT_FALSE(IsUpperLimit()); |
297 } | 294 } |
298 | 295 |
| 296 // Tests the cache size is estimated if the timeout runs out. |
| 297 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Timeout) { |
| 298 CreateCacheEntry(); |
| 299 |
| 300 Profile* profile = browser()->profile(); |
| 301 CacheCounter counter(profile); |
| 302 counter.SetTimeout(base::TimeDelta()); |
| 303 counter.Init( |
| 304 profile->GetPrefs(), |
| 305 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
| 306 |
| 307 SetDeletionPeriodPref(browsing_data::LAST_DAY); |
| 308 WaitForIOThread(); |
| 309 EXPECT_GT(GetResult(), 0); |
| 310 EXPECT_TRUE(IsUpperLimit()); |
| 311 |
| 312 // Even with a timeout of 0, ALL_TIME shouldn't be returned as upper limit. |
| 313 SetDeletionPeriodPref(browsing_data::ALL_TIME); |
| 314 WaitForIOThread(); |
| 315 EXPECT_GT(GetResult(), 0); |
| 316 EXPECT_FALSE(IsUpperLimit()); |
| 317 } |
| 318 |
299 } // namespace | 319 } // namespace |
OLD | NEW |