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

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: Addressing feedback 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 and then expire 2 of them.
961 std::pair<SavePageResult, int64_t> saved_pages[3];
962 saved_pages[0] = SavePage(kTestUrl, kTestClientId1);
963 saved_pages[1] = SavePage(kTestUrl2, kTestClientId2);
964 saved_pages[2] = SavePage(kTestUrl3, kTestClientId3);
965
966 for (const auto& save_result : saved_pages) {
967 ASSERT_EQ(OfflinePageModel::SavePageResult::SUCCESS,
968 std::get<0>(save_result));
bburns 2016/05/20 18:23:27 does this fit on the previous line?
fgorski 2016/05/20 20:54:54 misses it by 3. git cl format argument again.
969 }
970
971 // First two pages will be expired.
972 std::vector<int64_t> pages_to_expire = {std::get<1>(saved_pages[0]),
bburns 2016/05/20 18:23:27 personally I would break the line at the '='
fgorski 2016/05/20 20:54:54 git cl format
973 std::get<1>(saved_pages[1])};
974 // Pages are marked as expired if they have an expiration_time set.
975 base::Time expiration_time =
976 base::Time::Now() + base::TimeDelta::FromMinutes(5);
977
978 model()->ExpirePages(pages_to_expire, expiration_time);
979 PumpLoop();
980
981 const std::vector<OfflinePageItem>& offline_pages = GetAllPages();
982 for (const auto& offline_page : offline_pages) {
983 if (std::find(pages_to_expire.begin(), pages_to_expire.end(),
984 offline_page.offline_id) != pages_to_expire.end()) {
985 EXPECT_EQ(expiration_time, offline_page.expiration_time);
986 EXPECT_TRUE(offline_page.IsExpired());
987 } else {
988 EXPECT_EQ(base::Time(), offline_page.expiration_time);
989 EXPECT_FALSE(offline_page.IsExpired());
990 }
991 }
992 }
993
959 TEST(CommandLineFlagsTest, OfflineBookmarks) { 994 TEST(CommandLineFlagsTest, OfflineBookmarks) {
960 // Disabled by default. 995 // Disabled by default.
961 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled()); 996 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled());
962 997
963 // Check if feature is correctly enabled by command-line flag. 998 // Check if feature is correctly enabled by command-line flag.
964 base::FeatureList::ClearInstanceForTesting(); 999 base::FeatureList::ClearInstanceForTesting();
965 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 1000 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
966 feature_list->InitializeFromCommandLine( 1001 feature_list->InitializeFromCommandLine(
967 offline_pages::kOfflineBookmarksFeature.name, ""); 1002 offline_pages::kOfflineBookmarksFeature.name, "");
968 base::FeatureList::SetInstance(std::move(feature_list)); 1003 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); 1044 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList);
1010 feature_list2->InitializeFromCommandLine( 1045 feature_list2->InitializeFromCommandLine(
1011 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 1046 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," +
1012 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, 1047 offline_pages::kOfflinePagesBackgroundLoadingFeature.name,
1013 ""); 1048 "");
1014 base::FeatureList::SetInstance(std::move(feature_list2)); 1049 base::FeatureList::SetInstance(std::move(feature_list2));
1015 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 1050 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
1016 } 1051 }
1017 1052
1018 } // namespace offline_pages 1053 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698