chromium/content/browser/service_worker/service_worker_container_host_unittest.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 "content/browser/service_worker/service_worker_container_host.h"

#include <memory>
#include <set>
#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/service_worker/embedded_worker_test_helper.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_host.h"
#include "content/browser/service_worker/service_worker_register_job.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/browser/service_worker/service_worker_security_utils.h"
#include "content/browser/service_worker/service_worker_test_utils.h"
#include "content/browser/service_worker/service_worker_version.h"
#include "content/common/content_navigation_policy.h"
#include "content/common/url_schemes.h"
#include "content/public/browser/child_process_host.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/origin_util.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
#include "content/test/test_content_browser_client.h"
#include "content/test/test_content_client.h"
#include "mojo/public/cpp/system/functions.h"
#include "net/cookies/site_for_cookies.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration_options.mojom.h"
#include "url/origin.h"
#include "url/url_util.h"

namespace content {

namespace {

const char kServiceWorkerScheme[] =;

class ServiceWorkerTestContentClient : public TestContentClient {};

class ServiceWorkerTestContentBrowserClient : public TestContentBrowserClient {};

enum class ClientType {};

}  // namespace

class ServiceWorkerContainerHostTest : public testing::Test {};

// Run tests with PlzDedicatedWorker.
// TODO(crbug.com/40093136): Merge this test fixture into
// ServiceWorkerContainerHostTest once PlzDedicatedWorker is enabled by default.
class ServiceWorkerContainerHostTestWithPlzDedicatedWorker
    : public ServiceWorkerContainerHostTest {};

TEST_F(ServiceWorkerContainerHostTest, MatchRegistration) {}

TEST_F(ServiceWorkerContainerHostTest, ContextSecurity) {}

TEST_F(ServiceWorkerContainerHostTest, UpdateUrls_SameOriginRedirect) {}

TEST_F(ServiceWorkerContainerHostTest, UpdateUrls_CrossOriginRedirect) {}

TEST_F(ServiceWorkerContainerHostTest, UpdateUrls_CorrectStorageKey) {}

TEST_F(ServiceWorkerContainerHostTest, ForServiceWorker_CorrectStorageKey) {}

TEST_F(ServiceWorkerContainerHostTest,
       ForServiceWorkerWithTopLevelSite_CorrectStorageKey) {}

TEST_F(ServiceWorkerContainerHostTest,
       GetCorrectStorageKeyForWebSecurityState) {}

TEST_F(ServiceWorkerContainerHostTest, RemoveProvider) {}

class MockServiceWorkerContainer : public blink::mojom::ServiceWorkerContainer {};

TEST_F(ServiceWorkerContainerHostTest, Controller) {}

TEST_F(ServiceWorkerContainerHostTest, UncontrolledWithMatchingRegistration) {}

TEST_F(ServiceWorkerContainerHostTest,
       Register_ContentSettingsDisallowsServiceWorker) {}

TEST_F(ServiceWorkerContainerHostTest, AllowServiceWorker) {}

TEST_F(ServiceWorkerContainerHostTest, Register_HTTPS) {}

TEST_F(ServiceWorkerContainerHostTest, Register_NonSecureTransportLocalhost) {}

TEST_F(ServiceWorkerContainerHostTest, Register_InvalidScopeShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest, Register_InvalidScriptShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest, Register_NonSecureOriginShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest, Register_CrossOriginShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest, Register_BadCharactersShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest, Register_FileSystemDocumentShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest,
       Register_FileSystemScriptOrScopeShouldFail) {}

class WebUIUntrustedServiceWorkerContainerHostTest
    : public ServiceWorkerContainerHostTest,
      public testing::WithParamInterface<bool> {};

// Test that chrome:// webuis can't register service workers even if the
// chrome-untrusted:// SW flag is on.
TEST_P(WebUIUntrustedServiceWorkerContainerHostTest,
       Register_RegistrationShouldFail) {}

TEST_P(WebUIUntrustedServiceWorkerContainerHostTest,
       Register_UntrustedRegistrationShouldFail) {}

INSTANTIATE_TEST_SUITE_P();

class WebUIServiceWorkerContainerHostTest
    : public ServiceWorkerContainerHostTest,
      public testing::WithParamInterface<bool> {};

TEST_P(WebUIServiceWorkerContainerHostTest, Register_RegistrationShouldFail) {}

// Test that chrome-untrusted:// service workers are disallowed with the
// chrome:// flag turned on.
TEST_P(WebUIServiceWorkerContainerHostTest,
       Register_UntrustedRegistrationShouldFail) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(ServiceWorkerContainerHostTest, EarlyContextDeletion) {}

TEST_F(ServiceWorkerContainerHostTest, GetRegistration_Success) {}

TEST_F(ServiceWorkerContainerHostTest,
       GetRegistration_NotFoundShouldReturnNull) {}

TEST_F(ServiceWorkerContainerHostTest, GetRegistration_CrossOriginShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest, GetRegistration_InvalidScopeShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest,
       GetRegistration_NonSecureOriginShouldFail) {}

TEST_F(ServiceWorkerContainerHostTest, GetRegistrations_SecureOrigin) {}

TEST_F(ServiceWorkerContainerHostTest,
       GetRegistrations_NonSecureOriginShouldFail) {}

class ServiceWorkerContainerHostTestByClientType
    : public ServiceWorkerContainerHostTest,
      public testing::WithParamInterface<ClientType> {};

// Test that a "reserved" (i.e., not execution ready) client is not included
// when iterating over client container hosts. If it were, it'd be undesirably
// exposed via the Clients API.
TEST_P(ServiceWorkerContainerHostTestByClientType,
       ReservedClientsAreNotExposedToClientsApi) {}

// Tests the client phase transitions.
TEST_P(ServiceWorkerContainerHostTestByClientType, ClientPhaseTransition) {}

TEST_P(ServiceWorkerContainerHostTestByClientType,
       LifetimeScopedClientReleased) {}

TEST_P(ServiceWorkerContainerHostTestByClientType,
       LifetimeScopedClientDestroyed) {}

TEST_P(ServiceWorkerContainerHostTestByClientType,
       LifetimeCommittedClientDestroyed) {}

TEST_P(ServiceWorkerContainerHostTestByClientType,
       LifetimeCommittedClientReset) {}

TEST_P(ServiceWorkerContainerHostTestByClientType, LifetimeContextDestroyed) {}

INSTANTIATE_TEST_SUITE_P();

// Run tests with BackForwardCache.
class ServiceWorkerContainerHostTestWithBackForwardCache
    : public ServiceWorkerContainerHostTest {};

// Test that a client in BackForwardCache is not included
// when iterating over client container hosts. If it were, it'd be undesirably
// exposed via the Clients API.
void ServiceWorkerContainerHostTest::TestBackForwardCachedClientsAreNotExposed(
    const GURL& url) {}

TEST_F(ServiceWorkerContainerHostTestWithBackForwardCache,
       SkipBackForwardCachedServiceWorker) {}

class TestServiceWorkerContextCoreObserver
    : public ServiceWorkerContextCoreObserver {};

TEST_F(ServiceWorkerContainerHostTestWithBackForwardCache, ControlleeEvents) {}

// Tests that the service worker involved with a navigation (via
// AddServiceWorkerToUpdate) is updated when the host for the navigation is
// destroyed.
TEST_F(ServiceWorkerContainerHostTest, UpdateServiceWorkerOnDestruction) {}

// Tests that the service worker involved with a navigation is updated when the
// host receives a HintToUpdateServiceWorker message.
TEST_F(ServiceWorkerContainerHostTest, HintToUpdateServiceWorker) {}

// Tests that the host receives a HintToUpdateServiceWorker message but
// there was no service worker at main resource request time. This
// can happen due to claim().
TEST_F(ServiceWorkerContainerHostTest,
       HintToUpdateServiceWorkerButNoVersionToUpdate) {}

TEST_F(ServiceWorkerContainerHostTest, HintToUpdateServiceWorkerMultiple) {}

}  // namespace content