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

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 3 years, 10 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(storage::kQuotaErrorAbort, storage::QuotaSettings(), 0, 0,
55 0, false);
63 return; 56 return;
64 } 57 }
65 if (!task_for_get_usage_and_quota_.is_null()) 58 if (!task_for_get_usage_and_quota_.is_null())
66 task_for_get_usage_and_quota_.Run(); 59 task_for_get_usage_and_quota_.Run();
67 UsageAndQuota quota_and_usage(-1, GetUsage(), quota_, available_space_); 60 callback.Run(storage::kQuotaStatusOk, settings_, available_space_,
68 callback.Run(storage::kQuotaStatusOk, quota_and_usage); 61 available_space_ * 2, GetUsage(), true);
69 } 62 }
70 63
71 void GetEvictionOrigin(StorageType type, 64 void GetEvictionOrigin(StorageType type,
72 const std::set<GURL>& exceptions, 65 const std::set<GURL>& exceptions,
73 int64_t global_quota, 66 int64_t global_quota,
74 const storage::GetOriginCallback& callback) override { 67 const storage::GetOriginCallback& callback) override {
75 if (origin_order_.empty()) 68 if (origin_order_.empty())
76 callback.Run(GURL()); 69 callback.Run(GURL());
77 else 70 else
78 callback.Run(GURL(origin_order_.front())); 71 callback.Run(GURL(origin_order_.front()));
79 } 72 }
80 73
81 int64_t GetUsage() const { 74 int64_t GetUsage() const {
82 int64_t total_usage = 0; 75 int64_t total_usage = 0;
83 for (std::map<GURL, int64_t>::const_iterator p = origins_.begin(); 76 for (std::map<GURL, int64_t>::const_iterator p = origins_.begin();
84 p != origins_.end(); ++p) 77 p != origins_.end(); ++p)
85 total_usage += p->second; 78 total_usage += p->second;
86 return total_usage; 79 return total_usage;
87 } 80 }
88 81
89 void set_quota(int64_t quota) { quota_ = quota; } 82 const storage::QuotaSettings& settings() const { return settings_; }
83 void SetPoolSize(int64_t pool_size) {
84 settings_.pool_size = pool_size;
85 settings_.per_host_quota = pool_size / 5;
86 settings_.should_remain_available = pool_size / 5;
87 settings_.must_remain_available = pool_size / 100;
88 settings_.refresh_interval = base::TimeDelta::Max();
89 }
90 void set_available_space(int64_t available_space) { 90 void set_available_space(int64_t available_space) {
91 available_space_ = available_space; 91 available_space_ = available_space;
92 } 92 }
93 void set_task_for_get_usage_and_quota(const base::Closure& task) { 93 void set_task_for_get_usage_and_quota(const base::Closure& task) {
94 task_for_get_usage_and_quota_= task; 94 task_for_get_usage_and_quota_= task;
95 } 95 }
96 void set_error_on_evict_origin_data(bool error_on_evict_origin_data) { 96 void set_error_on_evict_origin_data(bool error_on_evict_origin_data) {
97 error_on_evict_origin_data_ = error_on_evict_origin_data; 97 error_on_evict_origin_data_ = error_on_evict_origin_data;
98 } 98 }
99 void set_error_on_get_usage_and_quota(bool error_on_get_usage_and_quota) { 99 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()) 123 if (origins_.find(origin) == origins_.end())
124 return -1; 124 return -1;
125 else 125 else
126 origin_usage = origins_[origin]; 126 origin_usage = origins_[origin];
127 127
128 origins_.erase(origin); 128 origins_.erase(origin);
129 origin_order_.remove(origin); 129 origin_order_.remove(origin);
130 return origin_usage; 130 return origin_usage;
131 } 131 }
132 132
133 int64_t quota_; 133 storage::QuotaSettings settings_;
134 int64_t available_space_; 134 int64_t available_space_;
135 std::list<GURL> origin_order_; 135 std::list<GURL> origin_order_;
136 std::map<GURL, int64_t> origins_; 136 std::map<GURL, int64_t> origins_;
137 bool error_on_evict_origin_data_; 137 bool error_on_evict_origin_data_;
138 bool error_on_get_usage_and_quota_; 138 bool error_on_get_usage_and_quota_;
139 139
140 base::Closure task_for_get_usage_and_quota_; 140 base::Closure task_for_get_usage_and_quota_;
141 }; 141 };
142 142
143 } // namespace 143 } // namespace
(...skipping 18 matching lines...) Expand all
162 base::RunLoop().RunUntilIdle(); 162 base::RunLoop().RunUntilIdle();
163 } 163 }
164 164
165 void TaskForRepeatedEvictionTest( 165 void TaskForRepeatedEvictionTest(
166 const std::pair<GURL, int64_t>& origin_to_be_added, 166 const std::pair<GURL, int64_t>& origin_to_be_added,
167 const GURL& origin_to_be_accessed, 167 const GURL& origin_to_be_accessed,
168 int expected_usage_after_first, 168 int expected_usage_after_first,
169 int expected_usage_after_second) { 169 int expected_usage_after_second) {
170 EXPECT_GE(4, num_get_usage_and_quota_for_eviction_); 170 EXPECT_GE(4, num_get_usage_and_quota_for_eviction_);
171 switch (num_get_usage_and_quota_for_eviction_) { 171 switch (num_get_usage_and_quota_for_eviction_) {
172 case 2: 172 case 2:
173 EXPECT_EQ(expected_usage_after_first, 173 EXPECT_EQ(expected_usage_after_first,
174 quota_eviction_handler()->GetUsage()); 174 quota_eviction_handler()->GetUsage());
175 if (!origin_to_be_added.first.is_empty()) 175 if (!origin_to_be_added.first.is_empty())
176 quota_eviction_handler()->AddOrigin(origin_to_be_added.first, 176 quota_eviction_handler()->AddOrigin(origin_to_be_added.first,
177 origin_to_be_added.second); 177 origin_to_be_added.second);
178 if (!origin_to_be_accessed.is_empty()) 178 if (!origin_to_be_accessed.is_empty())
179 quota_eviction_handler()->AccessOrigin(origin_to_be_accessed); 179 quota_eviction_handler()->AccessOrigin(origin_to_be_accessed);
180 break; 180 break;
181 case 3: 181 case 3:
182 EXPECT_EQ(expected_usage_after_second, 182 EXPECT_EQ(expected_usage_after_second,
183 quota_eviction_handler()->GetUsage()); 183 quota_eviction_handler()->GetUsage());
184 temporary_storage_evictor()->set_repeated_eviction(false); 184 temporary_storage_evictor()->timer_disabled_for_testing_ = true;
185 break; 185 break;
186 } 186 }
187 ++num_get_usage_and_quota_for_eviction_; 187 ++num_get_usage_and_quota_for_eviction_;
188 } 188 }
189 189
190 protected: 190 protected:
191 MockQuotaEvictionHandler* quota_eviction_handler() const { 191 MockQuotaEvictionHandler* quota_eviction_handler() const {
192 return static_cast<MockQuotaEvictionHandler*>( 192 return static_cast<MockQuotaEvictionHandler*>(
193 quota_eviction_handler_.get()); 193 quota_eviction_handler_.get());
194 } 194 }
195 195
196 QuotaTemporaryStorageEvictor* temporary_storage_evictor() const { 196 QuotaTemporaryStorageEvictor* temporary_storage_evictor() const {
197 return temporary_storage_evictor_.get(); 197 return temporary_storage_evictor_.get();
198 } 198 }
199 199
200 const QuotaTemporaryStorageEvictor::Statistics& statistics() const { 200 const QuotaTemporaryStorageEvictor::Statistics& statistics() const {
201 return temporary_storage_evictor()->statistics_; 201 return temporary_storage_evictor()->statistics_;
202 } 202 }
203 203
204 void set_repeated_eviction(bool repeated_eviction) const { 204 void disable_timer_for_testing() const {
205 return temporary_storage_evictor_->set_repeated_eviction(repeated_eviction); 205 temporary_storage_evictor_->timer_disabled_for_testing_ = true;
206 } 206 }
207 207
208 int num_get_usage_and_quota_for_eviction() const { 208 int num_get_usage_and_quota_for_eviction() const {
209 return num_get_usage_and_quota_for_eviction_; 209 return num_get_usage_and_quota_for_eviction_;
210 } 210 }
211 211
212 int64_t default_min_available_disk_space_to_start_eviction() const {
213 return 1000 * 1000 * 500;
214 }
215
216 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(
218 value);
219 }
220
221 void reset_min_available_disk_space_to_start_eviction() const {
222 temporary_storage_evictor_->
223 reset_min_available_disk_space_to_start_eviction();
224 }
225
226 base::MessageLoop message_loop_; 212 base::MessageLoop message_loop_;
227 std::unique_ptr<MockQuotaEvictionHandler> quota_eviction_handler_; 213 std::unique_ptr<MockQuotaEvictionHandler> quota_eviction_handler_;
228 std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; 214 std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_;
229
230 int num_get_usage_and_quota_for_eviction_; 215 int num_get_usage_and_quota_for_eviction_;
231
232 base::WeakPtrFactory<QuotaTemporaryStorageEvictorTest> weak_factory_; 216 base::WeakPtrFactory<QuotaTemporaryStorageEvictorTest> weak_factory_;
233
234 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest); 217 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest);
235 }; 218 };
236 219
237 TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) { 220 TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) {
238 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 3000); 221 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 3000);
239 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 200); 222 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 200);
240 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 500); 223 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 500);
241 quota_eviction_handler()->set_quota(4000); 224 quota_eviction_handler()->SetPoolSize(4000);
242 quota_eviction_handler()->set_available_space(1000000000); 225 quota_eviction_handler()->set_available_space(1000000000);
243 EXPECT_EQ(3000 + 200 + 500, quota_eviction_handler()->GetUsage()); 226 EXPECT_EQ(3000 + 200 + 500, quota_eviction_handler()->GetUsage());
244 set_repeated_eviction(false); 227 disable_timer_for_testing();
245 temporary_storage_evictor()->Start(); 228 temporary_storage_evictor()->Start();
246 base::RunLoop().RunUntilIdle(); 229 base::RunLoop().RunUntilIdle();
247 EXPECT_EQ(200 + 500, quota_eviction_handler()->GetUsage()); 230 EXPECT_EQ(200 + 500, quota_eviction_handler()->GetUsage());
248 231
249 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 232 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
250 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 233 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
251 EXPECT_EQ(1, statistics().num_evicted_origins); 234 EXPECT_EQ(1, statistics().num_evicted_origins);
252 EXPECT_EQ(1, statistics().num_eviction_rounds); 235 EXPECT_EQ(1, statistics().num_eviction_rounds);
253 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); 236 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
254 } 237 }
255 238
256 TEST_F(QuotaTemporaryStorageEvictorTest, MultipleEvictionTest) { 239 TEST_F(QuotaTemporaryStorageEvictorTest, MultipleEvictionTest) {
257 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 20); 240 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 20);
258 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 2900); 241 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 2900);
259 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450); 242 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450);
260 quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 400); 243 quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 400);
261 quota_eviction_handler()->set_quota(4000); 244 quota_eviction_handler()->SetPoolSize(4000);
262 quota_eviction_handler()->set_available_space(1000000000); 245 quota_eviction_handler()->set_available_space(1000000000);
263 EXPECT_EQ(20 + 2900 + 450 + 400, quota_eviction_handler()->GetUsage()); 246 EXPECT_EQ(20 + 2900 + 450 + 400, quota_eviction_handler()->GetUsage());
264 set_repeated_eviction(false); 247 disable_timer_for_testing();
265 temporary_storage_evictor()->Start(); 248 temporary_storage_evictor()->Start();
266 base::RunLoop().RunUntilIdle(); 249 base::RunLoop().RunUntilIdle();
267 EXPECT_EQ(450 + 400, quota_eviction_handler()->GetUsage()); 250 EXPECT_EQ(450 + 400, quota_eviction_handler()->GetUsage());
268 251
269 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 252 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
270 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 253 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
271 EXPECT_EQ(2, statistics().num_evicted_origins); 254 EXPECT_EQ(2, statistics().num_evicted_origins);
272 EXPECT_EQ(1, statistics().num_eviction_rounds); 255 EXPECT_EQ(1, statistics().num_eviction_rounds);
273 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); 256 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
274 } 257 }
275 258
276 TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) { 259 TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) {
277 const int64_t a_size = 400; 260 const int64_t a_size = 400;
278 const int64_t b_size = 150; 261 const int64_t b_size = 150;
279 const int64_t c_size = 120; 262 const int64_t c_size = 120;
280 const int64_t d_size = 292; 263 const int64_t d_size = 292;
281 const int64_t initial_total_size = a_size + b_size + c_size + d_size; 264 const int64_t initial_total_size = a_size + b_size + c_size + d_size;
282 const int64_t e_size = 275; 265 const int64_t e_size = 275;
283 266
284 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size); 267 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size);
285 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size); 268 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
286 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size); 269 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
287 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size); 270 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
288 quota_eviction_handler()->set_quota(1000); 271 quota_eviction_handler()->SetPoolSize(1000);
289 quota_eviction_handler()->set_available_space(1000000000); 272 quota_eviction_handler()->set_available_space(1000000000);
290 quota_eviction_handler()->set_task_for_get_usage_and_quota( 273 quota_eviction_handler()->set_task_for_get_usage_and_quota(
291 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest, 274 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
292 weak_factory_.GetWeakPtr(), 275 weak_factory_.GetWeakPtr(),
293 std::make_pair(GURL("http://www.e.com"), e_size), GURL(), 276 std::make_pair(GURL("http://www.e.com"), e_size), GURL(),
294 initial_total_size - d_size, 277 initial_total_size - d_size,
295 initial_total_size - d_size + e_size - c_size)); 278 initial_total_size - d_size + e_size - c_size));
296 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage()); 279 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
297 temporary_storage_evictor()->Start(); 280 temporary_storage_evictor()->Start();
298 base::RunLoop().RunUntilIdle(); 281 base::RunLoop().RunUntilIdle();
(...skipping 12 matching lines...) Expand all
311 const int64_t a_size = 400; 294 const int64_t a_size = 400;
312 const int64_t b_size = 150; 295 const int64_t b_size = 150;
313 const int64_t c_size = 120; 296 const int64_t c_size = 120;
314 const int64_t d_size = 292; 297 const int64_t d_size = 292;
315 const int64_t initial_total_size = a_size + b_size + c_size + d_size; 298 const int64_t initial_total_size = a_size + b_size + c_size + d_size;
316 299
317 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size); 300 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size);
318 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size); 301 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
319 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size); 302 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
320 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size); 303 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
321 quota_eviction_handler()->set_quota(1000); 304 quota_eviction_handler()->SetPoolSize(1000);
322 quota_eviction_handler()->set_available_space(1000000000); 305 quota_eviction_handler()->set_available_space(1000000000);
323 quota_eviction_handler()->set_task_for_get_usage_and_quota( 306 quota_eviction_handler()->set_task_for_get_usage_and_quota(
324 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest, 307 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
325 weak_factory_.GetWeakPtr(), std::make_pair(GURL(), 0), GURL(), 308 weak_factory_.GetWeakPtr(), std::make_pair(GURL(), 0), GURL(),
326 initial_total_size - d_size, initial_total_size - d_size)); 309 initial_total_size - d_size, initial_total_size - d_size));
327 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage()); 310 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
328 set_repeated_eviction(true); 311 // disable_timer_for_testing();
329 temporary_storage_evictor()->Start(); 312 temporary_storage_evictor()->Start();
330 base::RunLoop().RunUntilIdle(); 313 base::RunLoop().RunUntilIdle();
331 EXPECT_EQ(initial_total_size - d_size, quota_eviction_handler()->GetUsage()); 314 EXPECT_EQ(initial_total_size - d_size, quota_eviction_handler()->GetUsage());
332 EXPECT_EQ(4, num_get_usage_and_quota_for_eviction()); 315 EXPECT_EQ(4, num_get_usage_and_quota_for_eviction());
333 316
334 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 317 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
335 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 318 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
336 EXPECT_EQ(1, statistics().num_evicted_origins); 319 EXPECT_EQ(1, statistics().num_evicted_origins);
337 EXPECT_EQ(3, statistics().num_eviction_rounds); 320 EXPECT_EQ(3, statistics().num_eviction_rounds);
338 EXPECT_EQ(2, statistics().num_skipped_eviction_rounds); 321 EXPECT_EQ(2, statistics().num_skipped_eviction_rounds);
339 } 322 }
340 323
341 TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) { 324 TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
342 const int64_t a_size = 400; 325 const int64_t a_size = 400;
343 const int64_t b_size = 150; 326 const int64_t b_size = 150;
344 const int64_t c_size = 120; 327 const int64_t c_size = 120;
345 const int64_t d_size = 292; 328 const int64_t d_size = 292;
346 const int64_t initial_total_size = a_size + b_size + c_size + d_size; 329 const int64_t initial_total_size = a_size + b_size + c_size + d_size;
347 const int64_t e_size = 275; 330 const int64_t e_size = 275;
348 331
349 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size); 332 quota_eviction_handler()->AddOrigin(GURL("http://www.d.com"), d_size);
350 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size); 333 quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
351 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size); 334 quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
352 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size); 335 quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
353 quota_eviction_handler()->set_quota(1000); 336 quota_eviction_handler()->SetPoolSize(1000);
354 quota_eviction_handler()->set_available_space(1000000000); 337 quota_eviction_handler()->set_available_space(1000000000);
355 quota_eviction_handler()->set_task_for_get_usage_and_quota( 338 quota_eviction_handler()->set_task_for_get_usage_and_quota(
356 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest, 339 base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
357 weak_factory_.GetWeakPtr(), 340 weak_factory_.GetWeakPtr(),
358 std::make_pair(GURL("http://www.e.com"), e_size), 341 std::make_pair(GURL("http://www.e.com"), e_size),
359 GURL("http://www.c.com"), 342 GURL("http://www.c.com"),
360 initial_total_size - d_size, 343 initial_total_size - d_size,
361 initial_total_size - d_size + e_size - b_size)); 344 initial_total_size - d_size + e_size - b_size));
362 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage()); 345 EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
363 temporary_storage_evictor()->Start(); 346 temporary_storage_evictor()->Start();
364 base::RunLoop().RunUntilIdle(); 347 base::RunLoop().RunUntilIdle();
365 EXPECT_EQ(initial_total_size - d_size + e_size - b_size - a_size, 348 EXPECT_EQ(initial_total_size - d_size + e_size - b_size - a_size,
366 quota_eviction_handler()->GetUsage()); 349 quota_eviction_handler()->GetUsage());
367 EXPECT_EQ(5, num_get_usage_and_quota_for_eviction()); 350 EXPECT_EQ(5, num_get_usage_and_quota_for_eviction());
368 351
369 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 352 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
370 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 353 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
371 EXPECT_EQ(3, statistics().num_evicted_origins); 354 EXPECT_EQ(3, statistics().num_evicted_origins);
372 EXPECT_EQ(2, statistics().num_eviction_rounds); 355 EXPECT_EQ(2, statistics().num_eviction_rounds);
373 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); 356 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
374 } 357 }
375 358
376 TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) { 359 TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) {
377 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 414); 360 // If we're using so little that evicting all of it wouldn't
378 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450); 361 // do enough to alleviate a diskspace shortage, we don't evict.
379 quota_eviction_handler()->set_quota(10000); 362 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 10);
363 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 20);
364 quota_eviction_handler()->SetPoolSize(10000);
380 quota_eviction_handler()->set_available_space( 365 quota_eviction_handler()->set_available_space(
381 default_min_available_disk_space_to_start_eviction() - 350); 366 quota_eviction_handler()->settings().should_remain_available - 350);
382 EXPECT_EQ(414 + 450, quota_eviction_handler()->GetUsage()); 367 EXPECT_EQ(10 + 20, quota_eviction_handler()->GetUsage());
383 reset_min_available_disk_space_to_start_eviction(); 368 disable_timer_for_testing();
384 set_repeated_eviction(false);
385 temporary_storage_evictor()->Start(); 369 temporary_storage_evictor()->Start();
386 base::RunLoop().RunUntilIdle(); 370 base::RunLoop().RunUntilIdle();
387 EXPECT_EQ(414 + 450, quota_eviction_handler()->GetUsage()); 371 EXPECT_EQ(10 + 20, quota_eviction_handler()->GetUsage());
388 372
389 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 373 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
390 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 374 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
391 EXPECT_EQ(0, statistics().num_evicted_origins); 375 EXPECT_EQ(0, statistics().num_evicted_origins);
392 EXPECT_EQ(1, statistics().num_eviction_rounds); 376 EXPECT_EQ(1, statistics().num_eviction_rounds);
393 EXPECT_EQ(1, statistics().num_skipped_eviction_rounds); 377 EXPECT_EQ(1, statistics().num_skipped_eviction_rounds);
394 } 378 }
395 379
396 TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceEvictionTest) { 380 TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceEvictionTest) {
397 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 294); 381 quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 294);
398 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 120); 382 quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 120);
399 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 150); 383 quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 150);
400 quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 300); 384 quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 300);
401 quota_eviction_handler()->set_quota(10000); 385 quota_eviction_handler()->SetPoolSize(10000);
402 quota_eviction_handler()->set_available_space( 386 quota_eviction_handler()->set_available_space(
403 default_min_available_disk_space_to_start_eviction() - 350); 387 quota_eviction_handler()->settings().should_remain_available - 350);
404 EXPECT_EQ(294 + 120 + 150 + 300, quota_eviction_handler()->GetUsage()); 388 EXPECT_EQ(294 + 120 + 150 + 300, quota_eviction_handler()->GetUsage());
405 set_min_available_disk_space_to_start_eviction( 389 disable_timer_for_testing();
406 default_min_available_disk_space_to_start_eviction());
407 set_repeated_eviction(false);
408 temporary_storage_evictor()->Start(); 390 temporary_storage_evictor()->Start();
409 base::RunLoop().RunUntilIdle(); 391 base::RunLoop().RunUntilIdle();
410 EXPECT_EQ(150 + 300, quota_eviction_handler()->GetUsage()); 392 EXPECT_EQ(150 + 300, quota_eviction_handler()->GetUsage());
411 393
412 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); 394 EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
413 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); 395 EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
414 EXPECT_EQ(2, statistics().num_evicted_origins); 396 EXPECT_EQ(2, statistics().num_evicted_origins);
415 EXPECT_EQ(1, statistics().num_eviction_rounds); 397 EXPECT_EQ(1, statistics().num_eviction_rounds);
416 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); 398 EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); // FIXME?
417 } 399 }
418 400
419 } // namespace content 401 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/quota/quota_manager_unittest.cc ('k') | content/browser/quota/storage_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698