| 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 12 matching lines...) Expand all Loading... |
| 23 #include "components/bookmarks/browser/bookmark_client.h" | 23 #include "components/bookmarks/browser/bookmark_client.h" |
| 24 #include "components/bookmarks/browser/bookmark_model.h" | 24 #include "components/bookmarks/browser/bookmark_model.h" |
| 25 #include "components/bookmarks/browser/bookmark_node.h" | 25 #include "components/bookmarks/browser/bookmark_node.h" |
| 26 #include "components/bookmarks/browser/bookmark_storage.h" | 26 #include "components/bookmarks/browser/bookmark_storage.h" |
| 27 #include "components/bookmarks/browser/bookmark_undo_delegate.h" | 27 #include "components/bookmarks/browser/bookmark_undo_delegate.h" |
| 28 #include "components/bookmarks/browser/bookmark_undo_provider.h" | 28 #include "components/bookmarks/browser/bookmark_undo_provider.h" |
| 29 #include "components/bookmarks/test/test_bookmark_client.h" | 29 #include "components/bookmarks/test/test_bookmark_client.h" |
| 30 #include "components/offline_pages/offline_page_bookmark_bridge.h" | 30 #include "components/offline_pages/offline_page_bookmark_bridge.h" |
| 31 #include "components/offline_pages/offline_page_feature.h" | 31 #include "components/offline_pages/offline_page_feature.h" |
| 32 #include "components/offline_pages/offline_page_item.h" | 32 #include "components/offline_pages/offline_page_item.h" |
| 33 #include "components/offline_pages/offline_page_switches.h" | |
| 34 #include "components/offline_pages/offline_page_test_archiver.h" | 33 #include "components/offline_pages/offline_page_test_archiver.h" |
| 35 #include "components/offline_pages/offline_page_test_store.h" | 34 #include "components/offline_pages/offline_page_test_store.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 38 | 37 |
| 39 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult; | 38 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult; |
| 40 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult; | 39 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult; |
| 41 using GetAllPagesResult = offline_pages::OfflinePageModel::GetAllPagesResult; | 40 using GetAllPagesResult = offline_pages::OfflinePageModel::GetAllPagesResult; |
| 42 | 41 |
| 43 namespace offline_pages { | 42 namespace offline_pages { |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 | 1110 |
| 1112 std::set<int64_t> id_set; | 1111 std::set<int64_t> id_set; |
| 1113 for (size_t i = 0; i < ids.size(); i++) { | 1112 for (size_t i = 0; i < ids.size(); i++) { |
| 1114 id_set.insert(ids[i]); | 1113 id_set.insert(ids[i]); |
| 1115 } | 1114 } |
| 1116 | 1115 |
| 1117 EXPECT_TRUE(id_set.find(offline1) != id_set.end()); | 1116 EXPECT_TRUE(id_set.find(offline1) != id_set.end()); |
| 1118 EXPECT_TRUE(id_set.find(offline2) != id_set.end()); | 1117 EXPECT_TRUE(id_set.find(offline2) != id_set.end()); |
| 1119 } | 1118 } |
| 1120 | 1119 |
| 1121 TEST(CommandLineFlagsTest, OffliningRecentPages) { | 1120 TEST(CommandLineFlagsTest, OfflineBookmarks) { |
| 1122 // TODO(dimich): once offline pages are enabled by default, remove this. | |
| 1123 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1124 switches::kEnableOfflinePages); | |
| 1125 // Disabled by default. | 1121 // Disabled by default. |
| 1126 EXPECT_FALSE(offline_pages::IsOffliningRecentPagesEnabled()); | 1122 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled()); |
| 1127 | 1123 |
| 1128 // Check if feature is correctly enabled by command-line flag. | 1124 // Check if feature is correctly enabled by command-line flag. |
| 1129 base::FeatureList::ClearInstanceForTesting(); | 1125 base::FeatureList::ClearInstanceForTesting(); |
| 1130 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | 1126 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 1131 feature_list->InitializeFromCommandLine( | 1127 feature_list->InitializeFromCommandLine( |
| 1132 offline_pages::kOffliningRecentPagesFeature.name, ""); | 1128 offline_pages::kOfflineBookmarksFeature.name, ""); |
| 1133 base::FeatureList::SetInstance(std::move(feature_list)); | 1129 base::FeatureList::SetInstance(std::move(feature_list)); |
| 1130 EXPECT_TRUE(offline_pages::IsOfflineBookmarksEnabled()); |
| 1131 } |
| 1132 |
| 1133 TEST(CommandLineFlagsTest, OffliningRecentPages) { |
| 1134 // Enable offline bookmarks feature first. |
| 1135 // TODO(dimich): once offline pages are enabled by default, remove this. |
| 1136 base::FeatureList::ClearInstanceForTesting(); |
| 1137 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 1138 feature_list->InitializeFromCommandLine( |
| 1139 offline_pages::kOfflineBookmarksFeature.name, ""); |
| 1140 base::FeatureList::SetInstance(std::move(feature_list)); |
| 1141 |
| 1142 // This feature is still disabled by default. |
| 1143 EXPECT_FALSE(offline_pages::IsOffliningRecentPagesEnabled()); |
| 1144 |
| 1145 // Check if feature is correctly enabled by command-line flag. |
| 1146 base::FeatureList::ClearInstanceForTesting(); |
| 1147 scoped_ptr<base::FeatureList> feature_list2(new base::FeatureList); |
| 1148 feature_list2->InitializeFromCommandLine( |
| 1149 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + |
| 1150 offline_pages::kOffliningRecentPagesFeature.name, |
| 1151 ""); |
| 1152 base::FeatureList::SetInstance(std::move(feature_list2)); |
| 1134 EXPECT_TRUE(offline_pages::IsOffliningRecentPagesEnabled()); | 1153 EXPECT_TRUE(offline_pages::IsOffliningRecentPagesEnabled()); |
| 1135 } | 1154 } |
| 1136 | 1155 |
| 1137 TEST(CommandLineFlagsTest, OfflinePagesBackgroundLoading) { | 1156 TEST(CommandLineFlagsTest, OfflinePagesBackgroundLoading) { |
| 1157 // Enable offline bookmarks feature first. |
| 1138 // TODO(dimich): once offline pages are enabled by default, remove this. | 1158 // TODO(dimich): once offline pages are enabled by default, remove this. |
| 1139 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1159 base::FeatureList::ClearInstanceForTesting(); |
| 1140 switches::kEnableOfflinePages); | 1160 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 1141 // Disabled by default. | 1161 feature_list->InitializeFromCommandLine( |
| 1162 offline_pages::kOfflineBookmarksFeature.name, ""); |
| 1163 base::FeatureList::SetInstance(std::move(feature_list)); |
| 1164 |
| 1165 // This feature is still disabled by default. |
| 1142 EXPECT_FALSE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); | 1166 EXPECT_FALSE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); |
| 1143 | 1167 |
| 1144 // Check if feature is correctly enabled by command-line flag. | 1168 // Check if feature is correctly enabled by command-line flag. |
| 1145 base::FeatureList::ClearInstanceForTesting(); | 1169 base::FeatureList::ClearInstanceForTesting(); |
| 1146 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | 1170 scoped_ptr<base::FeatureList> feature_list2(new base::FeatureList); |
| 1147 feature_list->InitializeFromCommandLine( | 1171 feature_list2->InitializeFromCommandLine( |
| 1148 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, ""); | 1172 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + |
| 1149 base::FeatureList::SetInstance(std::move(feature_list)); | 1173 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, |
| 1174 ""); |
| 1175 base::FeatureList::SetInstance(std::move(feature_list2)); |
| 1150 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); | 1176 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); |
| 1151 } | 1177 } |
| 1152 | 1178 |
| 1153 } // namespace offline_pages | 1179 } // namespace offline_pages |
| OLD | NEW |