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

Side by Side 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 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); 48 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
49 explicit OfflinePageTestStore(const OfflinePageTestStore& other_store); 49 explicit OfflinePageTestStore(const OfflinePageTestStore& other_store);
50 ~OfflinePageTestStore() override; 50 ~OfflinePageTestStore() override;
51 51
52 // OfflinePageMetadataStore overrides: 52 // OfflinePageMetadataStore overrides:
53 void Load(const LoadCallback& callback) override; 53 void Load(const LoadCallback& callback) override;
54 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, 54 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page,
55 const UpdateCallback& callback) override; 55 const UpdateCallback& callback) override;
56 void RemoveOfflinePages(const std::vector<int64>& bookmark_ids, 56 void RemoveOfflinePages(const std::vector<int64>& bookmark_ids,
57 const UpdateCallback& callback) override; 57 const UpdateCallback& callback) override;
58 void Reset(const ResetCallback& callback) override;
58 59
59 void UpdateLastAccessTime(int64 bookmark_id, 60 void UpdateLastAccessTime(int64 bookmark_id,
60 const base::Time& last_access_time); 61 const base::Time& last_access_time);
61 62
62 const OfflinePageItem& last_saved_page() const { return last_saved_page_; } 63 const OfflinePageItem& last_saved_page() const { return last_saved_page_; }
63 64
64 void set_test_scenario(TestScenario scenario) { scenario_ = scenario; }; 65 void set_test_scenario(TestScenario scenario) { scenario_ = scenario; };
65 66
66 const std::vector<OfflinePageItem>& offline_pages() const { 67 const std::vector<OfflinePageItem>& offline_pages() const {
67 return offline_pages_; 68 return offline_pages_;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 offline_pages_.erase(iter); 125 offline_pages_.erase(iter);
125 result = true; 126 result = true;
126 break; 127 break;
127 } 128 }
128 } 129 }
129 } 130 }
130 131
131 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); 132 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
132 } 133 }
133 134
135 void OfflinePageTestStore::Reset(const ResetCallback& callback) {
136 offline_pages_.clear();
137 task_runner_->PostTask(FROM_HERE, base::Bind(callback, true));
138 }
139
134 void OfflinePageTestStore:: UpdateLastAccessTime( 140 void OfflinePageTestStore:: UpdateLastAccessTime(
135 int64 bookmark_id, const base::Time& last_access_time) { 141 int64 bookmark_id, const base::Time& last_access_time) {
136 for (auto& offline_page : offline_pages_) { 142 for (auto& offline_page : offline_pages_) {
137 if (offline_page.bookmark_id == bookmark_id) { 143 if (offline_page.bookmark_id == bookmark_id) {
138 offline_page.last_access_time = last_access_time; 144 offline_page.last_access_time = last_access_time;
139 return; 145 return;
140 } 146 }
141 } 147 }
142 } 148 }
143 149
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 void TearDown() override; 194 void TearDown() override;
189 195
190 // OfflinePageModel::Observer implementation. 196 // OfflinePageModel::Observer implementation.
191 void OfflinePageModelLoaded(OfflinePageModel* model) override; 197 void OfflinePageModelLoaded(OfflinePageModel* model) override;
192 void OfflinePageModelChanged(OfflinePageModel* model) override; 198 void OfflinePageModelChanged(OfflinePageModel* model) override;
193 void OfflinePageDeleted(int64 bookmark_id) override; 199 void OfflinePageDeleted(int64 bookmark_id) override;
194 200
195 // OfflinePageModel callbacks. 201 // OfflinePageModel callbacks.
196 void OnSavePageDone(SavePageResult result); 202 void OnSavePageDone(SavePageResult result);
197 void OnDeletePageDone(DeletePageResult result); 203 void OnDeletePageDone(DeletePageResult result);
204 void OnClearAllDone();
198 205
199 // OfflinePageMetadataStore callbacks. 206 // OfflinePageMetadataStore callbacks.
200 void OnStoreUpdateDone(bool /* success */); 207 void OnStoreUpdateDone(bool /* success */);
201 208
202 scoped_ptr<OfflinePageTestArchiver> BuildArchiver( 209 scoped_ptr<OfflinePageTestArchiver> BuildArchiver(
203 const GURL& url, 210 const GURL& url,
204 OfflinePageArchiver::ArchiverResult result); 211 OfflinePageArchiver::ArchiverResult result);
205 scoped_ptr<OfflinePageMetadataStore> BuildStore(); 212 scoped_ptr<OfflinePageMetadataStore> BuildStore();
206 scoped_ptr<OfflinePageModel> BuildModel( 213 scoped_ptr<OfflinePageModel> BuildModel(
207 scoped_ptr<OfflinePageMetadataStore> store); 214 scoped_ptr<OfflinePageMetadataStore> store);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 325
319 void OfflinePageModelTest::OnSavePageDone( 326 void OfflinePageModelTest::OnSavePageDone(
320 OfflinePageModel::SavePageResult result) { 327 OfflinePageModel::SavePageResult result) {
321 last_save_result_ = result; 328 last_save_result_ = result;
322 } 329 }
323 330
324 void OfflinePageModelTest::OnDeletePageDone(DeletePageResult result) { 331 void OfflinePageModelTest::OnDeletePageDone(DeletePageResult result) {
325 last_delete_result_ = result; 332 last_delete_result_ = result;
326 } 333 }
327 334
335 void OfflinePageModelTest::OnClearAllDone() {
336 base::RunLoop().RunUntilIdle();
337 }
338
328 void OfflinePageModelTest::OnStoreUpdateDone(bool /* success - ignored */) { 339 void OfflinePageModelTest::OnStoreUpdateDone(bool /* success - ignored */) {
329 } 340 }
330 341
331 scoped_ptr<OfflinePageTestArchiver> OfflinePageModelTest::BuildArchiver( 342 scoped_ptr<OfflinePageTestArchiver> OfflinePageModelTest::BuildArchiver(
332 const GURL& url, 343 const GURL& url,
333 OfflinePageArchiver::ArchiverResult result) { 344 OfflinePageArchiver::ArchiverResult result) {
334 return scoped_ptr<OfflinePageTestArchiver>(new OfflinePageTestArchiver( 345 return scoped_ptr<OfflinePageTestArchiver>(new OfflinePageTestArchiver(
335 this, url, temp_dir_.path(), result, task_runner())); 346 this, url, temp_dir_.path(), result, task_runner()));
336 } 347 }
337 348
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 892
882 TEST_F(OfflinePageModelTest, CanSavePage) { 893 TEST_F(OfflinePageModelTest, CanSavePage) {
883 EXPECT_TRUE(OfflinePageModel::CanSavePage(GURL("http://foo"))); 894 EXPECT_TRUE(OfflinePageModel::CanSavePage(GURL("http://foo")));
884 EXPECT_TRUE(OfflinePageModel::CanSavePage(GURL("https://foo"))); 895 EXPECT_TRUE(OfflinePageModel::CanSavePage(GURL("https://foo")));
885 EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("file:///foo"))); 896 EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("file:///foo")));
886 EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("data:image/png;base64,ab"))); 897 EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("data:image/png;base64,ab")));
887 EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("chrome://version"))); 898 EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("chrome://version")));
888 EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("chrome-native://newtab/"))); 899 EXPECT_FALSE(OfflinePageModel::CanSavePage(GURL("chrome-native://newtab/")));
889 } 900 }
890 901
902 TEST_F(OfflinePageModelTest, ClearAll) {
903 scoped_ptr<OfflinePageTestArchiver> archiver(
904 BuildArchiver(kTestUrl,
905 OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
906 .Pass());
907 model()->SavePage(
908 kTestUrl, kTestPageBookmarkId1, archiver.Pass(),
909 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
910 PumpLoop();
911 const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages();
912 EXPECT_EQ(1UL, offline_pages.size());
913 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.
914 base::FilePath archiver_path = offline_pages[0].file_path;
915 EXPECT_TRUE(base::PathExists(archiver_path));
916
917 // ClearAll should delete all the files and wipe out both cache and store.
918 model()->ClearAll(
919 base::Bind(&OfflinePageModelTest::OnClearAllDone, AsWeakPtr()));
920 PumpLoop();
921 EXPECT_EQ(0UL, model()->GetAllPages().size());
922 EXPECT_EQ(0UL, GetStore()->offline_pages().size());
923 EXPECT_FALSE(base::PathExists(archiver_path));
924
925 // The model should reload the store after the reset. All model operations
926 // should continue to work.
927 scoped_ptr<OfflinePageTestArchiver> archiver2(
928 BuildArchiver(kTestUrl2,
929 OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
930 .Pass());
931 model()->SavePage(
932 kTestUrl2, kTestPageBookmarkId2, archiver2.Pass(),
933 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
934 PumpLoop();
935 EXPECT_EQ(1UL, model()->GetAllPages().size());
936 EXPECT_EQ(1UL, GetStore()->offline_pages().size());
937 }
938
891 } // namespace offline_pages 939 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698