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

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

Issue 2331423004: Offline Pages - Removes the "ClearAllPages" API. (Closed)
Patch Set: Rebase Created 4 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_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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void OfflinePageDeleted(int64_t offline_id, 77 void OfflinePageDeleted(int64_t offline_id,
78 const ClientId& client_id) override; 78 const ClientId& client_id) override;
79 79
80 // OfflinePageTestArchiver::Observer implementation. 80 // OfflinePageTestArchiver::Observer implementation.
81 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override; 81 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override;
82 82
83 // OfflinePageModel callbacks. 83 // OfflinePageModel callbacks.
84 void OnSavePageDone(SavePageResult result, int64_t offline_id); 84 void OnSavePageDone(SavePageResult result, int64_t offline_id);
85 void OnDeletePageDone(DeletePageResult result); 85 void OnDeletePageDone(DeletePageResult result);
86 void OnCheckPagesExistOfflineDone(const CheckPagesExistOfflineResult& result); 86 void OnCheckPagesExistOfflineDone(const CheckPagesExistOfflineResult& result);
87 void OnClearAllDone();
88 void OnGetOfflineIdsForClientIdDone(MultipleOfflineIdResult* storage, 87 void OnGetOfflineIdsForClientIdDone(MultipleOfflineIdResult* storage,
89 const MultipleOfflineIdResult& result); 88 const MultipleOfflineIdResult& result);
90 void OnGetSingleOfflinePageItemResult(const OfflinePageItem** storage, 89 void OnGetSingleOfflinePageItemResult(const OfflinePageItem** storage,
91 const OfflinePageItem* result); 90 const OfflinePageItem* result);
92 void OnGetMultipleOfflinePageItemsResult( 91 void OnGetMultipleOfflinePageItemsResult(
93 MultipleOfflinePageItemResult* storage, 92 MultipleOfflinePageItemResult* storage,
94 const MultipleOfflinePageItemResult& result); 93 const MultipleOfflinePageItemResult& result);
95 void OnPagesExpired(bool result); 94 void OnPagesExpired(bool result);
96 95
97 // OfflinePageMetadataStore callbacks. 96 // OfflinePageMetadataStore callbacks.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 238
240 void OfflinePageModelImplTest::OnDeletePageDone(DeletePageResult result) { 239 void OfflinePageModelImplTest::OnDeletePageDone(DeletePageResult result) {
241 last_delete_result_ = result; 240 last_delete_result_ = result;
242 } 241 }
243 242
244 void OfflinePageModelImplTest::OnCheckPagesExistOfflineDone( 243 void OfflinePageModelImplTest::OnCheckPagesExistOfflineDone(
245 const CheckPagesExistOfflineResult& result) { 244 const CheckPagesExistOfflineResult& result) {
246 last_pages_exist_result_ = result; 245 last_pages_exist_result_ = result;
247 } 246 }
248 247
249 void OfflinePageModelImplTest::OnClearAllDone() {
250 PumpLoop();
251 }
252
253 void OfflinePageModelImplTest::OnStoreUpdateDone(bool /* success - ignored */) { 248 void OfflinePageModelImplTest::OnStoreUpdateDone(bool /* success - ignored */) {
254 } 249 }
255 250
256 std::unique_ptr<OfflinePageTestArchiver> 251 std::unique_ptr<OfflinePageTestArchiver>
257 OfflinePageModelImplTest::BuildArchiver( 252 OfflinePageModelImplTest::BuildArchiver(
258 const GURL& url, 253 const GURL& url,
259 OfflinePageArchiver::ArchiverResult result) { 254 OfflinePageArchiver::ArchiverResult result) {
260 return std::unique_ptr<OfflinePageTestArchiver>( 255 return std::unique_ptr<OfflinePageTestArchiver>(
261 new OfflinePageTestArchiver(this, url, result, kTestTitle, kTestFileSize, 256 new OfflinePageTestArchiver(this, url, result, kTestTitle, kTestFileSize,
262 base::ThreadTaskRunnerHandle::Get())); 257 base::ThreadTaskRunnerHandle::Get()));
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 TEST_F(OfflinePageModelImplTest, CanSaveURL) { 954 TEST_F(OfflinePageModelImplTest, CanSaveURL) {
960 EXPECT_TRUE(OfflinePageModel::CanSaveURL(GURL("http://foo"))); 955 EXPECT_TRUE(OfflinePageModel::CanSaveURL(GURL("http://foo")));
961 EXPECT_TRUE(OfflinePageModel::CanSaveURL(GURL("https://foo"))); 956 EXPECT_TRUE(OfflinePageModel::CanSaveURL(GURL("https://foo")));
962 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("file:///foo"))); 957 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("file:///foo")));
963 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("data:image/png;base64,ab"))); 958 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("data:image/png;base64,ab")));
964 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("chrome://version"))); 959 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("chrome://version")));
965 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("chrome-native://newtab/"))); 960 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("chrome-native://newtab/")));
966 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("/invalid/url.mhtml"))); 961 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("/invalid/url.mhtml")));
967 } 962 }
968 963
969 TEST_F(OfflinePageModelImplTest, ClearAll) {
970 SavePage(kTestUrl, kTestClientId1);
971 SavePage(kTestUrl2, kTestClientId2);
972
973 const std::vector<OfflinePageItem>& offline_pages = GetAllPages();
974 EXPECT_EQ(2UL, offline_pages.size());
975 EXPECT_EQ(2UL, GetStore()->GetAllPages().size());
976 base::FilePath archiver_path = offline_pages[0].file_path;
977 EXPECT_TRUE(base::PathExists(archiver_path));
978
979 // ClearAll should delete all the files and wipe out both cache and store.
980 model()->ClearAll(
981 base::Bind(&OfflinePageModelImplTest::OnClearAllDone, AsWeakPtr()));
982 PumpLoop();
983 EXPECT_EQ(0UL, GetAllPages().size());
984 EXPECT_EQ(0UL, GetStore()->GetAllPages().size());
985 EXPECT_FALSE(base::PathExists(archiver_path));
986
987 // The model should reload the store after the reset. All model operations
988 // should continue to work.
989 SavePage(kTestUrl2, kTestClientId2);
990 EXPECT_EQ(1UL, GetAllPages().size());
991 EXPECT_EQ(1UL, GetStore()->GetAllPages().size());
992 }
993
994 TEST_F(OfflinePageModelImplTest, SaveRetrieveMultipleClientIds) { 964 TEST_F(OfflinePageModelImplTest, SaveRetrieveMultipleClientIds) {
995 EXPECT_FALSE(HasPages(kTestClientNamespace)); 965 EXPECT_FALSE(HasPages(kTestClientNamespace));
996 SavePage(kTestUrl, kTestClientId1); 966 SavePage(kTestUrl, kTestClientId1);
997 int64_t offline1 = last_save_offline_id(); 967 int64_t offline1 = last_save_offline_id();
998 EXPECT_TRUE(HasPages(kTestClientNamespace)); 968 EXPECT_TRUE(HasPages(kTestClientNamespace));
999 969
1000 SavePage(kTestUrl2, kTestClientId1); 970 SavePage(kTestUrl2, kTestClientId1);
1001 int64_t offline2 = last_save_offline_id(); 971 int64_t offline2 = last_save_offline_id();
1002 972
1003 EXPECT_NE(offline1, offline2); 973 EXPECT_NE(offline1, offline2);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 // Check if feature is correctly enabled by command-line flag. 1197 // Check if feature is correctly enabled by command-line flag.
1228 scoped_feature_list.reset(new base::test::ScopedFeatureList); 1198 scoped_feature_list.reset(new base::test::ScopedFeatureList);
1229 scoped_feature_list->InitFromCommandLine( 1199 scoped_feature_list->InitFromCommandLine(
1230 std::string(kOfflineBookmarksFeature.name) + "," + 1200 std::string(kOfflineBookmarksFeature.name) + "," +
1231 kOfflinePagesSharingFeature.name, 1201 kOfflinePagesSharingFeature.name,
1232 ""); 1202 "");
1233 EXPECT_TRUE(offline_pages::IsOfflinePagesSharingEnabled()); 1203 EXPECT_TRUE(offline_pages::IsOfflinePagesSharingEnabled());
1234 } 1204 }
1235 1205
1236 } // namespace offline_pages 1206 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model_impl.cc ('k') | components/offline_pages/stub_offline_page_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698