chromium/content/browser/renderer_host/back_forward_cache_subframe_navigation_throttle_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 "content/browser/renderer_host/back_forward_cache_subframe_navigation_throttle.h"

#include "base/test/bind.h"
#include "content/public/test/test_navigation_throttle.h"
#include "content/test/navigation_simulator_impl.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {
namespace {

IsNull;
NotNull;

}  // namespace

class BackForwardCacheSubframeNavigationThrottleTestBase
    : public RenderViewHostImplTestHarness,
      public WebContentsObserver {};

// A test suite to cover BFCaching a page with subframe navigation without
// URLLoader.
// See also "1. No-URL loader navigations" from the doc below for more details
// https://docs.google.com/document/d/1XLOQuHjCVmBfXAJhgrASkVyrHAK_DGmcYPyrTnOrSPM/edit?resourcekey=0-uNz75Ux7INdCLhj2FWVILg&tab=t.0#heading=h.uagir4pgy4kp
class BackForwardCacheSubframeNavigationThrottleWithoutUrlLoaderTest
    : public BackForwardCacheSubframeNavigationThrottleTestBase {};

TEST_F(BackForwardCacheSubframeNavigationThrottleWithoutUrlLoaderTest,
       CreateThrottleForSubframe) {}

TEST_F(BackForwardCacheSubframeNavigationThrottleWithoutUrlLoaderTest,
       DoesNotCreateThrottleForMainFrame) {}

TEST_F(BackForwardCacheSubframeNavigationThrottleWithoutUrlLoaderTest,
       DeferIfInBackForwardCache) {}

TEST_F(BackForwardCacheSubframeNavigationThrottleWithoutUrlLoaderTest,
       DoesNotDeferIfNotInBackForwardCache) {}

TEST_F(BackForwardCacheSubframeNavigationThrottleWithoutUrlLoaderTest,
       ResumeNavigationWhenNavigatedBackIfSubframeNavigationWasDeferred) {}

TEST_F(
    BackForwardCacheSubframeNavigationThrottleWithoutUrlLoaderTest,
    DoesNotResumeNavigationWhenNavigatedBackIfSubframeNavigationWasNotDeferred) {}

// A test suite to cover BFCaching a page with subframe navigation involving
// URLLoader.
// See also "2. URL loader navigations" from the doc below for more details
// https://docs.google.com/document/d/1XLOQuHjCVmBfXAJhgrASkVyrHAK_DGmcYPyrTnOrSPM/edit?resourcekey=0-uNz75Ux7INdCLhj2FWVILg&tab=t.0#heading=h.uagir4pgy4kp
class BackForwardCacheSubframeNavigationThrottleTest
    : public BackForwardCacheSubframeNavigationThrottleTestBase {};

// Tests a subframe navigation with URL loader will be deferred by
// `BackForwardCacheSubframeNavigationThrottle::WillStartRequest()` if the
// subframe's lifecycle state is `kInBackForwardCache`.
TEST_F(BackForwardCacheSubframeNavigationThrottleTest,
       DeferInWillStartRequestIfInBFCache) {}

// Tests a subframe navigation with URL loader will not be deferred by
// `BackForwardCacheSubframeNavigationThrottle::WillStartRequest()` if the
// subframe's lifecycle state is not `kInBackForwardCache`.
TEST_F(BackForwardCacheSubframeNavigationThrottleTest,
       DoesNotDeferInWillStartRequestIfNotInBFCache) {}

// Tests a subframe navigation with URL loader will not be deferred by
// `BackForwardCacheSubframeNavigationThrottle::WillProcessResponse()` if the
// subframe's lifecycle state is not `kInBackForwardCache`.
// Note that it is not allowed to call WillProcessResponse() along with the
// `kInBackForwardCache` state.
TEST_F(BackForwardCacheSubframeNavigationThrottleTest,
       DoesNotDeferInWillProcessResponseIfNotInBFCache) {}

// Tests a subframe navigation with URL loader will not be deferred by
// `BackForwardCacheSubframeNavigationThrottle::WillRedirectRequest()` if the
// subframe's lifecycle state is not `kInBackForwardCache`.
// Note that it is not allowed to call WillRedirectRequest() along with the
// `kInBackForwardCache` state.
TEST_F(BackForwardCacheSubframeNavigationThrottleTest,
       DoesNotDeferInWillRedirectRequestIfNotInBFCache) {}

// Tests a subframe navigation with URL loader will not be deferred by
// `BackForwardCacheSubframeNavigationThrottle::WillFailRequest()` if the
// subframe's lifecycle state is not `kInBackForwardCache`.
// Note that it is not allowed to call WillFailRequest() along with the
// `kInBackForwardCache` state.
TEST_F(BackForwardCacheSubframeNavigationThrottleTest,
       DoesNotDeferInWillFailRequestIfNotInBFCache) {}

// A test suite to cover back navigation to a BFCached page with subframe
// navigation involving URLLoader.
class BackForwardCacheSubframeNavigationThrottleAndNavigateBackTest
    : public BackForwardCacheSubframeNavigationThrottleTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(BackForwardCacheSubframeNavigationThrottleAndNavigateBackTest,
       NavigateBackToBFCachedPage) {}

}  // namespace content