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