Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: components/subresource_filter/core/browser/subresource_filter_features_test_support.h

Issue 2844063002: Add support for multiple simultaneous subresource_filter::Configurations. (Closed)
Patch Set: Comment nit. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
31 void ResetConfiguration(std::vector<Configuration> config);
29 32
30 private: 33 private:
31 scoped_refptr<ConfigurationList> original_config_; 34 scoped_refptr<ConfigurationList> original_config_;
32 35
33 DISALLOW_COPY_AND_ASSIGN(ScopedSubresourceFilterConfigurator); 36 DISALLOW_COPY_AND_ASSIGN(ScopedSubresourceFilterConfigurator);
34 }; 37 };
35 38
36 // Helper class to override the state of the |kSafeBrowsingSubresourceFilter| 39 // Helper class to override the state of the |kSafeBrowsingSubresourceFilter|
37 // feature. 40 // feature.
38 // 41 //
39 // Clears the active subresource filtering configuration override, upon 42 // Clears the active subresource filtering configuration override, upon
40 // construction, if any, and restores it on destruction. So while the instance 43 // construction, if any, and restores it on destruction. So while the instance
41 // is in scope, calls to GetActiveConfigurations() will default to returning the 44 // is in scope, calls to GetEnabledConfigurations() will default to returning
42 // hard-coded configuration corresponding to the forced feature state. Tests 45 // the hard-coded configuration corresponding to the forced feature state. Tests
43 // that need to toggle both the feature and override the active configuration 46 // that need to toggle both the feature and override the active configuration
44 // should therefore do so in that order. 47 // should therefore do so in that order.
45 class ScopedSubresourceFilterFeatureToggle { 48 class ScopedSubresourceFilterFeatureToggle {
46 public: 49 public:
47 explicit ScopedSubresourceFilterFeatureToggle( 50 explicit ScopedSubresourceFilterFeatureToggle(
48 base::FeatureList::OverrideState subresource_filter_state); 51 base::FeatureList::OverrideState subresource_filter_state);
49 ~ScopedSubresourceFilterFeatureToggle(); 52 ~ScopedSubresourceFilterFeatureToggle();
50 53
51 private: 54 private:
52 ScopedSubresourceFilterConfigurator scoped_configuration_; 55 ScopedSubresourceFilterConfigurator scoped_configuration_;
53 base::test::ScopedFeatureList scoped_feature_list_; 56 base::test::ScopedFeatureList scoped_feature_list_;
54 57
55 DISALLOW_COPY_AND_ASSIGN(ScopedSubresourceFilterFeatureToggle); 58 DISALLOW_COPY_AND_ASSIGN(ScopedSubresourceFilterFeatureToggle);
56 }; 59 };
57 60
58 } // namespace testing 61 } // namespace testing
59 } // namespace subresource_filter 62 } // namespace subresource_filter
60 63
61 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE S_TEST_SUPPORT_H_ 64 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE S_TEST_SUPPORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698