chromium/content/browser/back_forward_cache_network_request_browsertest.cc

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

#include "build/build_config.h"
#include "content/browser/back_forward_cache_browsertest.h"

#include "base/task/single_thread_task_runner.h"
#include "content/browser/renderer_host/navigation_request.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "third_party/blink/public/common/features.h"

// This file contains back-/forward-cache tests for fetching from the network.
// It was forked from
// https://source.chromium.org/chromium/chromium/src/+/main:content/browser/back_forward_cache_browsertest.cc;drc=748acc7b301b489567691500c558c5fde8cfd538
//
// When adding tests please also add WPTs. See
// third_party/blink/web_tests/external/wpt/html/browsers/browsing-the-web/back-forward-cache/README.md

namespace content {

NotRestoredReason;

// When loading task is unfreezable with the feature flag
// kLoadingTaskUnfreezable, a page will keep processing the in-flight network
// requests while the page is frozen in BackForwardCache.
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, FetchWhileStoring) {}

// Eviction is triggered when a normal fetch request gets redirected while the
// page is in back-forward cache.
// TODO(crbug.com/40937269): Disabled due to flakiness.
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest,
                       DISABLED_FetchRedirectedWhileStoring) {}

// Eviction is triggered when a keepalive fetch request gets redirected while
// the page is in back-forward cache.
// TODO(crbug.com/40724916): We should not trigger eviction on redirects
// of keepalive fetches.
// TODO(crbug.com/40874525): Disabled for flakiness.
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest,
                       DISABLED_KeepAliveFetchRedirectedWhileStoring) {}

class BackForwardCacheDrainedAsBytesConsumerTest
    : public BackForwardCacheBrowserTest,
      public testing::WithParamInterface<bool> {};

// Tests the case when the header was received before the page is frozen,
// but parts of the response body is received when the page is frozen.
IN_PROC_BROWSER_TEST_F(
    BackForwardCacheDrainedAsBytesConsumerTest,
    PageWithDrainedDatapipeRequestsForFetchShouldBeEvictedOrNot) {}

// If too much data is processed while in bfcache, evict the entry.
// TODO(crbug.com/325558875): Flaky on Mac and ChromeOS bots.
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_PageWithDrainedDatapipeAsBytesConsumerCannotProcessTooMuchData
#else
#define MAYBE_PageWithDrainedDatapipeAsBytesConsumerCannotProcessTooMuchData
#endif
IN_PROC_BROWSER_TEST_F(
    BackForwardCacheDrainedAsBytesConsumerTest,
    MAYBE_PageWithDrainedDatapipeAsBytesConsumerCannotProcessTooMuchData) {}

IN_PROC_BROWSER_TEST_F(
    BackForwardCacheBrowserTest,
    PageWithDrainedDatapipeRequestsForScriptStreamerShouldNotBeEvicted) {}

enum class BackgroundResourceFetchTestCase {};

class BackForwardCacheNetworkLimitBrowserTest
    : public BackForwardCacheBrowserTest,
      public testing::WithParamInterface<BackgroundResourceFetchTestCase> {};

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(
    BackForwardCacheNetworkLimitBrowserTest,
    PageWithDrainedDatapipeRequestsForScriptStreamerShouldBeEvictedIfStreamedTooMuch) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheNetworkLimitBrowserTest,
                       ImageStillLoading_ResponseStartedWhileFrozen) {}

IN_PROC_BROWSER_TEST_P(
    BackForwardCacheNetworkLimitBrowserTest,
    ImageStillLoading_ResponseStartedWhileRestoring_DoNotTriggerEviction) {}

#if BUILDFLAG(IS_MAC)
#define MAYBE_ImageStillLoading_ResponseStartedWhileFrozen_ExceedsPerProcessBytesLimit
#else
#define MAYBE_ImageStillLoading_ResponseStartedWhileFrozen_ExceedsPerProcessBytesLimit
#endif
IN_PROC_BROWSER_TEST_P(
    BackForwardCacheNetworkLimitBrowserTest,
    MAYBE_ImageStillLoading_ResponseStartedWhileFrozen_ExceedsPerProcessBytesLimit) {}

#if BUILDFLAG(IS_MAC)
#define MAYBE_ImageStillLoading_ResponseStartedWhileFrozen_ExceedsPerProcessBytesLimit_SameSiteSubframe
#else
#define MAYBE_ImageStillLoading_ResponseStartedWhileFrozen_ExceedsPerProcessBytesLimit_SameSiteSubframe
#endif
IN_PROC_BROWSER_TEST_P(
    BackForwardCacheNetworkLimitBrowserTest,
    MAYBE_ImageStillLoading_ResponseStartedWhileFrozen_ExceedsPerProcessBytesLimit_SameSiteSubframe) {}

IN_PROC_BROWSER_TEST_P(
    BackForwardCacheNetworkLimitBrowserTest,
    ImageStillLoading_ResponseStartedWhileFrozen_ExceedsPerProcessBytesLimit_ResetOnRestore) {}

IN_PROC_BROWSER_TEST_P(
    BackForwardCacheNetworkLimitBrowserTest,
    ImageStillLoading_ResponseStartedWhileFrozen_ExceedsPerProcessBytesLimit_ResetOnDetach) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheNetworkLimitBrowserTest,
                       ImageStillLoading_ResponseStartedWhileFrozen_Timeout) {}

#if BUILDFLAG(IS_MAC)
#define MAYBE_ImageStillLoading_ResponseStartedBeforeFreezing_ExceedsPerProcessBytesLimit
#else
#define MAYBE_ImageStillLoading_ResponseStartedBeforeFreezing_ExceedsPerProcessBytesLimit
#endif
IN_PROC_BROWSER_TEST_P(
    BackForwardCacheNetworkLimitBrowserTest,
    MAYBE_ImageStillLoading_ResponseStartedBeforeFreezing_ExceedsPerProcessBytesLimit) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheNetworkLimitBrowserTest,
                       TimeoutNotTriggeredAfterDone) {}

IN_PROC_BROWSER_TEST_P(
    BackForwardCacheNetworkLimitBrowserTest,
    TimeoutNotTriggeredAfterDone_ResponseStartedBeforeFreezing) {}

IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest,
                       ImageStillLoading_ResponseStartedBeforeFreezing) {}

class BackForwardCacheBrowserTestWithDisallowJavaScriptExecution
    : public BackForwardCacheBrowserTest {};

IN_PROC_BROWSER_TEST_F(
    BackForwardCacheBrowserTestWithDisallowJavaScriptExecution,
    EvictWillNotTriggerReadystatechange) {}

class BackForwardCacheWithKeepaliveSupportBrowserTest
    : public BackForwardCacheBrowserTest {};

// With the feature, keepalive doesn't prevent the page from entering into the
// bfcache.
IN_PROC_BROWSER_TEST_F(BackForwardCacheWithKeepaliveSupportBrowserTest,
                       KeepAliveFetch) {}

}  // namespace content