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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 run_loop_->Quit(); | 131 run_loop_->Quit(); |
132 } | 132 } |
133 | 133 |
134 // Callback from the counter. | 134 // Callback from the counter. |
135 void CountingCallback( | 135 void CountingCallback( |
136 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 136 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
137 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
138 finished_ = result->Finished(); | 138 finished_ = result->Finished(); |
139 | 139 |
140 if (finished_) { | 140 if (finished_) { |
141 result_ = | 141 auto cache_result = static_cast<CacheCounter::CacheResult*>(result.get()); |
142 static_cast<browsing_data::BrowsingDataCounter::FinishedResult*>( | 142 result_ = cache_result->cache_size(); |
143 result.get()) | 143 is_upper_limit_ = cache_result->is_upper_limit(); |
144 ->Value(); | |
145 } | 144 } |
146 | 145 |
147 if (run_loop_ && finished_) | 146 if (run_loop_ && finished_) |
148 run_loop_->Quit(); | 147 run_loop_->Quit(); |
149 } | 148 } |
150 | 149 |
151 browsing_data::BrowsingDataCounter::ResultInt GetResult() { | 150 browsing_data::BrowsingDataCounter::ResultInt GetResult() { |
152 DCHECK(finished_); | 151 DCHECK(finished_); |
153 return result_; | 152 return result_; |
154 } | 153 } |
155 | 154 |
| 155 bool IsUpperLimit() { |
| 156 DCHECK(finished_); |
| 157 return is_upper_limit_; |
| 158 } |
| 159 |
156 private: | 160 private: |
157 enum CacheEntryCreationStep { | 161 enum CacheEntryCreationStep { |
158 GET_CACHE, | 162 GET_CACHE, |
159 CREATE_ENTRY, | 163 CREATE_ENTRY, |
160 WRITE_DATA, | 164 WRITE_DATA, |
161 DONE | 165 DONE |
162 }; | 166 }; |
163 CacheEntryCreationStep next_step_; | 167 CacheEntryCreationStep next_step_; |
164 content::StoragePartition* storage_partition_; | 168 content::StoragePartition* storage_partition_; |
165 disk_cache::Backend* backend_; | 169 disk_cache::Backend* backend_; |
166 disk_cache::Entry* entry_; | 170 disk_cache::Entry* entry_; |
167 | 171 |
168 std::unique_ptr<base::RunLoop> run_loop_; | 172 std::unique_ptr<base::RunLoop> run_loop_; |
169 | 173 |
170 bool finished_; | 174 bool finished_; |
171 browsing_data::BrowsingDataCounter::ResultInt result_; | 175 browsing_data::BrowsingDataCounter::ResultInt result_; |
| 176 bool is_upper_limit_; |
172 }; | 177 }; |
173 | 178 |
174 // Tests that for the empty cache, the result is zero. | 179 // Tests that for the empty cache, the result is zero. |
175 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Empty) { | 180 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Empty) { |
176 Profile* profile = browser()->profile(); | 181 Profile* profile = browser()->profile(); |
177 | 182 |
178 CacheCounter counter(profile); | 183 CacheCounter counter(profile); |
179 counter.Init( | 184 counter.Init( |
180 profile->GetPrefs(), | 185 profile->GetPrefs(), |
181 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 186 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 266 |
262 Profile* profile = browser()->profile(); | 267 Profile* profile = browser()->profile(); |
263 CacheCounter counter(profile); | 268 CacheCounter counter(profile); |
264 counter.Init( | 269 counter.Init( |
265 profile->GetPrefs(), | 270 profile->GetPrefs(), |
266 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); | 271 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); |
267 | 272 |
268 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 273 SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
269 WaitForIOThread(); | 274 WaitForIOThread(); |
270 browsing_data::BrowsingDataCounter::ResultInt result = GetResult(); | 275 browsing_data::BrowsingDataCounter::ResultInt result = GetResult(); |
| 276 EXPECT_TRUE(IsUpperLimit()); |
271 | 277 |
272 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 278 SetDeletionPeriodPref(browsing_data::LAST_DAY); |
273 WaitForIOThread(); | 279 WaitForIOThread(); |
274 EXPECT_EQ(result, GetResult()); | 280 EXPECT_EQ(result, GetResult()); |
| 281 EXPECT_TRUE(IsUpperLimit()); |
275 | 282 |
276 SetDeletionPeriodPref(browsing_data::LAST_WEEK); | 283 SetDeletionPeriodPref(browsing_data::LAST_WEEK); |
277 WaitForIOThread(); | 284 WaitForIOThread(); |
278 EXPECT_EQ(result, GetResult()); | 285 EXPECT_EQ(result, GetResult()); |
| 286 EXPECT_TRUE(IsUpperLimit()); |
279 | 287 |
280 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 288 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |
281 WaitForIOThread(); | 289 WaitForIOThread(); |
282 EXPECT_EQ(result, GetResult()); | 290 EXPECT_EQ(result, GetResult()); |
| 291 EXPECT_TRUE(IsUpperLimit()); |
283 | 292 |
284 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 293 SetDeletionPeriodPref(browsing_data::ALL_TIME); |
285 WaitForIOThread(); | 294 WaitForIOThread(); |
286 EXPECT_EQ(result, GetResult()); | 295 EXPECT_EQ(result, GetResult()); |
| 296 EXPECT_FALSE(IsUpperLimit()); |
287 } | 297 } |
288 | 298 |
289 } // namespace | 299 } // namespace |
OLD | NEW |