diff options
Diffstat (limited to 'chromium/gin/v8_platform_unittest.cc')
-rw-r--r-- | chromium/gin/v8_platform_unittest.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/chromium/gin/v8_platform_unittest.cc b/chromium/gin/v8_platform_unittest.cc index 5409e89f642..d2ea2b7768c 100644 --- a/chromium/gin/v8_platform_unittest.cc +++ b/chromium/gin/v8_platform_unittest.cc @@ -4,6 +4,9 @@ #include "gin/public/v8_platform.h" +#include <atomic> + +#include "base/test/task_environment.h" #include "base/trace_event/trace_event.h" #include "testing/gtest/include/gtest/gtest.h" @@ -62,4 +65,26 @@ TEST(V8PlatformTest, TraceStateObserverFired) { ASSERT_EQ(0, test_observer.Disabled()); } +// Tests that PostJob runs a task and is done after Join. +TEST(V8PlatformTest, PostJobSimple) { + base::test::TaskEnvironment task_environment; + std::atomic_size_t num_tasks_to_run(4); + class Task : public v8::JobTask { + public: + explicit Task(std::atomic_size_t* num_tasks_to_run) + : num_tasks_to_run(num_tasks_to_run) {} + void Run(v8::JobDelegate* delegate) override { --(*num_tasks_to_run); } + size_t GetMaxConcurrency() const override { return *num_tasks_to_run; } + + std::atomic_size_t* num_tasks_to_run; + }; + auto handle = + V8Platform::Get()->PostJob(v8::TaskPriority::kUserVisible, + std::make_unique<Task>(&num_tasks_to_run)); + EXPECT_TRUE(handle->IsRunning()); + handle->Join(); + EXPECT_FALSE(handle->IsRunning()); + DCHECK_EQ(num_tasks_to_run, 0U); +} + } // namespace gin |