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

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

Issue 1843893002: Support resaving offline page right after it is being deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 PumpLoop(); 481 PumpLoop();
482 482
483 EXPECT_EQ(1UL, GetStore()->GetAllPages().size()); 483 EXPECT_EQ(1UL, GetStore()->GetAllPages().size());
484 484
485 // Fast forward to trigger the page deletion. 485 // Fast forward to trigger the page deletion.
486 FastForwardBy(OfflinePageModel::GetFinalDeletionDelayForTesting()); 486 FastForwardBy(OfflinePageModel::GetFinalDeletionDelayForTesting());
487 487
488 EXPECT_EQ(0UL, GetStore()->GetAllPages().size()); 488 EXPECT_EQ(0UL, GetStore()->GetAllPages().size());
489 } 489 }
490 490
491 TEST_F(OfflinePageModelTest, ResavePageAfterMarkingPageForDeletion) {
fgorski 2016/03/30 01:43:30 SavePageAfter...
jianli 2016/03/31 21:02:42 Done.
492 scoped_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
493 kTestUrl, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED));
494 model()->SavePage(
495 kTestUrl, kTestPageBookmarkId1, std::move(archiver),
496 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
497 PumpLoop();
498
499 // Mark the page for deletion.
500 model()->MarkPageForDeletion(
501 last_save_offline_id(),
502 base::Bind(&OfflinePageModelTest::OnDeletePageDone, AsWeakPtr()));
503 PumpLoop();
504
505 EXPECT_EQ(1UL, GetStore()->GetAllPages().size());
506
507 // Re-save the same page.
508 scoped_ptr<OfflinePageTestArchiver> archiver2(BuildArchiver(
509 kTestUrl, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED));
510 model()->SavePage(
511 kTestUrl, kTestPageBookmarkId1, std::move(archiver2),
512 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
513
514 // Fast forward to trigger the page cleanup.
515 FastForwardBy(OfflinePageModel::GetFinalDeletionDelayForTesting());
516
517 // The re-saved page should still exist.
518 const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages();
519 ASSERT_EQ(1UL, offline_pages.size());
520 EXPECT_EQ(kTestUrl, offline_pages[0].url);
521 EXPECT_EQ(kTestPageBookmarkId1, offline_pages[0].client_id);
522 EXPECT_EQ(kTestFileSize, offline_pages[0].file_size);
523 EXPECT_EQ(0, offline_pages[0].access_count);
524 }
525
491 TEST_F(OfflinePageModelTest, GetAllPagesStoreEmpty) { 526 TEST_F(OfflinePageModelTest, GetAllPagesStoreEmpty) {
492 const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages(); 527 const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages();
493 528
494 EXPECT_EQ(0UL, offline_pages.size()); 529 EXPECT_EQ(0UL, offline_pages.size());
495 } 530 }
496 531
497 TEST_F(OfflinePageModelTest, GetAllPagesStoreFailure) { 532 TEST_F(OfflinePageModelTest, GetAllPagesStoreFailure) {
498 GetStore()->set_test_scenario( 533 GetStore()->set_test_scenario(
499 OfflinePageTestStore::TestScenario::LOAD_FAILED); 534 OfflinePageTestStore::TestScenario::LOAD_FAILED);
500 const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages(); 535 const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages();
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 // Check if feature is correctly enabled by command-line flag. 1067 // Check if feature is correctly enabled by command-line flag.
1033 base::FeatureList::ClearInstanceForTesting(); 1068 base::FeatureList::ClearInstanceForTesting();
1034 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); 1069 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
1035 feature_list->InitializeFromCommandLine( 1070 feature_list->InitializeFromCommandLine(
1036 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, ""); 1071 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, "");
1037 base::FeatureList::SetInstance(std::move(feature_list)); 1072 base::FeatureList::SetInstance(std::move(feature_list));
1038 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 1073 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
1039 } 1074 }
1040 1075
1041 } // namespace offline_pages 1076 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698