chromium/content/browser/service_worker/service_worker_process_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 "base/command_line.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.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/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/shell/browser/shell.h"
#include "net/dns/mock_host_resolver.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/origin.h"

// This file has tests involving render process selection for service workers.

namespace content {

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

class ServiceWorkerProcessBrowserTest
    : public ContentBrowserTest,
      public ::testing::WithParamInterface<bool> {};

// Tests that a service worker started due to a navigation shares the same
// process as the navigation.
// Flaky on Android; see https://crbug.com/1320972.
// Flaky on TSan Linux; see https://crbug.com/349316554.
#if BUILDFLAG(IS_ANDROID) ||                            \
    ((BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && \
     defined(THREAD_SANITIZER))
#define MAYBE_ServiceWorkerAndPageShareProcess
#else
#define MAYBE_ServiceWorkerAndPageShareProcess
#endif
IN_PROC_BROWSER_TEST_P(ServiceWorkerProcessBrowserTest,
                       MAYBE_ServiceWorkerAndPageShareProcess) {}

// Tests whether a service worker and navigation share the same process in the
// special case where the service worker starts before the navigation starts,
// and the navigation transitions out of a page with no site URL. This special
// case happens in real life when doing a search from the omnibox while on the
// Android native NTP page: the service worker starts first due to the
// navigation hint from the omnibox, and the native page has no site URL. See
// https://crbug.com/1012143.
IN_PROC_BROWSER_TEST_P(ServiceWorkerProcessBrowserTest,
                       NavigateFromUnassignedSiteInstance) {}

// Toggle Site Isolation.
INSTANTIATE_TEST_SUITE_P();

}  // namespace content