Chromium Code Reviews| 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 Configuration actual_configuration = GetActiveConfiguration(); | 45 auto active_configurations = GetActiveConfigurations(); |
|
Sorin Jianu
2017/04/24 21:58:59
can this be const, here and below?
engedy
2017/04/25 08:34:24
Yep, done.
| |
| 46 const Configuration& actual_configuration = | |
| 47 active_configurations->the_one_and_only(); | |
| 46 EXPECT_EQ(test_case.expected_activation_level, | 48 EXPECT_EQ(test_case.expected_activation_level, |
| 47 actual_configuration.activation_level); | 49 actual_configuration.activation_level); |
| 48 EXPECT_EQ(ActivationScope::NO_SITES, actual_configuration.activation_scope); | 50 EXPECT_EQ(ActivationScope::NO_SITES, actual_configuration.activation_scope); |
| 49 } | 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 52 TEST(SubresourceFilterFeaturesTest, ActivationScope) { | 54 TEST(SubresourceFilterFeaturesTest, ActivationScope) { |
| 53 const struct { | 55 const struct { |
| 54 bool feature_enabled; | 56 bool feature_enabled; |
| 55 const char* activation_scope_param; | 57 const char* activation_scope_param; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 72 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); | 74 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); |
| 73 SCOPED_TRACE(::testing::Message("ActivationScopeParam = \"") | 75 SCOPED_TRACE(::testing::Message("ActivationScopeParam = \"") |
| 74 << test_case.activation_scope_param << "\""); | 76 << test_case.activation_scope_param << "\""); |
| 75 | 77 |
| 76 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 78 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 77 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 79 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 78 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 80 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 79 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 81 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 80 kActivationLevelDisabled, test_case.activation_scope_param); | 82 kActivationLevelDisabled, test_case.activation_scope_param); |
| 81 | 83 |
| 82 Configuration actual_configuration = GetActiveConfiguration(); | 84 auto active_configurations = GetActiveConfigurations(); |
| 85 const Configuration& actual_configuration = | |
| 86 active_configurations->the_one_and_only(); | |
| 83 EXPECT_EQ(ActivationLevel::DISABLED, actual_configuration.activation_level); | 87 EXPECT_EQ(ActivationLevel::DISABLED, actual_configuration.activation_level); |
| 84 EXPECT_EQ(test_case.expected_activation_scope, | 88 EXPECT_EQ(test_case.expected_activation_scope, |
| 85 actual_configuration.activation_scope); | 89 actual_configuration.activation_scope); |
| 86 } | 90 } |
| 87 } | 91 } |
| 88 | 92 |
| 89 TEST(SubresourceFilterFeaturesTest, ActivationLevelAndScope) { | 93 TEST(SubresourceFilterFeaturesTest, ActivationLevelAndScope) { |
| 90 const struct { | 94 const struct { |
| 91 bool feature_enabled; | 95 bool feature_enabled; |
| 92 const char* activation_level_param; | 96 const char* activation_level_param; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 123 {false, kActivationLevelEnabled, ActivationLevel::DISABLED, | 127 {false, kActivationLevelEnabled, ActivationLevel::DISABLED, |
| 124 kActivationScopeAllSites, ActivationScope::NO_SITES}}; | 128 kActivationScopeAllSites, ActivationScope::NO_SITES}}; |
| 125 | 129 |
| 126 for (const auto& test_case : kTestCases) { | 130 for (const auto& test_case : kTestCases) { |
| 127 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 131 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 128 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 132 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 129 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 133 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 130 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 134 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 131 test_case.activation_level_param, test_case.activation_scope_param); | 135 test_case.activation_level_param, test_case.activation_scope_param); |
| 132 | 136 |
| 133 Configuration actual_configuration = GetActiveConfiguration(); | 137 auto active_configurations = GetActiveConfigurations(); |
| 138 const Configuration& actual_configuration = | |
| 139 active_configurations->the_one_and_only(); | |
| 134 EXPECT_EQ(test_case.expected_activation_level, | 140 EXPECT_EQ(test_case.expected_activation_level, |
| 135 actual_configuration.activation_level); | 141 actual_configuration.activation_level); |
| 136 EXPECT_EQ(test_case.expected_activation_scope, | 142 EXPECT_EQ(test_case.expected_activation_scope, |
| 137 actual_configuration.activation_scope); | 143 actual_configuration.activation_scope); |
| 138 } | 144 } |
| 139 } | 145 } |
| 140 | 146 |
| 141 TEST(SubresourceFilterFeaturesTest, ActivationList) { | 147 TEST(SubresourceFilterFeaturesTest, ActivationList) { |
| 142 const std::string activation_soc_eng( | 148 const std::string activation_soc_eng( |
| 143 kActivationListSocialEngineeringAdsInterstitial); | 149 kActivationListSocialEngineeringAdsInterstitial); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 SCOPED_TRACE(::testing::Message("ActivationListParam = \"") | 185 SCOPED_TRACE(::testing::Message("ActivationListParam = \"") |
| 180 << test_case.activation_list_param << "\""); | 186 << test_case.activation_list_param << "\""); |
| 181 | 187 |
| 182 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 188 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 183 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 189 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 184 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 190 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 185 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 191 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 186 kActivationLevelDisabled, kActivationScopeNoSites, | 192 kActivationLevelDisabled, kActivationScopeNoSites, |
| 187 test_case.activation_list_param); | 193 test_case.activation_list_param); |
| 188 | 194 |
| 189 Configuration actual_configuration = GetActiveConfiguration(); | 195 auto active_configurations = GetActiveConfigurations(); |
| 196 const Configuration& actual_configuration = | |
| 197 active_configurations->the_one_and_only(); | |
| 190 EXPECT_EQ(test_case.expected_activation_list, | 198 EXPECT_EQ(test_case.expected_activation_list, |
| 191 actual_configuration.activation_list); | 199 actual_configuration.activation_list); |
| 192 } | 200 } |
| 193 } | 201 } |
| 194 | 202 |
| 195 TEST(SubresourceFilterFeaturesTest, PerfMeasurementRate) { | 203 TEST(SubresourceFilterFeaturesTest, PerfMeasurementRate) { |
| 196 const struct { | 204 const struct { |
| 197 bool feature_enabled; | 205 bool feature_enabled; |
| 198 const char* perf_measurement_param; | 206 const char* perf_measurement_param; |
| 199 double expected_perf_measurement_rate; | 207 double expected_perf_measurement_rate; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 216 SCOPED_TRACE(::testing::Message("PerfMeasurementParam = \"") | 224 SCOPED_TRACE(::testing::Message("PerfMeasurementParam = \"") |
| 217 << test_case.perf_measurement_param << "\""); | 225 << test_case.perf_measurement_param << "\""); |
| 218 | 226 |
| 219 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 227 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 220 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 228 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 221 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 229 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 222 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 230 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 223 {{kPerformanceMeasurementRateParameterName, | 231 {{kPerformanceMeasurementRateParameterName, |
| 224 test_case.perf_measurement_param}}); | 232 test_case.perf_measurement_param}}); |
| 225 | 233 |
| 226 Configuration actual_configuration = GetActiveConfiguration(); | 234 auto active_configurations = GetActiveConfigurations(); |
| 235 const Configuration& actual_configuration = | |
| 236 active_configurations->the_one_and_only(); | |
| 227 EXPECT_EQ(test_case.expected_perf_measurement_rate, | 237 EXPECT_EQ(test_case.expected_perf_measurement_rate, |
| 228 actual_configuration.performance_measurement_rate); | 238 actual_configuration.performance_measurement_rate); |
| 229 } | 239 } |
| 230 } | 240 } |
| 231 | 241 |
| 232 TEST(SubresourceFilterFeaturesTest, SuppressNotifications) { | 242 TEST(SubresourceFilterFeaturesTest, SuppressNotifications) { |
| 233 const struct { | 243 const struct { |
| 234 bool feature_enabled; | 244 bool feature_enabled; |
| 235 const char* suppress_notifications_param; | 245 const char* suppress_notifications_param; |
| 236 bool expected_suppress_notifications_value; | 246 bool expected_suppress_notifications_value; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 250 SCOPED_TRACE(::testing::Message("SuppressNotificationsParam = \"") | 260 SCOPED_TRACE(::testing::Message("SuppressNotificationsParam = \"") |
| 251 << test_case.suppress_notifications_param << "\""); | 261 << test_case.suppress_notifications_param << "\""); |
| 252 | 262 |
| 253 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 263 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 254 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 264 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 255 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 265 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 256 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 266 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 257 {{kSuppressNotificationsParameterName, | 267 {{kSuppressNotificationsParameterName, |
| 258 test_case.suppress_notifications_param}}); | 268 test_case.suppress_notifications_param}}); |
| 259 | 269 |
| 260 Configuration actual_configuration = GetActiveConfiguration(); | 270 auto active_configurations = GetActiveConfigurations(); |
| 271 const Configuration& actual_configuration = | |
| 272 active_configurations->the_one_and_only(); | |
| 261 EXPECT_EQ(test_case.expected_suppress_notifications_value, | 273 EXPECT_EQ(test_case.expected_suppress_notifications_value, |
| 262 actual_configuration.should_suppress_notifications); | 274 actual_configuration.should_suppress_notifications); |
| 263 } | 275 } |
| 264 } | 276 } |
| 265 | 277 |
| 266 TEST(SubresourceFilterFeaturesTest, WhitelistSiteOnReload) { | 278 TEST(SubresourceFilterFeaturesTest, WhitelistSiteOnReload) { |
| 267 const struct { | 279 const struct { |
| 268 bool feature_enabled; | 280 bool feature_enabled; |
| 269 const char* whitelist_site_on_reload_param; | 281 const char* whitelist_site_on_reload_param; |
| 270 bool expected_whitelist_site_on_reload_value; | 282 bool expected_whitelist_site_on_reload_value; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 284 SCOPED_TRACE(::testing::Message("WhitelistSiteOnReloadParam = \"") | 296 SCOPED_TRACE(::testing::Message("WhitelistSiteOnReloadParam = \"") |
| 285 << test_case.whitelist_site_on_reload_param << "\""); | 297 << test_case.whitelist_site_on_reload_param << "\""); |
| 286 | 298 |
| 287 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 299 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 288 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 300 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 289 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 301 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 290 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 302 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 291 {{kWhitelistSiteOnReloadParameterName, | 303 {{kWhitelistSiteOnReloadParameterName, |
| 292 test_case.whitelist_site_on_reload_param}}); | 304 test_case.whitelist_site_on_reload_param}}); |
| 293 | 305 |
| 294 Configuration actual_configuration = GetActiveConfiguration(); | 306 auto active_configurations = GetActiveConfigurations(); |
| 307 const Configuration& actual_configuration = | |
| 308 active_configurations->the_one_and_only(); | |
| 295 EXPECT_EQ(test_case.expected_whitelist_site_on_reload_value, | 309 EXPECT_EQ(test_case.expected_whitelist_site_on_reload_value, |
| 296 actual_configuration.should_whitelist_site_on_reload); | 310 actual_configuration.should_whitelist_site_on_reload); |
| 297 } | 311 } |
| 298 } | 312 } |
| 299 | 313 |
| 300 } // namespace subresource_filter | 314 } // namespace subresource_filter |
| OLD | NEW |