#include "components/subresource_filter/content/shared/browser/ruleset_service.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/containers/span.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/test_simple_task_runner.h"
#include "build/build_config.h"
#include "components/prefs/testing_pref_service.h"
#include "components/subresource_filter/content/shared/browser/ruleset_publisher.h"
#include "components/subresource_filter/content/shared/browser/unindexed_ruleset_stream_generator.h"
#include "components/subresource_filter/core/common/constants.h"
#include "components/subresource_filter/core/common/test_ruleset_creator.h"
#include "components/url_pattern_index/proto/rules.pb.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/mock_resource_bundle_delegate.h"
#include "ui/base/resource/resource_bundle.h"
namespace subresource_filter {
namespace {
const char kTestContentVersion1[] = …;
const char kTestContentVersion2[] = …;
const char kTestContentVersion3[] = …;
const char kTestDisallowedSuffix1[] = …;
const char kTestDisallowedSuffix2[] = …;
const char kTestDisallowedSuffix3[] = …;
const char kTestLicenseContents[] = …;
template <typename Fun>
class ScopedFunctionOverride { … };
template <typename Fun>
std::unique_ptr<ScopedFunctionOverride<Fun>> OverrideFunctionForScope(
Fun* target,
Fun replacement) { … }
std::vector<uint8_t> ReadFileContentsToVector(base::File* file) { … }
class MockRulesetPublisher : public RulesetPublisher { … };
bool MockFailingReplaceFile(const base::FilePath&,
const base::FilePath&,
base::File::Error* error) { … }
#if GTEST_HAS_DEATH_TEST
bool MockCrashingIndexRuleset(const RulesetConfig&,
UnindexedRulesetStreamGenerator*,
RulesetIndexer*) { … }
#else
bool MockFailingIndexRuleset(const RulesetConfig&,
UnindexedRulesetStreamGenerator*,
RulesetIndexer*) {
return false;
}
#endif
}
_;
Return;
TestRulesetCreator;
TestRulesetPair;
class SubresourceFilteringRulesetServiceTest : public ::testing::Test { … };
class SubresourceFilteringRulesetServiceDeathTest
: public SubresourceFilteringRulesetServiceTest { … };
const char SubresourceFilteringRulesetServiceDeathTest::kInheritedTempDirKey[] = …;
TEST_F(SubresourceFilteringRulesetServiceTest, PathsAreSane) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, WriteRuleset) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
WriteRuleset_NonExistentLicensePath) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, WriteRuleset_EmptyLicensePath) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, DeleteObsoleteRulesets_Noop) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, DeleteObsoleteRulesets) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, Startup_NoRulesetNotPublished) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
Startup_MissingRulesetNotPublished) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
Startup_LegacyFormatRulesetNotPublishedButDeleted) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
Startup_ExistingRulesetPublishedAndNotDeleted) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, NewRuleset_Published) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
RulesetFromResourceId_Published) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRulesetWithEmptyVersion_NotPublished) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRulesetEarly_PublishedAfterStartupCompleted) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, NewRuleset_Persisted) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRuleset_OverwritesBadCopyOfSameVersionOnDisk) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRuleset_SuccessWithUnsupportedRules) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRuleset_CannotOpenUnindexedRulesetFile) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, NewRuleset_ParseFailure) { … }
TEST_F(SubresourceFilteringRulesetServiceDeathTest, NewRuleset_IndexingCrash) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, NewRuleset_WriteFailure) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRulesetTwice_SecondRulesetPrevails) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRulesetTwiceWithTheSameVersion_SecondIsIgnored) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
MultipleNewRulesetsEarly_MostRecentIsPublishedAfterStartupIsComplete) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRulesetSetShortlyBeforeDestruction_NoCrashes) { … }
TEST_F(SubresourceFilteringRulesetServiceTest,
NewRulesetTwiceInQuickSuccession_SecondRulesetPrevails) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, RulesetIsReadonly) { … }
TEST_F(SubresourceFilteringRulesetServiceTest, ParallelOpenOfTwoFiles) { … }
}