| 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_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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/feature_list.h" | 13 #include "base/feature_list.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/test/test_mock_time_task_runner.h" | 20 #include "base/test/test_mock_time_task_runner.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "components/offline_pages/client_namespace_constants.h" |
| 23 #include "components/offline_pages/client_policy_controller.h" | 24 #include "components/offline_pages/client_policy_controller.h" |
| 24 #include "components/offline_pages/offline_page_client_policy.h" | 25 #include "components/offline_pages/offline_page_client_policy.h" |
| 25 #include "components/offline_pages/offline_page_feature.h" | 26 #include "components/offline_pages/offline_page_feature.h" |
| 26 #include "components/offline_pages/offline_page_item.h" | 27 #include "components/offline_pages/offline_page_item.h" |
| 27 #include "components/offline_pages/offline_page_storage_manager.h" | 28 #include "components/offline_pages/offline_page_storage_manager.h" |
| 28 #include "components/offline_pages/offline_page_test_archiver.h" | 29 #include "components/offline_pages/offline_page_test_archiver.h" |
| 29 #include "components/offline_pages/offline_page_test_store.h" | 30 #include "components/offline_pages/offline_page_test_store.h" |
| 30 #include "components/offline_pages/offline_page_types.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 namespace offline_pages { | 35 namespace offline_pages { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 const char kTestClientNamespace[] = "CLIENT_NAMESPACE"; | 38 const char kTestClientNamespace[] = "CLIENT_NAMESPACE"; |
| 38 const GURL kTestUrl("http://example.com"); | 39 const GURL kTestUrl("http://example.com"); |
| 39 const GURL kTestUrl2("http://other.page.com"); | 40 const GURL kTestUrl2("http://other.page.com"); |
| 40 const GURL kTestUrl3("http://test.xyz"); | 41 const GURL kTestUrl3("http://test.xyz"); |
| 42 const GURL kTestUrl4("http://page.net"); |
| 41 const GURL kFileUrl("file:///foo"); | 43 const GURL kFileUrl("file:///foo"); |
| 42 const ClientId kTestClientId1(kTestClientNamespace, "1234"); | 44 const ClientId kTestClientId1(kTestClientNamespace, "1234"); |
| 43 const ClientId kTestClientId2(kTestClientNamespace, "5678"); | 45 const ClientId kTestClientId2(kTestClientNamespace, "5678"); |
| 44 const ClientId kTestClientId3(kTestClientNamespace, "42"); | 46 const ClientId kTestClientId3(kTestClientNamespace, "42"); |
| 45 const int64_t kTestFileSize = 876543LL; | 47 const int64_t kTestFileSize = 876543LL; |
| 46 | 48 |
| 47 bool URLSpecContains(std::string contains_value, const GURL& url) { | 49 bool URLSpecContains(std::string contains_value, const GURL& url) { |
| 48 std::string spec = url.spec(); | 50 std::string spec = url.spec(); |
| 49 return spec.find(contains_value) != std::string::npos; | 51 return spec.find(contains_value) != std::string::npos; |
| 50 } | 52 } |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 EXPECT_EQ(kTestClientId1, pages[0].client_id); | 883 EXPECT_EQ(kTestClientId1, pages[0].client_id); |
| 882 | 884 |
| 883 pages = GetPagesByOnlineURL(GURL("http://foo")); | 885 pages = GetPagesByOnlineURL(GURL("http://foo")); |
| 884 EXPECT_EQ(0U, pages.size()); | 886 EXPECT_EQ(0U, pages.size()); |
| 885 } | 887 } |
| 886 | 888 |
| 887 TEST_F(OfflinePageModelImplTest, CheckPagesExistOffline) { | 889 TEST_F(OfflinePageModelImplTest, CheckPagesExistOffline) { |
| 888 SavePage(kTestUrl, kTestClientId1); | 890 SavePage(kTestUrl, kTestClientId1); |
| 889 SavePage(kTestUrl2, kTestClientId2); | 891 SavePage(kTestUrl2, kTestClientId2); |
| 890 | 892 |
| 893 // TODO(dewittj): Remove the "Last N" restriction in favor of a better query |
| 894 // interface. See https://crbug.com/622763 for information. |
| 895 const ClientId last_n_client_id(kLastNNamespace, "1234"); |
| 896 SavePage(kTestUrl3, last_n_client_id); |
| 897 |
| 891 std::set<GURL> input; | 898 std::set<GURL> input; |
| 892 input.insert(kTestUrl); | 899 input.insert(kTestUrl); |
| 893 input.insert(kTestUrl2); | 900 input.insert(kTestUrl2); |
| 894 input.insert(kTestUrl3); | 901 input.insert(kTestUrl3); |
| 902 input.insert(kTestUrl4); |
| 895 | 903 |
| 896 CheckPagesExistOfflineResult existing_pages = CheckPagesExistOffline(input); | 904 CheckPagesExistOfflineResult existing_pages = CheckPagesExistOffline(input); |
| 897 EXPECT_EQ(2U, existing_pages.size()); | 905 EXPECT_EQ(2U, existing_pages.size()); |
| 898 EXPECT_NE(existing_pages.end(), existing_pages.find(kTestUrl)); | 906 EXPECT_NE(existing_pages.end(), existing_pages.find(kTestUrl)); |
| 899 EXPECT_NE(existing_pages.end(), existing_pages.find(kTestUrl2)); | 907 EXPECT_NE(existing_pages.end(), existing_pages.find(kTestUrl2)); |
| 900 EXPECT_EQ(existing_pages.end(), existing_pages.find(kTestUrl3)); | 908 EXPECT_EQ(existing_pages.end(), existing_pages.find(kTestUrl3)); |
| 909 EXPECT_EQ(existing_pages.end(), existing_pages.find(kTestUrl4)); |
| 901 } | 910 } |
| 902 | 911 |
| 903 TEST_F(OfflinePageModelImplTest, CanSaveURL) { | 912 TEST_F(OfflinePageModelImplTest, CanSaveURL) { |
| 904 EXPECT_TRUE(OfflinePageModel::CanSaveURL(GURL("http://foo"))); | 913 EXPECT_TRUE(OfflinePageModel::CanSaveURL(GURL("http://foo"))); |
| 905 EXPECT_TRUE(OfflinePageModel::CanSaveURL(GURL("https://foo"))); | 914 EXPECT_TRUE(OfflinePageModel::CanSaveURL(GURL("https://foo"))); |
| 906 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("file:///foo"))); | 915 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("file:///foo"))); |
| 907 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("data:image/png;base64,ab"))); | 916 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("data:image/png;base64,ab"))); |
| 908 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("chrome://version"))); | 917 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("chrome://version"))); |
| 909 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("chrome-native://newtab/"))); | 918 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("chrome-native://newtab/"))); |
| 910 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("/invalid/url.mhtml"))); | 919 EXPECT_FALSE(OfflinePageModel::CanSaveURL(GURL("/invalid/url.mhtml"))); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); | 1080 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); |
| 1072 feature_list2->InitializeFromCommandLine( | 1081 feature_list2->InitializeFromCommandLine( |
| 1073 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + | 1082 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + |
| 1074 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, | 1083 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, |
| 1075 ""); | 1084 ""); |
| 1076 base::FeatureList::SetInstance(std::move(feature_list2)); | 1085 base::FeatureList::SetInstance(std::move(feature_list2)); |
| 1077 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); | 1086 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); |
| 1078 } | 1087 } |
| 1079 | 1088 |
| 1080 } // namespace offline_pages | 1089 } // namespace offline_pages |
| OLD | NEW |