#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 { … };
}
class ServiceWorkerContainerHostTest : public testing::Test { … };
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_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_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_P(ServiceWorkerContainerHostTestByClientType,
ReservedClientsAreNotExposedToClientsApi) { … }
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(…);
class ServiceWorkerContainerHostTestWithBackForwardCache
: public ServiceWorkerContainerHostTest { … };
void ServiceWorkerContainerHostTest::TestBackForwardCachedClientsAreNotExposed(
const GURL& url) { … }
TEST_F(ServiceWorkerContainerHostTestWithBackForwardCache,
SkipBackForwardCachedServiceWorker) { … }
class TestServiceWorkerContextCoreObserver
: public ServiceWorkerContextCoreObserver { … };
TEST_F(ServiceWorkerContainerHostTestWithBackForwardCache, ControlleeEvents) { … }
TEST_F(ServiceWorkerContainerHostTest, UpdateServiceWorkerOnDestruction) { … }
TEST_F(ServiceWorkerContainerHostTest, HintToUpdateServiceWorker) { … }
TEST_F(ServiceWorkerContainerHostTest,
HintToUpdateServiceWorkerButNoVersionToUpdate) { … }
TEST_F(ServiceWorkerContainerHostTest, HintToUpdateServiceWorkerMultiple) { … }
}