chromium/components/fingerprinting_protection_filter/renderer/renderer_agent_unittest.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/fingerprinting_protection_filter/renderer/renderer_agent.h"

#include <memory>
#include <string_view>
#include <utility>

#include "base/files/file.h"
#include "base/time/time.h"
#include "components/fingerprinting_protection_filter/renderer/unverified_ruleset_dealer.h"
#include "components/subresource_filter/core/common/memory_mapped_ruleset.h"
#include "components/subresource_filter/core/common/test_ruleset_creator.h"
#include "components/subresource_filter/core/mojom/subresource_filter.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_document_subresource_filter.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "url/gurl.h"

namespace fingerprinting_protection_filter {

namespace {

// The RendererAgent with its dependencies on Blink mocked out.
//
// This approach is somewhat rudimentary, but appears to be the best compromise
// considering the alternatives:
//  -- Passing in a TestRenderFrame would itself require bringing up a
//     significant number of supporting classes.
//  -- Using a RenderViewTest would not allow having any non-filtered resource
//     loads due to not having a child thread and ResourceDispatcher.
// The real implementations of the mocked-out methods will be exercised in
// browsertests.
class RendererAgentUnderTest : public RendererAgent {};

constexpr const char kTestFirstURL[] =;
constexpr const char kTestSecondURL[] =;
constexpr const char kTestFirstURLPathSuffix[] =;
constexpr const char kTestSecondURLPathSuffix[] =;
constexpr const char kTestBothURLsPathSuffix[] =;

}  // namespace

class RendererAgentTest : public ::testing::Test {};

TEST_F(RendererAgentTest, RulesetUnset_RulesetNotAvailable) {}

TEST_F(RendererAgentTest, DisabledByDefault_NoFilterIsInjected) {}

TEST_F(RendererAgentTest, MmapFailure_FailsToInjectFilter) {}

TEST_F(RendererAgentTest, Disabled_NoFilterIsInjected) {}

TEST_F(RendererAgentTest, EnabledButRulesetUnavailable_NoFilterIsInjected) {}

// Never inject a filter for root frame about:blank loads, even though we do for
// child frame loads. Those are tested via browser tests.
TEST_F(RendererAgentTest, EmptyDocumentLoad_NoFilterIsInjected) {}

TEST_F(RendererAgentTest, Enabled_FilteringIsInEffectForOneLoad) {}

TEST_F(RendererAgentTest, Enabled_NewRulesetIsPickedUpAtNextLoad) {}

// Make sure that the activation decision does not outlive a failed provisional
// load (and affect the second next load).
TEST_F(RendererAgentTest,
       Enabled_FilteringNoLongerActiveAfterProvisionalLoadIsCancelled) {}

TEST_F(RendererAgentTest, DryRun_ResourcesAreEvaluatedButNotFiltered) {}

TEST_F(RendererAgentTest,
       SignalFirstSubresourceDisallowed_OncePerDocumentLoad) {}

TEST_F(RendererAgentTest,
       SignalFirstSubresourceDisallowed_ComesAfterAgentDestroyed) {}

TEST_F(RendererAgentTest,
       FailedInitialLoad_FilterInjectedOnInitialDocumentCreation) {}

TEST_F(RendererAgentTest,
       FailedInitialMainFrameLoad_FilterInjectedOnInitialDocumentCreation) {}

}  // namespace fingerprinting_protection_filter