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