Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: content/browser/quota/quota_temporary_storage_evictor_unittest.cc

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "content/public/test/mock_storage_client.h" 17 #include "content/public/test/mock_storage_client.h"
18 #include "storage/browser/quota/quota_manager.h" 18 #include "storage/browser/quota/quota_manager.h"
19 #include "storage/browser/quota/quota_temporary_storage_evictor.h" 19 #include "storage/browser/quota/quota_temporary_storage_evictor.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 using storage::QuotaTemporaryStorageEvictor; 22 using storage::QuotaTemporaryStorageEvictor;
23 using storage::StorageType; 23 using storage::StorageType;
24 using storage::UsageAndQuota;
25 24
26 namespace content { 25 namespace content {
27 26
28 class QuotaTemporaryStorageEvictorTest; 27 class QuotaTemporaryStorageEvictorTest;
29 28
30 namespace { 29 namespace {
31 30
32 class MockQuotaEvictionHandler : public storage::QuotaEvictionHandler { 31 class MockQuotaEvictionHandler : public storage::QuotaEvictionHandler {
33 public: 32 public:
34 explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test) 33 explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test)
35 : quota_(0), 34 : available_space_(0),
36 available_space_(0),
37 error_on_evict_origin_data_(false), 35 error_on_evict_origin_data_(false),
38 error_on_get_usage_and_quota_(false) {} 36 error_on_get_usage_and_quota_(false) {}
39 37
40 void EvictOriginData(const GURL& origin, 38 void EvictOriginData(const GURL& origin,
41 StorageType type, 39 StorageType type,
42 const EvictOriginDataCallback& callback) override { 40 const storage::StatusCallback& callback) override {
43 if (error_on_evict_origin_data_) { 41 if (error_on_evict_origin_data_) {
44 callback.Run(storage::kQuotaErrorInvalidModification); 42 callback.Run(storage::kQuotaErrorInvalidModification);
45 return; 43 return;
46 } 44 }
47 int64_t origin_usage = EnsureOriginRemoved(origin); 45 int64_t origin_usage = EnsureOriginRemoved(origin);
48 if (origin_usage >= 0) 46 if (origin_usage >= 0)
49 available_space_ += origin_usage; 47 available_space_ += origin_usage;
50 callback.Run(storage::kQuotaStatusOk); 48 callback.Run(storage::kQuotaStatusOk);
51 } 49 }
52 50
53 void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) override { 51 void GetEvictionRoundInfo(
54 uint64_t available = static_cast<uint64_t>(available_space_); 52 const EvictionRoundInfoCallback& callback) override {
55 uint64_t total = (1024 * 1024 * 1024) + (2 * available); // 1G plus some.
56 callback.Run(true, available, total);
57 }
58
59 void GetUsageAndQuotaForEviction(
60 const UsageAndQuotaCallback& callback) override {
61 if (error_on_get_usage_and_quota_) { 53 if (error_on_get_usage_and_quota_) {
62 callback.Run(storage::kQuotaErrorInvalidAccess, UsageAndQuota()); 54 callback.Run(
55 storage::kQuotaErrorAbort,
56 storage::TemporaryStorageConfiguration(), 0, 0,
57 0, false);
63 return; 58 return;
64 } 59 }
65 if (!task_for_get_usage_and_quota_.is_null()) 60 if (!task_for_get_usage_and_quota_.is_null())
66 task_for_get_usage_and_quota_.Run(); 61 task_for_get_usage_and_quota_.Run();
67 UsageAndQuota quota_and_usage(-1, GetUsage(), quota_, available_space_); 62 callback.Run(
68 callback.Run(storage::kQuotaStatusOk, quota_and_usage); 63 storage::kQuotaStatusOk,
64 config_, available_space_, available_space_ * 2,
65 GetUsage(), true);
69 } 66 }
70 67
71 void GetEvictionOrigin(StorageType type, 68 void GetEvictionOrigin(StorageType type,
72 const std::set<GURL>& exceptions, 69 const std::set<GURL>& exceptions,
73 int64_t global_quota, 70 int64_t global_quota,
74 const storage::GetOriginCallback& callback) override { 71 const storage::GetOriginCallback& callback) override {
75 if (origin_order_.empty()) 72 if (origin_order_.empty())
76 callback.Run(GURL()); 73 callback.Run(GURL());
77 else 74 else
78 callback.Run(GURL(origin_order_.front())); 75 callback.Run(GURL(origin_order_.front()));
79 } 76 }
80 77
81 int64_t GetUsage() const { 78 int64_t GetUsage() const {
82 int64_t total_usage = 0; 79 int64_t total_usage = 0;
83 for (std::map<GURL, int64_t>::const_iterator p = origins_.begin(); 80 for (std::map<GURL, int64_t>::const_iterator p = origins_.begin();
84 p != origins_.end(); ++p) 81 p != origins_.end(); ++p)
85 total_usage += p->second; 82 total_usage += p->second;
86 return total_usage; 83 return total_usage;
87 } 84 }
88 85
89 void set_quota(int64_t quota) { quota_ = quota; } 86 void SetPoolSize(int64_t pool_size) {
87 config_.pool_size = pool_size;
88 config_.per_host_quota = pool_size / 5;
89 config_.must_remain_available = pool_size / 5;
90 config_.refresh_interval = base::TimeDelta::Max();
91 }
90 void set_available_space(int64_t available_space) { 92 void set_available_space(int64_t available_space) {
91 available_space_ = available_space; 93 available_space_ = available_space;
92 } 94 }
93 void set_task_for_get_usage_and_quota(const base::Closure& task) { 95 void set_task_for_get_usage_and_quota(const base::Closure& task) {
94 task_for_get_usage_and_quota_= task; 96 task_for_get_usage_and_quota_= task;
95 } 97 }
96 void set_error_on_evict_origin_data(bool error_on_evict_origin_data) { 98 void set_error_on_evict_origin_data(bool error_on_evict_origin_data) {
97 error_on_evict_origin_data_ = error_on_evict_origin_data; 99 error_on_evict_origin_data_ = error_on_evict_origin_data;
98 } 100 }
99 void set_error_on_get_usage_and_quota(bool error_on_get_usage_and_quota) { 101 void set_error_on_get_usage_and_quota(bool error_on_get_usage_and_quota) {
(...skipping 23 matching lines...) Expand all
123 if (origins_.find(origin) == origins_.end()) 125 if (origins_.find(origin) == origins_.end())
124 return -1; 126 return -1;
125 else 127 else
126 origin_usage = origins_[origin]; 128 origin_usage = origins_[origin];
127 129
128 origins_.erase(origin); 130 origins_.erase(origin);
129 origin_order_.remove(origin); 131 origin_order_.remove(origin);
130 return origin_usage; 132 return origin_usage;
131 } 133 }
132 134
133 int64_t quota_; 135 storage::TemporaryStorageConfiguration config_;
134 int64_t available_space_; 136 int64_t available_space_;
135 std::list<GURL> origin_order_; 137 std::list<GURL> origin_order_;
136 std::map<GURL, int64_t> origins_; 138 std::map<GURL, int64_t> origins_;
137 bool error_on_evict_origin_data_; 139 bool error_on_evict_origin_data_;
138 bool error_on_get_usage_and_quota_; 140 bool error_on_get_usage_and_quota_;
139 141
140 base::Closure task_for_get_usage_and_quota_; 142 base::Closure task_for_get_usage_and_quota_;
141 }; 143 };
142 144
143 } // namespace 145 } // namespace
(...skipping 18 matching lines...) Expand all
162 base::RunLoop().RunUntilIdle(); 164 base::RunLoop().RunUntilIdle();
163 } 165 }
164 166
165 void TaskForRepeatedEvictionTest( 167 void TaskForRepeatedEvictionTest(
166 const std::pair<GURL, int64_t>& origin_to_be_added, 168 const std::pair<GURL, int64_t>& origin_to_be_added,
167 const GURL& origin_to_be_accessed, 169 const GURL& origin_to_be_accessed,
168 int expected_usage_after_first, 170 int expected_usage_after_first,
169 int expected_usage_after_second) { 171 int expected_usage_after_second) {
170 EXPECT_GE(4, num_get_usage_and_quota_for_eviction_); 172 EXPECT_GE(4, num_get_usage_and_quota_for_eviction_);
171 switch (num_get_usage_and_quota_for_eviction_) { 173 switch (num_get_usage_and_quota_for_eviction_) {
172 case 2: 174 case 2:
173 EXPECT_EQ(expected_usage_after_first, 175 EXPECT_EQ(expected_usage_after_first,
174 quota_eviction_handler()->GetUsage()); 176 quota_eviction_handler()->GetUsage());
175 if (!origin_to_be_added.first.is_empty()) 177 if (!origin_to_be_added.first.is_empty())
176 quota_eviction_handler()->AddOrigin(origin_to_be_added.first, 178 quota_eviction_handler()->AddOrigin(origin_to_be_added.first,
177 origin_to_be_added.second); 179 origin_to_be_added.second);
178 if (!origin_to_be_accessed.is_empty()) 180 if (!origin_to_be_accessed.is_empty())
179 quota_eviction_handler()->AccessOrigin(origin_to_be_accessed); 181 quota_eviction_handler()->AccessOrigin(origin_to_be_accessed);
180 break; 182 break;
181 case 3: 183 case 3:
182 EXPECT_EQ(expected_usage_after_second, 184 EXPECT_EQ(expected_usage_after_second,
183 quota_eviction_handler()->GetUsage()); 185 quota_eviction_handler()->GetUsage());
184 temporary_storage_evictor()->set_repeated_eviction(false); 186 temporary_storage_evictor()->timer_disabled_for_testing_ = true;
185 break; 187 break;
186 } 188 }
187 ++num_get_usage_and_quota_for_eviction_; 189 ++num_get_usage_and_quota_for_eviction_;
188 } 190 }
189 191
190 protected: 192 protected:
191 MockQuotaEvictionHandler* quota_eviction_handler() const { 193 MockQuotaEvictionHandler* quota_eviction_handler() const {
192 return static_cast<MockQuotaEvictionHandler*>( 194 return static_cast<MockQuotaEvictionHandler*>(
193 quota_eviction_handler_.get()); 195 quota_eviction_handler_.get());
194 } 196 }
195 197
196 QuotaTemporaryStorageEvictor* temporary_storage_evictor() const { 198 QuotaTemporaryStorageEvictor* temporary_storage_evictor() const {
197 return temporary_storage_evictor_.get(); 199 return temporary_storage_evictor_.get();
198 } 200 }
199 201
200 const QuotaTemporaryStorageEvictor::Statistics& statistics() const { 202 const QuotaTemporaryStorageEvictor::Statistics& statistics() const {
201 return temporary_storage_evictor()->statistics_; 203 return temporary_storage_evictor()->statistics_;
202 } 204 }
203 205
204 void set_repeated_eviction(bool repeated_eviction) const { 206 void disable_timer_for_testing() const {
205 return temporary_storage_evictor_->set_repeated_eviction(repeated_eviction); 207 temporary_storage_evictor_->timer_disabled_for_testing_ = true;
206 } 208 }
207 209
208 int num_get_usage_and_quota_for_eviction() const { 210 int num_get_usage_and_quota_for_eviction() const {
209 return num_get_usage_and_quota_for_eviction_; 211 return num_get_usage_and_quota_for_eviction_;
210 } 212 }
211 213
212 int64_t default_min_available_disk_space_to_start_eviction() const { 214 int64_t default_min_available_disk_space_to_start_eviction() const {
213 return 1000 * 1000 * 500; 215 return 1000 * 1000 * 500;
214 } 216 }
215 217
216 void set_min_available_disk_space_to_start_eviction(int64_t value) const { 218 void set_min_available_disk_space_to_start_eviction(int64_t value) const {
217 temporary_storage_evictor_->set_min_available_disk_space_to_start_eviction( 219 //temporary_storage_evictor_->set_min_available_disk_space_to_start_eviction (
218 value); 220 // value);
219 } 221 }
220 222
221 void reset_min_available_disk_space_to_start_eviction() const { 223 void reset_min_available_disk_space_to_start_eviction() const {
222 temporary_storage_evictor_-> 224 //temporary_storage_evictor_->
223 reset_min_available_disk_space_to_start_eviction(); 225 // reset_min_available_disk_space_to_start_eviction();
224 } 226 }
225 227
226 base::MessageLoop message_loop_; 228 base::MessageLoop message_loop_;
227 std::unique_ptr<MockQuotaEvictionHandler> quota_eviction_handler_; 229 std::unique_ptr<MockQuotaEvictionHandler> quota_eviction_handler_;
228 std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; 230 std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_;
229 231
230 int num_get_usage_and_quota_for_eviction_; 232 int num_get_usage_and_quota_for_eviction_;
231 233
232 base::WeakPtrFactory<QuotaTemporaryStorageEvictorTest> weak_factory_; 234 base::WeakPtrFactory<QuotaTemporaryStorageEvictorTest> weak_factory_;
233 235
234 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest); 236 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest);
235 }; 237 };
236 238
237 TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) { 239 TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) {
238 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 3000); 240 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 3000);
239 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 200); 241 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 200);
240 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 500); 242 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 500);
241 quota_eviction_handler()->set_quota(4000); 243 quota_eviction_handler()->SetPoolSize(4000);
242 quota_eviction_handler()->set_available_space(1000000000); 244 quota_eviction_handler()->set_available_space(1000000000);
243 EXPECT_EQ(3000 + 200 + 500, quota_eviction_handler()->GetUsage()); 245 EXPECT_EQ(3000 + 200 + 500, quota_eviction_handler()->GetUsage());
244 set_repeated_eviction(false); 246 disable_timer_for_testing();
245 temporary_storage_evictor()->Start(); 247 temporary_storage_evictor()->Start();
246 base::RunLoop().RunUntilIdle(); 248 base::RunLoop().RunUntilIdle();
247 EXPECT_EQ(200 + 500, quota_eviction_handler()->GetUsage()); 249 EXPECT_EQ(200 + 500, quota_eviction_handler()->GetUsage());
248 250
249 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 251 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
250 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 252 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
251 EXPECT_EQ(1, statistics().num_evicted_origins); 253 EXPECT_EQ(1, statistics().num_evicted_origins);
252 EXPECT_EQ(1, statistics().num_eviction_rounds); 254 EXPECT_EQ(1, statistics().num_eviction_rounds);
253 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); 255 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
254 } 256 }
255 257
256 TEST_F(QuotaTemporaryStorageEvictorTest, MultipleEvictionTest) { 258 TEST_F(QuotaTemporaryStorageEvictorTest, MultipleEvictionTest) {
257 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 20); 259 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 20);
258 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 2900); 260 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 2900);
259 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450); 261 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450);
260 quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 400); 262 quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 400);
261 quota_eviction_handler()->set_quota(4000); 263 quota_eviction_handler()->SetPoolSize(4000);
262 quota_eviction_handler()->set_available_space(1000000000); 264 quota_eviction_handler()->set_available_space(1000000000);
263 EXPECT_EQ(20 + 2900 + 450 + 400, quota_eviction_handler()->GetUsage()); 265 EXPECT_EQ(20 + 2900 + 450 + 400, quota_eviction_handler()->GetUsage());
264 set_repeated_eviction(false); 266 disable_timer_for_testing();
265 temporary_storage_evictor()->Start(); 267 temporary_storage_evictor()->Start();
266 base::RunLoop().RunUntilIdle(); 268 base::RunLoop().RunUntilIdle();
267 EXPECT_EQ(450 + 400, quota_eviction_handler()->GetUsage()); 269 EXPECT_EQ(450 + 400, quota_eviction_handler()->GetUsage());
268 270
269 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 271 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
270 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 272 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
271 EXPECT_EQ(2, statistics().num_evicted_origins); 273 EXPECT_EQ(2, statistics().num_evicted_origins);
272 EXPECT_EQ(1, statistics().num_eviction_rounds); 274 EXPECT_EQ(1, statistics().num_eviction_rounds);
273 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); 275 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
274 } 276 }
275 277
276 TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) { 278 TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) {
277 const int64_t a_size = 400; 279 const int64_t a_size = 400;
278 const int64_t b_size = 150; 280 const int64_t b_size = 150;
279 const int64_t c_size = 120; 281 const int64_t c_size = 120;
280 const int64_t d_size = 292; 282 const int64_t d_size = 292;
281 const int64_t initial_total_size = a_size + b_size + c_size + d_size; 283 const int64_t initial_total_size = a_size + b_size + c_size + d_size;
282 const int64_t e_size = 275; 284 const int64_t e_size = 275;
283 285
284 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size); 286 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size);
285 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size); 287 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
286 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size); 288 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
287 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size); 289 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
288 quota_eviction_handler()->set_quota(1000); 290 quota_eviction_handler()->SetPoolSize(1000);
289 quota_eviction_handler()->set_available_space(1000000000); 291 quota_eviction_handler()->set_available_space(1000000000);
290 quota_eviction_handler()->set_task_for_get_usage_and_quota( 292 quota_eviction_handler()->set_task_for_get_usage_and_quota(
291 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest, 293 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
292 weak_factory_.GetWeakPtr(), 294 weak_factory_.GetWeakPtr(),
293 std::make_pair(GURL("http://www.e.com"), e_size), GURL(), 295 std::make_pair(GURL("http://www.e.com"), e_size), GURL(),
294 initial_total_size - d_size, 296 initial_total_size - d_size,
295 initial_total_size - d_size + e_size - c_size)); 297 initial_total_size - d_size + e_size - c_size));
296 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage()); 298 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
297 temporary_storage_evictor()->Start(); 299 temporary_storage_evictor()->Start();
298 base::RunLoop().RunUntilIdle(); 300 base::RunLoop().RunUntilIdle();
(...skipping 12 matching lines...) Expand all
311 const int64_t a_size = 400; 313 const int64_t a_size = 400;
312 const int64_t b_size = 150; 314 const int64_t b_size = 150;
313 const int64_t c_size = 120; 315 const int64_t c_size = 120;
314 const int64_t d_size = 292; 316 const int64_t d_size = 292;
315 const int64_t initial_total_size = a_size + b_size + c_size + d_size; 317 const int64_t initial_total_size = a_size + b_size + c_size + d_size;
316 318
317 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size); 319 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size);
318 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size); 320 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
319 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size); 321 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
320 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size); 322 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
321 quota_eviction_handler()->set_quota(1000); 323 quota_eviction_handler()->SetPoolSize(1000);
322 quota_eviction_handler()->set_available_space(1000000000); 324 quota_eviction_handler()->set_available_space(1000000000);
323 quota_eviction_handler()->set_task_for_get_usage_and_quota( 325 quota_eviction_handler()->set_task_for_get_usage_and_quota(
324 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest, 326 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
325 weak_factory_.GetWeakPtr(), std::make_pair(GURL(), 0), GURL(), 327 weak_factory_.GetWeakPtr(), std::make_pair(GURL(), 0), GURL(),
326 initial_total_size - d_size, initial_total_size - d_size)); 328 initial_total_size - d_size, initial_total_size - d_size));
327 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage()); 329 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
328 set_repeated_eviction(true); 330 //disable_timer_for_testing();
329 temporary_storage_evictor()->Start(); 331 temporary_storage_evictor()->Start();
330 base::RunLoop().RunUntilIdle(); 332 base::RunLoop().RunUntilIdle();
331 EXPECT_EQ(initial_total_size - d_size, quota_eviction_handler()->GetUsage()); 333 EXPECT_EQ(initial_total_size - d_size, quota_eviction_handler()->GetUsage());
332 EXPECT_EQ(4, num_get_usage_and_quota_for_eviction()); 334 EXPECT_EQ(4, num_get_usage_and_quota_for_eviction());
333 335
334 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 336 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
335 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 337 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
336 EXPECT_EQ(1, statistics().num_evicted_origins); 338 EXPECT_EQ(1, statistics().num_evicted_origins);
337 EXPECT_EQ(3, statistics().num_eviction_rounds); 339 EXPECT_EQ(3, statistics().num_eviction_rounds);
338 EXPECT_EQ(2, statistics().num_skipped_eviction_rounds); 340 EXPECT_EQ(2, statistics().num_skipped_eviction_rounds);
339 } 341 }
340 342
341 TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) { 343 TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
342 const int64_t a_size = 400; 344 const int64_t a_size = 400;
343 const int64_t b_size = 150; 345 const int64_t b_size = 150;
344 const int64_t c_size = 120; 346 const int64_t c_size = 120;
345 const int64_t d_size = 292; 347 const int64_t d_size = 292;
346 const int64_t initial_total_size = a_size + b_size + c_size + d_size; 348 const int64_t initial_total_size = a_size + b_size + c_size + d_size;
347 const int64_t e_size = 275; 349 const int64_t e_size = 275;
348 350
349 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size); 351 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size);
350 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size); 352 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
351 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size); 353 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
352 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size); 354 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
353 quota_eviction_handler()->set_quota(1000); 355 quota_eviction_handler()->SetPoolSize(1000);
354 quota_eviction_handler()->set_available_space(1000000000); 356 quota_eviction_handler()->set_available_space(1000000000);
355 quota_eviction_handler()->set_task_for_get_usage_and_quota( 357 quota_eviction_handler()->set_task_for_get_usage_and_quota(
356 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest, 358 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
357 weak_factory_.GetWeakPtr(), 359 weak_factory_.GetWeakPtr(),
358 std::make_pair(GURL("http://www.e.com"), e_size), 360 std::make_pair(GURL("http://www.e.com"), e_size),
359 GURL("http://www.c.com"), 361 GURL("http://www.c.com"),
360 initial_total_size - d_size, 362 initial_total_size - d_size,
361 initial_total_size - d_size + e_size - b_size)); 363 initial_total_size - d_size + e_size - b_size));
362 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage()); 364 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
363 temporary_storage_evictor()->Start(); 365 temporary_storage_evictor()->Start();
364 base::RunLoop().RunUntilIdle(); 366 base::RunLoop().RunUntilIdle();
365 EXPECT_EQ(initial_total_size - d_size + e_size - b_size - a_size, 367 EXPECT_EQ(initial_total_size - d_size + e_size - b_size - a_size,
366 quota_eviction_handler()->GetUsage()); 368 quota_eviction_handler()->GetUsage());
367 EXPECT_EQ(5, num_get_usage_and_quota_for_eviction()); 369 EXPECT_EQ(5, num_get_usage_and_quota_for_eviction());
368 370
369 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 371 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
370 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 372 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
371 EXPECT_EQ(3, statistics().num_evicted_origins); 373 EXPECT_EQ(3, statistics().num_evicted_origins);
372 EXPECT_EQ(2, statistics().num_eviction_rounds); 374 EXPECT_EQ(2, statistics().num_eviction_rounds);
373 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); 375 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
374 } 376 }
375 377
376 TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) { 378 TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) {
377 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 414); 379 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 414);
378 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450); 380 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450);
379 quota_eviction_handler()->set_quota(10000); 381 quota_eviction_handler()->SetPoolSize(10000);
380 quota_eviction_handler()->set_available_space( 382 quota_eviction_handler()->set_available_space(
381 default_min_available_disk_space_to_start_eviction() - 350); 383 default_min_available_disk_space_to_start_eviction() - 350);
382 EXPECT_EQ(414 + 450, quota_eviction_handler()->GetUsage()); 384 EXPECT_EQ(414 + 450, quota_eviction_handler()->GetUsage());
383 reset_min_available_disk_space_to_start_eviction(); 385 reset_min_available_disk_space_to_start_eviction();
384 set_repeated_eviction(false); 386 disable_timer_for_testing();
385 temporary_storage_evictor()->Start(); 387 temporary_storage_evictor()->Start();
386 base::RunLoop().RunUntilIdle(); 388 base::RunLoop().RunUntilIdle();
387 EXPECT_EQ(414 + 450, quota_eviction_handler()->GetUsage()); 389 EXPECT_EQ(414 + 450, quota_eviction_handler()->GetUsage());
388 390
389 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 391 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
390 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 392 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
391 EXPECT_EQ(0, statistics().num_evicted_origins); 393 EXPECT_EQ(0, statistics().num_evicted_origins);
392 EXPECT_EQ(1, statistics().num_eviction_rounds); 394 EXPECT_EQ(1, statistics().num_eviction_rounds);
393 EXPECT_EQ(1, statistics().num_skipped_eviction_rounds); 395 EXPECT_EQ(1, statistics().num_skipped_eviction_rounds);
394 } 396 }
395 397
396 TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceEvictionTest) { 398 TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceEvictionTest) {
397 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 294); 399 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 294);
398 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 120); 400 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 120);
399 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 150); 401 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 150);
400 quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 300); 402 quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 300);
401 quota_eviction_handler()->set_quota(10000); 403 quota_eviction_handler()->SetPoolSize(10000);
402 quota_eviction_handler()->set_available_space( 404 quota_eviction_handler()->set_available_space(
403 default_min_available_disk_space_to_start_eviction() - 350); 405 default_min_available_disk_space_to_start_eviction() - 350);
404 EXPECT_EQ(294 + 120 + 150 + 300, quota_eviction_handler()->GetUsage()); 406 EXPECT_EQ(294 + 120 + 150 + 300, quota_eviction_handler()->GetUsage());
405 set_min_available_disk_space_to_start_eviction( 407 set_min_available_disk_space_to_start_eviction(
406 default_min_available_disk_space_to_start_eviction()); 408 default_min_available_disk_space_to_start_eviction());
407 set_repeated_eviction(false); 409 disable_timer_for_testing();
408 temporary_storage_evictor()->Start(); 410 temporary_storage_evictor()->Start();
409 base::RunLoop().RunUntilIdle(); 411 base::RunLoop().RunUntilIdle();
410 EXPECT_EQ(150 + 300, quota_eviction_handler()->GetUsage()); 412 EXPECT_EQ(150 + 300, quota_eviction_handler()->GetUsage());
411 413
412 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 414 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
413 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 415 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
414 EXPECT_EQ(2, statistics().num_evicted_origins); 416 EXPECT_EQ(2, statistics().num_evicted_origins);
415 EXPECT_EQ(1, statistics().num_eviction_rounds); 417 EXPECT_EQ(1, statistics().num_eviction_rounds);
416 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); 418 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
417 } 419 }
418 420
419 } // namespace content 421 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698