| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "wtf/PtrUtil.h" | 28 #include "wtf/PtrUtil.h" |
| 29 #include <memory> | 29 #include <memory> |
| 30 | 30 |
| 31 namespace blink { | 31 namespace blink { |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // A null InProcessWorkerObjectProxy, supplied when creating | 34 // A null InProcessWorkerObjectProxy, supplied when creating |
| 35 // CompositorWorkerThreads. | 35 // CompositorWorkerThreads. |
| 36 class TestCompositorWorkerObjectProxy : public InProcessWorkerObjectProxy { | 36 class TestCompositorWorkerObjectProxy : public InProcessWorkerObjectProxy { |
| 37 public: | 37 public: |
| 38 static std::unique_ptr<TestCompositorWorkerObjectProxy> create() { | 38 static std::unique_ptr<TestCompositorWorkerObjectProxy> create( |
| 39 return WTF::wrapUnique(new TestCompositorWorkerObjectProxy()); | 39 ParentFrameTaskRunners* parentFrameTaskRunners) { |
| 40 return WTF::wrapUnique( |
| 41 new TestCompositorWorkerObjectProxy(parentFrameTaskRunners)); |
| 40 } | 42 } |
| 41 | 43 |
| 42 // (Empty) WorkerReportingProxy implementation: | 44 // (Empty) WorkerReportingProxy implementation: |
| 43 virtual void dispatchErrorEvent(const String& errorMessage, | 45 virtual void dispatchErrorEvent(const String& errorMessage, |
| 44 std::unique_ptr<SourceLocation>, | 46 std::unique_ptr<SourceLocation>, |
| 45 int exceptionId) {} | 47 int exceptionId) {} |
| 46 void reportConsoleMessage(MessageSource, | 48 void reportConsoleMessage(MessageSource, |
| 47 MessageLevel, | 49 MessageLevel, |
| 48 const String& message, | 50 const String& message, |
| 49 SourceLocation*) override {} | 51 SourceLocation*) override {} |
| 50 void postMessageToPageInspector(const String&) override {} | 52 void postMessageToPageInspector(const String&) override {} |
| 51 void didCreateWorkerGlobalScope(WorkerOrWorkletGlobalScope*) override {} | 53 void didCreateWorkerGlobalScope(WorkerOrWorkletGlobalScope*) override {} |
| 52 void didEvaluateWorkerScript(bool success) override {} | 54 void didEvaluateWorkerScript(bool success) override {} |
| 53 void didCloseWorkerGlobalScope() override {} | 55 void didCloseWorkerGlobalScope() override {} |
| 54 void willDestroyWorkerGlobalScope() override {} | 56 void willDestroyWorkerGlobalScope() override {} |
| 55 void didTerminateWorkerThread() override {} | 57 void didTerminateWorkerThread() override {} |
| 56 | 58 |
| 57 private: | 59 private: |
| 58 TestCompositorWorkerObjectProxy() | 60 explicit TestCompositorWorkerObjectProxy( |
| 59 : InProcessWorkerObjectProxy(nullptr, | 61 ParentFrameTaskRunners* parentFrameTaskRunners) |
| 60 ParentFrameTaskRunners::create(nullptr)) {} | 62 : InProcessWorkerObjectProxy(nullptr, parentFrameTaskRunners) {} |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 class TestCompositorProxyClient | 65 class TestCompositorProxyClient |
| 64 : public GarbageCollected<TestCompositorProxyClient>, | 66 : public GarbageCollected<TestCompositorProxyClient>, |
| 65 public CompositorProxyClient { | 67 public CompositorProxyClient { |
| 66 USING_GARBAGE_COLLECTED_MIXIN(TestCompositorProxyClient); | 68 USING_GARBAGE_COLLECTED_MIXIN(TestCompositorProxyClient); |
| 67 | 69 |
| 68 public: | 70 public: |
| 69 TestCompositorProxyClient() {} | 71 TestCompositorProxyClient() {} |
| 70 | 72 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 90 std::unique_ptr<WebThread> m_thread; | 92 std::unique_ptr<WebThread> m_thread; |
| 91 TestingCompositorSupport m_compositorSupport; | 93 TestingCompositorSupport m_compositorSupport; |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 } // namespace | 96 } // namespace |
| 95 | 97 |
| 96 class CompositorWorkerThreadTest : public ::testing::Test { | 98 class CompositorWorkerThreadTest : public ::testing::Test { |
| 97 public: | 99 public: |
| 98 void SetUp() override { | 100 void SetUp() override { |
| 99 CompositorWorkerThread::createSharedBackingThreadForTest(); | 101 CompositorWorkerThread::createSharedBackingThreadForTest(); |
| 100 m_objectProxy = TestCompositorWorkerObjectProxy::create(); | 102 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr); |
| 103 m_objectProxy = |
| 104 TestCompositorWorkerObjectProxy::create(m_parentFrameTaskRunners.get()); |
| 101 m_securityOrigin = | 105 m_securityOrigin = |
| 102 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); | 106 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); |
| 103 } | 107 } |
| 104 | 108 |
| 105 void TearDown() override { | 109 void TearDown() override { |
| 106 CompositorWorkerThread::clearSharedBackingThread(); | 110 CompositorWorkerThread::clearSharedBackingThread(); |
| 107 } | 111 } |
| 108 | 112 |
| 109 std::unique_ptr<CompositorWorkerThread> createCompositorWorker() { | 113 std::unique_ptr<CompositorWorkerThread> createCompositorWorker() { |
| 110 std::unique_ptr<CompositorWorkerThread> workerThread = | 114 std::unique_ptr<CompositorWorkerThread> workerThread = |
| 111 CompositorWorkerThread::create(nullptr, *m_objectProxy, 0); | 115 CompositorWorkerThread::create(nullptr, *m_objectProxy, |
| 116 m_parentFrameTaskRunners.get(), 0); |
| 112 WorkerClients* clients = WorkerClients::create(); | 117 WorkerClients* clients = WorkerClients::create(); |
| 113 provideCompositorProxyClientTo(clients, new TestCompositorProxyClient); | 118 provideCompositorProxyClientTo(clients, new TestCompositorProxyClient); |
| 114 workerThread->start(WorkerThreadStartupData::create( | 119 workerThread->start(WorkerThreadStartupData::create( |
| 115 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", | 120 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", |
| 116 "//fake source code", nullptr, DontPauseWorkerGlobalScopeOnStart, | 121 "//fake source code", nullptr, DontPauseWorkerGlobalScopeOnStart, |
| 117 nullptr, "", m_securityOrigin.get(), clients, WebAddressSpaceLocal, | 122 nullptr, "", m_securityOrigin.get(), clients, WebAddressSpaceLocal, |
| 118 nullptr, nullptr, WorkerV8Settings::Default(), | 123 nullptr, nullptr, WorkerV8Settings::Default(), |
| 119 false /* inspectorNetworkCapability */)); | 124 false /* inspectorNetworkCapability */)); |
| 120 return workerThread; | 125 return workerThread; |
| 121 } | 126 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 137 WorkerOrWorkletScriptController* scriptController = | 142 WorkerOrWorkletScriptController* scriptController = |
| 138 worker->globalScope()->scriptController(); | 143 worker->globalScope()->scriptController(); |
| 139 bool evaluateResult = scriptController->evaluate( | 144 bool evaluateResult = scriptController->evaluate( |
| 140 ScriptSourceCode("var counter = 0; ++counter;")); | 145 ScriptSourceCode("var counter = 0; ++counter;")); |
| 141 DCHECK(evaluateResult); | 146 DCHECK(evaluateResult); |
| 142 waitEvent->signal(); | 147 waitEvent->signal(); |
| 143 } | 148 } |
| 144 | 149 |
| 145 RefPtr<SecurityOrigin> m_securityOrigin; | 150 RefPtr<SecurityOrigin> m_securityOrigin; |
| 146 std::unique_ptr<InProcessWorkerObjectProxy> m_objectProxy; | 151 std::unique_ptr<InProcessWorkerObjectProxy> m_objectProxy; |
| 152 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; |
| 147 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> m_platform; | 153 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> m_platform; |
| 148 }; | 154 }; |
| 149 | 155 |
| 150 TEST_F(CompositorWorkerThreadTest, Basic) { | 156 TEST_F(CompositorWorkerThreadTest, Basic) { |
| 151 std::unique_ptr<CompositorWorkerThread> compositorWorker = | 157 std::unique_ptr<CompositorWorkerThread> compositorWorker = |
| 152 createCompositorWorker(); | 158 createCompositorWorker(); |
| 153 checkWorkerCanExecuteScript(compositorWorker.get()); | 159 checkWorkerCanExecuteScript(compositorWorker.get()); |
| 154 compositorWorker->terminateAndWait(); | 160 compositorWorker->terminateAndWait(); |
| 155 } | 161 } |
| 156 | 162 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 ASSERT_TRUE(secondIsolate); | 242 ASSERT_TRUE(secondIsolate); |
| 237 EXPECT_EQ(firstIsolate, secondIsolate); | 243 EXPECT_EQ(firstIsolate, secondIsolate); |
| 238 | 244 |
| 239 // Verify that the isolate can run some scripts correctly in the second | 245 // Verify that the isolate can run some scripts correctly in the second |
| 240 // worker. | 246 // worker. |
| 241 checkWorkerCanExecuteScript(secondWorker.get()); | 247 checkWorkerCanExecuteScript(secondWorker.get()); |
| 242 secondWorker->terminateAndWait(); | 248 secondWorker->terminateAndWait(); |
| 243 } | 249 } |
| 244 | 250 |
| 245 } // namespace blink | 251 } // namespace blink |
| OLD | NEW |