chromium/content/browser/service_worker/service_worker_browsertest.cc

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

#include <stddef.h>
#include <stdint.h>

#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/statistics_recorder.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/with_feature_override.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/services/storage/public/mojom/cache_storage_control.mojom.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/process_lock.h"
#include "content/browser/renderer_host/code_cache_host_impl.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/service_worker/service_worker_client.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_core_observer.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_controllee_request_handler.h"
#include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/browser/service_worker/service_worker_test_utils.h"
#include "content/browser/service_worker/service_worker_version.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/browser/web_package/signed_exchange_consts.h"
#include "content/common/content_constants_internal.h"
#include "content/common/features.h"
#include "content/common/service_worker/race_network_request_write_buffer_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/console_message.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/cors_origin_pattern_setter.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/service_worker_context_observer.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/back_forward_cache_util.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_content_browser_client.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/mock_client_hints_controller_delegate.h"
#include "content/public/test/navigation_handle_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "media/media_buildflags.h"
#include "net/base/test_completion_callback.h"
#include "net/cert/cert_status_flags.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_status_code.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 "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "services/network/public/mojom/service_worker_router_info.mojom-shared.h"
#include "storage/browser/blob/blob_handle.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/mojom/loader/code_cache.mojom-test-utils.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration_options.mojom.h"
#include "third_party/re2/src/re2/re2.h"

CacheStorageError;

namespace content {

namespace {
MainResourceLoadCompletedUkmEntry;

// V8ScriptRunner::setCacheTimeStamp() stores 16 byte data (marker + tag +
// timestamp).
const int kV8CacheTimeStampDataSize =;

void ExpectRegisterResultAndRun(blink::ServiceWorkerStatusCode expected,
                                base::RepeatingClosure continuation,
                                blink::ServiceWorkerStatusCode actual) {}

void ExpectUnregisterResultAndRun(
    blink::ServiceWorkerStatusCode expected_status,
    base::RepeatingClosure continuation,
    blink::ServiceWorkerStatusCode actual_status) {}

class WorkerStateObserver : public ServiceWorkerContextCoreObserver {};

class WorkerClientDestroyedObserver : public ServiceWorkerContextCoreObserver {};

std::unique_ptr<net::test_server::HttpResponse> VerifySaveDataHeaderInRequest(
    const net::test_server::HttpRequest& request) {}

std::unique_ptr<net::test_server::HttpResponse>
VerifySaveDataNotInAccessControlRequestHeader(
    const net::test_server::HttpRequest& request) {}

void CountScriptResources(ServiceWorkerContextWrapper* wrapper,
                          const GURL& scope,
                          int* num_resources) {}

void StoreString(std::string* result,
                 base::OnceClosure callback,
                 base::Value value) {}

int GetInt(const base::Value::Dict& dict, std::string_view key) {}

std::string GetString(const base::Value::Dict& dict, std::string_view key) {}

bool GetBoolean(const base::Value::Dict& dict, std::string_view key) {}

bool CheckHeader(const base::Value::Dict& dict,
                 std::string_view header_name,
                 std::string_view header_value) {}

bool HasHeader(const base::Value::Dict& dict, std::string_view header_name) {}

const char kNavigationPreloadNetworkError[] =;

void CheckPageIsMarkedSecure(
    Shell* shell,
    scoped_refptr<net::X509Certificate> expected_certificate) {}

}  // namespace

class ServiceWorkerBrowserTest : public ContentBrowserTest {};

class MockContentBrowserClient : public ContentBrowserTestContentBrowserClient {};

// An observer that waits for the service worker to be running.
class WorkerRunningStatusObserver : public ServiceWorkerContextObserver {};

// Tests the |top_frame_origin| and |request_initiator| on the main resource and
// subresource requests from service workers, in order to ensure proper handling
// by the SplitCache. See https://crbug.com/918868.
IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, RequestOrigin) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, FetchPageWithSaveData) {}

// Tests that when data saver is enabled and a cross-origin fetch by a webpage
// is intercepted by a serviceworker, and the serviceworker does a fetch, the
// preflight request does not have save-data in Access-Control-Request-Headers.
IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, CrossOriginFetchWithSaveData) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest,
                       FetchPageWithSaveDataPassThroughOnFetch) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, Reload) {}

// Test when the renderer requests termination because the service worker is
// idle, and the browser ignores the request because DevTools is attached. The
// renderer should continue processing events on the service worker instead of
// waiting for termination or an event from the browser. Regression test for
// https://crbug.com/878667.
IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, IdleTimerWithDevTools) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest,
                       ResponseFromHTTPSServiceWorkerIsMarkedAsSecure) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest,
                       ResponseFromHTTPServiceWorkerIsNotMarkedAsSecure) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, ImportsBustMemcache) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, GetRunningServiceWorkerInfos) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, StartWorkerWhileInstalling) {}

#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
// http://crbug.com/1347684
#define MAYBE_DispatchFetchEventToStoppedWorkerSynchronously
#else
#define MAYBE_DispatchFetchEventToStoppedWorkerSynchronously
#endif
// Make sure that a fetch event is dispatched to a stopped worker in the task
// which calls ServiceWorkerFetchDispatcher::Run().
IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest,
                       MAYBE_DispatchFetchEventToStoppedWorkerSynchronously) {}

// Check if a fetch event can be failed without crashing if starting a service
// worker fails. This is a regression test for https://crbug.com/1106977.
IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest,
                       DispatchFetchEventToBrokenWorker) {}

class UserAgentServiceWorkerBrowserTest : public ServiceWorkerBrowserTest {};

IN_PROC_BROWSER_TEST_F(UserAgentServiceWorkerBrowserTest, NavigatorUserAgent) {}

// Regression test for https://crbug.com/1077916.
// Update the service worker by registering a worker with different script url.
// This test makes sure the worker can handle the fetch event using CacheStorage
// API.
// TODO(crbug.com/40695132): flaky on all platforms.
IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest,
                       DISABLED_UpdateOnScriptUrlChange) {}

// TODO(crbug.com/40514526): ServiceWorkerNavigationPreloadTest should be
// converted to WPT.
class ServiceWorkerNavigationPreloadTest : public ServiceWorkerBrowserTest {};

const std::string
    ServiceWorkerNavigationPreloadTest::kNavigationPreloadHeaderName(
        "Service-Worker-Navigation-Preload");

const std::string
    ServiceWorkerNavigationPreloadTest::kEnableNavigationPreloadScript(
        "self.addEventListener('activate', event => {\n"
        "    event.waitUntil(self.registration.navigationPreload.enable());\n"
        "  });\n");

const std::string
    ServiceWorkerNavigationPreloadTest::kPreloadResponseTestScript =;

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest, NetworkFallback) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest, SetHeaderValue) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       RespondWithNavigationPreload) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest, GetResponseText) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       GetLargeResponseText) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       GetLargeResponseCloneText) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       GetLargeResponseReadableStream) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest, NetworkError) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       PreloadHeadersSimple) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest, NotEnabled) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       PreloadHeadersCustom) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       InvalidRedirect_MultiLocation) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       InvalidRedirect_InvalidLocation) {}

// Tests responding with the navigation preload response when the navigation
// occurred after a redirect.
IN_PROC_BROWSER_TEST_F(ServiceWorkerNavigationPreloadTest,
                       RedirectAndRespondWithNavigationPreload) {}

static int CountRenderProcessHosts() {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, Registration) {}

enum class ServiceWorkerScriptImportType {};

struct ServiceWorkerScriptChecksumInfo {};

class ServiceWorkerSha256ScriptChecksumBrowserTest
    : public ServiceWorkerBrowserTest,
      public testing::WithParamInterface<
          std::tuple<ServiceWorkerScriptImportType, bool, bool>> {};

IN_PROC_BROWSER_TEST_P(ServiceWorkerSha256ScriptChecksumBrowserTest,
                       Sha256ScriptChecksum) {}

INSTANTIATE_TEST_SUITE_P();

class CacheStorageSideDataSizeChecker
    : public base::RefCounted<CacheStorageSideDataSizeChecker> {};

class ServiceWorkerV8CodeCacheForCacheStorageTest
    : public ServiceWorkerBrowserTest {};

const char ServiceWorkerV8CodeCacheForCacheStorageTest::kPageUrl[] =;
const char ServiceWorkerV8CodeCacheForCacheStorageTest::kWorkerUrl[] =;
const char ServiceWorkerV8CodeCacheForCacheStorageTest::kScriptUrl[] =;

IN_PROC_BROWSER_TEST_F(ServiceWorkerV8CodeCacheForCacheStorageTest,
                       V8CacheOnCacheStorage) {}

class ServiceWorkerV8CodeCacheForCacheStorageNoneTest
    : public ServiceWorkerV8CodeCacheForCacheStorageTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerV8CodeCacheForCacheStorageNoneTest,
                       V8CacheOnCacheStorage) {}

namespace {

class CacheStorageControlForBadOrigin
    : public storage::mojom::CacheStorageControl {};

}  // namespace

class ServiceWorkerCacheStorageFullCodeCacheFromInstallEventTest
    : public ServiceWorkerV8CodeCacheForCacheStorageTest {};

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerCacheStorageFullCodeCacheFromInstallEventTest,
    FullCodeCacheGenerated) {}

class ServiceWorkerCacheStorageFullCodeCacheFromInstallEventDisabledByHintTest
    : public ServiceWorkerV8CodeCacheForCacheStorageTest {};

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerCacheStorageFullCodeCacheFromInstallEventDisabledByHintTest,
    FullCodeCacheNotGenerated) {}

class ServiceWorkerCacheStorageFullCodeCacheFromInstallEventOpaqueResponseTest
    : public ServiceWorkerV8CodeCacheForCacheStorageTest {};

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerCacheStorageFullCodeCacheFromInstallEventOpaqueResponseTest,
    FullCodeCacheGenerated) {}

// ServiceWorkerDisableWebSecurityTests check the behavior when the web security
// is disabled. If '--disable-web-security' flag is set, we don't check the
// origin equality in Blink. So the Service Worker related APIs should succeed
// even if it is thouching other origin Service Workers.
class ServiceWorkerDisableWebSecurityTest : public ServiceWorkerBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerDisableWebSecurityTest,
                       GetRegistrationNoCrash) {}

#if BUILDFLAG(IS_ANDROID)
// Flaky on Android, http://crbug.com/1141870.
#define MAYBE_RegisterNoCrash
#else
#define MAYBE_RegisterNoCrash
#endif
IN_PROC_BROWSER_TEST_F(ServiceWorkerDisableWebSecurityTest,
                       MAYBE_RegisterNoCrash) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerDisableWebSecurityTest, UnregisterNoCrash) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerDisableWebSecurityTest, UpdateNoCrash) {}

class HeaderInjectingThrottle : public blink::URLLoaderThrottle {};

class ThrottlingContentBrowserClient
    : public ContentBrowserTestContentBrowserClient {};

class ServiceWorkerURLLoaderThrottleTest : public ServiceWorkerBrowserTest {};

// Test that the throttles can inject headers during navigation that are
// observable inside the service worker's fetch event.
IN_PROC_BROWSER_TEST_F(ServiceWorkerURLLoaderThrottleTest,
                       FetchEventForNavigationHasThrottledRequest) {}

// Test that redirects by throttles occur before service worker interception.
IN_PROC_BROWSER_TEST_F(ServiceWorkerURLLoaderThrottleTest,
                       RedirectOccursBeforeFetchEvent) {}

// Test that the headers injected by throttles during navigation are
// present in the network request in the case of network fallback.
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerURLLoaderThrottleTest,
    NavigationHasThrottledRequestHeadersAfterNetworkFallback) {}

// Test that the headers injected by throttles during navigation are
// present in the navigation preload request.
IN_PROC_BROWSER_TEST_F(ServiceWorkerURLLoaderThrottleTest,
                       NavigationPreloadHasThrottledRequestHeaders) {}

// Test fixture to support validating throttling from within an installing
// service worker.
class ServiceWorkerThrottlingTest : public ServiceWorkerBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerThrottlingTest, ThrottleInstalling) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerThrottlingTest,
                       ThrottleInstallingWithCacheAddAll) {}

// The following tests verify that different values of cross-origin isolation
// enforce the expected process assignments. The page starting the ServiceWorker
// can have COOP+COEP, making it cross-origin isolated, and the ServiceWorker
// itself can have COEP on its main script making it cross-origin isolated. If
// cross-origin isolation status of the page and the script are different, the
// ServiceWorker should be put out of process. It should be put in process
// otherwise.
class ServiceWorkerCrossOriginIsolatedBrowserTest
    : public ServiceWorkerBrowserTest,
      public testing::WithParamInterface<std::tuple<bool, bool>> {};

IN_PROC_BROWSER_TEST_P(ServiceWorkerCrossOriginIsolatedBrowserTest,
                       FreshInstall) {}

#if BUILDFLAG(IS_ANDROID)
// Flaky on Android, http://crbug.com/1335344.
#define MAYBE_PostInstallRun
#else
#define MAYBE_PostInstallRun
#endif
IN_PROC_BROWSER_TEST_P(ServiceWorkerCrossOriginIsolatedBrowserTest,
                       MAYBE_PostInstallRun) {}

// The following tests verify that the page starting the Serviceworker is always
// in the same process as the worker, even when it sets COOP.
class ServiceWorkerCoopBrowserTest : public ServiceWorkerBrowserTest,
                                     public testing::WithParamInterface<bool> {};

IN_PROC_BROWSER_TEST_P(ServiceWorkerCoopBrowserTest, FreshInstall) {}

// Sometimes disabled via the macros above
// ServiceWorkerCrossOriginIsolatedBrowserTest.PostInstallRun, as the tests
// flake for the same root cause.
IN_PROC_BROWSER_TEST_P(ServiceWorkerCoopBrowserTest, MAYBE_PostInstallRun) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

// Tests with BackForwardCache enabled.
class ServiceWorkerBackForwardCacheAndKeepActiveFreezingBrowserTest
    : public ServiceWorkerBrowserTest {};

// Tests that a service worker that shares a renderer process with a
// back-forward cached page and an active page still runs normally.
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerBackForwardCacheAndKeepActiveFreezingBrowserTest,
    ShareProcessWithBackForwardCachedPageAndLivePage) {}

// Tests that a service worker that shares a renderer process with a
// back-forward cached page and no active pages still runs normally.
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerBackForwardCacheAndKeepActiveFreezingBrowserTest,
    ShareProcessWithBackForwardCachedPageOnly) {}

// Tests with BackForwardCache enabled.
class ServiceWorkerBackForwardCacheBrowserTest
    : public ServiceWorkerBrowserTest {};

// Fails on Android. https://crbug.com/1216619
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_EvictionOfBackForwardCacheWithMultipleServiceWorkers
#else
#define MAYBE_EvictionOfBackForwardCacheWithMultipleServiceWorkers
#endif

// Regression test for https://crbug.com/1212618.
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerBackForwardCacheBrowserTest,
    MAYBE_EvictionOfBackForwardCacheWithMultipleServiceWorkers) {}

class ServiceWorkerFencedFrameBrowserTest : public ServiceWorkerBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerFencedFrameBrowserTest,
                       AncestorFrameTypeIsStoredInServiceWorker) {}

class ServiceWorkerFencedFrameProcessAllocationBrowserTest
    : public ServiceWorkerFencedFrameBrowserTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(ServiceWorkerFencedFrameProcessAllocationBrowserTest,
                       ServiceWorkerIsInFencedFrameProcess) {}

class ServiceWorkerBrowserTestWithStoragePartitioning
    : public base::test::WithFeatureOverride,
      public ServiceWorkerBrowserTest {};

INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();

// http://crbug.com/1385779
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID)
#define MAYBE_StorageKeyWithHostPermissionsWithDedicatedWorkers
#else
#define MAYBE_StorageKeyWithHostPermissionsWithDedicatedWorkers
#endif
IN_PROC_BROWSER_TEST_P(
    ServiceWorkerBrowserTestWithStoragePartitioning,
    MAYBE_StorageKeyWithHostPermissionsWithDedicatedWorkers) {}

// Android does not have Shared Workers, so skip the shared worker test.
#if !BUILDFLAG(IS_ANDROID)
// http://crbug.com/1385779
#if BUILDFLAG(IS_MAC)
#define MAYBE_StorageKeyWithHostPermissionsWithSharedWorkers
#else
#define MAYBE_StorageKeyWithHostPermissionsWithSharedWorkers
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(ServiceWorkerBrowserTestWithStoragePartitioning,
                       MAYBE_StorageKeyWithHostPermissionsWithSharedWorkers) {}
#endif  // !BUILDFLAG(IS_ANDROID)

enum class SpeculativeStartupNavigationType {};

// This is a test class to verify an optimization to speculatively start a
// service worker for navigation before the "beforeunload" event.
class ServiceWorkerSpeculativeStartupBrowserTest
    : public ServiceWorkerBrowserTest,
      public testing::WithParamInterface<SpeculativeStartupNavigationType> {};

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(ServiceWorkerSpeculativeStartupBrowserTest,
                       NavigationWillBeCanceledByBeforeUnload) {}

class ServiceWorkerSpeculativeStartupWithoutParamBrowserTest
    : public ServiceWorkerBrowserTest {};

// Regression test for https://crbug.com/1440062.
IN_PROC_BROWSER_TEST_F(ServiceWorkerSpeculativeStartupWithoutParamBrowserTest,
                       NavigatingToAboutSrcdocDoesNotCrash) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, WarmUpAndStartServiceWorker) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, WarmUpWorkerAndTimeout) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, WarmUpWorkerTwice) {}

// This is a test class to verify an optimization to speculatively
// warm-up a service worker.
class ServiceWorkerWarmUpBrowserTestBase : public ServiceWorkerBrowserTest {};

class ServiceWorkerWarmUpOnIdleTimeoutBrowserTest
    : public ServiceWorkerWarmUpBrowserTestBase {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerWarmUpOnIdleTimeoutBrowserTest,
                       DoNotWarmUpOnStopWithoutIdleTimeout) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerWarmUpOnIdleTimeoutBrowserTest,
                       WarmUpOnIdleTimeout) {}

// Pointer triggered ServiceWorkerWarmUp is not currently available on Android.
#if !BUILDFLAG(IS_ANDROID)

struct ServiceWorkerWarmUpByPointerBrowserTestParam {};

// This is a test class to verify an optimization to speculatively
// warm-up a service worker by pointer.
class ServiceWorkerWarmUpByPointerBrowserTest
    : public ServiceWorkerWarmUpBrowserTestBase,
      public testing::WithParamInterface<
          ServiceWorkerWarmUpByPointerBrowserTestParam> {};

const ServiceWorkerWarmUpByPointerBrowserTestParam
    kServiceWorkerWarmUpByPointerBrowserTestParams[] =;

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(ServiceWorkerWarmUpByPointerBrowserTest,
                       PointeroverOrPointerdownWillWarmUpServiceWorker) {}

#endif  // !BUILDFLAG(IS_ANDROID)

class ServiceWorkerSkipEmptyFetchHandlerBrowserTest
    : public ServiceWorkerBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerSkipEmptyFetchHandlerBrowserTest,
                       HasNotSkippedMetrics) {}

#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
// TODO(crbug.com/332989700): Disabled due to flakiness on Mac and Linux.
#define MAYBE_HasSkippedForEmptyFetchHandlerMetrics
#else
#define MAYBE_HasSkippedForEmptyFetchHandlerMetrics
#endif
IN_PROC_BROWSER_TEST_F(ServiceWorkerSkipEmptyFetchHandlerBrowserTest,
                       MAYBE_HasSkippedForEmptyFetchHandlerMetrics) {}

// Browser test for the Static Routing API's `race-network-and-fetch-handler`
// source.
class ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest
    : public ServiceWorkerBrowserTest {};

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins_PassThrough) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_NetworkRequest_Wins_PassThrough) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins_MarkedAsSecure) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins_MimeTypeSniffed) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins_Fetch_No_Respond) {}
// TODO(crbug.com/40074498) Add tests for
// kURLLoadOptionSendSSLInfoForCertificateError

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins_NotFound_FetchHandler_Respond) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins_NotFound_FetchHandler_NotRespond) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_NetworkRequest_Wins_FetchHandler_Fallback
#else
#define MAYBE_NetworkRequest_Wins_FetchHandler_Fallback
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_NetworkRequest_Wins_FetchHandler_Fallback) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins_FetchHandler_Fallback_LargeData) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    NetworkRequest_Wins_Post) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_NetworkRequest_Wins_Redirect
#else
#define MAYBE_NetworkRequest_Wins_Redirect
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_NetworkRequest_Wins_Redirect) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_NetworkRequest_Wins_Redirect_PassThrough
#else
#define MAYBE_NetworkRequest_Wins_Redirect_PassThrough
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_NetworkRequest_Wins_Redirect_PassThrough) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    FetchHandler_Wins) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    FetchHandler_Wins_Fallback) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    FetchHandler_Wins_NotFound) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_FetchHandler_Wins_Redirect
#else
#define MAYBE_FetchHandler_Wins_Redirect
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_FetchHandler_Wins_Redirect) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_FetchHandler_Wins_Redirect_PassThrough
#else
#define MAYBE_FetchHandler_Wins_Redirect_PassThrough
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_FetchHandler_Wins_Redirect_PassThrough) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    FetchHandler_PassThrough) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    FetchHandler_PassThrough_Clone) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_Subresource_NetworkRequest_Wins
#else
#define MAYBE_Subresource_NetworkRequest_Wins
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_Subresource_NetworkRequest_Wins) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_NetworkRequest_Wins_Fetch_No_Respond) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_NetworkRequest_Wins_NotFound) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_NetworkRequest_Wins_FetchHandler_Fallback) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_NetworkRequest_Wins_FetchHandler_Fallback_LargeData) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_NetworkRequest_Wins_FetchHandler_Fallback_Redirect) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_NetworkRequest_Wins_Post) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_Redirect_Multiple) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_Subresource_NetworkRequest_Wins_Redirect
#else
#define MAYBE_Subresource_NetworkRequest_Wins_Redirect
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_Subresource_NetworkRequest_Wins_Redirect) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_Subresource_NetworkRequest_Wins_Redirect_PassThrough
#else
#define MAYBE_Subresource_NetworkRequest_Wins_Redirect_PassThrough
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_Subresource_NetworkRequest_Wins_Redirect_PassThrough) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_FetchHandler_Wins) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_FetchHandler_Wins_Fallback) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_FetchHandler_Wins_Fallback_Redirect) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_FetchHandler_Wins_NotFound) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
// TODO(crbug.com/41490535): Flaky on Android.
#if BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_ANDROID)
#define MAYBE_Subresource_FetchHandler_Wins_Redirect
#else
#define MAYBE_Subresource_FetchHandler_Wins_Redirect
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_Subresource_FetchHandler_Wins_Redirect) {}

// TODO(crbug.com/40263529): Flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_Subresource_FetchHandler_Wins_Redirect_PassThrough
#else
#define MAYBE_Subresource_FetchHandler_Wins_Redirect_PassThrough
#endif
IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    MAYBE_Subresource_FetchHandler_Wins_Redirect_PassThrough) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest,
    Subresource_FetchHandler_PassThrough) {}

class ServiceWorkerAutoPreloadBrowserTest
    : public ServiceWorkerStaticRouterRaceNetworkAndFetchHandlerSourceBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest,
                       NetworkRequestRepliedFirstButFetchHandlerResultIsUsed) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest, PassThrough) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest,
                       PassThrough_LargeData) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest,
                       NetworkRequest_Wins_FetchHandler_Fallback) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest,
                       FetchHandler_Wins_Fallback) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerAutoPreloadBrowserTest,
    Subresource_NetworkRequestRepliedFirstButFetchHandlerResultIsUsed) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest,
                       Subresource_PassThrough) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest,
                       Subresource_PassThrough_LargeData) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest,
                       Subresource_NetworkRequest_Wins_FetchHandler_Fallback) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadBrowserTest,
                       Subresource_FetchHandler_Wins_Fallback) {}

class ServiceWorkerAutoPreloadWithBlockedHostsBrowserTest
    : public ServiceWorkerAutoPreloadBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadWithBlockedHostsBrowserTest,
                       BlockedHosts) {}

class ServiceWorkerAutoPreloadWithEnableSubresourcePreloadBrowserTest
    : public ServiceWorkerAutoPreloadBrowserTest {};

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerAutoPreloadWithEnableSubresourcePreloadBrowserTest,
    Disabled) {}

class ServiceWorkerAutoPreloadWithEnableOnlyWhenSWNotRunningBrowserTest
    : public ServiceWorkerAutoPreloadBrowserTest {};

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerAutoPreloadWithEnableOnlyWhenSWNotRunningBrowserTest,
    NotRunning) {}

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerAutoPreloadWithEnableOnlyWhenSWNotRunningBrowserTest,
    Running) {}

class ServiceWorkerAutoPreloadAllowListBrowserTest
    : public ServiceWorkerAutoPreloadBrowserTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(ServiceWorkerAutoPreloadAllowListBrowserTest,
                       EnableAutoPreloadIfScriptIsAllowed) {}

class ServiceWorkerAutoPreloadOptOutBrowserTest
    : public ServiceWorkerAutoPreloadBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadOptOutBrowserTest,
                       MainResourceFetchHandlerShouldNotRace) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerAutoPreloadOptOutBrowserTest,
                       SubresourceFetchHandlerShouldNotRace) {}

class CacheStorageDataChecker
    : public base::RefCounted<CacheStorageDataChecker> {};

// Test class for static routing API (crbug.com/1420517) browsertest.
class ServiceWorkerStaticRouterBrowserTest : public ServiceWorkerBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceFromFetchEventRule) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceNoRuleMatchedResponseFromFetchHandler) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceFromNetworkRule) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       SubresourceNoRuleMatchedResponseFromFetchHandler) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       SubresourceFromNetworkRule) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceRaceNetworkAndFetch) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       SubresourceRaceNetworkAndFetch) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceRunningStatus) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       SubresourceRunningStatus) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceCacheStorageHit) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceCacheStorageMissThenNetworkFallback) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceCacheStorageHitWithName) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       MainResourceCacheStorageMissDueToNameMismatch) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       SubresourceCacheStorageHit) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       SubresourceCacheStorageMiss) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       SubresourceCacheStorageHitWithName) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       SubresourceCacheStorageMissDueToNameMissmatch) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest,
                       FetchEventShouldBeUsedWithFetchHandler) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest, MainResourceNot) {}

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterBrowserTest, SubresourceNot) {}

// Test class for static routing API, if disables starting the ServiceWorker
// automatically when the request matches the registered route.
class ServiceWorkerStaticRouterDisablingServiceWorkerStartBrowserTest
    : public ServiceWorkerStaticRouterBrowserTest {};

IN_PROC_BROWSER_TEST_F(
    ServiceWorkerStaticRouterDisablingServiceWorkerStartBrowserTest,
    MainResourceNetworkFallback) {}

class ServiceWorkerStaticRouterOriginTrialBrowserTest
    : public ServiceWorkerStaticRouterBrowserTest {};

IN_PROC_BROWSER_TEST_F(ServiceWorkerStaticRouterOriginTrialBrowserTest,
                       Fallback) {}
}  // namespace content