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

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

Issue 2067143004: [Offline Pages] Duplicate pages when save/delete bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments from dimich@. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/offline_pages/offline_page_model_impl_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 12 matching lines...) Expand all
23 using LifetimePolicy = offline_pages::LifetimePolicy; 23 using LifetimePolicy = offline_pages::LifetimePolicy;
24 using ClearStorageResult = 24 using ClearStorageResult =
25 offline_pages::OfflinePageStorageManager::ClearStorageResult; 25 offline_pages::OfflinePageStorageManager::ClearStorageResult;
26 using StorageStats = offline_pages::ArchiveManager::StorageStats; 26 using StorageStats = offline_pages::ArchiveManager::StorageStats;
27 27
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 = 500 * (1 << 10); 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 EXPIRE_FAILURE = 1 << 1,
39 DELETE_FAILURE = 1 << 2, 39 DELETE_FAILURE = 1 << 2,
40 EXPIRE_AND_DELETE_FAILURES = EXPIRE_FAILURE | DELETE_FAILURE, 40 EXPIRE_AND_DELETE_FAILURES = EXPIRE_FAILURE | DELETE_FAILURE,
41 }; 41 };
42 42
43 struct PageSettings { 43 struct PageSettings {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 TryClearPages(); 284 TryClearPages();
285 EXPECT_EQ(45, last_cleared_page_count()); 285 EXPECT_EQ(45, last_cleared_page_count());
286 EXPECT_EQ(1, total_cleared_times()); 286 EXPECT_EQ(1, total_cleared_times());
287 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 287 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
288 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 288 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
289 } 289 }
290 290
291 TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreFreshPages) { 291 TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreFreshPages) {
292 Initialize(std::vector<PageSettings>( 292 Initialize(std::vector<PageSettings>(
293 {{kBookmarkNamespace, 30, 0}, {kLastNNamespace, 100, 1}}), 293 {{kBookmarkNamespace, 30, 0}, {kLastNNamespace, 100, 1}}),
294 {500 * (1 << 20), 0}); 294 {1000 * (1 << 20), 0});
295 clock()->Advance(base::TimeDelta::FromMinutes(30)); 295 clock()->Advance(base::TimeDelta::FromMinutes(30));
296 TryClearPages(); 296 TryClearPages();
297 int last_n_page_limit = static_cast<int>(policy_controller() 297 EXPECT_EQ(1, last_cleared_page_count());
298 ->GetPolicy(kLastNNamespace)
299 .lifetime_policy.page_limit);
300 EXPECT_EQ(1 + (100 - last_n_page_limit), last_cleared_page_count());
301 EXPECT_EQ(1, total_cleared_times()); 298 EXPECT_EQ(1, total_cleared_times());
302 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 299 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
303 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 300 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
304 } 301 }
305 302
306 TEST_F(OfflinePageStorageManagerTest, TestDeletionFailed) { 303 TEST_F(OfflinePageStorageManagerTest, TestDeletionFailed) {
307 Initialize(std::vector<PageSettings>( 304 Initialize(std::vector<PageSettings>(
308 {{kBookmarkNamespace, 10, 10}, {kLastNNamespace, 10, 10}}), 305 {{kBookmarkNamespace, 10, 10}, {kLastNNamespace, 10, 10}}),
309 {kFreeSpaceNormal, 0}, TestOptions::DELETE_FAILURE); 306 {kFreeSpaceNormal, 0}, TestOptions::DELETE_FAILURE);
310 TryClearPages(); 307 TryClearPages();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 TryClearPages(); 371 TryClearPages();
375 EXPECT_EQ(10, last_cleared_page_count()); 372 EXPECT_EQ(10, last_cleared_page_count());
376 EXPECT_EQ(2, total_cleared_times()); 373 EXPECT_EQ(2, total_cleared_times());
377 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 374 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
378 EXPECT_EQ(10, static_cast<int>(model()->GetRemovedPages().size())); 375 EXPECT_EQ(10, static_cast<int>(model()->GetRemovedPages().size()));
379 } 376 }
380 377
381 TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) { 378 TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) {
382 Initialize(std::vector<PageSettings>( 379 Initialize(std::vector<PageSettings>(
383 {{kBookmarkNamespace, 30, 0}, {kLastNNamespace, 100, 1}}), 380 {{kBookmarkNamespace, 30, 0}, {kLastNNamespace, 100, 1}}),
384 {500 * (1 << 20), 0}); 381 {1000 * (1 << 20), 0});
385 clock()->Advance(base::TimeDelta::FromMinutes(30)); 382 clock()->Advance(base::TimeDelta::FromMinutes(30));
386 LifetimePolicy policy = 383 LifetimePolicy policy =
387 policy_controller()->GetPolicy(kLastNNamespace).lifetime_policy; 384 policy_controller()->GetPolicy(kLastNNamespace).lifetime_policy;
388 int last_n_page_limit = static_cast<int>(policy.page_limit);
389 385
390 TryClearPages(); 386 TryClearPages();
391 EXPECT_EQ(1 + (100 - last_n_page_limit), last_cleared_page_count()); 387 EXPECT_EQ(1, last_cleared_page_count());
392 EXPECT_EQ(1, total_cleared_times()); 388 EXPECT_EQ(1, total_cleared_times());
393 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 389 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
394 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 390 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
395 391
396 // Advance the clock by expiration period of last_n namespace, should be 392 // Advance the clock by expiration period of last_n namespace, should be
397 // expiring all pages left in the namespace. 393 // expiring all pages left in the namespace.
398 clock()->Advance(policy.expiration_period); 394 clock()->Advance(policy.expiration_period);
399 TryClearPages(); 395 TryClearPages();
400 EXPECT_EQ(last_n_page_limit, last_cleared_page_count()); 396 EXPECT_EQ(100, last_cleared_page_count());
401 EXPECT_EQ(2, total_cleared_times()); 397 EXPECT_EQ(2, total_cleared_times());
402 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 398 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
403 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size())); 399 EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
404 400
405 // Only 1 ms passes and no changes in pages, so no need to clear page. 401 // Only 1 ms passes and no changes in pages, so no need to clear page.
406 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); 402 clock()->Advance(base::TimeDelta::FromMilliseconds(1));
407 TryClearPages(); 403 TryClearPages();
408 EXPECT_EQ(0, last_cleared_page_count()); 404 EXPECT_EQ(0, last_cleared_page_count());
409 EXPECT_EQ(3, total_cleared_times()); 405 EXPECT_EQ(3, total_cleared_times());
410 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result()); 406 EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result());
(...skipping 21 matching lines...) Expand all
432 EXPECT_EQ(0, model()->GetTotalSize()); 428 EXPECT_EQ(0, model()->GetTotalSize());
433 EXPECT_EQ(5, total_cleared_times()); 429 EXPECT_EQ(5, total_cleared_times());
434 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result()); 430 EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
435 // Number of removed pages should be the ones expired above and all the pages 431 // Number of removed pages should be the ones expired above and all the pages
436 // initially created for last_n namespace. 432 // initially created for last_n namespace.
437 EXPECT_EQ(expired_page_count + 101, 433 EXPECT_EQ(expired_page_count + 101,
438 static_cast<int>(model()->GetRemovedPages().size())); 434 static_cast<int>(model()->GetRemovedPages().size()));
439 } 435 }
440 436
441 } // namespace offline_pages 437 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698