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

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

Issue 2067143004: [Offline Pages] Duplicate pages when save/delete bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments from dimich@. 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 923 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 EXPECT_EQ(1UL, GetAllPages().size()); 934 EXPECT_EQ(1UL, GetAllPages().size());
935 EXPECT_EQ(1UL, GetStore()->GetAllPages().size()); 935 EXPECT_EQ(1UL, GetStore()->GetAllPages().size());
936 } 936 }
937 937
938 TEST_F(OfflinePageModelImplTest, SaveRetrieveMultipleClientIds) { 938 TEST_F(OfflinePageModelImplTest, SaveRetrieveMultipleClientIds) {
939 EXPECT_FALSE(HasPages(kTestClientNamespace)); 939 EXPECT_FALSE(HasPages(kTestClientNamespace));
940 SavePage(kTestUrl, kTestClientId1); 940 SavePage(kTestUrl, kTestClientId1);
941 int64_t offline1 = last_save_offline_id(); 941 int64_t offline1 = last_save_offline_id();
942 EXPECT_TRUE(HasPages(kTestClientNamespace)); 942 EXPECT_TRUE(HasPages(kTestClientNamespace));
943 943
944 SavePage(kTestUrl, kTestClientId1); 944 SavePage(kTestUrl2, kTestClientId1);
945 int64_t offline2 = last_save_offline_id(); 945 int64_t offline2 = last_save_offline_id();
946 946
947 EXPECT_NE(offline1, offline2); 947 EXPECT_NE(offline1, offline2);
948 948
949 const std::vector<int64_t> ids = GetOfflineIdsForClientId(kTestClientId1); 949 const std::vector<int64_t> ids = GetOfflineIdsForClientId(kTestClientId1);
950 950
951 EXPECT_EQ(2UL, ids.size()); 951 EXPECT_EQ(2UL, ids.size());
952 952
953 std::set<int64_t> id_set; 953 std::set<int64_t> id_set;
954 for (size_t i = 0; i < ids.size(); i++) { 954 for (size_t i = 0; i < ids.size(); i++) {
955 id_set.insert(ids[i]); 955 id_set.insert(ids[i]);
956 } 956 }
957 957
958 EXPECT_TRUE(id_set.find(offline1) != id_set.end()); 958 EXPECT_TRUE(id_set.find(offline1) != id_set.end());
959 EXPECT_TRUE(id_set.find(offline2) != id_set.end()); 959 EXPECT_TRUE(id_set.find(offline2) != id_set.end());
960 } 960 }
961 961
962 TEST_F(OfflinePageModelImplTest, SaveMultiplePagesWithSameURLBySameClientId) {
963 EXPECT_FALSE(HasPages(kTestClientNamespace));
964 SavePage(kTestUrl, kTestClientId1);
965 int64_t offline1 = last_save_offline_id();
966 EXPECT_TRUE(HasPages(kTestClientNamespace));
967
968 SavePage(kTestUrl, kTestClientId1);
969 int64_t offline2 = last_save_offline_id();
970
971 EXPECT_NE(offline1, offline2);
972
973 const std::vector<int64_t> ids = GetOfflineIdsForClientId(kTestClientId1);
974
975 EXPECT_EQ(1UL, ids.size());
976
977 std::set<int64_t> id_set;
978 for (size_t i = 0; i < ids.size(); i++) {
979 id_set.insert(ids[i]);
980 }
981
982 EXPECT_TRUE(id_set.find(offline2) != id_set.end());
983 }
984
962 TEST_F(OfflinePageModelImplTest, GetBestPage) { 985 TEST_F(OfflinePageModelImplTest, GetBestPage) {
963 // We will save 3 pages - two for the same URL, and one for a different URL. 986 // We will save 3 pages - two for the same URL, and one for a different URL.
964 // Correct behavior will pick the most recently saved page for the correct 987 // Correct behavior will pick the most recently saved page for the correct
965 // URL. 988 // URL.
966 std::pair<SavePageResult, int64_t> saved_pages[3]; 989 std::pair<SavePageResult, int64_t> saved_pages[3];
967 saved_pages[0] = SavePage(kTestUrl, kTestClientId1); 990 saved_pages[0] = SavePage(kTestUrl, kTestClientId1);
968 saved_pages[1] = SavePage(kTestUrl, kTestClientId1); 991 saved_pages[1] = SavePage(kTestUrl, kTestClientId1);
969 saved_pages[2] = SavePage(kTestUrl2, kTestClientId2); 992 saved_pages[2] = SavePage(kTestUrl2, kTestClientId2);
970 993
971 for (const auto& save_result : saved_pages) { 994 for (const auto& save_result : saved_pages) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); 1094 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList);
1072 feature_list2->InitializeFromCommandLine( 1095 feature_list2->InitializeFromCommandLine(
1073 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 1096 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," +
1074 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, 1097 offline_pages::kOfflinePagesBackgroundLoadingFeature.name,
1075 ""); 1098 "");
1076 base::FeatureList::SetInstance(std::move(feature_list2)); 1099 base::FeatureList::SetInstance(std::move(feature_list2));
1077 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 1100 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
1078 } 1101 }
1079 1102
1080 } // namespace offline_pages 1103 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model_impl.cc ('k') | components/offline_pages/offline_page_storage_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698