| 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 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_T
EST_SUPPORT_H_ | 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_T
EST_SUPPORT_H_ |
| 6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_T
EST_SUPPORT_H_ | 6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_T
EST_SUPPORT_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
| 12 #include "base/macros.h" | 9 #include "base/macros.h" |
| 13 #include "base/test/scoped_feature_list.h" | 10 #include "base/test/scoped_feature_list.h" |
| 11 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
| 14 | 12 |
| 15 namespace subresource_filter { | 13 namespace subresource_filter { |
| 16 namespace testing { | 14 namespace testing { |
| 17 | 15 |
| 18 // Helper to override the state of the |kSafeBrowsingSubresourceFilter| feature, | 16 // Helper class to override the active subresource filtering configuration to be |
| 19 // and its variation parameters, e.g., maximum activation level and activation | 17 // used in tests while the instance is in scope. |
| 20 // scope. Expects a pre-existing global base::FieldTrialList singleton. | 18 // |
| 19 // Configuration overrides can be nested, and will take effect regardless of |
| 20 // field trial, feature, and/or variation parameter states. |
| 21 class ScopedSubresourceFilterConfigurator { |
| 22 public: |
| 23 explicit ScopedSubresourceFilterConfigurator( |
| 24 scoped_refptr<ConfigurationList> configs = nullptr); |
| 25 explicit ScopedSubresourceFilterConfigurator(Configuration config); |
| 26 ~ScopedSubresourceFilterConfigurator(); |
| 27 |
| 28 void ResetConfiguration(Configuration config); |
| 29 |
| 30 private: |
| 31 scoped_refptr<ConfigurationList> original_config_; |
| 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(ScopedSubresourceFilterConfigurator); |
| 34 }; |
| 35 |
| 36 // Helper class to override the state of the |kSafeBrowsingSubresourceFilter| |
| 37 // feature. |
| 38 // |
| 39 // Clears the active subresource filtering configuration override, upon |
| 40 // construction, if any, and restores it on destruction. So while the instance |
| 41 // is in scope, calls to GetActiveConfigurations() will default to returning the |
| 42 // hard-coded configuration corresponding to the forced feature state. Tests |
| 43 // that need to toggle both the feature and override the active configuration |
| 44 // should therefore do so in that order. |
| 21 class ScopedSubresourceFilterFeatureToggle { | 45 class ScopedSubresourceFilterFeatureToggle { |
| 22 public: | 46 public: |
| 23 ScopedSubresourceFilterFeatureToggle( | 47 explicit ScopedSubresourceFilterFeatureToggle( |
| 24 base::FeatureList::OverrideState feature_state, | 48 base::FeatureList::OverrideState subresource_filter_state); |
| 25 const std::string& maximum_activation_level, | |
| 26 const std::string& activation_scope, | |
| 27 const std::string& activation_lists = std::string(), | |
| 28 const std::string& performance_measurement_rate = std::string(), | |
| 29 const std::string& suppress_notifications = std::string(), | |
| 30 const std::string& whitelist_site_on_reload = std::string()); | |
| 31 | |
| 32 ScopedSubresourceFilterFeatureToggle( | |
| 33 base::FeatureList::OverrideState feature_state, | |
| 34 std::map<std::string, std::string> variation_params); | |
| 35 | |
| 36 ~ScopedSubresourceFilterFeatureToggle(); | 49 ~ScopedSubresourceFilterFeatureToggle(); |
| 37 | 50 |
| 38 private: | 51 private: |
| 52 ScopedSubresourceFilterConfigurator scoped_configuration_; |
| 39 base::test::ScopedFeatureList scoped_feature_list_; | 53 base::test::ScopedFeatureList scoped_feature_list_; |
| 40 | 54 |
| 41 DISALLOW_COPY_AND_ASSIGN(ScopedSubresourceFilterFeatureToggle); | 55 DISALLOW_COPY_AND_ASSIGN(ScopedSubresourceFilterFeatureToggle); |
| 42 }; | 56 }; |
| 43 | 57 |
| 44 } // namespace testing | 58 } // namespace testing |
| 45 } // namespace subresource_filter | 59 } // namespace subresource_filter |
| 46 | 60 |
| 47 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE
S_TEST_SUPPORT_H_ | 61 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE
S_TEST_SUPPORT_H_ |
| OLD | NEW |