| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/subresource_filter/core/browser/subresource_filter_features
.h" | 5 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" | 10 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); | 35 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); |
| 36 SCOPED_TRACE(::testing::Message("ActivationLevelParam = \"") | 36 SCOPED_TRACE(::testing::Message("ActivationLevelParam = \"") |
| 37 << test_case.activation_level_param << "\""); | 37 << test_case.activation_level_param << "\""); |
| 38 | 38 |
| 39 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 39 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 40 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 40 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 41 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 41 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 42 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 42 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 43 test_case.activation_level_param, kActivationScopeNoSites); | 43 test_case.activation_level_param, kActivationScopeNoSites); |
| 44 | 44 |
| 45 EXPECT_EQ(test_case.expected_activation_level, GetMaximumActivationLevel()); | 45 Configuration actual_configuration = GetActiveConfiguration(); |
| 46 EXPECT_EQ(ActivationScope::NO_SITES, GetCurrentActivationScope()); | 46 EXPECT_EQ(test_case.expected_activation_level, |
| 47 actual_configuration.activation_level); |
| 48 EXPECT_EQ(ActivationScope::NO_SITES, actual_configuration.activation_scope); |
| 47 } | 49 } |
| 48 } | 50 } |
| 49 | 51 |
| 50 TEST(SubresourceFilterFeaturesTest, ActivationScope) { | 52 TEST(SubresourceFilterFeaturesTest, ActivationScope) { |
| 51 const struct { | 53 const struct { |
| 52 bool feature_enabled; | 54 bool feature_enabled; |
| 53 const char* activation_scope_param; | 55 const char* activation_scope_param; |
| 54 ActivationScope expected_activation_scope; | 56 ActivationScope expected_activation_scope; |
| 55 } kTestCases[] = { | 57 } kTestCases[] = { |
| 56 {false, "", ActivationScope::NO_SITES}, | 58 {false, "", ActivationScope::NO_SITES}, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 70 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); | 72 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); |
| 71 SCOPED_TRACE(::testing::Message("ActivationScopeParam = \"") | 73 SCOPED_TRACE(::testing::Message("ActivationScopeParam = \"") |
| 72 << test_case.activation_scope_param << "\""); | 74 << test_case.activation_scope_param << "\""); |
| 73 | 75 |
| 74 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 76 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 75 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 77 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 76 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 78 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 77 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 79 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 78 kActivationLevelDisabled, test_case.activation_scope_param); | 80 kActivationLevelDisabled, test_case.activation_scope_param); |
| 79 | 81 |
| 80 EXPECT_EQ(ActivationLevel::DISABLED, GetMaximumActivationLevel()); | 82 Configuration actual_configuration = GetActiveConfiguration(); |
| 81 EXPECT_EQ(test_case.expected_activation_scope, GetCurrentActivationScope()); | 83 EXPECT_EQ(ActivationLevel::DISABLED, actual_configuration.activation_level); |
| 84 EXPECT_EQ(test_case.expected_activation_scope, |
| 85 actual_configuration.activation_scope); |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 | 88 |
| 85 TEST(SubresourceFilterFeaturesTest, ActivationLevelAndScope) { | 89 TEST(SubresourceFilterFeaturesTest, ActivationLevelAndScope) { |
| 86 const struct { | 90 const struct { |
| 87 bool feature_enabled; | 91 bool feature_enabled; |
| 88 const char* activation_level_param; | 92 const char* activation_level_param; |
| 89 ActivationLevel expected_activation_level; | 93 ActivationLevel expected_activation_level; |
| 90 const char* activation_scope_param; | 94 const char* activation_scope_param; |
| 91 ActivationScope expected_activation_scope; | 95 ActivationScope expected_activation_scope; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 119 {false, kActivationLevelEnabled, ActivationLevel::DISABLED, | 123 {false, kActivationLevelEnabled, ActivationLevel::DISABLED, |
| 120 kActivationScopeAllSites, ActivationScope::NO_SITES}}; | 124 kActivationScopeAllSites, ActivationScope::NO_SITES}}; |
| 121 | 125 |
| 122 for (const auto& test_case : kTestCases) { | 126 for (const auto& test_case : kTestCases) { |
| 123 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 127 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 124 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 128 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 125 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 129 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 126 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 130 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 127 test_case.activation_level_param, test_case.activation_scope_param); | 131 test_case.activation_level_param, test_case.activation_scope_param); |
| 128 | 132 |
| 129 EXPECT_EQ(test_case.expected_activation_scope, GetCurrentActivationScope()); | 133 Configuration actual_configuration = GetActiveConfiguration(); |
| 130 EXPECT_EQ(test_case.expected_activation_level, GetMaximumActivationLevel()); | 134 EXPECT_EQ(test_case.expected_activation_level, |
| 135 actual_configuration.activation_level); |
| 136 EXPECT_EQ(test_case.expected_activation_scope, |
| 137 actual_configuration.activation_scope); |
| 131 } | 138 } |
| 132 } | 139 } |
| 133 | 140 |
| 134 TEST(SubresourceFilterFeaturesTest, ActivationList) { | 141 TEST(SubresourceFilterFeaturesTest, ActivationList) { |
| 135 const std::string activation_soc_eng( | 142 const std::string activation_soc_eng( |
| 136 kActivationListSocialEngineeringAdsInterstitial); | 143 kActivationListSocialEngineeringAdsInterstitial); |
| 137 const std::string activation_phishing(kActivationListPhishingInterstitial); | 144 const std::string activation_phishing(kActivationListPhishingInterstitial); |
| 138 const std::string socEngPhising = activation_soc_eng + activation_phishing; | 145 const std::string socEngPhising = activation_soc_eng + activation_phishing; |
| 139 const std::string socEngCommaPhising = | 146 const std::string socEngCommaPhising = |
| 140 activation_soc_eng + "," + activation_phishing; | 147 activation_soc_eng + "," + activation_phishing; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 SCOPED_TRACE(::testing::Message("ActivationListParam = \"") | 179 SCOPED_TRACE(::testing::Message("ActivationListParam = \"") |
| 173 << test_case.activation_list_param << "\""); | 180 << test_case.activation_list_param << "\""); |
| 174 | 181 |
| 175 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 182 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 176 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 183 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 177 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 184 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 178 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 185 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 179 kActivationLevelDisabled, kActivationScopeNoSites, | 186 kActivationLevelDisabled, kActivationScopeNoSites, |
| 180 test_case.activation_list_param); | 187 test_case.activation_list_param); |
| 181 | 188 |
| 182 EXPECT_EQ(test_case.expected_activation_list, GetCurrentActivationList()); | 189 Configuration actual_configuration = GetActiveConfiguration(); |
| 190 EXPECT_EQ(test_case.expected_activation_list, |
| 191 actual_configuration.activation_list); |
| 183 } | 192 } |
| 184 } | 193 } |
| 185 | 194 |
| 186 TEST(SubresourceFilterFeaturesTest, PerfMeasurementRate) { | 195 TEST(SubresourceFilterFeaturesTest, PerfMeasurementRate) { |
| 187 const struct { | 196 const struct { |
| 188 bool feature_enabled; | 197 bool feature_enabled; |
| 189 const char* perf_measurement_param; | 198 const char* perf_measurement_param; |
| 190 double expected_perf_measurement_rate; | 199 double expected_perf_measurement_rate; |
| 191 } kTestCases[] = {{false, "not_a_number", 0}, | 200 } kTestCases[] = {{false, "not_a_number", 0}, |
| 192 {false, "0", 0}, | 201 {false, "0", 0}, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 207 SCOPED_TRACE(::testing::Message("PerfMeasurementParam = \"") | 216 SCOPED_TRACE(::testing::Message("PerfMeasurementParam = \"") |
| 208 << test_case.perf_measurement_param << "\""); | 217 << test_case.perf_measurement_param << "\""); |
| 209 | 218 |
| 210 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 219 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 211 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 220 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 212 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 221 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 213 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 222 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 214 {{kPerformanceMeasurementRateParameterName, | 223 {{kPerformanceMeasurementRateParameterName, |
| 215 test_case.perf_measurement_param}}); | 224 test_case.perf_measurement_param}}); |
| 216 | 225 |
| 226 Configuration actual_configuration = GetActiveConfiguration(); |
| 217 EXPECT_EQ(test_case.expected_perf_measurement_rate, | 227 EXPECT_EQ(test_case.expected_perf_measurement_rate, |
| 218 GetPerformanceMeasurementRate()); | 228 actual_configuration.performance_measurement_rate); |
| 219 } | 229 } |
| 220 } | 230 } |
| 221 | 231 |
| 222 TEST(SubresourceFilterFeaturesTest, SuppressNotifications) { | 232 TEST(SubresourceFilterFeaturesTest, SuppressNotifications) { |
| 223 const struct { | 233 const struct { |
| 224 bool feature_enabled; | 234 bool feature_enabled; |
| 225 const char* suppress_notifications_param; | 235 const char* suppress_notifications_param; |
| 226 bool expected_suppress_notifications_value; | 236 bool expected_suppress_notifications_value; |
| 227 } kTestCases[] = {{false, "", false}, | 237 } kTestCases[] = {{false, "", false}, |
| 228 {false, "true", false}, | 238 {false, "true", false}, |
| 229 {false, "false", false}, | 239 {false, "false", false}, |
| 230 {false, "invalid value", false}, | 240 {false, "invalid value", false}, |
| 231 {true, "", false}, | 241 {true, "", false}, |
| 232 {true, "false", false}, | 242 {true, "false", false}, |
| 233 {true, "invalid value", false}, | 243 {true, "invalid value", false}, |
| 234 {true, "True", false}, | 244 {true, "True", true}, |
| 235 {true, "TRUE", false}, | 245 {true, "TRUE", true}, |
| 236 {true, "true", true}}; | 246 {true, "true", true}}; |
| 237 | 247 |
| 238 for (const auto& test_case : kTestCases) { | 248 for (const auto& test_case : kTestCases) { |
| 239 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); | 249 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); |
| 240 SCOPED_TRACE(::testing::Message("SuppressNotificationsParam = \"") | 250 SCOPED_TRACE(::testing::Message("SuppressNotificationsParam = \"") |
| 241 << test_case.suppress_notifications_param << "\""); | 251 << test_case.suppress_notifications_param << "\""); |
| 242 | 252 |
| 243 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 253 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 244 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 254 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 245 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 255 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 246 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 256 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 247 {{kSuppressNotificationsParameterName, | 257 {{kSuppressNotificationsParameterName, |
| 248 test_case.suppress_notifications_param}}); | 258 test_case.suppress_notifications_param}}); |
| 249 | 259 |
| 260 Configuration actual_configuration = GetActiveConfiguration(); |
| 250 EXPECT_EQ(test_case.expected_suppress_notifications_value, | 261 EXPECT_EQ(test_case.expected_suppress_notifications_value, |
| 251 ShouldSuppressNotifications()); | 262 actual_configuration.should_suppress_notifications); |
| 252 } | 263 } |
| 253 } | 264 } |
| 254 | 265 |
| 255 TEST(SubresourceFilterFeaturesTest, WhitelistSiteOnReload) { | 266 TEST(SubresourceFilterFeaturesTest, WhitelistSiteOnReload) { |
| 256 const struct { | 267 const struct { |
| 257 bool feature_enabled; | 268 bool feature_enabled; |
| 258 const char* whitelist_site_on_reload_param; | 269 const char* whitelist_site_on_reload_param; |
| 259 bool expected_whitelist_site_on_reload_value; | 270 bool expected_whitelist_site_on_reload_value; |
| 260 } kTestCases[] = {{false, "", false}, | 271 } kTestCases[] = {{false, "", false}, |
| 261 {false, "true", false}, | 272 {false, "true", false}, |
| 262 {false, "false", false}, | 273 {false, "false", false}, |
| 263 {false, "invalid value", false}, | 274 {false, "invalid value", false}, |
| 264 {true, "", false}, | 275 {true, "", false}, |
| 265 {true, "false", false}, | 276 {true, "false", false}, |
| 266 {true, "invalid value", false}, | 277 {true, "invalid value", false}, |
| 267 {true, "True", false}, | 278 {true, "True", true}, |
| 268 {true, "TRUE", false}, | 279 {true, "TRUE", true}, |
| 269 {true, "true", true}}; | 280 {true, "true", true}}; |
| 270 | 281 |
| 271 for (const auto& test_case : kTestCases) { | 282 for (const auto& test_case : kTestCases) { |
| 272 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); | 283 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); |
| 273 SCOPED_TRACE(::testing::Message("WhitelistSiteOnReloadParam = \"") | 284 SCOPED_TRACE(::testing::Message("WhitelistSiteOnReloadParam = \"") |
| 274 << test_case.whitelist_site_on_reload_param << "\""); | 285 << test_case.whitelist_site_on_reload_param << "\""); |
| 275 | 286 |
| 276 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 287 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 277 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 288 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 278 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 289 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 279 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 290 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 280 {{kWhitelistSiteOnReloadParameterName, | 291 {{kWhitelistSiteOnReloadParameterName, |
| 281 test_case.whitelist_site_on_reload_param}}); | 292 test_case.whitelist_site_on_reload_param}}); |
| 282 | 293 |
| 294 Configuration actual_configuration = GetActiveConfiguration(); |
| 283 EXPECT_EQ(test_case.expected_whitelist_site_on_reload_value, | 295 EXPECT_EQ(test_case.expected_whitelist_site_on_reload_value, |
| 284 ShouldWhitelistSiteOnReload()); | 296 actual_configuration.should_whitelist_site_on_reload); |
| 285 } | 297 } |
| 286 } | 298 } |
| 287 | 299 |
| 288 } // namespace subresource_filter | 300 } // namespace subresource_filter |
| OLD | NEW |