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

Unified Diff: components/offline_pages/offline_page_model_unittest.cc

Issue 1420003004: Wipe out offline page data on clearing cookie and site data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address more feedback Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/offline_page_model_unittest.cc
diff --git a/components/offline_pages/offline_page_model_unittest.cc b/components/offline_pages/offline_page_model_unittest.cc
index aab0a4a200b3d96b856e80d50c7282475e981c5d..e9a5ac92bcd3e05f07138c3a11426226507fd2b4 100644
--- a/components/offline_pages/offline_page_model_unittest.cc
+++ b/components/offline_pages/offline_page_model_unittest.cc
@@ -55,6 +55,7 @@ class OfflinePageTestStore : public OfflinePageMetadataStore {
const UpdateCallback& callback) override;
void RemoveOfflinePages(const std::vector<int64>& bookmark_ids,
const UpdateCallback& callback) override;
+ void Reset(const ResetCallback& callback) override;
void UpdateLastAccessTime(int64 bookmark_id,
const base::Time& last_access_time);
@@ -93,13 +94,15 @@ OfflinePageTestStore::~OfflinePageTestStore() {
}
void OfflinePageTestStore::Load(const LoadCallback& callback) {
+ OfflinePageMetadataStore::LoadStatus load_status;
if (scenario_ != TestScenario::LOAD_FAILED) {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(callback, true, offline_pages_));
+ load_status = OfflinePageMetadataStore::LOAD_SUCCEEDED;
} else {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(callback, false, std::vector<OfflinePageItem>()));
+ load_status = OfflinePageMetadataStore::STORE_LOAD_FAILED;
+ offline_pages_.clear();
}
+ task_runner_->PostTask(
+ FROM_HERE, base::Bind(callback, load_status, offline_pages_));
}
void OfflinePageTestStore::AddOrUpdateOfflinePage(
@@ -131,6 +134,11 @@ void OfflinePageTestStore::RemoveOfflinePages(
task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
}
+void OfflinePageTestStore::Reset(const ResetCallback& callback) {
+ offline_pages_.clear();
+ task_runner_->PostTask(FROM_HERE, base::Bind(callback, true));
+}
+
void OfflinePageTestStore:: UpdateLastAccessTime(
int64 bookmark_id, const base::Time& last_access_time) {
for (auto& offline_page : offline_pages_) {
@@ -195,6 +203,7 @@ class OfflinePageModelTest
// OfflinePageModel callbacks.
void OnSavePageDone(SavePageResult result);
void OnDeletePageDone(DeletePageResult result);
+ void OnClearAllDone();
// OfflinePageMetadataStore callbacks.
void OnStoreUpdateDone(bool /* success */);
@@ -325,6 +334,10 @@ void OfflinePageModelTest::OnDeletePageDone(DeletePageResult result) {
last_delete_result_ = result;
}
+void OfflinePageModelTest::OnClearAllDone() {
+ base::RunLoop().RunUntilIdle();
+}
+
void OfflinePageModelTest::OnStoreUpdateDone(bool /* success - ignored */) {
}
@@ -888,4 +901,51 @@ TEST_F(OfflinePageModelTest, CanSavePage) {
EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("chrome-native://newtab/")));
}
+TEST_F(OfflinePageModelTest, ClearAll) {
+ scoped_ptr<OfflinePageTestArchiver> archiver(
+ BuildArchiver(kTestUrl,
+ OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
+ .Pass());
+ model()->SavePage(
+ kTestUrl, kTestPageBookmarkId1, archiver.Pass(),
+ base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
+ PumpLoop();
+
+ scoped_ptr<OfflinePageTestArchiver> archiver2(
+ BuildArchiver(kTestUrl2,
+ OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
+ .Pass());
+ model()->SavePage(
+ kTestUrl2, kTestPageBookmarkId2, archiver2.Pass(),
+ base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
+ PumpLoop();
+
+ const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages();
+ EXPECT_EQ(2UL, offline_pages.size());
+ EXPECT_EQ(2UL, GetStore()->offline_pages().size());
+ base::FilePath archiver_path = offline_pages[0].file_path;
+ EXPECT_TRUE(base::PathExists(archiver_path));
+
+ // ClearAll should delete all the files and wipe out both cache and store.
+ model()->ClearAll(
+ base::Bind(&OfflinePageModelTest::OnClearAllDone, AsWeakPtr()));
+ PumpLoop();
+ EXPECT_EQ(0UL, model()->GetAllPages().size());
+ EXPECT_EQ(0UL, GetStore()->offline_pages().size());
+ EXPECT_FALSE(base::PathExists(archiver_path));
+
+ // The model should reload the store after the reset. All model operations
+ // should continue to work.
+ scoped_ptr<OfflinePageTestArchiver> archiver3(
+ BuildArchiver(kTestUrl2,
+ OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
+ .Pass());
+ model()->SavePage(
+ kTestUrl2, kTestPageBookmarkId2, archiver3.Pass(),
+ base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
+ PumpLoop();
+ EXPECT_EQ(1UL, model()->GetAllPages().size());
+ EXPECT_EQ(1UL, GetStore()->offline_pages().size());
+}
+
} // namespace offline_pages
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698