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

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

Issue 2536573003: [Offline pages] Preventing GetPagesMatchingQuery from running before model is loaded (Closed)
Patch Set: Adding a test for public method GetPagesMatchingQuery Created 4 years 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (page.client_id.name_space == name_space) 475 if (page.client_id.name_space == name_space)
476 return true; 476 return true;
477 } 477 }
478 478
479 return false; 479 return false;
480 } 480 }
481 481
482 TEST_F(OfflinePageModelImplTest, SavePageSuccessful) { 482 TEST_F(OfflinePageModelImplTest, SavePageSuccessful) {
483 EXPECT_FALSE(HasPages(kTestClientNamespace)); 483 EXPECT_FALSE(HasPages(kTestClientNamespace));
484 484
485 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 485 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
486 kTestUrl, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)); 486 kTestUrl, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED));
487 SavePageWithArchiverAsync( 487 SavePageWithArchiverAsync(
488 kTestUrl, kTestClientId1, kTestUrl2, std::move(archiver)); 488 kTestUrl, kTestClientId1, kTestUrl2, std::move(archiver));
489 PumpLoop(); 489 PumpLoop();
490 EXPECT_TRUE(HasPages(kTestClientNamespace)); 490 EXPECT_TRUE(HasPages(kTestClientNamespace));
491 491
492 OfflinePageTestStore* store = GetStore(); 492 OfflinePageTestStore* store = GetStore();
493 EXPECT_EQ(kTestUrl, store->last_saved_page().url); 493 EXPECT_EQ(kTestUrl, store->last_saved_page().url);
494 EXPECT_EQ(kTestClientId1.id, store->last_saved_page().client_id.id); 494 EXPECT_EQ(kTestClientId1.id, store->last_saved_page().client_id.id);
495 EXPECT_EQ(kTestClientId1.name_space, 495 EXPECT_EQ(kTestClientId1.name_space,
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 EXPECT_EQ(StoreState::FAILED_RESET, GetStore()->state()); 1264 EXPECT_EQ(StoreState::FAILED_RESET, GetStore()->state());
1265 EXPECT_EQ(0UL, offline_pages.size()); 1265 EXPECT_EQ(0UL, offline_pages.size());
1266 1266
1267 ResetResults(); 1267 ResetResults();
1268 std::pair<SavePageResult, int64_t> result = 1268 std::pair<SavePageResult, int64_t> result =
1269 SavePage(kTestUrl, ClientId(kDownloadNamespace, "123")); 1269 SavePage(kTestUrl, ClientId(kDownloadNamespace, "123"));
1270 1270
1271 EXPECT_EQ(SavePageResult::STORE_FAILURE, result.first); 1271 EXPECT_EQ(SavePageResult::STORE_FAILURE, result.first);
1272 } 1272 }
1273 1273
1274 TEST_F(OfflinePageModelImplTest, GetPagesMatchingQuery) {
1275 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
1276 kTestUrl, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED));
1277 SavePageWithArchiverAsync(kTestUrl, kTestClientId1, kTestUrl2,
1278 std::move(archiver));
1279 PumpLoop();
1280
1281 std::vector<ClientId> client_ids{kTestClientId1};
1282 OfflinePageModelQueryBuilder builder;
1283 builder.SetClientIds(OfflinePageModelQuery::Requirement::INCLUDE_MATCHING,
1284 client_ids);
1285
1286 MultipleOfflinePageItemResult offline_pages;
1287 model()->GetPagesMatchingQuery(
1288 builder.Build(model()->GetPolicyController()),
1289 base::Bind(&OfflinePageModelImplTest::OnGetMultipleOfflinePageItemsResult,
1290 AsWeakPtr(), base::Unretained(&offline_pages)));
1291 PumpLoop();
1292
1293 ASSERT_EQ(1UL, offline_pages.size());
1294 EXPECT_EQ(kTestUrl, offline_pages[0].url);
1295 EXPECT_EQ(kTestClientId1.id, offline_pages[0].client_id.id);
1296 EXPECT_EQ(kTestClientId1.name_space, offline_pages[0].client_id.name_space);
1297 EXPECT_EQ(last_archiver_path(), offline_pages[0].file_path);
1298 EXPECT_EQ(kTestFileSize, offline_pages[0].file_size);
1299 EXPECT_EQ(0, offline_pages[0].access_count);
1300 EXPECT_EQ(0, offline_pages[0].flags);
1301 EXPECT_EQ(kTestTitle, offline_pages[0].title);
1302 EXPECT_EQ(kTestUrl2, offline_pages[0].original_url);
1303 }
1304
1274 TEST(CommandLineFlagsTest, OfflineBookmarks) { 1305 TEST(CommandLineFlagsTest, OfflineBookmarks) {
1275 // Disabled by default. 1306 // Disabled by default.
1276 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled()); 1307 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled());
1277 1308
1278 // Check if feature is correctly enabled by command-line flag. 1309 // Check if feature is correctly enabled by command-line flag.
1279 base::test::ScopedFeatureList scoped_feature_list; 1310 base::test::ScopedFeatureList scoped_feature_list;
1280 scoped_feature_list.InitAndEnableFeature(kOfflineBookmarksFeature); 1311 scoped_feature_list.InitAndEnableFeature(kOfflineBookmarksFeature);
1281 EXPECT_TRUE(offline_pages::IsOfflineBookmarksEnabled()); 1312 EXPECT_TRUE(offline_pages::IsOfflineBookmarksEnabled());
1282 } 1313 }
1283 1314
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); 1355 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled());
1325 1356
1326 // Check if feature is correctly enabled by command-line flag. 1357 // Check if feature is correctly enabled by command-line flag.
1327 base::test::ScopedFeatureList scoped_feature_list; 1358 base::test::ScopedFeatureList scoped_feature_list;
1328 scoped_feature_list.InitAndEnableFeature( 1359 scoped_feature_list.InitAndEnableFeature(
1329 kOfflinePagesSvelteConcurrentLoadingFeature); 1360 kOfflinePagesSvelteConcurrentLoadingFeature);
1330 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); 1361 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled());
1331 } 1362 }
1332 1363
1333 } // namespace offline_pages 1364 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698