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

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

Issue 1993953002: [Offline pages] Adding expiration capability to OfflinePageModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 7 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.h" 5 #include "components/offline_pages/offline_page_model.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 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 std::get<0>(save_result)); 949 std::get<0>(save_result));
950 } 950 }
951 951
952 const OfflinePageItem* offline_page = 952 const OfflinePageItem* offline_page =
953 model()->MaybeGetBestPageForOnlineURL(kTestUrl); 953 model()->MaybeGetBestPageForOnlineURL(kTestUrl);
954 ASSERT_TRUE(nullptr != offline_page); 954 ASSERT_TRUE(nullptr != offline_page);
955 955
956 EXPECT_EQ(std::get<1>(saved_pages[1]), offline_page->offline_id); 956 EXPECT_EQ(std::get<1>(saved_pages[1]), offline_page->offline_id);
957 } 957 }
958 958
959 TEST_F(OfflinePageModelTest, ExpirePages) {
960 // We will save 3 pages - two for the same URL, and one for a different URL.
jianli 2016/05/19 20:39:54 The comment "two for the same URL" does not match
fgorski 2016/05/20 17:54:23 Done.
961 // Correct behavior will pick the most recently saved page for the correct
962 // URL.
963 std::pair<SavePageResult, int64_t> saved_pages[3];
jianli 2016/05/19 20:39:54 I found out that this pattern makes the code harde
fgorski 2016/05/20 17:54:23 Acknowledged.
964 saved_pages[0] = SavePage(kTestUrl, kTestClientId1);
965 saved_pages[1] = SavePage(kTestUrl2, kTestClientId2);
966 saved_pages[1] = SavePage(kTestUrl3, kTestClientId3);
jianli 2016/05/19 20:39:54 [1] => [2]?
fgorski 2016/05/20 17:54:23 Done.
967
968 for (const auto& save_result : saved_pages) {
969 ASSERT_EQ(OfflinePageModel::SavePageResult::SUCCESS,
970 std::get<0>(save_result));
971 }
972
973 // First two pages will be expired.
974 std::vector<int64_t> pages_to_expire = {std::get<1>(saved_pages[0]),
975 std::get<1>(saved_pages[1])};
976 // Pages are marked as expired if they have an expiration_time set.
977 base::Time expiration_time =
978 base::Time::Now() + base::TimeDelta::FromMinutes(5);
979
980 model()->ExpirePages(pages_to_expire, expiration_time);
981 PumpLoop();
982 const std::vector<OfflinePageItem>& offline_pages = GetStore()->GetAllPages();
jianli 2016/05/19 20:39:54 I think it would be better to verify against the i
fgorski 2016/05/20 17:54:23 I can do it right now, but GetAllPages will filter
983 for (const auto& offline_page : offline_pages) {
984 if (std::find(pages_to_expire.begin(), pages_to_expire.end(),
985 offline_page.offline_id) != pages_to_expire.end()) {
986 EXPECT_EQ(expiration_time, offline_page.expiration_time);
987 EXPECT_TRUE(offline_page.IsExpired());
988 } else {
989 EXPECT_EQ(base::Time(), offline_page.expiration_time);
990 EXPECT_FALSE(offline_page.IsExpired());
991 }
992 }
993 }
994
959 TEST(CommandLineFlagsTest, OfflineBookmarks) { 995 TEST(CommandLineFlagsTest, OfflineBookmarks) {
960 // Disabled by default. 996 // Disabled by default.
961 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled()); 997 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled());
962 998
963 // Check if feature is correctly enabled by command-line flag. 999 // Check if feature is correctly enabled by command-line flag.
964 base::FeatureList::ClearInstanceForTesting(); 1000 base::FeatureList::ClearInstanceForTesting();
965 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 1001 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
966 feature_list->InitializeFromCommandLine( 1002 feature_list->InitializeFromCommandLine(
967 offline_pages::kOfflineBookmarksFeature.name, ""); 1003 offline_pages::kOfflineBookmarksFeature.name, "");
968 base::FeatureList::SetInstance(std::move(feature_list)); 1004 base::FeatureList::SetInstance(std::move(feature_list));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); 1045 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList);
1010 feature_list2->InitializeFromCommandLine( 1046 feature_list2->InitializeFromCommandLine(
1011 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 1047 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," +
1012 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, 1048 offline_pages::kOfflinePagesBackgroundLoadingFeature.name,
1013 ""); 1049 "");
1014 base::FeatureList::SetInstance(std::move(feature_list2)); 1050 base::FeatureList::SetInstance(std::move(feature_list2));
1015 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 1051 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
1016 } 1052 }
1017 1053
1018 } // namespace offline_pages 1054 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698