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

Side by Side Diff: chrome/browser/component_updater/subresource_filter_component_installer_unittest.cc

Issue 2844063002: Add support for multiple simultaneous subresource_filter::Configurations. (Closed)
Patch Set: Address all comments. 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 #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>
11 #include <vector>
11 12
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/metrics/field_trial.h" 17 #include "base/metrics/field_trial.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/version.h" 21 #include "base/version.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 80
80 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override { 81 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override {
81 return base::ThreadTaskRunnerHandle::Get(); 82 return base::ThreadTaskRunnerHandle::Get();
82 } 83 }
83 84
84 private: 85 private:
85 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterMockComponentUpdateService); 86 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterMockComponentUpdateService);
86 }; 87 };
87 88
88 subresource_filter::Configuration CreateConfigUsingRulesetFlavor( 89 subresource_filter::Configuration CreateConfigUsingRulesetFlavor(
89 const char* ruleset_flavor) { 90 std::string ruleset_flavor) {
Sorin Jianu 2017/05/09 01:49:08 can we pass by ref to const and avoid the move bel
engedy 2017/05/09 11:39:35 Done.
90 subresource_filter::Configuration config; 91 subresource_filter::Configuration config;
91 config.ruleset_flavor = ruleset_flavor; 92 config.general_settings.ruleset_flavor = std::move(ruleset_flavor);
92 return config; 93 return config;
93 } 94 }
94 95
95 } // namespace 96 } // namespace
96 97
97 namespace component_updater { 98 namespace component_updater {
98 99
99 class SubresourceFilterComponentInstallerTest : public PlatformTest { 100 class SubresourceFilterComponentInstallerTest : public PlatformTest {
100 public: 101 public:
101 SubresourceFilterComponentInstallerTest() {} 102 SubresourceFilterComponentInstallerTest() {}
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 const base::Version expected_version(kTestRulesetVersion); 165 const base::Version expected_version(kTestRulesetVersion);
165 traits_->ComponentReady(expected_version, component_install_dir(), 166 traits_->ComponentReady(expected_version, component_install_dir(),
166 std::move(manifest)); 167 std::move(manifest));
167 base::RunLoop().RunUntilIdle(); 168 base::RunLoop().RunUntilIdle();
168 } 169 }
169 170
170 update_client::InstallerAttributes GetInstallerAttributes() { 171 update_client::InstallerAttributes GetInstallerAttributes() {
171 return traits_->GetInstallerAttributes(); 172 return traits_->GetInstallerAttributes();
172 } 173 }
173 174
174 void ExpectInstallerTag(const char* expected_tag,
175 const char* ruleset_flavor) {
176 subresource_filter::testing::ScopedSubresourceFilterConfigurator
177 scoped_configuration(CreateConfigUsingRulesetFlavor(ruleset_flavor));
178 EXPECT_EQ(expected_tag,
179 SubresourceFilterComponentInstallerTraits::GetInstallerTag());
180 }
181
182 private: 175 private:
183 base::ScopedTempDir component_install_dir_; 176 base::ScopedTempDir component_install_dir_;
184 base::ScopedTempDir ruleset_service_dir_; 177 base::ScopedTempDir ruleset_service_dir_;
185 178
186 content::TestBrowserThreadBundle thread_bundle_; 179 content::TestBrowserThreadBundle thread_bundle_;
187 std::unique_ptr<SubresourceFilterComponentInstallerTraits> traits_; 180 std::unique_ptr<SubresourceFilterComponentInstallerTraits> traits_;
188 TestingPrefServiceSimple pref_service_; 181 TestingPrefServiceSimple pref_service_;
189 182
190 TestRulesetService* test_ruleset_service_ = nullptr; 183 TestRulesetService* test_ruleset_service_ = nullptr;
191 184
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 std::string actual_license_contents; 248 std::string actual_license_contents;
256 ASSERT_TRUE(base::ReadFileToString(service()->ruleset_path(), 249 ASSERT_TRUE(base::ReadFileToString(service()->ruleset_path(),
257 &actual_ruleset_contents)); 250 &actual_ruleset_contents));
258 EXPECT_EQ(expected_ruleset_contents, actual_ruleset_contents); 251 EXPECT_EQ(expected_ruleset_contents, actual_ruleset_contents);
259 ASSERT_TRUE(base::ReadFileToString(service()->license_path(), 252 ASSERT_TRUE(base::ReadFileToString(service()->license_path(),
260 &actual_license_contents)); 253 &actual_license_contents));
261 EXPECT_EQ(expected_license_contents, actual_license_contents); 254 EXPECT_EQ(expected_license_contents, actual_license_contents);
262 } 255 }
263 256
264 TEST_F(SubresourceFilterComponentInstallerTest, InstallerTag) { 257 TEST_F(SubresourceFilterComponentInstallerTest, InstallerTag) {
265 ExpectInstallerTag("", ""); 258 const struct {
266 ExpectInstallerTag("a", "a"); 259 const char* expected_installer_tag_selected;
267 ExpectInstallerTag("b", "b"); 260 std::vector<std::string> ruleset_flavors;
268 ExpectInstallerTag("c", "c"); 261 } kTestCases[] = {{"", std::vector<std::string>()},
269 ExpectInstallerTag("d", "d"); 262 {"", {""}},
270 ExpectInstallerTag("invalid", "e"); 263 {"a", {"a"}},
271 ExpectInstallerTag("invalid", "foo"); 264 {"b", {"b"}},
265 {"c", {"c"}},
266 {"d", {"d"}},
267 {"invalid", {"e"}},
268 {"invalid", {"foo"}},
269 {"", {"", ""}},
270 {"a", {"a", ""}},
271 {"a", {"", "a"}},
272 {"a", {"a", "a"}},
273 {"c", {"b", "", "c"}},
274 {"b", {"", "b", "a"}},
275 {"c", {"aaa", "c", "aba"}},
276 {"invalid", {"", "a", "e"}},
277 {"invalid", {"foo", "a", "b"}}};
278
279 for (const auto& test_case : kTestCases) {
280 SCOPED_TRACE(::testing::Message()
281 << "ruleset_flavors: "
282 << ::testing::PrintToString(test_case.ruleset_flavors));
283
284 std::vector<subresource_filter::Configuration> configs;
285 for (const auto& ruleset_flavor : test_case.ruleset_flavors)
286 configs.push_back(CreateConfigUsingRulesetFlavor(ruleset_flavor));
287 subresource_filter::testing::ScopedSubresourceFilterConfigurator
288 scoped_configuration(std::move(configs));
289
290 EXPECT_EQ(test_case.expected_installer_tag_selected,
291 SubresourceFilterComponentInstallerTraits::GetInstallerTag());
292 }
272 } 293 }
273 294
274 TEST_F(SubresourceFilterComponentInstallerTest, InstallerAttributesDefault) { 295 TEST_F(SubresourceFilterComponentInstallerTest, InstallerAttributesDefault) {
275 subresource_filter::testing::ScopedSubresourceFilterConfigurator 296 subresource_filter::testing::ScopedSubresourceFilterConfigurator
276 scoped_configuration((subresource_filter::Configuration())); 297 scoped_configuration((subresource_filter::Configuration()));
277 EXPECT_EQ(update_client::InstallerAttributes(), GetInstallerAttributes()); 298 EXPECT_EQ(update_client::InstallerAttributes(), GetInstallerAttributes());
278 } 299 }
279 300
280 TEST_F(SubresourceFilterComponentInstallerTest, InstallerAttributesCustomTag) { 301 TEST_F(SubresourceFilterComponentInstallerTest, InstallerAttributesCustomTag) {
281 constexpr char kTagKey[] = "tag"; 302 constexpr char kTagKey[] = "tag";
282 constexpr char kTagValue[] = "a"; 303 constexpr char kTagValue[] = "a";
283 304
284 subresource_filter::testing::ScopedSubresourceFilterConfigurator 305 subresource_filter::testing::ScopedSubresourceFilterConfigurator
285 scoped_configuration(CreateConfigUsingRulesetFlavor(kTagValue)); 306 scoped_configuration(CreateConfigUsingRulesetFlavor(kTagValue));
286 EXPECT_EQ(update_client::InstallerAttributes({{kTagKey, kTagValue}}), 307 EXPECT_EQ(update_client::InstallerAttributes({{kTagKey, kTagValue}}),
287 GetInstallerAttributes()); 308 GetInstallerAttributes());
288 } 309 }
289 310
290 } // namespace component_updater 311 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698