#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include <memory>
#include <utility>
#include "base/run_loop.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/v8_cache_options.mojom-blink.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/inspector/inspector_task_runner.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h"
#include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_thread_test_helper.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/test/fake_task_runner.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
_;
AtMost;
namespace blink {
ExitCode;
namespace {
void WaitForSignalTask(WorkerThread* worker_thread,
base::WaitableEvent* waitable_event,
CrossThreadOnceClosure quit_closure) { … }
void TerminateParentOfNestedWorker(WorkerThread* parent_thread,
base::WaitableEvent* waitable_event) { … }
void PauseExecution(v8::Isolate* isolate, void* data) { … }
struct NestedWorkerHelper { … };
void CreateNestedWorkerThenTerminateParent(
WorkerThread* parent_thread,
NestedWorkerHelper* nested_worker_helper,
CrossThreadOnceClosure quit_closure) { … }
void VerifyParentAndChildAreTerminated(WorkerThread* parent_thread,
NestedWorkerHelper* nested_worker_helper,
base::WaitableEvent* waitable_event) { … }
}
class WorkerThreadTest : public testing::Test { … };
TEST_F(WorkerThreadTest, ShouldTerminateScriptExecution) { … }
TEST_F(WorkerThreadTest, AsyncTerminate_OnIdle) { … }
TEST_F(WorkerThreadTest, SyncTerminate_OnIdle) { … }
TEST_F(WorkerThreadTest, AsyncTerminate_ImmediatelyAfterStart) { … }
TEST_F(WorkerThreadTest, SyncTerminate_ImmediatelyAfterStart) { … }
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_AsyncTerminate_WhileTaskIsRunning …
#else
#define MAYBE_AsyncTerminate_WhileTaskIsRunning …
#endif
TEST_F(WorkerThreadTest, MAYBE_AsyncTerminate_WhileTaskIsRunning) { … }
TEST_F(WorkerThreadTest, SyncTerminate_WhileTaskIsRunning) { … }
TEST_F(WorkerThreadTest,
AsyncTerminateAndThenSyncTerminate_WhileTaskIsRunning) { … }
TEST_F(WorkerThreadTest, Terminate_WhileDebuggerTaskIsRunningOnInitialization) { … }
TEST_F(WorkerThreadTest, Terminate_WhileDebuggerTaskIsRunning) { … }
TEST_F(WorkerThreadTest, DISABLED_TerminateWorkerWhileChildIsLoading) { … }
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_TerminateWhileWorkerPausedByDebugger …
#else
#define MAYBE_TerminateWhileWorkerPausedByDebugger …
#endif
TEST_F(WorkerThreadTest, MAYBE_TerminateWhileWorkerPausedByDebugger) { … }
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_TerminateFrozenScript …
#else
#define MAYBE_TerminateFrozenScript …
#endif
TEST_F(WorkerThreadTest, MAYBE_TerminateFrozenScript) { … }
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_NestedPauseFreeze …
#else
#define MAYBE_NestedPauseFreeze …
#endif
TEST_F(WorkerThreadTest, MAYBE_NestedPauseFreeze) { … }
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_NestedPauseFreezeNoInterrupts …
#else
#define MAYBE_NestedPauseFreezeNoInterrupts …
#endif
TEST_F(WorkerThreadTest, MAYBE_NestedPauseFreezeNoInterrupts) { … }
}