| 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
_test_support.h" | 5 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 | 12 |
| 13 namespace subresource_filter { | 13 namespace subresource_filter { |
| 14 namespace testing { | 14 namespace testing { |
| 15 | 15 |
| 16 // ScopedSubresourceFilterConfigurator ---------------------------------------- | 16 // ScopedSubresourceFilterConfigurator ---------------------------------------- |
| 17 | 17 |
| 18 ScopedSubresourceFilterConfigurator::ScopedSubresourceFilterConfigurator( | 18 ScopedSubresourceFilterConfigurator::ScopedSubresourceFilterConfigurator( |
| 19 scoped_refptr<ConfigurationList> configs) | 19 scoped_refptr<ConfigurationList> configs_list) |
| 20 : original_config_(GetAndSetActivateConfigurations(configs)) {} | 20 : original_config_(GetAndSetActivateConfigurations(configs_list)) {} |
| 21 | 21 |
| 22 ScopedSubresourceFilterConfigurator::ScopedSubresourceFilterConfigurator( | 22 ScopedSubresourceFilterConfigurator::ScopedSubresourceFilterConfigurator( |
| 23 Configuration config) | 23 Configuration config) |
| 24 : ScopedSubresourceFilterConfigurator( | 24 : ScopedSubresourceFilterConfigurator( |
| 25 base::MakeShared<ConfigurationList>(std::move(config))) {} | 25 std::vector<Configuration>(1, std::move(config))) {} |
| 26 |
| 27 ScopedSubresourceFilterConfigurator::ScopedSubresourceFilterConfigurator( |
| 28 std::vector<Configuration> configs) |
| 29 : ScopedSubresourceFilterConfigurator( |
| 30 base::MakeShared<ConfigurationList>(std::move(configs))) {} |
| 26 | 31 |
| 27 ScopedSubresourceFilterConfigurator::~ScopedSubresourceFilterConfigurator() { | 32 ScopedSubresourceFilterConfigurator::~ScopedSubresourceFilterConfigurator() { |
| 28 GetAndSetActivateConfigurations(std::move(original_config_)); | 33 GetAndSetActivateConfigurations(std::move(original_config_)); |
| 29 } | 34 } |
| 30 | 35 |
| 31 void ScopedSubresourceFilterConfigurator::ResetConfiguration( | 36 void ScopedSubresourceFilterConfigurator::ResetConfiguration( |
| 37 scoped_refptr<ConfigurationList> configs_list) { |
| 38 GetAndSetActivateConfigurations(configs_list); |
| 39 } |
| 40 |
| 41 void ScopedSubresourceFilterConfigurator::ResetConfiguration( |
| 32 Configuration config) { | 42 Configuration config) { |
| 33 GetAndSetActivateConfigurations( | 43 ResetConfiguration(std::vector<Configuration>(1, std::move(config))); |
| 34 base::MakeShared<ConfigurationList>(std::move(config))); | 44 } |
| 45 |
| 46 void ScopedSubresourceFilterConfigurator::ResetConfiguration( |
| 47 std::vector<Configuration> config) { |
| 48 ResetConfiguration(base::MakeShared<ConfigurationList>(std::move(config))); |
| 35 } | 49 } |
| 36 | 50 |
| 37 // ScopedSubresourceFilterFeatureToggle --------------------------------------- | 51 // ScopedSubresourceFilterFeatureToggle --------------------------------------- |
| 38 | 52 |
| 53 ScopedSubresourceFilterFeatureToggle::ScopedSubresourceFilterFeatureToggle() {} |
| 39 ScopedSubresourceFilterFeatureToggle::ScopedSubresourceFilterFeatureToggle( | 54 ScopedSubresourceFilterFeatureToggle::ScopedSubresourceFilterFeatureToggle( |
| 40 base::FeatureList::OverrideState feature_state) { | 55 base::FeatureList::OverrideState feature_state, |
| 41 if (feature_state == base::FeatureList::OVERRIDE_ENABLE_FEATURE) | 56 const std::string& additional_features_to_enable) { |
| 42 scoped_feature_list_.InitAndEnableFeature(kSafeBrowsingSubresourceFilter); | 57 ResetSubresourceFilterState(feature_state, additional_features_to_enable); |
| 43 else if (feature_state == base::FeatureList::OVERRIDE_DISABLE_FEATURE) | 58 } |
| 44 scoped_feature_list_.InitAndDisableFeature(kSafeBrowsingSubresourceFilter); | 59 |
| 60 void ScopedSubresourceFilterFeatureToggle::ResetSubresourceFilterState( |
| 61 base::FeatureList::OverrideState feature_state, |
| 62 const std::string& additional_features_to_enable) { |
| 63 std::string enabled_features; |
| 64 std::string disabled_features; |
| 65 |
| 66 if (feature_state == base::FeatureList::OVERRIDE_ENABLE_FEATURE) { |
| 67 enabled_features = kSafeBrowsingSubresourceFilter.name; |
| 68 } else if (feature_state == base::FeatureList::OVERRIDE_DISABLE_FEATURE) { |
| 69 disabled_features = kSafeBrowsingSubresourceFilter.name; |
| 70 } |
| 71 |
| 72 if (!additional_features_to_enable.empty()) { |
| 73 if (!enabled_features.empty()) |
| 74 enabled_features += ','; |
| 75 enabled_features += additional_features_to_enable; |
| 76 } |
| 77 |
| 78 scoped_configuration_.ResetConfiguration(); |
| 79 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); |
| 80 scoped_feature_list_->InitFromCommandLine(enabled_features, |
| 81 disabled_features); |
| 45 } | 82 } |
| 46 | 83 |
| 47 ScopedSubresourceFilterFeatureToggle::~ScopedSubresourceFilterFeatureToggle() {} | 84 ScopedSubresourceFilterFeatureToggle::~ScopedSubresourceFilterFeatureToggle() {} |
| 48 | 85 |
| 49 } // namespace testing | 86 } // namespace testing |
| 50 } // namespace subresource_filter | 87 } // namespace subresource_filter |
| OLD | NEW |