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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 disk_cache::Entry* entry_; | 160 disk_cache::Entry* entry_; |
161 | 161 |
162 std::unique_ptr<base::RunLoop> run_loop_; | 162 std::unique_ptr<base::RunLoop> run_loop_; |
163 | 163 |
164 bool finished_; | 164 bool finished_; |
165 BrowsingDataCounter::ResultInt result_; | 165 BrowsingDataCounter::ResultInt result_; |
166 }; | 166 }; |
167 | 167 |
168 // Tests that for the empty cache, the result is zero. | 168 // Tests that for the empty cache, the result is zero. |
169 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Empty) { | 169 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Empty) { |
| 170 Profile* profile = browser()->profile(); |
| 171 |
170 CacheCounter counter; | 172 CacheCounter counter; |
171 counter.Init(browser()->profile(), | 173 counter.Init( |
172 base::Bind(&CacheCounterTest::CountingCallback, | 174 profile->GetPrefs(), prefs::kDeleteTimePeriod, |
173 base::Unretained(this))); | 175 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
174 counter.Restart(); | 176 counter.Restart(); |
175 | 177 |
176 WaitForIOThread(); | 178 WaitForIOThread(); |
177 EXPECT_EQ(0u, GetResult()); | 179 EXPECT_EQ(0u, GetResult()); |
178 } | 180 } |
179 | 181 |
180 // Tests that for a non-empty cache, the result is nonzero. | 182 // Tests that for a non-empty cache, the result is nonzero. |
181 IN_PROC_BROWSER_TEST_F(CacheCounterTest, NonEmpty) { | 183 IN_PROC_BROWSER_TEST_F(CacheCounterTest, NonEmpty) { |
182 CreateCacheEntry(); | 184 CreateCacheEntry(); |
183 | 185 |
184 CacheCounter counter; | 186 Profile* profile = browser()->profile(); |
185 counter.Init(browser()->profile(), | 187 CacheCounter counter(profile); |
186 base::Bind(&CacheCounterTest::CountingCallback, | 188 counter.Init( |
187 base::Unretained(this))); | 189 profile->GetPrefs(), prefs::kDeleteTimePeriod, |
| 190 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
188 counter.Restart(); | 191 counter.Restart(); |
189 | 192 |
190 WaitForIOThread(); | 193 WaitForIOThread(); |
191 | 194 |
192 EXPECT_NE(0u, GetResult()); | 195 EXPECT_NE(0u, GetResult()); |
193 } | 196 } |
194 | 197 |
195 // Tests that after dooming a nonempty cache, the result is zero. | 198 // Tests that after dooming a nonempty cache, the result is zero. |
196 IN_PROC_BROWSER_TEST_F(CacheCounterTest, AfterDoom) { | 199 IN_PROC_BROWSER_TEST_F(CacheCounterTest, AfterDoom) { |
197 CreateCacheEntry(); | 200 CreateCacheEntry(); |
198 | 201 |
199 CacheCounter counter; | 202 Profile* profile = browser()->profile(0); |
200 counter.Init(browser()->profile(), | 203 CacheCounter counter(profile); |
201 base::Bind(&CacheCounterTest::CountingCallback, | 204 counter.Init( |
202 base::Unretained(this))); | 205 profile->GetPrefs(), prefs::kDeleteTimePeriod, |
| 206 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
203 | 207 |
204 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( | 208 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( |
205 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()), | 209 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()), |
206 base::Time(), | 210 base::Time(), |
207 base::Time::Max())->Remove( | 211 base::Time::Max())->Remove( |
208 base::Bind(&CacheCounter::Restart, | 212 base::Bind(&CacheCounter::Restart, |
209 base::Unretained(&counter))); | 213 base::Unretained(&counter))); |
210 | 214 |
211 WaitForIOThread(); | 215 WaitForIOThread(); |
212 EXPECT_EQ(0u, GetResult()); | 216 EXPECT_EQ(0u, GetResult()); |
213 } | 217 } |
214 | 218 |
215 // Tests that the counter starts counting automatically when the deletion | 219 // Tests that the counter starts counting automatically when the deletion |
216 // pref changes to true. | 220 // pref changes to true. |
217 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefChanged) { | 221 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefChanged) { |
218 SetCacheDeletionPref(false); | 222 SetCacheDeletionPref(false); |
219 | 223 |
220 CacheCounter counter; | 224 Profile* profile = browser()->profile(); |
221 counter.Init(browser()->profile(), | 225 CacheCounter counter(profile); |
222 base::Bind(&CacheCounterTest::CountingCallback, | 226 counter.Init( |
223 base::Unretained(this))); | 227 profile->GetPrefs(), prefs::kDeleteTimePeriod, |
| 228 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
224 SetCacheDeletionPref(true); | 229 SetCacheDeletionPref(true); |
225 | 230 |
226 WaitForIOThread(); | 231 WaitForIOThread(); |
227 EXPECT_EQ(0u, GetResult()); | 232 EXPECT_EQ(0u, GetResult()); |
228 } | 233 } |
229 | 234 |
230 // Tests that the counter does not count if the deletion preference is false. | 235 // Tests that the counter does not count if the deletion preference is false. |
231 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefIsFalse) { | 236 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefIsFalse) { |
232 SetCacheDeletionPref(false); | 237 SetCacheDeletionPref(false); |
233 | 238 |
234 CacheCounter counter; | 239 Profile* profile = browser()->profile(); |
235 counter.Init(browser()->profile(), | 240 CacheCounter counte(profile); |
236 base::Bind(&CacheCounterTest::CountingCallback, | 241 counter.Init( |
237 base::Unretained(this))); | 242 profile->GetPrefs(), prefs::kDeleteTimePeriod, |
| 243 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
238 counter.Restart(); | 244 counter.Restart(); |
239 | 245 |
240 EXPECT_FALSE(counter.Pending()); | 246 EXPECT_FALSE(counter.Pending()); |
241 } | 247 } |
242 | 248 |
243 // Tests that the counting is restarted when the time period changes. Currently, | 249 // Tests that the counting is restarted when the time period changes. Currently, |
244 // the results should be the same for every period. This is because the counter | 250 // the results should be the same for every period. This is because the counter |
245 // always counts the size of the entire cache, and it is up to the UI | 251 // always counts the size of the entire cache, and it is up to the UI |
246 // to interpret it as exact value or upper bound. | 252 // to interpret it as exact value or upper bound. |
247 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PeriodChanged) { | 253 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PeriodChanged) { |
248 CreateCacheEntry(); | 254 CreateCacheEntry(); |
249 | 255 |
| 256 Profile* profile = browser()->profile(); |
250 CacheCounter counter; | 257 CacheCounter counter; |
251 counter.Init(browser()->profile(), | 258 counter.Init( |
252 base::Bind(&CacheCounterTest::CountingCallback, | 259 profile->GetPrefs(), prefs::kDeleteTimePeriod, |
253 base::Unretained(this))); | 260 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
254 | 261 |
255 SetDeletionPeriodPref(BrowsingDataRemover::LAST_HOUR); | 262 SetDeletionPeriodPref(BrowsingDataRemover::LAST_HOUR); |
256 WaitForIOThread(); | 263 WaitForIOThread(); |
257 BrowsingDataCounter::ResultInt result = GetResult(); | 264 BrowsingDataCounter::ResultInt result = GetResult(); |
258 | 265 |
259 SetDeletionPeriodPref(BrowsingDataRemover::LAST_DAY); | 266 SetDeletionPeriodPref(BrowsingDataRemover::LAST_DAY); |
260 WaitForIOThread(); | 267 WaitForIOThread(); |
261 EXPECT_EQ(result, GetResult()); | 268 EXPECT_EQ(result, GetResult()); |
262 | 269 |
263 SetDeletionPeriodPref(BrowsingDataRemover::LAST_WEEK); | 270 SetDeletionPeriodPref(BrowsingDataRemover::LAST_WEEK); |
264 WaitForIOThread(); | 271 WaitForIOThread(); |
265 EXPECT_EQ(result, GetResult()); | 272 EXPECT_EQ(result, GetResult()); |
266 | 273 |
267 SetDeletionPeriodPref(BrowsingDataRemover::FOUR_WEEKS); | 274 SetDeletionPeriodPref(BrowsingDataRemover::FOUR_WEEKS); |
268 WaitForIOThread(); | 275 WaitForIOThread(); |
269 EXPECT_EQ(result, GetResult()); | 276 EXPECT_EQ(result, GetResult()); |
270 | 277 |
271 SetDeletionPeriodPref(BrowsingDataRemover::EVERYTHING); | 278 SetDeletionPeriodPref(BrowsingDataRemover::EVERYTHING); |
272 WaitForIOThread(); | 279 WaitForIOThread(); |
273 EXPECT_EQ(result, GetResult()); | 280 EXPECT_EQ(result, GetResult()); |
274 } | 281 } |
275 | 282 |
276 } // namespace | 283 } // namespace |
OLD | NEW |