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

Side by Side Diff: components/offline_pages/offline_page_storage_manager_unittest.cc

Issue 2512073002: [Offline Pages] Removes two-step expiration related. (Closed)
Patch Set: adding unit in histograms. 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 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
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
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
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::DELETE_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(constants::kClearStorageInterval + 316 clock()->Advance(constants::kClearStorageInterval +
356 base::TimeDelta::FromMinutes(1)); 317 base::TimeDelta::FromMinutes(1));
357 TryClearPages(); 318 TryClearPages();
358 EXPECT_EQ(0, last_cleared_page_count()); 319 EXPECT_EQ(0, last_cleared_page_count());
359 EXPECT_EQ(2, total_cleared_times()); 320 EXPECT_EQ(2, total_cleared_times());
360 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 321 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
361 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 322 EXPECT_EQ(20, static_cast<int>(model()->GetRemovedPages().size()));
362 323
363 // Advance clock so we are still in the gap, should be unnecessary. 324 // Advance clock so we are still in the gap, should be unnecessary.
364 clock()->Advance(constants::kClearStorageInterval - 325 clock()->Advance(constants::kClearStorageInterval -
365 base::TimeDelta::FromMinutes(1)); 326 base::TimeDelta::FromMinutes(1));
366 TryClearPages(); 327 TryClearPages();
367 EXPECT_EQ(0, last_cleared_page_count()); 328 EXPECT_EQ(0, last_cleared_page_count());
368 EXPECT_EQ(3, total_cleared_times()); 329 EXPECT_EQ(3, total_cleared_times());
369 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result()); 330 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result());
370 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 331 EXPECT_EQ(20, static_cast<int>(model()->GetRemovedPages().size()));
371 }
372
373 TEST_F(OfflinePageStorageManagerTest, TestTwoStepExpiration) {
374 Initialize(std::vector<PageSettings>({{kBookmarkNamespace, 10, 10}}));
375 clock()->Advance(base::TimeDelta::FromMinutes(30));
376 TryClearPages();
377 EXPECT_EQ(10, last_cleared_page_count());
378 EXPECT_EQ(1, total_cleared_times());
379 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
380 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
381
382 clock()->Advance(constants::kRemovePageItemInterval +
383 base::TimeDelta::FromDays(1));
384 TryClearPages();
385 EXPECT_EQ(10, last_cleared_page_count());
386 EXPECT_EQ(2, total_cleared_times());
387 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
388 EXPECT_EQ(10, static_cast<int>(model()->GetRemovedPages().size()));
389 } 332 }
390 333
391 TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) { 334 TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) {
392 Initialize(std::vector<PageSettings>({{kBookmarkNamespace, 30, 0}, 335 Initialize(std::vector<PageSettings>({{kBookmarkNamespace, 30, 0},
393 {kLastNNamespace, 100, 1}, 336 {kLastNNamespace, 100, 1},
394 {kAsyncNamespace, 40, 0}}), 337 {kAsyncNamespace, 40, 0}}),
395 {1000 * (1 << 20), 0}); 338 {1000 * (1 << 20), 0});
396 clock()->Advance(base::TimeDelta::FromMinutes(30)); 339 clock()->Advance(base::TimeDelta::FromMinutes(30));
397 LifetimePolicy policy = 340 LifetimePolicy policy =
398 policy_controller()->GetPolicy(kLastNNamespace).lifetime_policy; 341 policy_controller()->GetPolicy(kLastNNamespace).lifetime_policy;
399 342
400 TryClearPages(); 343 TryClearPages();
401 EXPECT_EQ(1, last_cleared_page_count()); 344 EXPECT_EQ(1, last_cleared_page_count());
402 EXPECT_EQ(1, total_cleared_times()); 345 EXPECT_EQ(1, total_cleared_times());
403 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 346 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
404 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 347 EXPECT_EQ(1, static_cast<int>(model()->GetRemovedPages().size()));
405 348
406 // Advance the clock by expiration period of last_n namespace, should be 349 // Advance the clock by expiration period of last_n namespace, should be
407 // expiring all pages left in the namespace. 350 // expiring all pages left in the namespace.
408 clock()->Advance(policy.expiration_period); 351 clock()->Advance(policy.expiration_period);
409 TryClearPages(); 352 TryClearPages();
410 EXPECT_EQ(100, last_cleared_page_count()); 353 EXPECT_EQ(100, last_cleared_page_count());
411 EXPECT_EQ(2, total_cleared_times()); 354 EXPECT_EQ(2, total_cleared_times());
412 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 355 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
413 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 356 EXPECT_EQ(101, static_cast<int>(model()->GetRemovedPages().size()));
414 357
415 // Only 1 ms passes and no changes in pages, so no need to clear page. 358 // Only 1 ms passes and no changes in pages, so no need to clear page.
416 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); 359 clock()->Advance(base::TimeDelta::FromMilliseconds(1));
417 TryClearPages(); 360 TryClearPages();
418 EXPECT_EQ(0, last_cleared_page_count()); 361 EXPECT_EQ(0, last_cleared_page_count());
419 EXPECT_EQ(3, total_cleared_times()); 362 EXPECT_EQ(3, total_cleared_times());
420 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result()); 363 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result());
421 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 364 EXPECT_EQ(101, static_cast<int>(model()->GetRemovedPages().size()));
422 365
423 // Adding more fresh pages to make it go over limit. 366 // Adding more fresh pages to make it go over limit.
424 clock()->Advance(base::TimeDelta::FromMinutes(5)); 367 clock()->Advance(base::TimeDelta::FromMinutes(5));
425 model()->AddPages({kBookmarkNamespace, 400, 0}); 368 model()->AddPages({kBookmarkNamespace, 400, 0});
426 int64_t total_size_before = model()->GetTotalSize(); 369 int64_t total_size_before = model()->GetTotalSize();
427 int64_t available_space = 300 * (1 << 20); // 300 MB 370 int64_t available_space = 300 * (1 << 20); // 300 MB
428 test_archive_manager()->SetValues({available_space, total_size_before}); 371 test_archive_manager()->SetValues({available_space, total_size_before});
429 EXPECT_GE(total_size_before, constants::kOfflinePageStorageLimit * 372 EXPECT_GE(total_size_before, constants::kOfflinePageStorageLimit *
430 (available_space + total_size_before)); 373 (available_space + total_size_before));
431 TryClearPages(); 374 TryClearPages();
432 EXPECT_LE(total_size_before * constants::kOfflinePageStorageClearThreshold, 375 EXPECT_LE(total_size_before * constants::kOfflinePageStorageClearThreshold,
433 model()->GetTotalSize()); 376 model()->GetTotalSize());
434 EXPECT_EQ(4, total_cleared_times()); 377 EXPECT_EQ(4, total_cleared_times());
435 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 378 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
436 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 379 int deleted_page_total = last_cleared_page_count() + 101;
437 int expired_page_count = last_cleared_page_count(); 380 EXPECT_EQ(deleted_page_total,
381 static_cast<int>(model()->GetRemovedPages().size()));
438 382
439 // After more days, all pages should be expired and . 383 // After more days, all pages should be deleted.
440 clock()->Advance(constants::kRemovePageItemInterval + 384 clock()->Advance(base::TimeDelta::FromDays(30));
441 base::TimeDelta::FromDays(1));
442 TryClearPages(); 385 TryClearPages();
443 EXPECT_EQ(0, model()->GetTotalSize()); 386 EXPECT_EQ(0, model()->GetTotalSize());
444 EXPECT_EQ(5, total_cleared_times()); 387 EXPECT_EQ(5, total_cleared_times());
445 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 388 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
446 // Number of removed pages should be the ones expired above and all the pages 389 // Number of removed pages should be all the pages initially created plus 400
447 // initially created for last_n namespace. 390 // more pages added above for bookmark namespace.
448 EXPECT_EQ(expired_page_count + 101, 391 EXPECT_EQ(171 + 400, static_cast<int>(model()->GetRemovedPages().size()));
449 static_cast<int>(model()->GetRemovedPages().size()));
450 } 392 }
451 393
452 } // namespace offline_pages 394 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_storage_manager.cc ('k') | components/offline_pages/stub_offline_page_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698