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

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

Issue 2497703002: [Offline pages] Resetting offline page metadata store to handle LOAD/INIT failures (Closed)
Patch Set: Addressing STORE_INIT_FAILED 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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 EXPECT_EQ(kTestFileSize, offline_pages[0].file_size); 602 EXPECT_EQ(kTestFileSize, offline_pages[0].file_size);
603 EXPECT_EQ(1, offline_pages[0].access_count); 603 EXPECT_EQ(1, offline_pages[0].access_count);
604 } 604 }
605 605
606 TEST_F(OfflinePageModelImplTest, GetAllPagesStoreEmpty) { 606 TEST_F(OfflinePageModelImplTest, GetAllPagesStoreEmpty) {
607 const std::vector<OfflinePageItem>& offline_pages = GetAllPages(); 607 const std::vector<OfflinePageItem>& offline_pages = GetAllPages();
608 608
609 EXPECT_EQ(0UL, offline_pages.size()); 609 EXPECT_EQ(0UL, offline_pages.size());
610 } 610 }
611 611
612 TEST_F(OfflinePageModelImplTest, GetAllPagesStoreFailure) {
613 GetStore()->set_test_scenario(
614 OfflinePageTestStore::TestScenario::LOAD_FAILED);
615 const std::vector<OfflinePageItem>& offline_pages = GetAllPages();
616
617 EXPECT_EQ(0UL, offline_pages.size());
618 }
619
620 TEST_F(OfflinePageModelImplTest, DeletePageSuccessful) { 612 TEST_F(OfflinePageModelImplTest, DeletePageSuccessful) {
621 OfflinePageTestStore* store = GetStore(); 613 OfflinePageTestStore* store = GetStore();
622 614
623 // Save one page. 615 // Save one page.
624 SavePage(kTestUrl, kTestClientId1); 616 SavePage(kTestUrl, kTestClientId1);
625 int64_t offline1 = last_save_offline_id(); 617 int64_t offline1 = last_save_offline_id();
626 EXPECT_EQ(SavePageResult::SUCCESS, last_save_result()); 618 EXPECT_EQ(SavePageResult::SUCCESS, last_save_result());
627 EXPECT_EQ(1u, store->GetAllPages().size()); 619 EXPECT_EQ(1u, store->GetAllPages().size());
628 620
629 ResetResults(); 621 ResetResults();
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 1169
1178 TEST_F(OfflinePageModelImplTest, NewTabPageNamespace) { 1170 TEST_F(OfflinePageModelImplTest, NewTabPageNamespace) {
1179 SavePage(kTestUrl, ClientId(kNTPSuggestionsNamespace, "123")); 1171 SavePage(kTestUrl, ClientId(kNTPSuggestionsNamespace, "123"));
1180 std::string histogram_name = "OfflinePages.SavePageResult."; 1172 std::string histogram_name = "OfflinePages.SavePageResult.";
1181 histogram_name += kNTPSuggestionsNamespace; 1173 histogram_name += kNTPSuggestionsNamespace;
1182 1174
1183 histograms().ExpectUniqueSample(histogram_name, 1175 histograms().ExpectUniqueSample(histogram_name,
1184 static_cast<int>(SavePageResult::SUCCESS), 1); 1176 static_cast<int>(SavePageResult::SUCCESS), 1);
1185 } 1177 }
1186 1178
1179 TEST_F(OfflinePageModelImplTest, StoreResetSuccessful) {
1180 GetStore()->set_test_scenario(
1181 OfflinePageTestStore::TestScenario::LOAD_FAILED_RESET_SUCCESS);
1182 ResetModel();
1183
1184 const std::vector<OfflinePageItem>& offline_pages = GetAllPages();
1185
1186 EXPECT_TRUE(model()->is_loaded());
1187 EXPECT_EQ(StoreState::LOADED, GetStore()->state());
1188 EXPECT_EQ(0UL, offline_pages.size());
1189
1190 std::pair<SavePageResult, int64_t> result =
1191 SavePage(kTestUrl, ClientId(kDownloadNamespace, "123"));
1192
1193 EXPECT_EQ(SavePageResult::SUCCESS, result.first);
1194 }
1195
1196 TEST_F(OfflinePageModelImplTest, StoreResetFailed) {
1197 GetStore()->set_test_scenario(
1198 OfflinePageTestStore::TestScenario::LOAD_FAILED_RESET_FAILED);
1199 ResetModel();
1200
1201 const std::vector<OfflinePageItem>& offline_pages = GetAllPages();
1202
1203 EXPECT_TRUE(model()->is_loaded());
1204 EXPECT_EQ(StoreState::FAILED_RESET, GetStore()->state());
1205 EXPECT_EQ(0UL, offline_pages.size());
1206
1207 std::pair<SavePageResult, int64_t> result =
1208 SavePage(kTestUrl, ClientId(kDownloadNamespace, "123"));
1209
1210 EXPECT_EQ(SavePageResult::STORE_FAILURE, result.first);
1211 }
1212
1187 TEST(CommandLineFlagsTest, OfflineBookmarks) { 1213 TEST(CommandLineFlagsTest, OfflineBookmarks) {
1188 // Disabled by default. 1214 // Disabled by default.
1189 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled()); 1215 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled());
1190 1216
1191 // Check if feature is correctly enabled by command-line flag. 1217 // Check if feature is correctly enabled by command-line flag.
1192 base::test::ScopedFeatureList scoped_feature_list; 1218 base::test::ScopedFeatureList scoped_feature_list;
1193 scoped_feature_list.InitAndEnableFeature(kOfflineBookmarksFeature); 1219 scoped_feature_list.InitAndEnableFeature(kOfflineBookmarksFeature);
1194 EXPECT_TRUE(offline_pages::IsOfflineBookmarksEnabled()); 1220 EXPECT_TRUE(offline_pages::IsOfflineBookmarksEnabled());
1195 } 1221 }
1196 1222
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); 1263 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled());
1238 1264
1239 // Check if feature is correctly enabled by command-line flag. 1265 // Check if feature is correctly enabled by command-line flag.
1240 base::test::ScopedFeatureList scoped_feature_list; 1266 base::test::ScopedFeatureList scoped_feature_list;
1241 scoped_feature_list.InitAndEnableFeature( 1267 scoped_feature_list.InitAndEnableFeature(
1242 kOfflinePagesSvelteConcurrentLoadingFeature); 1268 kOfflinePagesSvelteConcurrentLoadingFeature);
1243 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); 1269 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled());
1244 } 1270 }
1245 1271
1246 } // namespace offline_pages 1272 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698