#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "extensions/browser/api/declarative_net_request/flat_ruleset_indexer.h"
#include <stdint.h>
#include <map>
#include <string>
#include <string_view>
#include "base/format_macros.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/strings/stringprintf.h"
#include "base/test/values_test_util.h"
#include "components/url_pattern_index/flat/url_pattern_index_generated.h"
#include "extensions/browser/api/declarative_net_request/constants.h"
#include "extensions/browser/api/declarative_net_request/flat/extension_ruleset_generated.h"
#include "extensions/browser/api/declarative_net_request/indexed_rule.h"
#include "extensions/browser/api/declarative_net_request/test_utils.h"
#include "extensions/browser/api/declarative_net_request/utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions::declarative_net_request {
namespace {
flat_rule;
dnr_api;
FlatRulesetIndexerTest;
std::string ToString(const flatbuffers::String* string) { … }
std::vector<std::string> ToVector(
const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>*
vec) { … }
std::vector<dnr_api::ModifyHeaderInfo> ToVector(
const ::flatbuffers::Vector<::flatbuffers::Offset<flat::ModifyHeaderInfo>>*
vec) { … }
dnr_api::URLTransform CreateUrlTransform() { … }
bool VerifyUrlTransform(const flat::UrlTransform& flat_transform) { … }
IndexedRule CreateIndexedRule(
uint32_t id,
uint32_t priority,
uint8_t options,
uint16_t element_types,
uint8_t activation_types,
flat_rule::UrlPatternType url_pattern_type,
flat_rule::AnchorType anchor_left,
flat_rule::AnchorType anchor_right,
std::string url_pattern,
std::vector<std::string> domains,
std::vector<std::string> excluded_domains,
std::optional<std::string> redirect_url,
dnr_api::RuleActionType action_type,
std::optional<dnr_api::URLTransform> url_transform,
std::optional<std::string> regex_substitution,
std::vector<dnr_api::ModifyHeaderInfo> request_headers_to_modify,
std::vector<dnr_api::ModifyHeaderInfo> response_headers_to_modify,
std::vector<dnr_api::HeaderInfo> response_headers,
std::vector<dnr_api::HeaderInfo> excluded_response_headers) { … }
bool AreRulesEqual(const IndexedRule* indexed_rule,
const flat_rule::UrlRule* rule) { … }
std::vector<const flat_rule::UrlRule*> GetAllRulesFromIndex(
const flat_rule::UrlPatternIndex* index) { … }
void VerifyIndexEquality(const std::vector<const IndexedRule*>& rules,
const flat_rule::UrlPatternIndex* index) { … }
void VerifyExtensionMetadata(
const std::vector<const IndexedRule*>& rules,
const ::flatbuffers::Vector<flatbuffers::Offset<flat::UrlRuleMetadata>>*
extension_metdata) { … }
const flat::ExtensionIndexedRuleset* AddRuleAndGetRuleset(
const std::vector<IndexedRule>& rules_to_index,
flatbuffers::DetachedBuffer* buffer) { … }
void AddRulesAndVerifyIndex(
const std::vector<IndexedRule>& rules_to_index,
const std::vector<const IndexedRule*>
before_request_expected_index_lists[flat::IndexType_count],
const std::vector<const IndexedRule*>
headers_received_expected_index_lists[flat::IndexType_count]) { … }
TEST_F(FlatRulesetIndexerTest, TestEmptyIndex) { … }
TEST_F(FlatRulesetIndexerTest, MultipleRules) { … }
TEST_F(FlatRulesetIndexerTest, RegexRules) { … }
}
}