OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" |
| 6 |
| 7 #include <map> |
| 8 #include <memory> |
| 9 |
| 10 #include "base/metrics/field_trial.h" |
| 11 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
| 12 #include "components/variations/variations_associated_data.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace subresource_filter { |
| 16 namespace testing { |
| 17 |
| 18 namespace { |
| 19 const char kTestFieldTrialName[] = "FieldTrialNameShouldNotMatter"; |
| 20 const char kTestExperimentGroupName[] = "GroupNameShouldNotMatter"; |
| 21 } // namespace |
| 22 |
| 23 ScopedSubresourceFilterFeatureToggle::ScopedSubresourceFilterFeatureToggle( |
| 24 base::FeatureList::OverrideState feature_state, |
| 25 const std::string& maximum_activation_state) { |
| 26 base::FeatureList::ClearInstanceForTesting(); |
| 27 variations::testing::ClearAllVariationParams(); |
| 28 |
| 29 std::map<std::string, std::string> variation_params; |
| 30 variation_params[kActivationStateParameterName] = maximum_activation_state; |
| 31 EXPECT_TRUE(variations::AssociateVariationParams( |
| 32 kTestFieldTrialName, kTestExperimentGroupName, variation_params)); |
| 33 |
| 34 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( |
| 35 kTestFieldTrialName, kTestExperimentGroupName); |
| 36 |
| 37 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 38 feature_list->RegisterFieldTrialOverride(kSafeBrowsingSubresourceFilter.name, |
| 39 feature_state, field_trial); |
| 40 base::FeatureList::SetInstance(std::move(feature_list)); |
| 41 } |
| 42 |
| 43 ScopedSubresourceFilterFeatureToggle::~ScopedSubresourceFilterFeatureToggle() { |
| 44 variations::testing::ClearAllVariationParams(); |
| 45 base::FeatureList::ClearInstanceForTesting(); |
| 46 } |
| 47 |
| 48 } // namespace testing |
| 49 } // namespace subresource_filter |
OLD | NEW |