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
.h" | 5 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" | 10 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 124 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
125 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 125 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
126 : base::FeatureList::OVERRIDE_USE_DEFAULT, | 126 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
127 test_case.activation_state_param, test_case.activation_scope_param); | 127 test_case.activation_state_param, test_case.activation_scope_param); |
128 | 128 |
129 EXPECT_EQ(test_case.expected_activation_scope, GetCurrentActivationScope()); | 129 EXPECT_EQ(test_case.expected_activation_scope, GetCurrentActivationScope()); |
130 EXPECT_EQ(test_case.expected_activation_state, GetMaximumActivationState()); | 130 EXPECT_EQ(test_case.expected_activation_state, GetMaximumActivationState()); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
| 134 TEST(SubresourceFilterFeaturesTest, ActivationList) { |
| 135 const std::string activation_soc_eng( |
| 136 kActivationListSocialEngineeringAdsInterstitial); |
| 137 const std::string activation_phishing(kActivationListPhishingInterstitial); |
| 138 const std::string socEngPhising = activation_soc_eng + activation_phishing; |
| 139 const std::string socEngCommaPhising = |
| 140 activation_soc_eng + "," + activation_phishing; |
| 141 const std::string phishingCommaSocEng = |
| 142 activation_phishing + "," + activation_soc_eng; |
| 143 const std::string socEngCommaPhisingCommaGarbage = |
| 144 socEngCommaPhising + "," + "Garbage"; |
| 145 const struct { |
| 146 bool feature_enabled; |
| 147 const char* activation_list_param; |
| 148 ActivationList expected_activation_list; |
| 149 } kTestCases[] = { |
| 150 {false, "", ActivationList::NONE}, |
| 151 {false, "social eng ads intertitial", ActivationList::NONE}, |
| 152 {false, "phishing,interstital", ActivationList::NONE}, |
| 153 {false, "%$ garbage !%", ActivationList::NONE}, |
| 154 {true, "", ActivationList::NONE}, |
| 155 {true, "social eng ads intertitial", ActivationList::NONE}, |
| 156 {true, "phishing interstital", ActivationList::NONE}, |
| 157 {true, "%$ garbage !%", ActivationList::NONE}, |
| 158 {true, kActivationListSocialEngineeringAdsInterstitial, |
| 159 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL}, |
| 160 {true, kActivationListPhishingInterstitial, |
| 161 ActivationList::PHISHING_INTERSTITIAL}, |
| 162 {true, socEngPhising.c_str(), ActivationList::NONE}, |
| 163 {true, socEngCommaPhising.c_str(), ActivationList::PHISHING_INTERSTITIAL}, |
| 164 {true, phishingCommaSocEng.c_str(), |
| 165 ActivationList::PHISHING_INTERSTITIAL}, |
| 166 {true, socEngCommaPhisingCommaGarbage.c_str(), |
| 167 ActivationList::PHISHING_INTERSTITIAL}, |
| 168 {true, "List1, List2", ActivationList::NONE}}; |
| 169 |
| 170 for (const auto& test_case : kTestCases) { |
| 171 SCOPED_TRACE(::testing::Message("Enabled = ") << test_case.feature_enabled); |
| 172 SCOPED_TRACE(::testing::Message("ActivationListParam = \"") |
| 173 << test_case.activation_list_param << "\""); |
| 174 |
| 175 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 176 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 177 test_case.feature_enabled ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
| 178 : base::FeatureList::OVERRIDE_USE_DEFAULT, |
| 179 kActivationStateDisabled, kActivationScopeNoSites, |
| 180 test_case.activation_list_param); |
| 181 |
| 182 EXPECT_EQ(test_case.expected_activation_list, GetCurrentActivationList()); |
| 183 } |
| 184 } |
| 185 |
134 } // namespace subresource_filter | 186 } // namespace subresource_filter |
OLD | NEW |