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

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

Issue 2226063002: Add a ScopedFeatureList class for testing and start using it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issue in previous patchset. Created 4 years, 4 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
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/histogram_tester.h" 20 #include "base/test/histogram_tester.h"
21 #include "base/test/scoped_feature_list.h"
21 #include "base/test/test_mock_time_task_runner.h" 22 #include "base/test/test_mock_time_task_runner.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "components/offline_pages/client_namespace_constants.h" 25 #include "components/offline_pages/client_namespace_constants.h"
25 #include "components/offline_pages/client_policy_controller.h" 26 #include "components/offline_pages/client_policy_controller.h"
26 #include "components/offline_pages/offline_page_client_policy.h" 27 #include "components/offline_pages/offline_page_client_policy.h"
27 #include "components/offline_pages/offline_page_feature.h" 28 #include "components/offline_pages/offline_page_feature.h"
28 #include "components/offline_pages/offline_page_item.h" 29 #include "components/offline_pages/offline_page_item.h"
29 #include "components/offline_pages/offline_page_storage_manager.h" 30 #include "components/offline_pages/offline_page_storage_manager.h"
30 #include "components/offline_pages/offline_page_test_archiver.h" 31 #include "components/offline_pages/offline_page_test_archiver.h"
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 1076
1076 histograms().ExpectUniqueSample(histogram_name, 1077 histograms().ExpectUniqueSample(histogram_name,
1077 static_cast<int>(SavePageResult::SUCCESS), 1); 1078 static_cast<int>(SavePageResult::SUCCESS), 1);
1078 } 1079 }
1079 1080
1080 TEST(CommandLineFlagsTest, OfflineBookmarks) { 1081 TEST(CommandLineFlagsTest, OfflineBookmarks) {
1081 // Disabled by default. 1082 // Disabled by default.
1082 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled()); 1083 EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled());
1083 1084
1084 // Check if feature is correctly enabled by command-line flag. 1085 // Check if feature is correctly enabled by command-line flag.
1085 base::FeatureList::ClearInstanceForTesting(); 1086 base::test::ScopedFeatureList scoped_feature_list;
1086 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 1087 scoped_feature_list.InitAndEnableFeature(kOfflineBookmarksFeature);
1087 feature_list->InitializeFromCommandLine(
1088 offline_pages::kOfflineBookmarksFeature.name, "");
1089 base::FeatureList::SetInstance(std::move(feature_list));
1090 EXPECT_TRUE(offline_pages::IsOfflineBookmarksEnabled()); 1088 EXPECT_TRUE(offline_pages::IsOfflineBookmarksEnabled());
1091 } 1089 }
1092 1090
1093 TEST(CommandLineFlagsTest, OffliningRecentPages) { 1091 TEST(CommandLineFlagsTest, OffliningRecentPages) {
1094 // Enable offline bookmarks feature first. 1092 // Enable offline bookmarks feature first.
1095 // TODO(dimich): once offline pages are enabled by default, remove this. 1093 // TODO(dimich): once offline pages are enabled by default, remove this.
1096 base::FeatureList::ClearInstanceForTesting(); 1094 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list(
1097 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 1095 new base::test::ScopedFeatureList);
1098 feature_list->InitializeFromCommandLine( 1096 scoped_feature_list->InitAndEnableFeature(kOfflineBookmarksFeature);
1099 offline_pages::kOfflineBookmarksFeature.name, "");
1100 base::FeatureList::SetInstance(std::move(feature_list));
1101 1097
1102 // This feature is still disabled by default. 1098 // This feature is still disabled by default.
1103 EXPECT_FALSE(offline_pages::IsOffliningRecentPagesEnabled()); 1099 EXPECT_FALSE(offline_pages::IsOffliningRecentPagesEnabled());
1104 1100
1105 // Check if feature is correctly enabled by command-line flag. 1101 // Check if feature is correctly enabled by command-line flag.
1106 base::FeatureList::ClearInstanceForTesting(); 1102 scoped_feature_list.reset(new base::test::ScopedFeatureList);
1107 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); 1103 scoped_feature_list->InitFromCommandLine(
1108 feature_list2->InitializeFromCommandLine( 1104 std::string(kOfflineBookmarksFeature.name) + "," +
1109 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 1105 kOffliningRecentPagesFeature.name,
1110 offline_pages::kOffliningRecentPagesFeature.name,
1111 ""); 1106 "");
1112 base::FeatureList::SetInstance(std::move(feature_list2));
1113 EXPECT_TRUE(offline_pages::IsOffliningRecentPagesEnabled()); 1107 EXPECT_TRUE(offline_pages::IsOffliningRecentPagesEnabled());
1114 } 1108 }
1115 1109
1116 TEST(CommandLineFlagsTest, OfflinePagesBackgroundLoading) { 1110 TEST(CommandLineFlagsTest, OfflinePagesBackgroundLoading) {
1117 // Enable offline bookmarks feature first. 1111 // Enable offline bookmarks feature first.
1118 // TODO(dimich): once offline pages are enabled by default, remove this. 1112 // TODO(dimich): once offline pages are enabled by default, remove this.
1119 base::FeatureList::ClearInstanceForTesting(); 1113 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list(
1120 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 1114 new base::test::ScopedFeatureList);
1121 feature_list->InitializeFromCommandLine( 1115 scoped_feature_list->InitAndEnableFeature(kOfflineBookmarksFeature);
1122 offline_pages::kOfflineBookmarksFeature.name, "");
1123 base::FeatureList::SetInstance(std::move(feature_list));
1124 1116
1125 // This feature is still disabled by default. 1117 // This feature is still disabled by default.
1126 EXPECT_FALSE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 1118 EXPECT_FALSE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
1127 1119
1128 // Check if feature is correctly enabled by command-line flag. 1120 // Check if feature is correctly enabled by command-line flag.
1129 base::FeatureList::ClearInstanceForTesting(); 1121 scoped_feature_list.reset(new base::test::ScopedFeatureList);
1130 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); 1122 scoped_feature_list->InitFromCommandLine(
1131 feature_list2->InitializeFromCommandLine( 1123 std::string(kOfflineBookmarksFeature.name) + "," +
1132 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 1124 kOfflinePagesBackgroundLoadingFeature.name,
1133 offline_pages::kOfflinePagesBackgroundLoadingFeature.name,
1134 ""); 1125 "");
1135 base::FeatureList::SetInstance(std::move(feature_list2));
1136 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 1126 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
1137 } 1127 }
1138 1128
1139 TEST(CommandLineFlagsTest, OfflinePagesSharing) { 1129 TEST(CommandLineFlagsTest, OfflinePagesSharing) {
1140 // Enable offline bookmarks feature first. 1130 // Enable offline bookmarks feature first.
1141 // TODO(dimich): once offline pages are enabled by default, remove this. 1131 // TODO(dimich): once offline pages are enabled by default, remove this.
1142 base::FeatureList::ClearInstanceForTesting(); 1132 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list(
1143 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 1133 new base::test::ScopedFeatureList);
1144 feature_list->InitializeFromCommandLine( 1134 scoped_feature_list->InitAndEnableFeature(kOfflineBookmarksFeature);
1145 offline_pages::kOfflineBookmarksFeature.name, "");
1146 base::FeatureList::SetInstance(std::move(feature_list));
1147 1135
1148 // This feature is still disabled by default. 1136 // This feature is still disabled by default.
1149 EXPECT_FALSE(offline_pages::IsOfflinePagesSharingEnabled()); 1137 EXPECT_FALSE(offline_pages::IsOfflinePagesSharingEnabled());
1150 1138
1151 // Check if feature is correctly enabled by command-line flag. 1139 // Check if feature is correctly enabled by command-line flag.
1152 base::FeatureList::ClearInstanceForTesting(); 1140 scoped_feature_list.reset(new base::test::ScopedFeatureList);
1153 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); 1141 scoped_feature_list->InitFromCommandLine(
1154 feature_list2->InitializeFromCommandLine( 1142 std::string(kOfflineBookmarksFeature.name) + "," +
1155 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 1143 kOfflinePagesSharingFeature.name,
1156 offline_pages::kOfflinePagesSharingFeature.name,
1157 ""); 1144 "");
1158 base::FeatureList::SetInstance(std::move(feature_list2));
1159 EXPECT_TRUE(offline_pages::IsOfflinePagesSharingEnabled()); 1145 EXPECT_TRUE(offline_pages::IsOfflinePagesSharingEnabled());
1160 } 1146 }
1161 1147
1162 } // namespace offline_pages 1148 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698