chromium/content/browser/network/split_cache_browsertest.cc

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

#include <atomic>

#include "base/path_service.h"
#include "base/strings/pattern.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "content/browser/renderer_host/back_forward_cache_disable.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/renderer.mojom.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_paths.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/resource_load_observer.h"
#include "content/shell/browser/shell.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "net/base/features.h"
#include "net/base/network_isolation_key.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/scoped_mutually_exclusive_feature_list.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/frame/fullscreen.mojom.h"
#include "url/gurl.h"

namespace content {
namespace {

class SplitCacheContentBrowserTest : public ContentBrowserTest {};

enum class SplitCacheTestCase {};

const struct {} kTestCaseToFeatureMapping[] =;

class SplitCacheContentBrowserTestEnabled
    : public SplitCacheContentBrowserTest,
      public testing::WithParamInterface<SplitCacheTestCase> {};

INSTANTIATE_TEST_SUITE_P();

class SplitCacheContentBrowserTestPlzDedicatedWorker
    : public SplitCacheContentBrowserTest,
      public ::testing::WithParamInterface<bool> {};

class SplitCacheContentBrowserTestDisabled
    : public SplitCacheContentBrowserTest {};

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled, MainFrame) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled, MainFrameRedirect) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled, Subframe) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled, MainFrameDataUrl) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled,
                       MainFrameAboutBlank) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled, SubFrameRedirect) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled, SubFrameDataUrl) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled,
                       SubframeAboutBlank) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled, Popup) {}

IN_PROC_BROWSER_TEST_F(SplitCacheContentBrowserTestDisabled, NonSplitCache) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled,
                       NavigationResources) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled,
                       SubframeNavigationResources) {}

// Tests that when a subresource URL which is same-site to the fetching frame
// is later used to create a subframe from the same top-level site, it should
// not be a cache hit (crbug.com/1135149).
IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled,
                       SubframeNavigationResource) {}

// Tests that a cross-site navigation to a document that was previously loaded
// via top-level navigation doesn't use the cache, since doing so could enable
// cross-site leaks.
IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled,
                       CrossSiteNavigation) {}

// Tests that a cross-origin but same-site navigation to a document that was
// previously loaded via top-level navigation uses the cache.
IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled,
                       CrossOriginSameSiteNavigation) {}

// This class invokes ComputeHttpCacheSize on the Network Context and
// waits for the callback to be invoked.
class SplitCacheComputeHttpCacheSize {};

// Tests that NotifyExternalCacheHit() has the correct value of
// is_subframe_document_resource by checking that the size of the http cache
// resources accessed after the resource is loaded from the blink cache is the
// same as before that.
// TODO(crbug.com/40164302): Test is flaky on Win.
#if BUILDFLAG(IS_WIN)
#define MAYBE_NotifyExternalCacheHitCheckSubframeBit
#else
#define MAYBE_NotifyExternalCacheHitCheckSubframeBit
#endif
IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestEnabled,
                       MAYBE_NotifyExternalCacheHitCheckSubframeBit) {}

IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestPlzDedicatedWorker,
                       DedicatedWorkers) {}

// https://crbug.com/1218723 started flaking after Field Trial Testing Config
// was enabled for content_browsertests.
IN_PROC_BROWSER_TEST_P(SplitCacheContentBrowserTestPlzDedicatedWorker,
                       DISABLED_DedicatedWorkersScripts) {}

IN_PROC_BROWSER_TEST_F(SplitCacheContentBrowserTestDisabled, DedicatedWorkers) {}

INSTANTIATE_TEST_SUITE_P();

class ScopeBlinkMemoryCachePerContext : public SplitCacheContentBrowserTest {};

// TODO(crbug.com/40892607): Flaky on multiple platforms.
IN_PROC_BROWSER_TEST_F(ScopeBlinkMemoryCachePerContext, DISABLED_CheckFeature) {}

class SplitCacheByIncludeCredentialsTest : public ContentBrowserTest {};

// Note: Compared to .DifferentProcess and .DifferentProcessVariant, this test
// emits requests from the same renderer process. This is useful for checking
// the behavior of blink's memory cache instead of the HTTP cache.
IN_PROC_BROWSER_TEST_F(SplitCacheByIncludeCredentialsTest, SameProcess) {}

IN_PROC_BROWSER_TEST_F(SplitCacheByIncludeCredentialsTest, SameProcessVariant) {}

// Note: Compared to .SameProcess and .SameProcessVariant, this test emits
// requests from two different renderer process. This is useful for checking the
// behavior of the HTTP cache instead of blink's memory cache.
//
// COOP+COEP are used to get two same-origin documents loaded from different
// renderer process. This avoids interferences from
// SplitCacheByNetworkIsolationKey.
IN_PROC_BROWSER_TEST_F(SplitCacheByIncludeCredentialsTest, DifferentProcess) {}

IN_PROC_BROWSER_TEST_F(SplitCacheByIncludeCredentialsTest,
                       DifferentProcessVariant) {}

}  // namespace
}  // namespace content