#include "components/subresource_filter/core/browser/verified_ruleset_dealer.h"
#include <memory>
#include <vector>
#include "base/check.h"
#include "base/files/file.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/hash/hash.h"
#include "base/test/task_environment.h"
#include "base/test/test_simple_task_runner.h"
#include "components/subresource_filter/core/common/constants.h"
#include "components/subresource_filter/core/common/memory_mapped_ruleset.h"
#include "components/subresource_filter/core/common/test_ruleset_creator.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace subresource_filter {
namespace {
class TestRulesets { … };
constexpr const char TestRulesets::kTestRulesetSuffix1[];
constexpr const char TestRulesets::kTestRulesetSuffix2[];
constexpr int TestRulesets::kNumberOfRulesInBigRuleset;
std::vector<uint8_t> ReadRulesetContents(const MemoryMappedRuleset* ruleset) { … }
std::vector<uint8_t> ReadFileContent(base::File* file) { … }
}
class SubresourceFilterVerifiedRulesetDealerTest : public ::testing::Test { … };
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
RulesetIsMemoryMappedAndVerifiedLazily) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
CorruptedRulesetIsNeitherProvidedNorCached) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest, MmapFailureInitial) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest, MmapFailureSubsequent) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
TruncatingFileMakesRulesetInvalid) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
FillingRangeMakesRulesetInvalid) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
RulesetIsVerifiedAfterUpdate) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
OpenAndSetRulesetFileValidNoChecksum) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
OpenAndSetRulesetFileInvalidChecksum) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
OpenAndSetRulesetFileReturnsCorrectFileOnSuccess) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerTest,
OpenAndSetRulesetFileReturnsNullFileOnFailure) { … }
namespace {
class TestVerifiedRulesetDealerClient { … };
}
class SubresourceFilterVerifiedRulesetDealerHandleTest
: public ::testing::Test { … };
TEST_F(SubresourceFilterVerifiedRulesetDealerHandleTest,
RulesetIsMappedLazily) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerHandleTest, RulesetFileIsUpdated) { … }
TEST_F(SubresourceFilterVerifiedRulesetDealerHandleTest,
InvalidFileDoesNotReplaceTheValidOne) { … }
namespace {
class TestVerifiedRulesetClient { … };
}
class SubresourceFilterVerifiedRulesetHandleTest : public ::testing::Test { … };
TEST_F(SubresourceFilterVerifiedRulesetHandleTest,
RulesetHandleKeepsRulesetMemoryMappedAndVerified) { … }
TEST_F(SubresourceFilterVerifiedRulesetHandleTest,
RulesetUnmappedOnlyAfterLastHandleIsDeleted) { … }
TEST_F(SubresourceFilterVerifiedRulesetHandleTest,
OldRulesetRemainsMappedAfterUpdateUntilHandleIsDeleted) { … }
TEST_F(SubresourceFilterVerifiedRulesetHandleTest,
CorruptRulesetIsNotHandedOut) { … }
}