| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/compositorworker/CompositorWorkerThread.h" | 5 #include "modules/compositorworker/CompositorWorkerThread.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptSourceCode.h" | 7 #include "bindings/core/v8/ScriptSourceCode.h" |
| 8 #include "bindings/core/v8/SourceLocation.h" | 8 #include "bindings/core/v8/SourceLocation.h" |
| 9 #include "bindings/core/v8/V8GCController.h" | 9 #include "bindings/core/v8/V8GCController.h" |
| 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 11 #include "core/dom/CompositorProxyClient.h" | 11 #include "core/dom/CompositorProxyClient.h" |
| 12 #include "core/inspector/ConsoleMessage.h" | 12 #include "core/inspector/ConsoleMessage.h" |
| 13 #include "core/testing/DummyPageHolder.h" | |
| 14 #include "core/workers/InProcessWorkerObjectProxy.h" | 13 #include "core/workers/InProcessWorkerObjectProxy.h" |
| 15 #include "core/workers/ParentFrameTaskRunners.h" | 14 #include "core/workers/ParentFrameTaskRunners.h" |
| 16 #include "core/workers/WorkerBackingThread.h" | 15 #include "core/workers/WorkerBackingThread.h" |
| 17 #include "core/workers/WorkerLoaderProxy.h" | 16 #include "core/workers/WorkerLoaderProxy.h" |
| 18 #include "core/workers/WorkerOrWorkletGlobalScope.h" | 17 #include "core/workers/WorkerOrWorkletGlobalScope.h" |
| 19 #include "core/workers/WorkerThreadStartupData.h" | 18 #include "core/workers/WorkerThreadStartupData.h" |
| 20 #include "platform/CrossThreadFunctional.h" | 19 #include "platform/CrossThreadFunctional.h" |
| 21 #include "platform/WaitableEvent.h" | 20 #include "platform/WaitableEvent.h" |
| 22 #include "platform/WebThreadSupportingGC.h" | 21 #include "platform/WebThreadSupportingGC.h" |
| 23 #include "platform/heap/Handle.h" | 22 #include "platform/heap/Handle.h" |
| 24 #include "platform/testing/TestingPlatformSupport.h" | 23 #include "platform/testing/TestingPlatformSupport.h" |
| 25 #include "platform/testing/UnitTestHelpers.h" | 24 #include "platform/testing/UnitTestHelpers.h" |
| 26 #include "public/platform/Platform.h" | 25 #include "public/platform/Platform.h" |
| 27 #include "public/platform/WebAddressSpace.h" | 26 #include "public/platform/WebAddressSpace.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "wtf/PtrUtil.h" | 28 #include "wtf/PtrUtil.h" |
| 30 #include <memory> | 29 #include <memory> |
| 31 | 30 |
| 32 namespace blink { | 31 namespace blink { |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 // A null InProcessWorkerObjectProxy, supplied when creating | 34 // A null InProcessWorkerObjectProxy, supplied when creating |
| 36 // CompositorWorkerThreads. | 35 // CompositorWorkerThreads. |
| 37 class TestCompositorWorkerObjectProxy : public InProcessWorkerObjectProxy { | 36 class TestCompositorWorkerObjectProxy : public InProcessWorkerObjectProxy { |
| 38 public: | 37 public: |
| 39 static std::unique_ptr<TestCompositorWorkerObjectProxy> create( | 38 static std::unique_ptr<TestCompositorWorkerObjectProxy> create() { |
| 40 ExecutionContext* context) { | 39 return wrapUnique(new TestCompositorWorkerObjectProxy()); |
| 41 return wrapUnique(new TestCompositorWorkerObjectProxy(context)); | |
| 42 } | 40 } |
| 43 | 41 |
| 44 // (Empty) WorkerReportingProxy implementation: | 42 // (Empty) WorkerReportingProxy implementation: |
| 45 virtual void dispatchErrorEvent(const String& errorMessage, | 43 virtual void dispatchErrorEvent(const String& errorMessage, |
| 46 std::unique_ptr<SourceLocation>, | 44 std::unique_ptr<SourceLocation>, |
| 47 int exceptionId) {} | 45 int exceptionId) {} |
| 48 void reportConsoleMessage(MessageSource, | 46 void reportConsoleMessage(MessageSource, |
| 49 MessageLevel, | 47 MessageLevel, |
| 50 const String& message, | 48 const String& message, |
| 51 SourceLocation*) override {} | 49 SourceLocation*) override {} |
| 52 void postMessageToPageInspector(const String&) override {} | 50 void postMessageToPageInspector(const String&) override {} |
| 53 ParentFrameTaskRunners* getParentFrameTaskRunners() override { | |
| 54 return m_parentFrameTaskRunners.get(); | |
| 55 } | |
| 56 | |
| 57 void didCreateWorkerGlobalScope(WorkerOrWorkletGlobalScope*) override {} | 51 void didCreateWorkerGlobalScope(WorkerOrWorkletGlobalScope*) override {} |
| 58 void didEvaluateWorkerScript(bool success) override {} | 52 void didEvaluateWorkerScript(bool success) override {} |
| 59 void didCloseWorkerGlobalScope() override {} | 53 void didCloseWorkerGlobalScope() override {} |
| 60 void willDestroyWorkerGlobalScope() override {} | 54 void willDestroyWorkerGlobalScope() override {} |
| 61 void didTerminateWorkerThread() override {} | 55 void didTerminateWorkerThread() override {} |
| 62 | 56 |
| 63 ExecutionContext* getExecutionContext() override { | |
| 64 return m_executionContext.get(); | |
| 65 } | |
| 66 | |
| 67 private: | 57 private: |
| 68 TestCompositorWorkerObjectProxy(ExecutionContext* context) | 58 TestCompositorWorkerObjectProxy() |
| 69 : InProcessWorkerObjectProxy(nullptr), | 59 : InProcessWorkerObjectProxy(nullptr, |
| 70 m_executionContext(context), | 60 ParentFrameTaskRunners::create(nullptr)) {} |
| 71 m_parentFrameTaskRunners(ParentFrameTaskRunners::create(nullptr)) {} | |
| 72 | |
| 73 Persistent<ExecutionContext> m_executionContext; | |
| 74 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | |
| 75 }; | 61 }; |
| 76 | 62 |
| 77 class TestCompositorProxyClient | 63 class TestCompositorProxyClient |
| 78 : public GarbageCollected<TestCompositorProxyClient>, | 64 : public GarbageCollected<TestCompositorProxyClient>, |
| 79 public CompositorProxyClient { | 65 public CompositorProxyClient { |
| 80 USING_GARBAGE_COLLECTED_MIXIN(TestCompositorProxyClient); | 66 USING_GARBAGE_COLLECTED_MIXIN(TestCompositorProxyClient); |
| 81 | 67 |
| 82 public: | 68 public: |
| 83 TestCompositorProxyClient() {} | 69 TestCompositorProxyClient() {} |
| 84 | 70 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 104 std::unique_ptr<WebThread> m_thread; | 90 std::unique_ptr<WebThread> m_thread; |
| 105 TestingCompositorSupport m_compositorSupport; | 91 TestingCompositorSupport m_compositorSupport; |
| 106 }; | 92 }; |
| 107 | 93 |
| 108 } // namespace | 94 } // namespace |
| 109 | 95 |
| 110 class CompositorWorkerThreadTest : public ::testing::Test { | 96 class CompositorWorkerThreadTest : public ::testing::Test { |
| 111 public: | 97 public: |
| 112 void SetUp() override { | 98 void SetUp() override { |
| 113 CompositorWorkerThread::createSharedBackingThreadForTest(); | 99 CompositorWorkerThread::createSharedBackingThreadForTest(); |
| 114 m_page = DummyPageHolder::create(); | 100 m_objectProxy = TestCompositorWorkerObjectProxy::create(); |
| 115 m_objectProxy = | |
| 116 TestCompositorWorkerObjectProxy::create(&m_page->document()); | |
| 117 m_securityOrigin = | 101 m_securityOrigin = |
| 118 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); | 102 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); |
| 119 } | 103 } |
| 120 | 104 |
| 121 void TearDown() override { | 105 void TearDown() override { |
| 122 m_page.reset(); | |
| 123 CompositorWorkerThread::clearSharedBackingThread(); | 106 CompositorWorkerThread::clearSharedBackingThread(); |
| 124 } | 107 } |
| 125 | 108 |
| 126 std::unique_ptr<CompositorWorkerThread> createCompositorWorker() { | 109 std::unique_ptr<CompositorWorkerThread> createCompositorWorker() { |
| 127 std::unique_ptr<CompositorWorkerThread> workerThread = | 110 std::unique_ptr<CompositorWorkerThread> workerThread = |
| 128 CompositorWorkerThread::create(nullptr, *m_objectProxy, 0); | 111 CompositorWorkerThread::create(nullptr, *m_objectProxy, 0); |
| 129 WorkerClients* clients = WorkerClients::create(); | 112 WorkerClients* clients = WorkerClients::create(); |
| 130 provideCompositorProxyClientTo(clients, new TestCompositorProxyClient); | 113 provideCompositorProxyClientTo(clients, new TestCompositorProxyClient); |
| 131 workerThread->start(WorkerThreadStartupData::create( | 114 workerThread->start(WorkerThreadStartupData::create( |
| 132 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", | 115 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", |
| (...skipping 18 matching lines...) Expand all Loading... |
| 151 private: | 134 private: |
| 152 void executeScriptInWorker(WorkerThread* worker, WaitableEvent* waitEvent) { | 135 void executeScriptInWorker(WorkerThread* worker, WaitableEvent* waitEvent) { |
| 153 WorkerOrWorkletScriptController* scriptController = | 136 WorkerOrWorkletScriptController* scriptController = |
| 154 worker->globalScope()->scriptController(); | 137 worker->globalScope()->scriptController(); |
| 155 bool evaluateResult = scriptController->evaluate( | 138 bool evaluateResult = scriptController->evaluate( |
| 156 ScriptSourceCode("var counter = 0; ++counter;")); | 139 ScriptSourceCode("var counter = 0; ++counter;")); |
| 157 DCHECK(evaluateResult); | 140 DCHECK(evaluateResult); |
| 158 waitEvent->signal(); | 141 waitEvent->signal(); |
| 159 } | 142 } |
| 160 | 143 |
| 161 std::unique_ptr<DummyPageHolder> m_page; | |
| 162 RefPtr<SecurityOrigin> m_securityOrigin; | 144 RefPtr<SecurityOrigin> m_securityOrigin; |
| 163 std::unique_ptr<InProcessWorkerObjectProxy> m_objectProxy; | 145 std::unique_ptr<InProcessWorkerObjectProxy> m_objectProxy; |
| 164 CompositorWorkerTestPlatform m_testPlatform; | 146 CompositorWorkerTestPlatform m_testPlatform; |
| 165 }; | 147 }; |
| 166 | 148 |
| 167 TEST_F(CompositorWorkerThreadTest, Basic) { | 149 TEST_F(CompositorWorkerThreadTest, Basic) { |
| 168 std::unique_ptr<CompositorWorkerThread> compositorWorker = | 150 std::unique_ptr<CompositorWorkerThread> compositorWorker = |
| 169 createCompositorWorker(); | 151 createCompositorWorker(); |
| 170 checkWorkerCanExecuteScript(compositorWorker.get()); | 152 checkWorkerCanExecuteScript(compositorWorker.get()); |
| 171 compositorWorker->terminateAndWait(); | 153 compositorWorker->terminateAndWait(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 ASSERT_TRUE(secondIsolate); | 235 ASSERT_TRUE(secondIsolate); |
| 254 EXPECT_EQ(firstIsolate, secondIsolate); | 236 EXPECT_EQ(firstIsolate, secondIsolate); |
| 255 | 237 |
| 256 // Verify that the isolate can run some scripts correctly in the second | 238 // Verify that the isolate can run some scripts correctly in the second |
| 257 // worker. | 239 // worker. |
| 258 checkWorkerCanExecuteScript(secondWorker.get()); | 240 checkWorkerCanExecuteScript(secondWorker.get()); |
| 259 secondWorker->terminateAndWait(); | 241 secondWorker->terminateAndWait(); |
| 260 } | 242 } |
| 261 | 243 |
| 262 } // namespace blink | 244 } // namespace blink |
| OLD | NEW |