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 "chrome/browser/component_updater/subresource_filter_component_installe
r.h" | 5 #include "chrome/browser/component_updater/subresource_filter_component_installe
r.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 ~SubresourceFilterMockComponentUpdateService() override {} | 78 ~SubresourceFilterMockComponentUpdateService() override {} |
79 | 79 |
80 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override { | 80 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override { |
81 return base::ThreadTaskRunnerHandle::Get(); | 81 return base::ThreadTaskRunnerHandle::Get(); |
82 } | 82 } |
83 | 83 |
84 private: | 84 private: |
85 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterMockComponentUpdateService); | 85 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterMockComponentUpdateService); |
86 }; | 86 }; |
87 | 87 |
| 88 subresource_filter::Configuration CreateConfigUsingRulesetFlavor( |
| 89 const char* ruleset_flavor) { |
| 90 subresource_filter::Configuration config; |
| 91 config.ruleset_flavor = ruleset_flavor; |
| 92 return config; |
| 93 } |
| 94 |
88 } // namespace | 95 } // namespace |
89 | 96 |
90 namespace component_updater { | 97 namespace component_updater { |
91 | 98 |
92 class SubresourceFilterComponentInstallerTest : public PlatformTest { | 99 class SubresourceFilterComponentInstallerTest : public PlatformTest { |
93 public: | 100 public: |
94 SubresourceFilterComponentInstallerTest() {} | 101 SubresourceFilterComponentInstallerTest() {} |
95 | 102 |
96 void SetUp() override { | 103 void SetUp() override { |
97 PlatformTest::SetUp(); | 104 PlatformTest::SetUp(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 std::move(manifest)); | 166 std::move(manifest)); |
160 base::RunLoop().RunUntilIdle(); | 167 base::RunLoop().RunUntilIdle(); |
161 } | 168 } |
162 | 169 |
163 update_client::InstallerAttributes GetInstallerAttributes() { | 170 update_client::InstallerAttributes GetInstallerAttributes() { |
164 return traits_->GetInstallerAttributes(); | 171 return traits_->GetInstallerAttributes(); |
165 } | 172 } |
166 | 173 |
167 void ExpectInstallerTag(const char* expected_tag, | 174 void ExpectInstallerTag(const char* expected_tag, |
168 const char* ruleset_flavor) { | 175 const char* ruleset_flavor) { |
169 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 176 subresource_filter::testing::ScopedSubresourceFilterConfigurator |
170 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle | 177 configurator(CreateConfigUsingRulesetFlavor(ruleset_flavor)); |
171 scoped_feature_toggle(base::FeatureList::OVERRIDE_ENABLE_FEATURE, | |
172 {{subresource_filter::kRulesetFlavorParameterName, | |
173 ruleset_flavor}}); | |
174 EXPECT_EQ(expected_tag, | 178 EXPECT_EQ(expected_tag, |
175 SubresourceFilterComponentInstallerTraits::GetInstallerTag()); | 179 SubresourceFilterComponentInstallerTraits::GetInstallerTag()); |
176 } | 180 } |
177 | 181 |
178 private: | 182 private: |
179 base::ScopedTempDir component_install_dir_; | 183 base::ScopedTempDir component_install_dir_; |
180 base::ScopedTempDir ruleset_service_dir_; | 184 base::ScopedTempDir ruleset_service_dir_; |
181 | 185 |
182 content::TestBrowserThreadBundle thread_bundle_; | 186 content::TestBrowserThreadBundle thread_bundle_; |
183 std::unique_ptr<SubresourceFilterComponentInstallerTraits> traits_; | 187 std::unique_ptr<SubresourceFilterComponentInstallerTraits> traits_; |
184 TestingPrefServiceSimple pref_service_; | 188 TestingPrefServiceSimple pref_service_; |
185 | 189 |
186 TestRulesetService* test_ruleset_service_ = nullptr; | 190 TestRulesetService* test_ruleset_service_ = nullptr; |
187 | 191 |
188 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterComponentInstallerTest); | 192 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterComponentInstallerTest); |
189 }; | 193 }; |
190 | 194 |
191 TEST_F(SubresourceFilterComponentInstallerTest, | 195 TEST_F(SubresourceFilterComponentInstallerTest, |
192 TestComponentRegistrationWhenFeatureDisabled) { | 196 TestComponentRegistrationWhenFeatureDisabled) { |
193 base::FieldTrialList field_trial_list(nullptr); | |
194 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle | 197 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle |
195 scoped_feature_toggle(base::FeatureList::OVERRIDE_DISABLE_FEATURE, | 198 feature_toggle(base::FeatureList::OVERRIDE_DISABLE_FEATURE); |
196 subresource_filter::kActivationLevelEnabled, | |
197 subresource_filter::kActivationScopeNoSites); | |
198 std::unique_ptr<SubresourceFilterMockComponentUpdateService> | 199 std::unique_ptr<SubresourceFilterMockComponentUpdateService> |
199 component_updater(new SubresourceFilterMockComponentUpdateService()); | 200 component_updater(new SubresourceFilterMockComponentUpdateService()); |
200 EXPECT_CALL(*component_updater, RegisterComponent(testing::_)).Times(0); | 201 EXPECT_CALL(*component_updater, RegisterComponent(testing::_)).Times(0); |
201 RegisterSubresourceFilterComponent(component_updater.get()); | 202 RegisterSubresourceFilterComponent(component_updater.get()); |
202 base::RunLoop().RunUntilIdle(); | 203 base::RunLoop().RunUntilIdle(); |
203 } | 204 } |
204 | 205 |
205 TEST_F(SubresourceFilterComponentInstallerTest, | 206 TEST_F(SubresourceFilterComponentInstallerTest, |
206 TestComponentRegistrationWhenFeatureEnabled) { | 207 TestComponentRegistrationWhenFeatureEnabled) { |
207 base::FieldTrialList field_trial_list(nullptr); | |
208 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle | 208 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle |
209 scoped_feature_toggle(base::FeatureList::OVERRIDE_ENABLE_FEATURE, | 209 feature_toggle(base::FeatureList::OVERRIDE_ENABLE_FEATURE); |
210 subresource_filter::kActivationLevelDisabled, | |
211 subresource_filter::kActivationScopeNoSites); | |
212 std::unique_ptr<SubresourceFilterMockComponentUpdateService> | 210 std::unique_ptr<SubresourceFilterMockComponentUpdateService> |
213 component_updater(new SubresourceFilterMockComponentUpdateService()); | 211 component_updater(new SubresourceFilterMockComponentUpdateService()); |
214 EXPECT_CALL(*component_updater, RegisterComponent(testing::_)) | 212 EXPECT_CALL(*component_updater, RegisterComponent(testing::_)) |
215 .Times(1) | 213 .Times(1) |
216 .WillOnce(testing::Return(true)); | 214 .WillOnce(testing::Return(true)); |
217 RegisterSubresourceFilterComponent(component_updater.get()); | 215 RegisterSubresourceFilterComponent(component_updater.get()); |
218 base::RunLoop().RunUntilIdle(); | 216 base::RunLoop().RunUntilIdle(); |
219 } | 217 } |
220 | 218 |
221 TEST_F(SubresourceFilterComponentInstallerTest, LoadEmptyRuleset) { | 219 TEST_F(SubresourceFilterComponentInstallerTest, LoadEmptyRuleset) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 ExpectInstallerTag("", ""); | 265 ExpectInstallerTag("", ""); |
268 ExpectInstallerTag("a", "a"); | 266 ExpectInstallerTag("a", "a"); |
269 ExpectInstallerTag("b", "b"); | 267 ExpectInstallerTag("b", "b"); |
270 ExpectInstallerTag("c", "c"); | 268 ExpectInstallerTag("c", "c"); |
271 ExpectInstallerTag("d", "d"); | 269 ExpectInstallerTag("d", "d"); |
272 ExpectInstallerTag("invalid", "e"); | 270 ExpectInstallerTag("invalid", "e"); |
273 ExpectInstallerTag("invalid", "foo"); | 271 ExpectInstallerTag("invalid", "foo"); |
274 } | 272 } |
275 | 273 |
276 TEST_F(SubresourceFilterComponentInstallerTest, InstallerAttributesDefault) { | 274 TEST_F(SubresourceFilterComponentInstallerTest, InstallerAttributesDefault) { |
277 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 275 subresource_filter::testing::ScopedSubresourceFilterConfigurator |
278 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle | 276 scoped_configuration((subresource_filter::Configuration())); |
279 scoped_feature_toggle(base::FeatureList::OVERRIDE_ENABLE_FEATURE, | |
280 std::map<std::string, std::string>()); | |
281 EXPECT_EQ(update_client::InstallerAttributes(), GetInstallerAttributes()); | 277 EXPECT_EQ(update_client::InstallerAttributes(), GetInstallerAttributes()); |
282 } | 278 } |
283 | 279 |
284 TEST_F(SubresourceFilterComponentInstallerTest, InstallerAttributesCustomTag) { | 280 TEST_F(SubresourceFilterComponentInstallerTest, InstallerAttributesCustomTag) { |
285 constexpr char kTagKey[] = "tag"; | 281 constexpr char kTagKey[] = "tag"; |
286 constexpr char kTagValue[] = "a"; | 282 constexpr char kTagValue[] = "a"; |
287 | 283 |
288 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | 284 subresource_filter::testing::ScopedSubresourceFilterConfigurator |
289 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle | 285 scoped_configuration(CreateConfigUsingRulesetFlavor(kTagValue)); |
290 scoped_feature_toggle( | |
291 base::FeatureList::OVERRIDE_ENABLE_FEATURE, | |
292 {{subresource_filter::kRulesetFlavorParameterName, kTagValue}}); | |
293 EXPECT_EQ(update_client::InstallerAttributes({{kTagKey, kTagValue}}), | 286 EXPECT_EQ(update_client::InstallerAttributes({{kTagKey, kTagValue}}), |
294 GetInstallerAttributes()); | 287 GetInstallerAttributes()); |
295 } | 288 } |
296 | 289 |
297 TEST_F(SubresourceFilterComponentInstallerTest, | |
298 InstallerAttributesFeatureDisabled) { | |
299 constexpr char kTagValue[] = "test_value"; | |
300 | |
301 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); | |
302 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle | |
303 scoped_feature_toggle( | |
304 base::FeatureList::OVERRIDE_USE_DEFAULT, | |
305 {{subresource_filter::kRulesetFlavorParameterName, kTagValue}}); | |
306 EXPECT_EQ(update_client::InstallerAttributes(), GetInstallerAttributes()); | |
307 } | |
308 | |
309 } // namespace component_updater | 290 } // namespace component_updater |
OLD | NEW |