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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 bool is_upper_limit_; | 176 bool is_upper_limit_; |
177 }; | 177 }; |
178 | 178 |
179 // Tests that for the empty cache, the result is zero. | 179 // Tests that for the empty cache, the result is zero. |
180 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Empty) { | 180 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Empty) { |
181 Profile* profile = browser()->profile(); | 181 Profile* profile = browser()->profile(); |
182 | 182 |
183 CacheCounter counter(profile); | 183 CacheCounter counter(profile); |
184 counter.Init( | 184 counter.Init( |
185 profile->GetPrefs(), | 185 profile->GetPrefs(), |
| 186 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
186 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 187 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
187 counter.Restart(); | 188 counter.Restart(); |
188 | 189 |
189 WaitForIOThread(); | 190 WaitForIOThread(); |
190 EXPECT_EQ(0u, GetResult()); | 191 EXPECT_EQ(0u, GetResult()); |
191 } | 192 } |
192 | 193 |
193 // Tests that for a non-empty cache, the result is nonzero. | 194 // Tests that for a non-empty cache, the result is nonzero. |
194 IN_PROC_BROWSER_TEST_F(CacheCounterTest, NonEmpty) { | 195 IN_PROC_BROWSER_TEST_F(CacheCounterTest, NonEmpty) { |
195 CreateCacheEntry(); | 196 CreateCacheEntry(); |
196 | 197 |
197 Profile* profile = browser()->profile(); | 198 Profile* profile = browser()->profile(); |
198 CacheCounter counter(profile); | 199 CacheCounter counter(profile); |
199 counter.Init( | 200 counter.Init( |
200 profile->GetPrefs(), | 201 profile->GetPrefs(), |
| 202 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
201 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 203 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
202 counter.Restart(); | 204 counter.Restart(); |
203 | 205 |
204 WaitForIOThread(); | 206 WaitForIOThread(); |
205 | 207 |
206 EXPECT_NE(0u, GetResult()); | 208 EXPECT_NE(0u, GetResult()); |
207 } | 209 } |
208 | 210 |
209 // Tests that after dooming a nonempty cache, the result is zero. | 211 // Tests that after dooming a nonempty cache, the result is zero. |
210 IN_PROC_BROWSER_TEST_F(CacheCounterTest, AfterDoom) { | 212 IN_PROC_BROWSER_TEST_F(CacheCounterTest, AfterDoom) { |
211 CreateCacheEntry(); | 213 CreateCacheEntry(); |
212 | 214 |
213 Profile* profile = browser()->profile(); | 215 Profile* profile = browser()->profile(); |
214 CacheCounter counter(profile); | 216 CacheCounter counter(profile); |
215 counter.Init( | 217 counter.Init( |
216 profile->GetPrefs(), | 218 profile->GetPrefs(), |
| 219 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
217 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 220 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
218 | 221 |
219 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( | 222 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( |
220 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()), | 223 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()), |
221 base::Time(), | 224 base::Time(), |
222 base::Time::Max())->Remove( | 225 base::Time::Max())->Remove( |
223 base::Bind(&CacheCounter::Restart, | 226 base::Bind(&CacheCounter::Restart, |
224 base::Unretained(&counter))); | 227 base::Unretained(&counter))); |
225 | 228 |
226 WaitForIOThread(); | 229 WaitForIOThread(); |
227 EXPECT_EQ(0u, GetResult()); | 230 EXPECT_EQ(0u, GetResult()); |
228 } | 231 } |
229 | 232 |
230 // Tests that the counter starts counting automatically when the deletion | 233 // Tests that the counter starts counting automatically when the deletion |
231 // pref changes to true. | 234 // pref changes to true. |
232 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefChanged) { | 235 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefChanged) { |
233 SetCacheDeletionPref(false); | 236 SetCacheDeletionPref(false); |
234 | 237 |
235 Profile* profile = browser()->profile(); | 238 Profile* profile = browser()->profile(); |
236 CacheCounter counter(profile); | 239 CacheCounter counter(profile); |
237 counter.Init( | 240 counter.Init( |
238 profile->GetPrefs(), | 241 profile->GetPrefs(), |
| 242 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
239 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 243 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
240 SetCacheDeletionPref(true); | 244 SetCacheDeletionPref(true); |
241 | 245 |
242 WaitForIOThread(); | 246 WaitForIOThread(); |
243 EXPECT_EQ(0u, GetResult()); | 247 EXPECT_EQ(0u, GetResult()); |
244 } | 248 } |
245 | 249 |
246 // Tests that the counting is restarted when the time period changes. | 250 // Tests that the counting is restarted when the time period changes. |
247 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PeriodChanged) { | 251 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PeriodChanged) { |
248 CreateCacheEntry(); | 252 CreateCacheEntry(); |
249 | 253 |
250 Profile* profile = browser()->profile(); | 254 Profile* profile = browser()->profile(); |
251 CacheCounter counter(profile); | 255 CacheCounter counter(profile); |
252 counter.Init( | 256 counter.Init( |
253 profile->GetPrefs(), | 257 profile->GetPrefs(), |
| 258 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
254 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 259 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
255 | 260 |
256 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 261 SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
257 WaitForIOThread(); | 262 WaitForIOThread(); |
258 browsing_data::BrowsingDataCounter::ResultInt result = GetResult(); | 263 browsing_data::BrowsingDataCounter::ResultInt result = GetResult(); |
259 | 264 |
260 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 265 SetDeletionPeriodPref(browsing_data::LAST_DAY); |
261 WaitForIOThread(); | 266 WaitForIOThread(); |
262 EXPECT_EQ(result, GetResult()); | 267 EXPECT_EQ(result, GetResult()); |
263 | 268 |
264 SetDeletionPeriodPref(browsing_data::LAST_WEEK); | 269 SetDeletionPeriodPref(browsing_data::LAST_WEEK); |
265 WaitForIOThread(); | 270 WaitForIOThread(); |
266 EXPECT_EQ(result, GetResult()); | 271 EXPECT_EQ(result, GetResult()); |
267 | 272 |
268 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 273 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |
269 WaitForIOThread(); | 274 WaitForIOThread(); |
270 EXPECT_EQ(result, GetResult()); | 275 EXPECT_EQ(result, GetResult()); |
271 | 276 |
272 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 277 SetDeletionPeriodPref(browsing_data::ALL_TIME); |
273 WaitForIOThread(); | 278 WaitForIOThread(); |
274 EXPECT_EQ(result, GetResult()); | 279 EXPECT_EQ(result, GetResult()); |
275 EXPECT_FALSE(IsUpperLimit()); | 280 EXPECT_FALSE(IsUpperLimit()); |
276 } | 281 } |
277 | 282 |
278 } // namespace | 283 } // namespace |
OLD | NEW |