Index: third_party/WebKit/Source/modules/compositorworker/AnimationWorkletThreadTest.cpp |
diff --git a/third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThreadTest.cpp b/third_party/WebKit/Source/modules/compositorworker/AnimationWorkletThreadTest.cpp |
similarity index 33% |
copy from third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThreadTest.cpp |
copy to third_party/WebKit/Source/modules/compositorworker/AnimationWorkletThreadTest.cpp |
index 3f7f3612d12d04faa8b8780d88f2ae9fc1ca83d8..a5fad2d0a0250598dd212249135f17477d6d0867 100644 |
--- a/third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThreadTest.cpp |
+++ b/third_party/WebKit/Source/modules/compositorworker/AnimationWorkletThreadTest.cpp |
@@ -2,15 +2,13 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "modules/compositorworker/CompositorWorkerThread.h" |
+#include "modules/compositorworker/AnimationWorkletThread.h" |
#include "bindings/core/v8/ScriptSourceCode.h" |
#include "bindings/core/v8/SourceLocation.h" |
#include "bindings/core/v8/V8GCController.h" |
#include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
-#include "core/dom/CompositorProxyClient.h" |
#include "core/inspector/ConsoleMessage.h" |
-#include "core/testing/DummyPageHolder.h" |
#include "core/workers/InProcessWorkerObjectProxy.h" |
#include "core/workers/WorkerBackingThread.h" |
#include "core/workers/WorkerLoaderProxy.h" |
@@ -31,16 +29,16 @@ |
namespace blink { |
namespace { |
-// A null InProcessWorkerObjectProxy, supplied when creating CompositorWorkerThreads. |
-class TestCompositorWorkerObjectProxy : public InProcessWorkerObjectProxy { |
+// A null WorkerReportingProxy, supplied when creating AnimationWorkletThreads. |
+class TestAnimationWorkletReportingProxy : public WorkerReportingProxy { |
public: |
- static std::unique_ptr<TestCompositorWorkerObjectProxy> create(ExecutionContext* context) |
+ static std::unique_ptr<TestAnimationWorkletReportingProxy> create() |
{ |
- return wrapUnique(new TestCompositorWorkerObjectProxy(context)); |
+ return wrapUnique(new TestAnimationWorkletReportingProxy()); |
} |
// (Empty) WorkerReportingProxy implementation: |
- virtual void reportException(const String& errorMessage, std::unique_ptr<SourceLocation>, int exceptionId) {} |
+ void reportException(const String& errorMessage, std::unique_ptr<SourceLocation>, int exceptionId) override {} |
void reportConsoleMessage(MessageSource, MessageLevel, const String& message, SourceLocation*) override {} |
void postMessageToPageInspector(const String&) override {} |
@@ -50,197 +48,154 @@ public: |
void workerThreadTerminated() override {} |
void willDestroyWorkerGlobalScope() override {} |
- ExecutionContext* getExecutionContext() override { return m_executionContext.get(); } |
- |
private: |
- TestCompositorWorkerObjectProxy(ExecutionContext* context) |
- : InProcessWorkerObjectProxy(nullptr) |
- , m_executionContext(context) |
- { |
- } |
- |
- Persistent<ExecutionContext> m_executionContext; |
-}; |
- |
-class TestCompositorProxyClient |
- : public GarbageCollected<TestCompositorProxyClient> |
- , public CompositorProxyClient { |
- USING_GARBAGE_COLLECTED_MIXIN(TestCompositorProxyClient); |
-public: |
- TestCompositorProxyClient() {} |
- |
- void setGlobalScope(WorkerGlobalScope*) override {} |
- void requestAnimationFrame() override {} |
- void registerCompositorProxy(CompositorProxy*) override {} |
- void unregisterCompositorProxy(CompositorProxy*) override {} |
-}; |
- |
-class CompositorWorkerTestPlatform : public TestingPlatformSupport { |
-public: |
- CompositorWorkerTestPlatform() |
- : m_thread(wrapUnique(m_oldPlatform->createThread("Compositor"))) |
- { |
- } |
- |
- WebThread* compositorThread() const override |
- { |
- return m_thread.get(); |
- } |
- |
- WebCompositorSupport* compositorSupport() override { return &m_compositorSupport; } |
- |
-private: |
- std::unique_ptr<WebThread> m_thread; |
- TestingCompositorSupport m_compositorSupport; |
+ TestAnimationWorkletReportingProxy() { } |
nhiroki
2016/08/17 05:56:57
nit: { } -> {}
ikilpatrick
2016/08/22 19:07:32
Done.
|
}; |
} // namespace |
-class CompositorWorkerThreadTest : public ::testing::Test { |
+class AnimationWorkletThreadTest : public ::testing::Test { |
public: |
void SetUp() override |
{ |
- CompositorWorkerThread::createSharedBackingThreadForTest(); |
- m_page = DummyPageHolder::create(); |
- m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->document()); |
+ AnimationWorkletThread::createSharedBackingThreadForTest(); |
+ m_reportingProxy = TestAnimationWorkletReportingProxy::create(); |
m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); |
} |
void TearDown() override |
{ |
- m_page.reset(); |
- CompositorWorkerThread::clearSharedBackingThread(); |
+ AnimationWorkletThread::clearSharedBackingThread(); |
} |
- std::unique_ptr<CompositorWorkerThread> createCompositorWorker() |
+ std::unique_ptr<AnimationWorkletThread> createAnimationWorkletThread() |
{ |
- std::unique_ptr<CompositorWorkerThread> workerThread = CompositorWorkerThread::create(nullptr, *m_objectProxy, 0); |
- WorkerClients* clients = WorkerClients::create(); |
- provideCompositorProxyClientTo(clients, new TestCompositorProxyClient); |
flackr
2016/08/22 18:41:14
Can you remind me how we will eventually get the C
ikilpatrick
2016/08/22 19:07:32
Can just be passed in here on worklet thread start
|
- workerThread->start(WorkerThreadStartupData::create( |
+ std::unique_ptr<AnimationWorkletThread> thread = AnimationWorkletThread::create(nullptr, *m_reportingProxy); |
+ thread->start(WorkerThreadStartupData::create( |
KURL(ParsedURLString, "http://fake.url/"), |
"fake user agent", |
- "//fake source code", |
+ "", |
nullptr, |
DontPauseWorkerGlobalScopeOnStart, |
nullptr, |
"", |
m_securityOrigin.get(), |
- clients, |
+ nullptr, |
WebAddressSpaceLocal, |
nullptr, |
nullptr, |
V8CacheOptionsDefault)); |
- return workerThread; |
+ return thread; |
} |
- // Attempts to run some simple script for |worker|. |
- void checkWorkerCanExecuteScript(WorkerThread* worker) |
+ // Attempts to run some simple script for |thread|. |
+ void checkWorkletCanExecuteScript(WorkerThread* thread) |
{ |
std::unique_ptr<WaitableEvent> waitEvent = wrapUnique(new WaitableEvent()); |
- worker->workerBackingThread().backingThread().postTask(BLINK_FROM_HERE, crossThreadBind(&CompositorWorkerThreadTest::executeScriptInWorker, crossThreadUnretained(this), |
- crossThreadUnretained(worker), crossThreadUnretained(waitEvent.get()))); |
+ thread->workerBackingThread().backingThread().postTask(BLINK_FROM_HERE, crossThreadBind(&AnimationWorkletThreadTest::executeScriptInWorklet, crossThreadUnretained(this), |
+ crossThreadUnretained(thread), crossThreadUnretained(waitEvent.get()))); |
waitEvent->wait(); |
} |
private: |
- void executeScriptInWorker(WorkerThread* worker, WaitableEvent* waitEvent) |
+ void executeScriptInWorklet(WorkerThread* thread, WaitableEvent* waitEvent) |
{ |
- WorkerOrWorkletScriptController* scriptController = worker->globalScope()->scriptController(); |
- bool evaluateResult = scriptController->evaluate(ScriptSourceCode("var counter = 0; ++counter;")); |
- ASSERT_UNUSED(evaluateResult, evaluateResult); |
+ WorkerOrWorkletScriptController* scriptController = thread->globalScope()->scriptController(); |
+ scriptController->evaluate(ScriptSourceCode("var counter = 0; ++counter;")); |
waitEvent->signal(); |
} |
- std::unique_ptr<DummyPageHolder> m_page; |
RefPtr<SecurityOrigin> m_securityOrigin; |
- std::unique_ptr<InProcessWorkerObjectProxy> m_objectProxy; |
- CompositorWorkerTestPlatform m_testPlatform; |
+ std::unique_ptr<WorkerReportingProxy> m_reportingProxy; |
}; |
-TEST_F(CompositorWorkerThreadTest, Basic) |
+TEST_F(AnimationWorkletThreadTest, Basic) |
{ |
- std::unique_ptr<CompositorWorkerThread> compositorWorker = createCompositorWorker(); |
- checkWorkerCanExecuteScript(compositorWorker.get()); |
- compositorWorker->terminateAndWait(); |
+ std::unique_ptr<AnimationWorkletThread> worklet = createAnimationWorkletThread(); |
+ checkWorkletCanExecuteScript(worklet.get()); |
+ worklet->terminateAndWait(); |
} |
-// Tests that the same WebThread is used for new workers if the WebThread is still alive. |
-TEST_F(CompositorWorkerThreadTest, CreateSecondAndTerminateFirst) |
+// Tests that the same WebThread is used for new worklets if the WebThread is |
+// still alive. |
+TEST_F(AnimationWorkletThreadTest, CreateSecondAndTerminateFirst) |
{ |
- // Create the first worker and wait until it is initialized. |
- std::unique_ptr<CompositorWorkerThread> firstWorker = createCompositorWorker(); |
- WebThreadSupportingGC* firstThread = &firstWorker->workerBackingThread().backingThread(); |
- checkWorkerCanExecuteScript(firstWorker.get()); |
- v8::Isolate* firstIsolate = firstWorker->isolate(); |
+ // Create the first worklet and wait until it is initialized. |
+ std::unique_ptr<AnimationWorkletThread> firstWorklet = createAnimationWorkletThread(); |
+ WebThreadSupportingGC* firstThread = &firstWorklet->workerBackingThread().backingThread(); |
+ checkWorkletCanExecuteScript(firstWorklet.get()); |
+ v8::Isolate* firstIsolate = firstWorklet->isolate(); |
ASSERT_TRUE(firstIsolate); |
- // Create the second worker and immediately destroy the first worker. |
- std::unique_ptr<CompositorWorkerThread> secondWorker = createCompositorWorker(); |
+ // Create the second worklet and immediately destroy the first worklet. |
+ std::unique_ptr<AnimationWorkletThread> secondWorklet = createAnimationWorkletThread(); |
// We don't use terminateAndWait here to avoid forcible termination. |
- firstWorker->terminate(); |
- firstWorker->waitForShutdownForTesting(); |
+ firstWorklet->terminate(); |
+ firstWorklet->waitForShutdownForTesting(); |
- // Wait until the second worker is initialized. Verify that the second worker is using the same |
- // thread and Isolate as the first worker. |
- WebThreadSupportingGC* secondThread = &secondWorker->workerBackingThread().backingThread(); |
+ // Wait until the second worklet is initialized. Verify that the second |
+ // worklet is using the same thread and Isolate as the first worklet. |
+ WebThreadSupportingGC* secondThread = &secondWorklet->workerBackingThread().backingThread(); |
ASSERT_EQ(firstThread, secondThread); |
- v8::Isolate* secondIsolate = secondWorker->isolate(); |
+ v8::Isolate* secondIsolate = secondWorklet->isolate(); |
ASSERT_TRUE(secondIsolate); |
EXPECT_EQ(firstIsolate, secondIsolate); |
- // Verify that the worker can still successfully execute script. |
- checkWorkerCanExecuteScript(secondWorker.get()); |
+ // Verify that the worklet can still successfully execute script. |
+ checkWorkletCanExecuteScript(secondWorklet.get()); |
- secondWorker->terminateAndWait(); |
+ secondWorklet->terminateAndWait(); |
} |
-// Tests that a new WebThread is created if all existing workers are terminated before a new worker is created. |
-TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) |
+// Tests that a new WebThread is created if all existing worklets are |
+// terminated before a new worklet is created. |
+TEST_F(AnimationWorkletThreadTest, TerminateFirstAndCreateSecond) |
{ |
- // Create the first worker, wait until it is initialized, and terminate it. |
- std::unique_ptr<CompositorWorkerThread> compositorWorker = createCompositorWorker(); |
- WebThreadSupportingGC* firstThread = &compositorWorker->workerBackingThread().backingThread(); |
- checkWorkerCanExecuteScript(compositorWorker.get()); |
+ // Create the first worklet, wait until it is initialized, and terminate it. |
+ std::unique_ptr<AnimationWorkletThread> worklet = createAnimationWorkletThread(); |
+ WebThreadSupportingGC* firstThread = &worklet->workerBackingThread().backingThread(); |
+ checkWorkletCanExecuteScript(worklet.get()); |
// We don't use terminateAndWait here to avoid forcible termination. |
- compositorWorker->terminate(); |
- compositorWorker->waitForShutdownForTesting(); |
+ worklet->terminate(); |
+ worklet->waitForShutdownForTesting(); |
- // Create the second worker. The backing thread is same. |
- compositorWorker = createCompositorWorker(); |
- WebThreadSupportingGC* secondThread = &compositorWorker->workerBackingThread().backingThread(); |
+ // Create the second worklet. The backing thread is same. |
+ worklet = createAnimationWorkletThread(); |
+ WebThreadSupportingGC* secondThread = &worklet->workerBackingThread().backingThread(); |
EXPECT_EQ(firstThread, secondThread); |
- checkWorkerCanExecuteScript(compositorWorker.get()); |
+ checkWorkletCanExecuteScript(worklet.get()); |
- compositorWorker->terminateAndWait(); |
+ worklet->terminateAndWait(); |
} |
-// Tests that v8::Isolate and WebThread are correctly set-up if a worker is created while another is terminating. |
-TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) |
+// Tests that v8::Isolate and WebThread are correctly set-up if a worklet is |
+// created while another is terminating. |
+TEST_F(AnimationWorkletThreadTest, CreatingSecondDuringTerminationOfFirst) |
{ |
- std::unique_ptr<CompositorWorkerThread> firstWorker = createCompositorWorker(); |
- checkWorkerCanExecuteScript(firstWorker.get()); |
- v8::Isolate* firstIsolate = firstWorker->isolate(); |
+ std::unique_ptr<AnimationWorkletThread> firstWorklet = createAnimationWorkletThread(); |
+ checkWorkletCanExecuteScript(firstWorklet.get()); |
+ v8::Isolate* firstIsolate = firstWorklet->isolate(); |
ASSERT_TRUE(firstIsolate); |
- // Request termination of the first worker and create the second worker |
+ // Request termination of the first worklet and create the second worklet |
// as soon as possible. |
- firstWorker->terminate(); |
+ firstWorklet->terminate(); |
// We don't wait for its termination. |
// Note: We rely on the assumption that the termination steps don't run |
- // on the worker thread so quickly. This could be a source of flakiness. |
+ // on the worklet thread so quickly. This could be a source of flakiness. |
- std::unique_ptr<CompositorWorkerThread> secondWorker = createCompositorWorker(); |
+ std::unique_ptr<AnimationWorkletThread> secondWorklet = createAnimationWorkletThread(); |
- v8::Isolate* secondIsolate = secondWorker->isolate(); |
+ v8::Isolate* secondIsolate = secondWorklet->isolate(); |
ASSERT_TRUE(secondIsolate); |
EXPECT_EQ(firstIsolate, secondIsolate); |
- // Verify that the isolate can run some scripts correctly in the second worker. |
- checkWorkerCanExecuteScript(secondWorker.get()); |
- secondWorker->terminateAndWait(); |
+ // Verify that the isolate can run some scripts correctly in the second |
+ // worklet. |
+ checkWorkletCanExecuteScript(secondWorklet.get()); |
+ secondWorklet->terminateAndWait(); |
} |
} // namespace blink |