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

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

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