Chromium Code Reviews| Index: components/subresource_filter/core/common/test_ruleset_creator.h |
| diff --git a/components/subresource_filter/core/common/test_ruleset_creator.h b/components/subresource_filter/core/common/test_ruleset_creator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1315424892de7333aafbb8afc44118e4229f8b98 |
| --- /dev/null |
| +++ b/components/subresource_filter/core/common/test_ruleset_creator.h |
| @@ -0,0 +1,46 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_TEST_RULESET_CREATOR_H_ |
| +#define COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_TEST_RULESET_CREATOR_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/files/file.h" |
| +#include "base/files/scoped_temp_dir.h" |
| +#include "base/macros.h" |
| + |
| +namespace subresource_filter { |
| +namespace testing { |
| + |
| +// Helper class to create subresource filtering rulesets for testing. |
| +class TestRulesetCreator { |
| + public: |
| + TestRulesetCreator(); |
| + ~TestRulesetCreator(); |
| + |
| + // Creates a testing ruleset to disallow subresource loads from URL paths |
| + // having the given |suffix|, and returns a read-only file handle to it in |
| + // |ruleset_file|. |
| + // |
| + // The underlying temporary file will be deleted when the TestRulesetCreator |
| + // instance goes out of scope, but the |ruleset_file| handle may outlive and |
| + // can still be used even after the destruction. |
| + // |
| + // Enclose the call to this method in ASSERT_NO_FATAL_FAILURE to detect |
| + // errors. |
| + void CreateRulesetToDisallowURLsWithPathSuffix(const std::string& suffix, |
|
pkalinnikov
2016/07/19 11:57:33
How about base::StringPiece?
engedy
2016/07/19 12:57:29
Done.
|
| + base::File* ruleset_file); |
| + |
| + private: |
| + base::ScopedTempDir scoped_temp_dir_; |
| + int next_ruleset_version_ = 1; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestRulesetCreator); |
| +}; |
| + |
| +} // namespace testing |
| +} // namespace subresource_filter |
| + |
| +#endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_TEST_RULESET_CREATOR_H_ |