OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/offline_pages/offline_page_storage_manager.h" | 5 #include "components/offline_pages/offline_page_storage_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 namespace offline_pages { | 28 namespace offline_pages { |
29 | 29 |
30 namespace { | 30 namespace { |
31 const GURL kTestUrl("http://example.com"); | 31 const GURL kTestUrl("http://example.com"); |
32 const base::FilePath::CharType kFilePath[] = FILE_PATH_LITERAL("/data"); | 32 const base::FilePath::CharType kFilePath[] = FILE_PATH_LITERAL("/data"); |
33 const int64_t kTestFileSize = 1 << 19; // Make a page 512KB. | 33 const int64_t kTestFileSize = 1 << 19; // Make a page 512KB. |
34 const int64_t kFreeSpaceNormal = 100 * (1 << 20); | 34 const int64_t kFreeSpaceNormal = 100 * (1 << 20); |
35 | 35 |
36 enum TestOptions { | 36 enum TestOptions { |
37 DEFAULT = 1 << 0, | 37 DEFAULT = 1 << 0, |
38 EXPIRE_FAILURE = 1 << 1, | 38 DELETE_FAILURE = 1 << 1, |
39 DELETE_FAILURE = 1 << 2, | |
40 EXPIRE_AND_DELETE_FAILURES = EXPIRE_FAILURE | DELETE_FAILURE, | |
41 }; | 39 }; |
42 | 40 |
43 struct PageSettings { | 41 struct PageSettings { |
44 std::string name_space; | 42 std::string name_space; |
45 int fresh_pages_count; | 43 int fresh_pages_count; |
46 int expired_pages_count; | 44 int expired_pages_count; |
47 }; | 45 }; |
48 } // namespace | 46 } // namespace |
49 | 47 |
50 class OfflinePageTestModel : public OfflinePageModelImpl { | 48 class OfflinePageTestModel : public OfflinePageModelImpl { |
(...skipping 14 matching lines...) Expand all Loading... |
65 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override { | 63 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override { |
66 MultipleOfflinePageItemResult pages; | 64 MultipleOfflinePageItemResult pages; |
67 for (const auto& id_page_pair : pages_) | 65 for (const auto& id_page_pair : pages_) |
68 pages.push_back(id_page_pair.second); | 66 pages.push_back(id_page_pair.second); |
69 callback.Run(pages); | 67 callback.Run(pages); |
70 } | 68 } |
71 | 69 |
72 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, | 70 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, |
73 const DeletePageCallback& callback) override; | 71 const DeletePageCallback& callback) override; |
74 | 72 |
75 void ExpirePages(const std::vector<int64_t>& offline_ids, | |
76 const base::Time& expiration_time, | |
77 const base::Callback<void(bool)>& callback) override; | |
78 | |
79 void AddPages(const PageSettings& setting); | 73 void AddPages(const PageSettings& setting); |
80 | 74 |
| 75 // The |removed_pages_| would not be cleared in during a test, so the number |
| 76 // of removed pages will be accumulative in a single test case. |
81 const std::vector<OfflinePageItem>& GetRemovedPages() { | 77 const std::vector<OfflinePageItem>& GetRemovedPages() { |
82 return removed_pages_; | 78 return removed_pages_; |
83 } | 79 } |
84 | 80 |
85 int64_t GetTotalSize() const; | 81 int64_t GetTotalSize() const; |
86 | 82 |
87 base::SimpleTestClock* clock() { return clock_; } | 83 base::SimpleTestClock* clock() { return clock_; } |
88 | 84 |
89 private: | 85 private: |
90 std::map<int64_t, OfflinePageItem> pages_; | 86 std::map<int64_t, OfflinePageItem> pages_; |
91 | 87 |
92 std::vector<OfflinePageItem> removed_pages_; | 88 std::vector<OfflinePageItem> removed_pages_; |
93 | 89 |
94 std::unique_ptr<ClientPolicyController> policy_controller_; | 90 std::unique_ptr<ClientPolicyController> policy_controller_; |
95 | 91 |
96 base::SimpleTestClock* clock_; | 92 base::SimpleTestClock* clock_; |
97 | 93 |
98 TestOptions options_; | 94 TestOptions options_; |
99 | 95 |
100 int64_t next_offline_id_; | 96 int64_t next_offline_id_; |
101 }; | 97 }; |
102 | 98 |
103 void OfflinePageTestModel::ExpirePages( | |
104 const std::vector<int64_t>& offline_ids, | |
105 const base::Time& expiration_time, | |
106 const base::Callback<void(bool)>& callback) { | |
107 for (const auto id : offline_ids) | |
108 pages_.at(id).expiration_time = expiration_time; | |
109 if (options_ & TestOptions::EXPIRE_FAILURE) { | |
110 callback.Run(false); | |
111 return; | |
112 } | |
113 callback.Run(true); | |
114 } | |
115 | |
116 void OfflinePageTestModel::DeletePagesByOfflineId( | 99 void OfflinePageTestModel::DeletePagesByOfflineId( |
117 const std::vector<int64_t>& offline_ids, | 100 const std::vector<int64_t>& offline_ids, |
118 const DeletePageCallback& callback) { | 101 const DeletePageCallback& callback) { |
119 if (options_ & TestOptions::DELETE_FAILURE) { | 102 if (options_ & TestOptions::DELETE_FAILURE) { |
120 callback.Run(DeletePageResult::STORE_FAILURE); | 103 callback.Run(DeletePageResult::STORE_FAILURE); |
121 return; | 104 return; |
122 } | 105 } |
123 for (const auto id : offline_ids) { | 106 for (const auto id : offline_ids) { |
124 removed_pages_.push_back(pages_.at(id)); | 107 removed_pages_.push_back(pages_.at(id)); |
125 pages_.erase(id); | 108 pages_.erase(id); |
126 } | 109 } |
127 callback.Run(DeletePageResult::SUCCESS); | 110 callback.Run(DeletePageResult::SUCCESS); |
128 } | 111 } |
129 | 112 |
130 int64_t OfflinePageTestModel::GetTotalSize() const { | 113 int64_t OfflinePageTestModel::GetTotalSize() const { |
131 int64_t res = 0; | 114 int64_t res = 0; |
132 for (const auto& id_page_pair : pages_) { | 115 for (const auto& id_page_pair : pages_) |
133 if (!id_page_pair.second.IsExpired()) | 116 res += id_page_pair.second.file_size; |
134 res += id_page_pair.second.file_size; | |
135 } | |
136 return res; | 117 return res; |
137 } | 118 } |
138 | 119 |
139 OfflinePageTestModel::~OfflinePageTestModel() {} | 120 OfflinePageTestModel::~OfflinePageTestModel() {} |
140 | 121 |
141 void OfflinePageTestModel::AddPages(const PageSettings& setting) { | 122 void OfflinePageTestModel::AddPages(const PageSettings& setting) { |
142 std::string name_space = setting.name_space; | 123 std::string name_space = setting.name_space; |
143 int fresh_pages_count = setting.fresh_pages_count; | 124 int fresh_pages_count = setting.fresh_pages_count; |
144 int expired_pages_count = setting.expired_pages_count; | 125 int expired_pages_count = setting.expired_pages_count; |
145 base::Time now = clock()->Now(); | 126 base::Time now = clock()->Now(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 248 } |
268 | 249 |
269 TEST_F(OfflinePageStorageManagerTest, TestClearPagesLessThanLimit) { | 250 TEST_F(OfflinePageStorageManagerTest, TestClearPagesLessThanLimit) { |
270 Initialize(std::vector<PageSettings>( | 251 Initialize(std::vector<PageSettings>( |
271 {{kBookmarkNamespace, 1, 1}, {kLastNNamespace, 1, 1}})); | 252 {{kBookmarkNamespace, 1, 1}, {kLastNNamespace, 1, 1}})); |
272 clock()->Advance(base::TimeDelta::FromMinutes(30)); | 253 clock()->Advance(base::TimeDelta::FromMinutes(30)); |
273 TryClearPages(); | 254 TryClearPages(); |
274 EXPECT_EQ(2, last_cleared_page_count()); | 255 EXPECT_EQ(2, last_cleared_page_count()); |
275 EXPECT_EQ(1, total_cleared_times()); | 256 EXPECT_EQ(1, total_cleared_times()); |
276 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 257 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
277 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 258 EXPECT_EQ(2, static_cast<int>(model()->GetRemovedPages().size())); |
278 } | 259 } |
279 | 260 |
280 TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreThanLimit) { | 261 TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreThanLimit) { |
281 Initialize(std::vector<PageSettings>( | 262 Initialize(std::vector<PageSettings>( |
282 {{kBookmarkNamespace, 10, 15}, {kLastNNamespace, 5, 30}})); | 263 {{kBookmarkNamespace, 10, 15}, {kLastNNamespace, 5, 30}})); |
283 clock()->Advance(base::TimeDelta::FromMinutes(30)); | 264 clock()->Advance(base::TimeDelta::FromMinutes(30)); |
284 TryClearPages(); | 265 TryClearPages(); |
285 EXPECT_EQ(45, last_cleared_page_count()); | 266 EXPECT_EQ(45, last_cleared_page_count()); |
286 EXPECT_EQ(1, total_cleared_times()); | 267 EXPECT_EQ(1, total_cleared_times()); |
287 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 268 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
288 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 269 EXPECT_EQ(45, static_cast<int>(model()->GetRemovedPages().size())); |
289 } | 270 } |
290 | 271 |
291 TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreFreshPages) { | 272 TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreFreshPages) { |
292 Initialize(std::vector<PageSettings>( | 273 Initialize(std::vector<PageSettings>( |
293 {{kBookmarkNamespace, 30, 0}, {kLastNNamespace, 100, 1}}), | 274 {{kBookmarkNamespace, 30, 0}, {kLastNNamespace, 100, 1}}), |
294 {1000 * (1 << 20), 0}); | 275 {1000 * (1 << 20), 0}); |
295 clock()->Advance(base::TimeDelta::FromMinutes(30)); | 276 clock()->Advance(base::TimeDelta::FromMinutes(30)); |
296 TryClearPages(); | 277 TryClearPages(); |
297 EXPECT_EQ(1, last_cleared_page_count()); | 278 EXPECT_EQ(1, last_cleared_page_count()); |
298 EXPECT_EQ(1, total_cleared_times()); | 279 EXPECT_EQ(1, total_cleared_times()); |
299 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 280 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
300 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 281 EXPECT_EQ(1, static_cast<int>(model()->GetRemovedPages().size())); |
301 } | 282 } |
302 | 283 |
303 TEST_F(OfflinePageStorageManagerTest, TestDeleteAsyncPages) { | 284 TEST_F(OfflinePageStorageManagerTest, TestDeleteAsyncPages) { |
304 Initialize(std::vector<PageSettings>({{kAsyncNamespace, 20, 0}})); | 285 Initialize(std::vector<PageSettings>({{kAsyncNamespace, 20, 0}})); |
305 clock()->Advance(base::TimeDelta::FromDays(367)); | 286 clock()->Advance(base::TimeDelta::FromDays(367)); |
306 TryClearPages(); | 287 TryClearPages(); |
307 EXPECT_EQ(0, last_cleared_page_count()); | 288 EXPECT_EQ(0, last_cleared_page_count()); |
308 EXPECT_EQ(1, total_cleared_times()); | 289 EXPECT_EQ(1, total_cleared_times()); |
309 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 290 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
310 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 291 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); |
311 } | 292 } |
312 | 293 |
313 TEST_F(OfflinePageStorageManagerTest, TestDeletionFailed) { | 294 TEST_F(OfflinePageStorageManagerTest, TestDeletionFailed) { |
314 Initialize(std::vector<PageSettings>( | 295 Initialize(std::vector<PageSettings>( |
315 {{kBookmarkNamespace, 10, 10}, {kLastNNamespace, 10, 10}}), | 296 {{kBookmarkNamespace, 10, 10}, {kLastNNamespace, 10, 10}}), |
316 {kFreeSpaceNormal, 0}, TestOptions::DELETE_FAILURE); | 297 {kFreeSpaceNormal, 0}, TestOptions::DELETE_FAILURE); |
317 TryClearPages(); | 298 TryClearPages(); |
318 EXPECT_EQ(20, last_cleared_page_count()); | 299 EXPECT_EQ(20, last_cleared_page_count()); |
319 EXPECT_EQ(1, total_cleared_times()); | 300 EXPECT_EQ(1, total_cleared_times()); |
320 EXPECT_EQ(ClearStorageResult::DELETE_FAILURE, last_clear_storage_result()); | 301 EXPECT_EQ(ClearStorageResult::CLEAR_FAILURE, last_clear_storage_result()); |
321 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 302 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); |
322 } | 303 } |
323 | 304 |
324 TEST_F(OfflinePageStorageManagerTest, TestRemoveFromStoreFailure) { | |
325 Initialize(std::vector<PageSettings>({{kBookmarkNamespace, 10, 10}}), {0, 0}, | |
326 TestOptions::EXPIRE_FAILURE); | |
327 clock()->Advance(base::TimeDelta::FromMinutes(30)); | |
328 TryClearPages(); | |
329 EXPECT_EQ(10, last_cleared_page_count()); | |
330 EXPECT_EQ(1, total_cleared_times()); | |
331 EXPECT_EQ(ClearStorageResult::EXPIRE_FAILURE, last_clear_storage_result()); | |
332 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | |
333 } | |
334 | |
335 TEST_F(OfflinePageStorageManagerTest, TestBothFailure) { | |
336 Initialize(std::vector<PageSettings>({{kBookmarkNamespace, 10, 10}}), {0, 0}, | |
337 TestOptions::EXPIRE_AND_DELETE_FAILURES); | |
338 clock()->Advance(base::TimeDelta::FromMinutes(30)); | |
339 TryClearPages(); | |
340 EXPECT_EQ(ClearStorageResult::EXPIRE_AND_DELETE_FAILURES, | |
341 last_clear_storage_result()); | |
342 } | |
343 | |
344 TEST_F(OfflinePageStorageManagerTest, TestStorageTimeInterval) { | 305 TEST_F(OfflinePageStorageManagerTest, TestStorageTimeInterval) { |
345 Initialize(std::vector<PageSettings>( | 306 Initialize(std::vector<PageSettings>( |
346 {{kBookmarkNamespace, 10, 10}, {kLastNNamespace, 10, 10}})); | 307 {{kBookmarkNamespace, 10, 10}, {kLastNNamespace, 10, 10}})); |
347 clock()->Advance(base::TimeDelta::FromMinutes(30)); | 308 clock()->Advance(base::TimeDelta::FromMinutes(30)); |
348 TryClearPages(); | 309 TryClearPages(); |
349 EXPECT_EQ(20, last_cleared_page_count()); | 310 EXPECT_EQ(20, last_cleared_page_count()); |
350 EXPECT_EQ(1, total_cleared_times()); | 311 EXPECT_EQ(1, total_cleared_times()); |
351 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 312 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
352 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 313 EXPECT_EQ(20, static_cast<int>(model()->GetRemovedPages().size())); |
353 | 314 |
354 // Advance clock so we go over the gap, but no expired pages. | 315 // Advance clock so we go over the gap, but no expired pages. |
355 clock()->Advance(kClearStorageInterval + base::TimeDelta::FromMinutes(1)); | 316 clock()->Advance(kClearStorageInterval + base::TimeDelta::FromMinutes(1)); |
356 TryClearPages(); | 317 TryClearPages(); |
357 EXPECT_EQ(0, last_cleared_page_count()); | 318 EXPECT_EQ(0, last_cleared_page_count()); |
358 EXPECT_EQ(2, total_cleared_times()); | 319 EXPECT_EQ(2, total_cleared_times()); |
359 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 320 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
360 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 321 EXPECT_EQ(20, static_cast<int>(model()->GetRemovedPages().size())); |
361 | 322 |
362 // Advance clock so we are still in the gap, should be unnecessary. | 323 // Advance clock so we are still in the gap, should be unnecessary. |
363 clock()->Advance(kClearStorageInterval - base::TimeDelta::FromMinutes(1)); | 324 clock()->Advance(kClearStorageInterval - base::TimeDelta::FromMinutes(1)); |
364 TryClearPages(); | 325 TryClearPages(); |
365 EXPECT_EQ(0, last_cleared_page_count()); | 326 EXPECT_EQ(0, last_cleared_page_count()); |
366 EXPECT_EQ(3, total_cleared_times()); | 327 EXPECT_EQ(3, total_cleared_times()); |
367 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result()); | 328 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result()); |
368 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 329 EXPECT_EQ(20, static_cast<int>(model()->GetRemovedPages().size())); |
369 } | |
370 | |
371 TEST_F(OfflinePageStorageManagerTest, TestTwoStepExpiration) { | |
372 Initialize(std::vector<PageSettings>({{kBookmarkNamespace, 10, 10}})); | |
373 clock()->Advance(base::TimeDelta::FromMinutes(30)); | |
374 TryClearPages(); | |
375 EXPECT_EQ(10, last_cleared_page_count()); | |
376 EXPECT_EQ(1, total_cleared_times()); | |
377 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | |
378 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | |
379 | |
380 clock()->Advance(kRemovePageItemInterval + base::TimeDelta::FromDays(1)); | |
381 TryClearPages(); | |
382 EXPECT_EQ(10, last_cleared_page_count()); | |
383 EXPECT_EQ(2, total_cleared_times()); | |
384 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | |
385 EXPECT_EQ(10, static_cast<int>(model()->GetRemovedPages().size())); | |
386 } | 330 } |
387 | 331 |
388 TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) { | 332 TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) { |
389 Initialize(std::vector<PageSettings>({{kBookmarkNamespace, 30, 0}, | 333 Initialize(std::vector<PageSettings>({{kBookmarkNamespace, 30, 0}, |
390 {kLastNNamespace, 100, 1}, | 334 {kLastNNamespace, 100, 1}, |
391 {kAsyncNamespace, 40, 0}}), | 335 {kAsyncNamespace, 40, 0}}), |
392 {1000 * (1 << 20), 0}); | 336 {1000 * (1 << 20), 0}); |
393 clock()->Advance(base::TimeDelta::FromMinutes(30)); | 337 clock()->Advance(base::TimeDelta::FromMinutes(30)); |
394 LifetimePolicy policy = | 338 LifetimePolicy policy = |
395 policy_controller()->GetPolicy(kLastNNamespace).lifetime_policy; | 339 policy_controller()->GetPolicy(kLastNNamespace).lifetime_policy; |
396 | 340 |
397 TryClearPages(); | 341 TryClearPages(); |
398 EXPECT_EQ(1, last_cleared_page_count()); | 342 EXPECT_EQ(1, last_cleared_page_count()); |
399 EXPECT_EQ(1, total_cleared_times()); | 343 EXPECT_EQ(1, total_cleared_times()); |
400 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 344 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
401 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 345 EXPECT_EQ(1, static_cast<int>(model()->GetRemovedPages().size())); |
402 | 346 |
403 // Advance the clock by expiration period of last_n namespace, should be | 347 // Advance the clock by expiration period of last_n namespace, should be |
404 // expiring all pages left in the namespace. | 348 // expiring all pages left in the namespace. |
405 clock()->Advance(policy.expiration_period); | 349 clock()->Advance(policy.expiration_period); |
406 TryClearPages(); | 350 TryClearPages(); |
407 EXPECT_EQ(100, last_cleared_page_count()); | 351 EXPECT_EQ(100, last_cleared_page_count()); |
408 EXPECT_EQ(2, total_cleared_times()); | 352 EXPECT_EQ(2, total_cleared_times()); |
409 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 353 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
410 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 354 EXPECT_EQ(101, static_cast<int>(model()->GetRemovedPages().size())); |
411 | 355 |
412 // Only 1 ms passes and no changes in pages, so no need to clear page. | 356 // Only 1 ms passes and no changes in pages, so no need to clear page. |
413 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); | 357 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); |
414 TryClearPages(); | 358 TryClearPages(); |
415 EXPECT_EQ(0, last_cleared_page_count()); | 359 EXPECT_EQ(0, last_cleared_page_count()); |
416 EXPECT_EQ(3, total_cleared_times()); | 360 EXPECT_EQ(3, total_cleared_times()); |
417 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result()); | 361 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result()); |
418 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 362 EXPECT_EQ(101, static_cast<int>(model()->GetRemovedPages().size())); |
419 | 363 |
420 // Adding more fresh pages to make it go over limit. | 364 // Adding more fresh pages to make it go over limit. |
421 clock()->Advance(base::TimeDelta::FromMinutes(5)); | 365 clock()->Advance(base::TimeDelta::FromMinutes(5)); |
422 model()->AddPages({kBookmarkNamespace, 400, 0}); | 366 model()->AddPages({kBookmarkNamespace, 400, 0}); |
423 int64_t total_size_before = model()->GetTotalSize(); | 367 int64_t total_size_before = model()->GetTotalSize(); |
424 int64_t available_space = 300 * (1 << 20); // 300 MB | 368 int64_t available_space = 300 * (1 << 20); // 300 MB |
425 test_archive_manager()->SetValues({available_space, total_size_before}); | 369 test_archive_manager()->SetValues({available_space, total_size_before}); |
426 EXPECT_GE(total_size_before, | 370 EXPECT_GE(total_size_before, |
427 kOfflinePageStorageLimit * (available_space + total_size_before)); | 371 kOfflinePageStorageLimit * (available_space + total_size_before)); |
428 TryClearPages(); | 372 TryClearPages(); |
429 EXPECT_LE(total_size_before * kOfflinePageStorageClearThreshold, | 373 EXPECT_LE(total_size_before * kOfflinePageStorageClearThreshold, |
430 model()->GetTotalSize()); | 374 model()->GetTotalSize()); |
431 EXPECT_EQ(4, total_cleared_times()); | 375 EXPECT_EQ(4, total_cleared_times()); |
432 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 376 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
433 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); | 377 int deleted_page_total = last_cleared_page_count() + 101; |
434 int expired_page_count = last_cleared_page_count(); | 378 EXPECT_EQ(deleted_page_total, |
| 379 static_cast<int>(model()->GetRemovedPages().size())); |
435 | 380 |
436 // After more days, all pages should be expired and . | 381 // After more days, all pages should be deleted. |
437 clock()->Advance(kRemovePageItemInterval + base::TimeDelta::FromDays(1)); | 382 clock()->Advance(base::TimeDelta::FromDays(30)); |
438 TryClearPages(); | 383 TryClearPages(); |
439 EXPECT_EQ(0, model()->GetTotalSize()); | 384 EXPECT_EQ(0, model()->GetTotalSize()); |
440 EXPECT_EQ(5, total_cleared_times()); | 385 EXPECT_EQ(5, total_cleared_times()); |
441 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); | 386 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); |
442 // Number of removed pages should be the ones expired above and all the pages | 387 // Number of removed pages should be all the pages initially created plus 400 |
443 // initially created for last_n namespace. | 388 // more pages added above for bookmark namespace. |
444 EXPECT_EQ(expired_page_count + 101, | 389 EXPECT_EQ(171 + 400, static_cast<int>(model()->GetRemovedPages().size())); |
445 static_cast<int>(model()->GetRemovedPages().size())); | |
446 } | 390 } |
447 | 391 |
448 } // namespace offline_pages | 392 } // namespace offline_pages |
OLD | NEW |