chromium/third_party/blink/renderer/core/loader/frame_fetch_context_test.cc

/*
 * Copyright (c) 2015, Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "third_party/blink/renderer/core/loader/frame_fetch_context.h"

#include <memory>
#include <optional>

#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/web_client_hints_types.mojom-blink.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/device_memory/approximated_device_memory.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/mojom/loader/request_context_frame_type.mojom-blink.h"
#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom-blink.h"
#include "third_party/blink/public/mojom/timing/resource_timing.mojom-blink-forward.h"
#include "third_party/blink/public/platform/scheduler/web_scoped_virtual_time_pauser.h"
#include "third_party/blink/public/platform/web_document_subresource_filter.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/ad_tracker.h"
#include "third_party/blink/renderer/core/frame/frame_owner.h"
#include "third_party/blink/renderer/core/frame/frame_types.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/loader/frame_resource_fetcher_properties.h"
#include "third_party/blink/renderer/core/loader/subresource_filter.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_info.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_timing_utils.h"
#include "third_party/blink/renderer/platform/loader/fetch/unique_identifier.h"
#include "third_party/blink/renderer/platform/loader/testing/mock_resource.h"
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/reporting_disposition.h"

namespace blink {

namespace {

class DummyFrameOwner final : public GarbageCollected<DummyFrameOwner>,
                              public FrameOwner {};

}  // namespace

Checkpoint;

class FrameFetchContextMockLocalFrameClient : public EmptyLocalFrameClient {};

class FixedPolicySubresourceFilter : public WebDocumentSubresourceFilter {};

class FrameFetchContextTest : public testing::Test {};

class FrameFetchContextSubresourceFilterTest : public FrameFetchContextTest {};

// This test class sets up a mock frame loader client.
class FrameFetchContextMockedLocalFrameClientTest
    : public FrameFetchContextTest {};

class FrameFetchContextModifyRequestTest : public FrameFetchContextTest {};

TEST_F(FrameFetchContextModifyRequestTest, UpgradeInsecureResourceRequests) {}

TEST_F(FrameFetchContextModifyRequestTest,
       DoNotUpgradeInsecureResourceRequests) {}

TEST_F(FrameFetchContextModifyRequestTest, IsAutomaticUpgradeSet) {}

TEST_F(FrameFetchContextModifyRequestTest, IsAutomaticUpgradeNotSet) {}

TEST_F(FrameFetchContextModifyRequestTest, SendUpgradeInsecureRequestHeader) {}

class FrameFetchContextHintsTest : public FrameFetchContextTest,
                                   public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();
// Verify that the client hints should be attached for subresources fetched
// over secure transport. Tests when the persistent client hint feature is
// enabled.
TEST_P(FrameFetchContextHintsTest, MonitorDeviceMemorySecureTransport) {}

// Verify that client hints are not attached when the resources do not belong to
// a secure context.
TEST_P(FrameFetchContextHintsTest, MonitorDeviceMemoryHintsInsecureContext) {}

// Verify that client hints are attched when the resources belong to a local
// context.
TEST_P(FrameFetchContextHintsTest, MonitorDeviceMemoryHintsLocalContext) {}

TEST_P(FrameFetchContextHintsTest, MonitorDeviceMemoryHints) {}

TEST_P(FrameFetchContextHintsTest, MonitorDPRHints) {}

TEST_P(FrameFetchContextHintsTest, MonitorDPRHintsInsecureTransport) {}

TEST_P(FrameFetchContextHintsTest, MonitorResourceWidthHints) {}

TEST_P(FrameFetchContextHintsTest, MonitorViewportWidthHints) {}

TEST_P(FrameFetchContextHintsTest, MonitorUAHints) {}

TEST_P(FrameFetchContextHintsTest, MonitorPrefersColorSchemeHint) {}

TEST_P(FrameFetchContextHintsTest, MonitorPrefersReducedMotionHint) {}

TEST_P(FrameFetchContextHintsTest, MonitorPrefersReducedTransparencyHint) {}

TEST_P(FrameFetchContextHintsTest, MonitorAllHints) {}

// Verify that the client hints should be attached for third-party subresources
// fetched over secure transport, when specifically allowed by permissions
// policy.
TEST_P(FrameFetchContextHintsTest, MonitorAllHintsPermissionsPolicy) {}

// Verify that only the specifically allowed client hints are attached for
// third-party subresources fetched over secure transport.
TEST_P(FrameFetchContextHintsTest, MonitorSomeHintsPermissionsPolicy) {}

// Verify that the client hints are not attached for third-party subresources
// fetched over insecure transport, even when specifically allowed by
// permissions policy.
TEST_P(FrameFetchContextHintsTest,
       MonitorHintsPermissionsPolicyInsecureContext) {}

TEST_F(FrameFetchContextTest, SubResourceCachePolicy) {}

// Tests if "Save-Data" header is correctly added on the first load and reload.
TEST_P(FrameFetchContextHintsTest, EnableDataSaver) {}

// Tests if "Save-Data" header is not added when the data saver is disabled.
TEST_P(FrameFetchContextHintsTest, DisabledDataSaver) {}

// Tests if reload variants can reflect the current data saver setting.
TEST_P(FrameFetchContextHintsTest, ChangeDataSaverConfig) {}

TEST_F(FrameFetchContextSubresourceFilterTest, Filter) {}

TEST_F(FrameFetchContextSubresourceFilterTest, Allow) {}

TEST_F(FrameFetchContextSubresourceFilterTest, DuringOnFreeze) {}

TEST_F(FrameFetchContextSubresourceFilterTest, WouldDisallow) {}

TEST_F(FrameFetchContextTest, AddAdditionalRequestHeadersWhenDetached) {}

TEST_F(FrameFetchContextTest, ResourceRequestCachePolicyWhenDetached) {}

TEST_F(FrameFetchContextMockedLocalFrameClientTest,
       PrepareRequestWhenDetached) {}

TEST_F(FrameFetchContextTest, PrepareRequestHistogramCount) {}

TEST_F(FrameFetchContextTest, AddResourceTimingWhenDetached) {}

TEST_F(FrameFetchContextTest, AllowImageWhenDetached) {}

TEST_F(FrameFetchContextTest, PopulateResourceRequestWhenDetached) {}

TEST_F(FrameFetchContextTest, SetFirstPartyCookieWhenDetached) {}

TEST_F(FrameFetchContextTest, TopFrameOrigin) {}

TEST_F(FrameFetchContextTest, TopFrameOriginDetached) {}

// Tests that CanRequestCanRequestBasedOnSubresourceFilterOnly will block ads
// or not correctly, depending on the FilterPolicy.
TEST_F(FrameFetchContextSubresourceFilterTest,
       CanRequestBasedOnSubresourceFilterOnly) {}

// Tests that CalculateIfAdSubresource with an alias URL will tag ads
// correctly according to the SubresourceFilter mode.
TEST_F(FrameFetchContextSubresourceFilterTest,
       CalculateIfAdSubresourceWithAliasURL) {}

class FrameFetchContextDisableReduceAcceptLanguageTest
    : public FrameFetchContextTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(FrameFetchContextDisableReduceAcceptLanguageTest,
       VerifyReduceAcceptLanguage) {}

}  // namespace blink