#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/subresource_filter/core/common/test_ruleset_creator.h"
#include <memory>
#include <string>
#include <string_view>
#include "base/check.h"
#include "base/files/file_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "components/subresource_filter/core/common/indexed_ruleset.h"
#include "components/subresource_filter/core/common/test_ruleset_utils.h"
#include "components/subresource_filter/core/common/unindexed_ruleset.h"
#include "components/url_pattern_index/proto/rules.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h"
namespace subresource_filter {
proto;
namespace {
static_assert …;
void WriteRulesetContents(const std::vector<uint8_t>& contents,
base::FilePath path) { … }
std::vector<uint8_t> SerializeUnindexedRulesetWithMultipleRules(
const std::vector<proto::UrlRule>& rules) { … }
std::vector<uint8_t> SerializeIndexedRulesetWithMultipleRules(
const std::vector<proto::UrlRule>& rules) { … }
}
namespace testing {
TestRuleset::TestRuleset() = default;
TestRuleset::~TestRuleset() = default;
base::File TestRuleset::Open(const TestRuleset& ruleset) { … }
void TestRuleset::CorruptByTruncating(const TestRuleset& ruleset,
size_t tail_size) { … }
void TestRuleset::CorruptByFilling(const TestRuleset& ruleset,
size_t from,
size_t to,
uint8_t fill_with) { … }
TestRulesetPair::TestRulesetPair() = default;
TestRulesetPair::~TestRulesetPair() = default;
TestRulesetCreator::TestRulesetCreator()
: … { … }
TestRulesetCreator::~TestRulesetCreator() { … }
void TestRulesetCreator::CreateRulesetToDisallowURLsWithPathSuffix(
std::string_view suffix,
TestRulesetPair* test_ruleset_pair) { … }
void TestRulesetCreator::CreateUnindexedRulesetToDisallowURLsWithPathSuffix(
std::string_view suffix,
TestRuleset* test_unindexed_ruleset) { … }
void TestRulesetCreator::CreateRulesetToDisallowURLWithSubstrings(
std::vector<std::string_view> substrings,
TestRulesetPair* test_ruleset_pair) { … }
void TestRulesetCreator::CreateRulesetToDisallowURLsWithManySuffixes(
std::string_view suffix,
int num_of_suffixes,
TestRulesetPair* test_ruleset_pair) { … }
void TestRulesetCreator::CreateRulesetWithRules(
const std::vector<proto::UrlRule>& rules,
TestRulesetPair* test_ruleset_pair) { … }
void TestRulesetCreator::CreateUnindexedRulesetWithRules(
const std::vector<proto::UrlRule>& rules,
TestRuleset* test_unindexed_ruleset) { … }
void TestRulesetCreator::GetUniqueTemporaryPath(base::FilePath* path) { … }
void TestRulesetCreator::CreateTestRulesetFromContents(
std::vector<uint8_t> ruleset_contents,
TestRuleset* ruleset) { … }
}
}