#include "content/browser/service_worker/service_worker_version.h"
#include <stdint.h>
#include <memory>
#include <tuple>
#include <utility>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
#include "base/uuid.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/fake_embedded_worker_instance_client.h"
#include "content/browser/service_worker/fake_service_worker.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_ping_controller.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/browser/service_worker/service_worker_test_utils.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_service.mojom.h"
#include "content/public/test/test_utils.h"
#include "net/base/test_completion_callback.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/service_worker/embedded_worker_status.h"
#include "third_party/blink/public/common/service_worker/service_worker_router_rule.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/service_worker/service_worker.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_installed_scripts_manager.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"
namespace content {
namespace service_worker_version_unittest {
constexpr base::TimeDelta kTestTimeoutBeyondRequestTimeout = …
base::Minutes(5) +
base::Minutes(1);
base::OnceCallback<void()> VerifyCalled(
bool* called,
base::OnceClosure quit_closure = base::OnceClosure()) { … }
void ObserveStatusChanges(ServiceWorkerVersion* version,
std::vector<ServiceWorkerVersion::Status>* statuses) { … }
base::Time GetYesterday() { … }
enum class StorageKeyTestCase { … };
class ServiceWorkerVersionTest
: public testing::Test,
public testing::WithParamInterface<StorageKeyTestCase> { … };
INSTANTIATE_TEST_SUITE_P(
All,
ServiceWorkerVersionTest,
testing::ValuesIn({ … };
class FailStartInstanceClient : public FakeEmbeddedWorkerInstanceClient { … };
TEST_P(ServiceWorkerVersionTest, ConcurrentStartAndStop) { … }
TEST_P(ServiceWorkerVersionTest, DispatchEventToStoppedWorker) { … }
TEST_P(ServiceWorkerVersionTest, StartUnregisteredButStillLiveWorker) { … }
TEST_P(ServiceWorkerVersionTest, InstallAndWaitCompletion) { … }
TEST_P(ServiceWorkerVersionTest, ActivateAndWaitCompletion) { … }
TEST_P(ServiceWorkerVersionTest, RepeatedlyObserveStatusChanges) { … }
TEST_P(ServiceWorkerVersionTest, Doom) { … }
TEST_P(ServiceWorkerVersionTest, SetDevToolsAttached) { … }
TEST_P(ServiceWorkerVersionTest, DevToolsAttachThenDetach) { … }
TEST_P(ServiceWorkerVersionTest, RequestTerminationWithDevToolsAttached) { … }
TEST_P(ServiceWorkerVersionTest, StaleUpdate_FreshWorker) { … }
TEST_P(ServiceWorkerVersionTest, StaleUpdate_NonActiveWorker) { … }
TEST_P(ServiceWorkerVersionTest, StaleUpdate_StartWorker) { … }
TEST_P(ServiceWorkerVersionTest, StaleUpdate_RunningWorker) { … }
TEST_P(ServiceWorkerVersionTest, StaleUpdate_DoNotDeferTimer) { … }
TEST_P(ServiceWorkerVersionTest, StartRequestWithNullContext) { … }
TEST_P(ServiceWorkerVersionTest, ResetUpdateDelay) { … }
TEST_P(ServiceWorkerVersionTest, UpdateCachedMetadata) { … }
TEST_P(ServiceWorkerVersionTest, RestartWorker) { … }
class DelayMessageWorker : public FakeServiceWorker { … };
TEST_P(ServiceWorkerVersionTest, RequestTimeout) { … }
TEST_P(ServiceWorkerVersionTest, RequestNowTimeout) { … }
TEST_P(ServiceWorkerVersionTest, RequestNowTimeoutKill) { … }
TEST_P(ServiceWorkerVersionTest, RequestCustomizedTimeout) { … }
TEST_P(ServiceWorkerVersionTest, MixedRequestTimeouts) { … }
TEST_P(ServiceWorkerVersionTest, FailToStart_RendererCrash) { … }
TEST_P(ServiceWorkerVersionTest, FailToStart_Timeout) { … }
TEST_P(ServiceWorkerVersionTest, StallInStopping_DetachThenStart) { … }
TEST_P(ServiceWorkerVersionTest, StallInStopping_DetachThenRestart) { … }
TEST_P(ServiceWorkerVersionTest, RendererCrashDuringEvent) { … }
TEST_P(ServiceWorkerVersionTest, PingController) { … }
TEST_P(ServiceWorkerVersionTest, BadOrigin) { … }
TEST_P(ServiceWorkerVersionTest,
ForegroundServiceWorkerCountUpdatedByControllee) { … }
TEST_P(ServiceWorkerVersionTest,
ForegroundServiceWorkerCountNotUpdatedBySameProcessControllee) { … }
TEST_P(ServiceWorkerVersionTest,
ForegroundServiceWorkerCountUpdatedByControlleeProcessIdChange) { … }
TEST_P(ServiceWorkerVersionTest,
ForegroundServiceWorkerCountUpdatedByWorkerStatus) { … }
TEST_P(ServiceWorkerVersionTest,
ForegroundServiceWorkerCountUpdatedByControlleeForegroundStateChange) { … }
class NoFetchHandlerClient : public FakeEmbeddedWorkerInstanceClient { … };
class ServiceWorkerVersionNoFetchHandlerTest : public ServiceWorkerVersionTest { … };
INSTANTIATE_TEST_SUITE_P(
All,
ServiceWorkerVersionNoFetchHandlerTest,
testing::ValuesIn({ … };
TEST_P(ServiceWorkerVersionNoFetchHandlerTest,
ForegroundServiceWorkerCountNotUpdated) { … }
TEST_P(ServiceWorkerVersionTest, FailToStart_UseNewRendererProcess) { … }
TEST_P(ServiceWorkerVersionTest, FailToStart_RestartStalledWorker) { … }
TEST_P(ServiceWorkerVersionTest, InstalledFetchEventHandlerExists) { … }
TEST_P(ServiceWorkerVersionNoFetchHandlerTest,
InstalledFetchEventHandlerDoesNotExist) { … }
class StoreMessageServiceWorker : public FakeServiceWorker { … };
TEST_P(ServiceWorkerVersionTest, AddMessageToConsole) { … }
TEST_P(ServiceWorkerVersionTest, WriteMetadata_RemoteStorageDisconnection) { … }
TEST_P(ServiceWorkerVersionTest, WriteMetadata_StorageDisabled) { … }
TEST_P(ServiceWorkerVersionTest, WriteMetadata_MultipleWrites) { … }
TEST_P(ServiceWorkerVersionTest, PendingExternalRequest) { … }
TEST_P(ServiceWorkerVersionTest, WorkerLifetimeWithExternalRequest) { … }
TEST_P(ServiceWorkerVersionTest,
DefaultTimeoutRequestDoesNotAffectMaxTimeoutRequest) { … }
TEST_P(ServiceWorkerVersionTest, SetResources) { … }
class ServiceWorkerVersionStaticRouterTest : public ServiceWorkerVersionTest { … };
INSTANTIATE_TEST_SUITE_P(
All,
ServiceWorkerVersionStaticRouterTest,
testing::ValuesIn({ … };
TEST_P(ServiceWorkerVersionStaticRouterTest, SetRouterEvaluator) { … }
class HidEventHandlerClient : public FakeEmbeddedWorkerInstanceClient { … };
TEST_P(ServiceWorkerVersionTest, HasHidEventHandler) { … }
TEST_P(ServiceWorkerVersionTest, NoHidEventHandler) { … }
class UsbEventHandlerClient : public FakeEmbeddedWorkerInstanceClient { … };
TEST_P(ServiceWorkerVersionTest, HasUsbEventHandler) { … }
TEST_P(ServiceWorkerVersionTest, NoUsbEventHandler) { … }
}
}