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

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: Rebase 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
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..7d1eb54ff47990a0882b9746e53536ad1b20d3f5 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);
@@ -131,6 +132,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 +201,7 @@ class OfflinePageModelTest
// OfflinePageModel callbacks.
void OnSavePageDone(SavePageResult result);
void OnDeletePageDone(DeletePageResult result);
+ void OnClearAllDone();
// OfflinePageMetadataStore callbacks.
void OnStoreUpdateDone(bool /* success */);
@@ -325,6 +332,10 @@ void OfflinePageModelTest::OnDeletePageDone(DeletePageResult result) {
last_delete_result_ = result;
}
+void OfflinePageModelTest::OnClearAllDone() {
+ base::RunLoop().RunUntilIdle();
+}
+
void OfflinePageModelTest::OnStoreUpdateDone(bool /* success - ignored */) {
}
@@ -888,4 +899,41 @@ 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();
+ const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages();
+ EXPECT_EQ(1UL, offline_pages.size());
+ EXPECT_EQ(1UL, GetStore()->offline_pages().size());
fgorski 2015/10/23 20:55:03 come on :) have at least 2 items in the store here
jianli 2015/10/26 21:42:44 Done.
+ 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> archiver2(
+ BuildArchiver(kTestUrl2,
+ OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
+ .Pass());
+ model()->SavePage(
+ kTestUrl2, kTestPageBookmarkId2, archiver2.Pass(),
+ base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
+ PumpLoop();
+ EXPECT_EQ(1UL, model()->GetAllPages().size());
+ EXPECT_EQ(1UL, GetStore()->offline_pages().size());
+}
+
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698