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

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

Issue 1378883002: [Offline pages] Selecting pages for clean up (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating string to clarify intent of the free up space action Created 5 years, 2 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.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_model.h" 5 #include "components/offline_pages/offline_page_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 EXPECT_EQ(kTestPageBookmarkId1, page->bookmark_id); 707 EXPECT_EQ(kTestPageBookmarkId1, page->bookmark_id);
708 708
709 page = model()->GetPageByOfflineURL(GURL("http://foo")); 709 page = model()->GetPageByOfflineURL(GURL("http://foo"));
710 EXPECT_FALSE(page); 710 EXPECT_FALSE(page);
711 } 711 }
712 712
713 // Test that model returns pages that are older than 30 days as candidates for 713 // Test that model returns pages that are older than 30 days as candidates for
714 // clean up, hence the numbers in time delta. 714 // clean up, hence the numbers in time delta.
715 TEST_F(OfflinePageModelTest, GetPagesToCleanUp) { 715 TEST_F(OfflinePageModelTest, GetPagesToCleanUp) {
716 base::Time now = base::Time::Now(); 716 base::Time now = base::Time::Now();
717 base::Time fourty_days_ago = now - base::TimeDelta::FromDays(40);
newt (away) 2015/10/05 16:45:21 spelling: "forty"
fgorski 2015/10/05 16:58:36 Wow. You live you learn :)
717 OfflinePageItem page_1( 718 OfflinePageItem page_1(
718 GURL(kTestUrl), kTestPageBookmarkId1, 719 GURL(kTestUrl), kTestPageBookmarkId1,
719 base::FilePath(FILE_PATH_LITERAL("/test/location/page1.mhtml")), 720 base::FilePath(FILE_PATH_LITERAL("/test/location/page1.mhtml")),
720 kTestFileSize, now - base::TimeDelta::FromDays(40)); 721 kTestFileSize, fourty_days_ago);
721 GetStore()->AddOrUpdateOfflinePage( 722 GetStore()->AddOrUpdateOfflinePage(
722 page_1, 723 page_1,
723 base::Bind(&OfflinePageModelTest::OnStoreUpdateDone, AsWeakPtr())); 724 base::Bind(&OfflinePageModelTest::OnStoreUpdateDone, AsWeakPtr()));
724 PumpLoop(); 725 PumpLoop();
725 726
726 OfflinePageItem page_2( 727 OfflinePageItem page_2(
727 GURL(kTestUrl2), kTestPageBookmarkId2, 728 GURL(kTestUrl2), kTestPageBookmarkId2,
728 base::FilePath(FILE_PATH_LITERAL("/test/location/page2.mhtml")), 729 base::FilePath(FILE_PATH_LITERAL("/test/location/page2.mhtml")),
729 kTestFileSize, now - base::TimeDelta::FromDays(31)); 730 kTestFileSize, fourty_days_ago);
731 page_2.last_access_time = now - base::TimeDelta::FromDays(31);
730 GetStore()->AddOrUpdateOfflinePage( 732 GetStore()->AddOrUpdateOfflinePage(
731 page_2, 733 page_2,
732 base::Bind(&OfflinePageModelTest::OnStoreUpdateDone, AsWeakPtr())); 734 base::Bind(&OfflinePageModelTest::OnStoreUpdateDone, AsWeakPtr()));
733 PumpLoop(); 735 PumpLoop();
734 736
735 OfflinePageItem page_3( 737 OfflinePageItem page_3(
736 GURL("http://test.xyz"), 42, 738 GURL("http://test.xyz"), 42,
737 base::FilePath(FILE_PATH_LITERAL("/test/location/page3.mhtml")), 739 base::FilePath(FILE_PATH_LITERAL("/test/location/page3.mhtml")),
738 kTestFileSize, now - base::TimeDelta::FromDays(29)); 740 kTestFileSize, fourty_days_ago);
741 page_3.last_access_time = now - base::TimeDelta::FromDays(29);
739 GetStore()->AddOrUpdateOfflinePage( 742 GetStore()->AddOrUpdateOfflinePage(
740 page_3, 743 page_3,
741 base::Bind(&OfflinePageModelTest::OnStoreUpdateDone, AsWeakPtr())); 744 base::Bind(&OfflinePageModelTest::OnStoreUpdateDone, AsWeakPtr()));
742 PumpLoop(); 745 PumpLoop();
743 746
744 ResetModel(); 747 ResetModel();
745 748
746 // Only page_1 and page_2 are expected to be picked up by the model as page_3 749 // Only page_1 and page_2 are expected to be picked up by the model as page_3
747 // has not been in the store long enough. 750 // has not been in the store long enough.
748 std::vector<OfflinePageItem> pages_to_clean_up = model()->GetPagesToCleanUp(); 751 std::vector<OfflinePageItem> pages_to_clean_up = model()->GetPagesToCleanUp();
749 EXPECT_EQ(2UL, pages_to_clean_up.size()); 752 EXPECT_EQ(2UL, pages_to_clean_up.size());
750 EXPECT_EQ(kTestUrl, pages_to_clean_up[0].url); 753 EXPECT_EQ(kTestUrl, pages_to_clean_up[0].url);
751 EXPECT_EQ(kTestPageBookmarkId1, pages_to_clean_up[0].bookmark_id); 754 EXPECT_EQ(kTestPageBookmarkId1, pages_to_clean_up[0].bookmark_id);
752 EXPECT_EQ(kTestUrl2, pages_to_clean_up[1].url); 755 EXPECT_EQ(kTestUrl2, pages_to_clean_up[1].url);
753 EXPECT_EQ(kTestPageBookmarkId2, pages_to_clean_up[1].bookmark_id); 756 EXPECT_EQ(kTestPageBookmarkId2, pages_to_clean_up[1].bookmark_id);
754 } 757 }
755 758
756 } // namespace offline_pages 759 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698