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