| OLD | NEW |
| 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 13 matching lines...) Expand all Loading... |
| 24 #include "components/offline_pages/client_policy_controller.h" | 24 #include "components/offline_pages/client_policy_controller.h" |
| 25 #include "components/offline_pages/offline_page_client_policy.h" | 25 #include "components/offline_pages/offline_page_client_policy.h" |
| 26 #include "components/offline_pages/offline_page_feature.h" | 26 #include "components/offline_pages/offline_page_feature.h" |
| 27 #include "components/offline_pages/offline_page_item.h" | 27 #include "components/offline_pages/offline_page_item.h" |
| 28 #include "components/offline_pages/offline_page_storage_manager.h" | 28 #include "components/offline_pages/offline_page_storage_manager.h" |
| 29 #include "components/offline_pages/offline_page_test_archiver.h" | 29 #include "components/offline_pages/offline_page_test_archiver.h" |
| 30 #include "components/offline_pages/offline_page_test_store.h" | 30 #include "components/offline_pages/offline_page_test_store.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 33 | 33 |
| 34 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult; | |
| 35 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult; | |
| 36 using SingleOfflinePageItemResult = | |
| 37 offline_pages::OfflinePageModel::SingleOfflinePageItemResult; | |
| 38 using MultipleOfflinePageItemResult = | |
| 39 offline_pages::OfflinePageModel::MultipleOfflinePageItemResult; | |
| 40 using CheckPagesExistOfflineResult = | |
| 41 offline_pages::OfflinePageModel::CheckPagesExistOfflineResult; | |
| 42 using MultipleOfflineIdResult = | |
| 43 offline_pages::OfflinePageModel::MultipleOfflineIdResult; | |
| 44 | |
| 45 namespace offline_pages { | 34 namespace offline_pages { |
| 46 | 35 |
| 47 namespace { | 36 namespace { |
| 48 const char kTestClientNamespace[] = "CLIENT_NAMESPACE"; | 37 const char kTestClientNamespace[] = "CLIENT_NAMESPACE"; |
| 49 const GURL kTestUrl("http://example.com"); | 38 const GURL kTestUrl("http://example.com"); |
| 50 const GURL kTestUrl2("http://other.page.com"); | 39 const GURL kTestUrl2("http://other.page.com"); |
| 51 const GURL kTestUrl3("http://test.xyz"); | 40 const GURL kTestUrl3("http://test.xyz"); |
| 52 const GURL kFileUrl("file:///foo"); | 41 const GURL kFileUrl("file:///foo"); |
| 53 const ClientId kTestClientId1(kTestClientNamespace, "1234"); | 42 const ClientId kTestClientId1(kTestClientNamespace, "1234"); |
| 54 const ClientId kTestClientId2(kTestClientNamespace, "5678"); | 43 const ClientId kTestClientId2(kTestClientNamespace, "5678"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 112 |
| 124 MultipleOfflinePageItemResult GetAllPages(); | 113 MultipleOfflinePageItemResult GetAllPages(); |
| 125 | 114 |
| 126 void SavePage(const GURL& url, ClientId client_id); | 115 void SavePage(const GURL& url, ClientId client_id); |
| 127 | 116 |
| 128 void SavePageWithArchiverResult(const GURL& url, | 117 void SavePageWithArchiverResult(const GURL& url, |
| 129 ClientId client_id, | 118 ClientId client_id, |
| 130 OfflinePageArchiver::ArchiverResult result); | 119 OfflinePageArchiver::ArchiverResult result); |
| 131 | 120 |
| 132 void DeletePage(int64_t offline_id, | 121 void DeletePage(int64_t offline_id, |
| 133 const OfflinePageModel::DeletePageCallback& callback) { | 122 const DeletePageCallback& callback) { |
| 134 std::vector<int64_t> offline_ids; | 123 std::vector<int64_t> offline_ids; |
| 135 offline_ids.push_back(offline_id); | 124 offline_ids.push_back(offline_id); |
| 136 model()->DeletePagesByOfflineId(offline_ids, callback); | 125 model()->DeletePagesByOfflineId(offline_ids, callback); |
| 137 } | 126 } |
| 138 | 127 |
| 139 bool HasPages(std::string name_space); | 128 bool HasPages(std::string name_space); |
| 140 | 129 |
| 141 CheckPagesExistOfflineResult CheckPagesExistOffline(std::set<GURL>); | 130 CheckPagesExistOfflineResult CheckPagesExistOffline(std::set<GURL>); |
| 142 | 131 |
| 143 MultipleOfflineIdResult GetOfflineIdsForClientId(const ClientId& client_id); | 132 MultipleOfflineIdResult GetOfflineIdsForClientId(const ClientId& client_id); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 const ClientId& client_id) { | 215 const ClientId& client_id) { |
| 227 last_deleted_offline_id_ = offline_id; | 216 last_deleted_offline_id_ = offline_id; |
| 228 last_deleted_client_id_ = client_id; | 217 last_deleted_client_id_ = client_id; |
| 229 } | 218 } |
| 230 | 219 |
| 231 void OfflinePageModelTest::SetLastPathCreatedByArchiver( | 220 void OfflinePageModelTest::SetLastPathCreatedByArchiver( |
| 232 const base::FilePath& file_path) { | 221 const base::FilePath& file_path) { |
| 233 last_archiver_path_ = file_path; | 222 last_archiver_path_ = file_path; |
| 234 } | 223 } |
| 235 | 224 |
| 236 void OfflinePageModelTest::OnSavePageDone( | 225 void OfflinePageModelTest::OnSavePageDone(SavePageResult result, |
| 237 OfflinePageModel::SavePageResult result, | 226 int64_t offline_id) { |
| 238 int64_t offline_id) { | |
| 239 last_save_result_ = result; | 227 last_save_result_ = result; |
| 240 last_save_offline_id_ = offline_id; | 228 last_save_offline_id_ = offline_id; |
| 241 } | 229 } |
| 242 | 230 |
| 243 void OfflinePageModelTest::OnDeletePageDone(DeletePageResult result) { | 231 void OfflinePageModelTest::OnDeletePageDone(DeletePageResult result) { |
| 244 last_delete_result_ = result; | 232 last_delete_result_ = result; |
| 245 } | 233 } |
| 246 | 234 |
| 247 void OfflinePageModelTest::OnHasPagesDone(bool result) { | 235 void OfflinePageModelTest::OnHasPagesDone(bool result) { |
| 248 last_has_pages_result_ = result; | 236 last_has_pages_result_ = result; |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); | 1024 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); |
| 1037 feature_list2->InitializeFromCommandLine( | 1025 feature_list2->InitializeFromCommandLine( |
| 1038 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + | 1026 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + |
| 1039 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, | 1027 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, |
| 1040 ""); | 1028 ""); |
| 1041 base::FeatureList::SetInstance(std::move(feature_list2)); | 1029 base::FeatureList::SetInstance(std::move(feature_list2)); |
| 1042 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); | 1030 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); |
| 1043 } | 1031 } |
| 1044 | 1032 |
| 1045 } // namespace offline_pages | 1033 } // namespace offline_pages |
| OLD | NEW |