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