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

Unified Diff: components/subresource_filter/core/common/test_ruleset_creator.h

Issue 2158833002: Factor DocumentSubresourceFilter out of SubresourceFilterAgent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from pkalinnikov@ Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
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..3601b98163d0f31c207921370fb3483558c52d67
--- /dev/null
+++ b/components/subresource_filter/core/common/test_ruleset_creator.h
@@ -0,0 +1,45 @@
+// 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 "base/files/file.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/macros.h"
+#include "base/strings/string_piece.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(base::StringPiece suffix,
+ 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_

Powered by Google App Engine
This is Rietveld 408576698