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

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

Issue 2512073002: [Offline Pages] Removes two-step expiration related. (Closed)
Patch Set: Created 4 years, 1 month 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 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 PumpLoop(); 1078 PumpLoop();
1079 // No change when we delete the last page. 1079 // No change when we delete the last page.
1080 histograms().ExpectTotalCount( 1080 histograms().ExpectTotalCount(
1081 "OfflinePages.DownloadDeletedPageDuplicateCount", 2); 1081 "OfflinePages.DownloadDeletedPageDuplicateCount", 2);
1082 histograms().ExpectBucketCount( 1082 histograms().ExpectBucketCount(
1083 "OfflinePages.DownloadDeletedPageDuplicateCount", 1, 1); 1083 "OfflinePages.DownloadDeletedPageDuplicateCount", 1, 1);
1084 histograms().ExpectBucketCount( 1084 histograms().ExpectBucketCount(
1085 "OfflinePages.DownloadDeletedPageDuplicateCount", 2, 1); 1085 "OfflinePages.DownloadDeletedPageDuplicateCount", 2, 1);
1086 } 1086 }
1087 1087
1088 TEST_F(OfflinePageModelImplTest, ExpirePages) { 1088 TEST_F(OfflinePageModelImplTest, GetPagesByClientIds) {
1089 // We will save 3 pages and then expire 2 of them. 1089 // We will save 2 pages.
1090 std::pair<SavePageResult, int64_t> saved_pages[3]; 1090 std::pair<SavePageResult, int64_t> saved_pages[3];
1091 saved_pages[0] = SavePage(kTestUrl, kTestClientId1); 1091 saved_pages[0] = SavePage(kTestUrl, kTestClientId1);
1092 saved_pages[1] = SavePage(kTestUrl2, kTestClientId2); 1092 saved_pages[1] = SavePage(kTestUrl2, kTestClientId2);
1093 saved_pages[2] = SavePage(kTestUrl3, kTestClientId3);
1094 1093
1095 for (const auto& save_result : saved_pages) { 1094 for (const auto& save_result : saved_pages) {
1096 ASSERT_EQ(OfflinePageModel::SavePageResult::SUCCESS, 1095 ASSERT_EQ(OfflinePageModel::SavePageResult::SUCCESS,
1097 std::get<0>(save_result)); 1096 std::get<0>(save_result));
1098 } 1097 }
1099 1098
1100 // First two pages will be expired. 1099 std::vector<ClientId> client_ids = {kTestClientId2};
1101 std::vector<int64_t> pages_to_expire = {std::get<1>(saved_pages[0]),
1102 std::get<1>(saved_pages[1])};
1103 // Pages are marked as expired if they have an expiration_time set.
1104 base::Time expiration_time =
1105 base::Time::Now() + base::TimeDelta::FromMinutes(5);
1106
1107 model()->ExpirePages(
1108 pages_to_expire, expiration_time,
1109 base::Bind(&OfflinePageModelImplTest::OnPagesExpired, AsWeakPtr()));
1110 PumpLoop();
1111
1112 const std::vector<OfflinePageItem>& offline_pages = GetAllPages();
1113 for (const auto& offline_page : offline_pages) {
1114 if (std::find(pages_to_expire.begin(), pages_to_expire.end(),
1115 offline_page.offline_id) != pages_to_expire.end()) {
1116 EXPECT_EQ(expiration_time, offline_page.expiration_time);
1117 EXPECT_TRUE(offline_page.IsExpired());
1118 } else {
1119 EXPECT_EQ(base::Time(), offline_page.expiration_time);
1120 EXPECT_FALSE(offline_page.IsExpired());
1121 }
1122 }
1123 EXPECT_TRUE(last_expire_page_result());
1124 }
1125
1126 TEST_F(OfflinePageModelImplTest, GetPagesByClientIds) {
1127 // We will save 3 pages. One will be expired.
1128 std::pair<SavePageResult, int64_t> saved_pages[3];
1129 saved_pages[0] = SavePage(kTestUrl, kTestClientId1);
1130 saved_pages[1] = SavePage(kTestUrl2, kTestClientId2);
1131 saved_pages[2] = SavePage(kTestUrl3, kTestClientId3);
1132
1133 for (const auto& save_result : saved_pages) {
1134 ASSERT_EQ(OfflinePageModel::SavePageResult::SUCCESS,
1135 std::get<0>(save_result));
1136 }
1137
1138 std::vector<int64_t> pages_to_expire = {std::get<1>(saved_pages[0])};
1139 // Pages are marked as expired if they have an expiration_time set.
1140 base::Time expiration_time =
1141 base::Time::Now() + base::TimeDelta::FromMinutes(5);
1142 model()->ExpirePages(
1143 pages_to_expire, expiration_time,
1144 base::Bind(&OfflinePageModelImplTest::OnPagesExpired, AsWeakPtr()));
1145 PumpLoop();
1146
1147 std::vector<ClientId> client_ids = {kTestClientId1, kTestClientId2};
1148 std::vector<OfflinePageItem> offline_pages = GetPagesByClientIds(client_ids); 1100 std::vector<OfflinePageItem> offline_pages = GetPagesByClientIds(client_ids);
1149 EXPECT_EQ(1U, offline_pages.size()); 1101 EXPECT_EQ(1U, offline_pages.size());
1150 1102
1151 const OfflinePageItem& item = offline_pages[0]; 1103 const OfflinePageItem& item = offline_pages[0];
1152 EXPECT_EQ(kTestClientId2.name_space, item.client_id.name_space); 1104 EXPECT_EQ(kTestClientId2.name_space, item.client_id.name_space);
1153 EXPECT_EQ(kTestClientId2.id, item.client_id.id); 1105 EXPECT_EQ(kTestClientId2.id, item.client_id.id);
1154 EXPECT_EQ(kTestUrl2, item.url); 1106 EXPECT_EQ(kTestUrl2, item.url);
1155 } 1107 }
1156 1108
1157 TEST_F(OfflinePageModelImplTest, DeletePagesByClientIds) { 1109 TEST_F(OfflinePageModelImplTest, DeletePagesByClientIds) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); 1209 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled());
1258 1210
1259 // Check if feature is correctly enabled by command-line flag. 1211 // Check if feature is correctly enabled by command-line flag.
1260 base::test::ScopedFeatureList scoped_feature_list; 1212 base::test::ScopedFeatureList scoped_feature_list;
1261 scoped_feature_list.InitAndEnableFeature( 1213 scoped_feature_list.InitAndEnableFeature(
1262 kOfflinePagesSvelteConcurrentLoadingFeature); 1214 kOfflinePagesSvelteConcurrentLoadingFeature);
1263 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); 1215 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled());
1264 } 1216 }
1265 1217
1266 } // namespace offline_pages 1218 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698