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

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

Issue 2041983006: [Offline Pages] Filtering expired pages and fix consistency check. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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_impl.h" 5 #include "components/offline_pages/offline_page_model_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 723
724 ResetResults(); 724 ResetResults();
725 725
726 base::Optional<OfflinePageItem> page = GetPageByOfflineId(offline_id); 726 base::Optional<OfflinePageItem> page = GetPageByOfflineId(offline_id);
727 727
728 // Delete the offline copy of the page and check the metadata. 728 // Delete the offline copy of the page and check the metadata.
729 base::DeleteFile(page->file_path, false); 729 base::DeleteFile(page->file_path, false);
730 model()->CheckForExternalFileDeletion(); 730 model()->CheckForExternalFileDeletion();
731 PumpLoop(); 731 PumpLoop();
732 732
733 EXPECT_EQ(last_deleted_offline_id(), offline_id); 733 // Check if the page has been expired.
734 EXPECT_EQ(0UL, GetAllPages().size()); 734 EXPECT_EQ(0UL, GetAllPages().size());
735 } 735 }
736 736
737 TEST_F(OfflinePageModelImplTest, DetectThatOfflineCopyIsMissingAfterLoad) { 737 TEST_F(OfflinePageModelImplTest, DetectThatOfflineCopyIsMissingAfterLoad) {
738 // Save a page. 738 // Save a page.
739 SavePage(kTestUrl, kTestClientId1); 739 SavePage(kTestUrl, kTestClientId1);
740 PumpLoop(); 740 PumpLoop();
741 int64_t offline_id = last_save_offline_id(); 741 int64_t offline_id = last_save_offline_id();
742 742
743 ResetResults(); 743 ResetResults();
744 744
745 base::Optional<OfflinePageItem> page = GetPageByOfflineId(offline_id); 745 base::Optional<OfflinePageItem> page = GetPageByOfflineId(offline_id);
746 // Delete the offline copy of the page and check the metadata. 746 // Delete the offline copy of the page and check the metadata.
747 base::DeleteFile(page->file_path, false); 747 base::DeleteFile(page->file_path, false);
748 // Reseting the model should trigger the metadata consistency check as well. 748 // Reseting the model should trigger the metadata consistency check as well.
749 ResetModel(); 749 ResetModel();
750 PumpLoop(); 750 PumpLoop();
751 751
752 EXPECT_EQ(last_deleted_offline_id(), offline_id); 752 // Check if the page has been expired.
753 EXPECT_EQ(0UL, GetAllPages().size()); 753 EXPECT_EQ(0UL, GetAllPages().size());
754 } 754 }
755 755
756 TEST_F(OfflinePageModelImplTest, DetectThatHeadlessPageIsDeleted) {
757 // Save a page.
758 SavePage(kTestUrl, kTestClientId1);
759 PumpLoop();
760 int64_t offline_id = last_save_offline_id();
761
762 ResetResults();
763 base::Optional<OfflinePageItem> page = GetPageByOfflineId(offline_id);
764 base::FilePath path = page->file_path;
765 EXPECT_TRUE(base::PathExists(path));
fgorski 2016/06/07 22:46:15 Could you also add this check before CheckForExter
romax 2016/06/08 01:31:26 Done.
766 GetStore()->ClearAllPages();
767 ResetModel();
768 PumpLoop();
769
770 model()->CheckForExternalFileDeletion();
771 PumpLoop();
772
773 EXPECT_EQ(0UL, GetAllPages().size());
774 EXPECT_FALSE(base::PathExists(path));
775 }
776
756 TEST_F(OfflinePageModelImplTest, DeleteMultiplePages) { 777 TEST_F(OfflinePageModelImplTest, DeleteMultiplePages) {
757 OfflinePageTestStore* store = GetStore(); 778 OfflinePageTestStore* store = GetStore();
758 779
759 // Save 3 pages. 780 // Save 3 pages.
760 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 781 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
761 kTestUrl, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)); 782 kTestUrl, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED));
762 model()->SavePage( 783 model()->SavePage(
763 kTestUrl, kTestClientId1, std::move(archiver), 784 kTestUrl, kTestClientId1, std::move(archiver),
764 base::Bind(&OfflinePageModelImplTest::OnSavePageDone, AsWeakPtr())); 785 base::Bind(&OfflinePageModelImplTest::OnSavePageDone, AsWeakPtr()));
765 PumpLoop(); 786 PumpLoop();
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); 1074 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList);
1054 feature_list2->InitializeFromCommandLine( 1075 feature_list2->InitializeFromCommandLine(
1055 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 1076 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," +
1056 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, 1077 offline_pages::kOfflinePagesBackgroundLoadingFeature.name,
1057 ""); 1078 "");
1058 base::FeatureList::SetInstance(std::move(feature_list2)); 1079 base::FeatureList::SetInstance(std::move(feature_list2));
1059 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 1080 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
1060 } 1081 }
1061 1082
1062 } // namespace offline_pages 1083 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698