#include "extensions/common/api/declarative_net_request.h"
#include <stddef.h>
#include <algorithm>
#include <functional>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/scoped_run_loop_timeout.h"
#include "base/test/test_timeouts.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/declarative_net_request/dnr_test_base.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/load_error_reporter.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/api/declarative_net_request/composite_matcher.h"
#include "extensions/browser/api/declarative_net_request/constants.h"
#include "extensions/browser/api/declarative_net_request/declarative_net_request_api.h"
#include "extensions/browser/api/declarative_net_request/file_backed_ruleset_source.h"
#include "extensions/browser/api/declarative_net_request/parse_info.h"
#include "extensions/browser/api/declarative_net_request/prefs_helper.h"
#include "extensions/browser/api/declarative_net_request/rule_counts.h"
#include "extensions/browser/api/declarative_net_request/rules_monitor_service.h"
#include "extensions/browser/api/declarative_net_request/ruleset_manager.h"
#include "extensions/browser/api/declarative_net_request/ruleset_matcher.h"
#include "extensions/browser/api/declarative_net_request/test_utils.h"
#include "extensions/browser/api/declarative_net_request/utils.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/common/api/declarative_net_request/constants.h"
#include "extensions/common/api/declarative_net_request/test_utils.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/file_util.h"
#include "extensions/common/install_warning.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/url_pattern.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace declarative_net_request {
namespace {
constexpr char kJSONRulesFilename[] = …;
constexpr char kSmallRegexFilter[] = …;
constexpr char kLargeRegexFilter[] = …;
constexpr char kId1[] = …;
constexpr char kId2[] = …;
constexpr char kId3[] = …;
constexpr char kId4[] = …;
constexpr char kDefaultRulesetID[] = …;
dnr_api;
ElementsAreArray;
Field;
Pointee;
Property;
UnorderedElementsAre;
UnorderedElementsAreArray;
template <class T>
base::Value::List VectorToList(const std::vector<T>& values) { … }
std::string GetErrorWithFilename(
const std::string& error,
const std::string& filename = kJSONRulesFilename) { … }
InstallWarning GetLargeRegexWarning(
int rule_id,
const std::string& filename = kJSONRulesFilename) { … }
std::vector<InstallWarning> GetFilteredInstallWarnings(
const Extension& extension) { … }
class DeclarativeNetRequestUnittest : public DNRTestBase { … };
class SingleRulesetTest : public DeclarativeNetRequestUnittest { … };
TEST_P(SingleRulesetTest, DuplicateResourceTypes) { … }
TEST_P(SingleRulesetTest, EmptyRedirectRuleUrl) { … }
TEST_P(SingleRulesetTest, InvalidRuleID) { … }
TEST_P(SingleRulesetTest, InvalidRedirectRulePriority) { … }
TEST_P(SingleRulesetTest, NoApplicableResourceTypes) { … }
TEST_P(SingleRulesetTest, DuplicateDomainsList) { … }
TEST_P(SingleRulesetTest, DuplicateExcludedDomainsList) { … }
TEST_P(SingleRulesetTest, EmptyDomainsList) { … }
TEST_P(SingleRulesetTest, EmptyInitiatorDomainsList) { … }
TEST_P(SingleRulesetTest, EmptyRequestDomainsList) { … }
TEST_P(SingleRulesetTest, NonAsciiDomainsList) { … }
TEST_P(SingleRulesetTest, NonAsciiExcludedDomainsList) { … }
TEST_P(SingleRulesetTest, NonAsciiInitiatorDomainsList) { … }
TEST_P(SingleRulesetTest, NonAsciiExcludedInitiatorDomainsList) { … }
TEST_P(SingleRulesetTest, NonAsciiRequestDomainsList) { … }
TEST_P(SingleRulesetTest, NonAsciiExcludedRequestDomainsList) { … }
TEST_P(SingleRulesetTest, EmptyResourceTypeList) { … }
TEST_P(SingleRulesetTest, EmptyURLFilter) { … }
TEST_P(SingleRulesetTest, InvalidRedirectURL) { … }
TEST_P(SingleRulesetTest, ListNotPassed) { … }
TEST_P(SingleRulesetTest, DuplicateIDS) { … }
TEST_P(SingleRulesetTest, TooManyParseFailures) { … }
TEST_P(SingleRulesetTest, InvalidJSONRules_StrongTypes) { … }
TEST_P(SingleRulesetTest, InvalidJSONRules_Parsed) { … }
TEST_P(SingleRulesetTest, LargeRegexIgnored) { … }
TEST_P(SingleRulesetTest, WarningAndError) { … }
TEST_P(SingleRulesetTest, RegexRuleCountExceeded) { … }
TEST_P(SingleRulesetTest, InvalidJSONFile) { … }
TEST_P(SingleRulesetTest, EmptyRuleset) { … }
TEST_P(SingleRulesetTest, AddSingleRule) { … }
TEST_P(SingleRulesetTest, AddTwoRules) { … }
TEST_P(SingleRulesetTest, ExtensionWithIndexedRuleset) { … }
TEST_P(SingleRulesetTest, DynamicRulesetRace) { … }
TEST_P(SingleRulesetTest, UpdateEnabledRulesetsRace) { … }
TEST_P(SingleRulesetTest, SessionRules) { … }
TEST_P(SingleRulesetTest, LargeRegexError_SessionRules) { … }
TEST_P(SingleRulesetTest, RuleCountLimitMatched) { … }
TEST_P(SingleRulesetTest, AllocationWhenDisabled) { … }
TEST_P(SingleRulesetTest, RuleCountLimitExceeded) { … }
TEST_P(SingleRulesetTest, DynamicAndSessionRuleLimits) { … }
class SingleRulesetWithoutSafeRulesTest : public SingleRulesetTest { … };
TEST_P(SingleRulesetWithoutSafeRulesTest, DynamicAndSessionRuleLimits) { … }
TEST_P(SingleRulesetTest, SharedDynamicAndSessionRegexRuleLimits) { … }
TEST_P(SingleRulesetTest, GetMatchedRulesInvalidTabID) { … }
class MultipleRulesetsTest : public DeclarativeNetRequestUnittest { … };
TEST_P(MultipleRulesetsTest, Success) { … }
TEST_P(MultipleRulesetsTest, ZeroRulesets) { … }
TEST_P(MultipleRulesetsTest, EmptyRulesets) { … }
TEST_P(MultipleRulesetsTest, ListNotPassed) { … }
TEST_P(MultipleRulesetsTest, InstallWarnings) { … }
TEST_P(MultipleRulesetsTest, EnabledRulesCount) { … }
TEST_P(MultipleRulesetsTest, RegexRuleCountExceeded) { … }
TEST_P(MultipleRulesetsTest, UpdateEnabledRulesets_InvalidRulesetID) { … }
TEST_P(MultipleRulesetsTest,
UpdateEnabledRulesets_EnabledRulesetCountExceeded) { … }
TEST_P(MultipleRulesetsTest, UpdateEnabledRulesets_RegexRuleCountExceeded) { … }
TEST_P(MultipleRulesetsTest, UpdateEnabledRulesets_InternalError) { … }
TEST_P(MultipleRulesetsTest, UpdateAndGetEnabledRulesets_Success) { … }
TEST_P(MultipleRulesetsTest, StaticRuleCountExceeded) { … }
TEST_P(MultipleRulesetsTest, RulesetIgnored) { … }
TEST_P(MultipleRulesetsTest, MultipleExtensions) { … }
TEST_P(MultipleRulesetsTest, MultipleExtensionsRuleLimitExceeded) { … }
TEST_P(MultipleRulesetsTest, UpdateAndGetEnabledRulesets_RuleCountAllocation) { … }
TEST_P(MultipleRulesetsTest, UpdateAndGetEnabledRulesets_RuleCountExceeded) { … }
TEST_P(MultipleRulesetsTest,
UpdateAndGetEnabledRulesets_KeepEnabledStaticRulesetsAfterReload) { … }
TEST_P(MultipleRulesetsTest,
UpdateAndGetEnabledRulesets_DisableRulesetsWhenEmptyEnabledRulesets) { … }
TEST_P(MultipleRulesetsTest, GetAvailableStaticRuleCount) { … }
TEST_P(MultipleRulesetsTest, UpdateStaticRulesDisableAndEnableRules) { … }
TEST_P(MultipleRulesetsTest, UpdateStaticRulesMakingNoChange) { … }
TEST_P(MultipleRulesetsTest, UpdateStaticRulesArgumentPriority) { … }
TEST_P(MultipleRulesetsTest, UpdateStaticRulesErrorWhenRuleLimitExceeded) { … }
TEST_P(MultipleRulesetsTest, GetDisabledStaticRuleIdsErrorForInvalidRuleset) { … }
TEST_P(MultipleRulesetsTest,
KeepDisabledStaticRulesWhenExtensionDisabledAndEnabled) { … }
TEST_P(MultipleRulesetsTest, ReclaimAllocationOnUnload) { … }
MultipleRulesetsTest_Unpacked;
TEST_P(MultipleRulesetsTest_Unpacked, UpdateAllocationOnReload) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
}
}
}