| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/compositorworker/CompositorWorkerManager.h" | 6 #include "modules/compositorworker/CompositorWorkerManager.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptSourceCode.h" | 8 #include "bindings/core/v8/ScriptSourceCode.h" |
| 9 #include "core/inspector/ConsoleMessage.h" |
| 9 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
| 10 #include "core/workers/WorkerLoaderProxy.h" | 11 #include "core/workers/WorkerLoaderProxy.h" |
| 11 #include "core/workers/WorkerObjectProxy.h" | 12 #include "core/workers/WorkerObjectProxy.h" |
| 12 #include "core/workers/WorkerReportingProxy.h" | |
| 13 #include "core/workers/WorkerThreadStartupData.h" | 13 #include "core/workers/WorkerThreadStartupData.h" |
| 14 #include "modules/compositorworker/CompositorWorkerThread.h" | 14 #include "modules/compositorworker/CompositorWorkerThread.h" |
| 15 #include "platform/NotImplemented.h" | 15 #include "platform/NotImplemented.h" |
| 16 #include "platform/ThreadSafeFunctional.h" | 16 #include "platform/ThreadSafeFunctional.h" |
| 17 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
| 18 #include "public/platform/WebWaitableEvent.h" | 18 #include "public/platform/WebWaitableEvent.h" |
| 19 #include <gtest/gtest.h> | 19 #include <gtest/gtest.h> |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 namespace { | 22 namespace { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 { | 46 { |
| 47 CompositorWorkerThread::terminateV8Execution(); | 47 CompositorWorkerThread::terminateV8Execution(); |
| 48 if (m_v8TerminationCallback) | 48 if (m_v8TerminationCallback) |
| 49 (*m_v8TerminationCallback)(); | 49 (*m_v8TerminationCallback)(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 WebWaitableEvent* m_startEvent; | 52 WebWaitableEvent* m_startEvent; |
| 53 OwnPtr<Function<void()>> m_v8TerminationCallback; | 53 OwnPtr<Function<void()>> m_v8TerminationCallback; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // A null WorkerObjectProxy, supplied when creating CompositorWorkerThreads. |
| 57 class TestCompositorWorkerObjectProxy : public WorkerObjectProxy { |
| 58 public: |
| 59 static PassOwnPtr<TestCompositorWorkerObjectProxy> create(ExecutionContext*
context) |
| 60 { |
| 61 return adoptPtr(new TestCompositorWorkerObjectProxy(context)); |
| 62 } |
| 63 |
| 64 // (Empty) WorkerReportingProxy implementation: |
| 65 virtual void reportException(const String& errorMessage, int lineNumber, int
columnNumber, const String& sourceURL, int exceptionId) { } |
| 66 virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) ov
erride { } |
| 67 virtual void postMessageToPageInspector(const String&) override { } |
| 68 virtual void postWorkerConsoleAgentEnabled() override { } |
| 69 |
| 70 virtual void didEvaluateWorkerScript(bool success) override { } |
| 71 virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override { } |
| 72 virtual void workerGlobalScopeClosed() override { } |
| 73 virtual void workerThreadTerminated() override { } |
| 74 virtual void willDestroyWorkerGlobalScope() override { } |
| 75 private: |
| 76 TestCompositorWorkerObjectProxy(ExecutionContext* context) |
| 77 : WorkerObjectProxy(context, nullptr) |
| 78 { |
| 79 } |
| 80 }; |
| 81 |
| 56 } // namespace | 82 } // namespace |
| 57 | 83 |
| 58 class CompositorWorkerManagerTest : public testing::Test { | 84 class CompositorWorkerManagerTest : public testing::Test { |
| 59 public: | 85 public: |
| 60 void SetUp() override | 86 void SetUp() override |
| 61 { | 87 { |
| 62 m_page = DummyPageHolder::create(); | 88 m_page = DummyPageHolder::create(); |
| 63 m_objectProxy = WorkerObjectProxy::create(&m_page->document(), nullptr); | 89 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen
t()); |
| 64 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http://
fake.url/")); | 90 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http://
fake.url/")); |
| 65 } | 91 } |
| 66 | 92 |
| 67 void TearDown() override | 93 void TearDown() override |
| 68 { | 94 { |
| 69 ASSERT(!managerHasThread()); | 95 ASSERT(!managerHasThread()); |
| 70 ASSERT(!managerHasIsolate()); | 96 ASSERT(!managerHasIsolate()); |
| 71 m_page.clear(); | 97 m_page.clear(); |
| 72 } | 98 } |
| 73 | 99 |
| 74 PassRefPtr<TestCompositorWorkerThread> createCompositorWorker(WebWaitableEve
nt* startEvent) | 100 PassRefPtr<TestCompositorWorkerThread> createCompositorWorker(WebWaitableEve
nt* startEvent) |
| 75 { | 101 { |
| 76 TestCompositorWorkerThread* workerThread = new TestCompositorWorkerThrea
d(nullptr, *m_objectProxy, 0, startEvent); | 102 TestCompositorWorkerThread* workerThread = new TestCompositorWorkerThrea
d(nullptr, *m_objectProxy, 0, startEvent); |
| 103 OwnPtrWillBeRawPtr<WorkerClients> clients = nullptr; |
| 77 workerThread->start(WorkerThreadStartupData::create( | 104 workerThread->start(WorkerThreadStartupData::create( |
| 78 KURL(ParsedURLString, "http://fake.url/"), | 105 KURL(ParsedURLString, "http://fake.url/"), |
| 79 "fake user agent", | 106 "fake user agent", |
| 80 "//fake source code", | 107 "//fake source code", |
| 81 nullptr, | 108 nullptr, |
| 82 DontPauseWorkerGlobalScopeOnStart, | 109 DontPauseWorkerGlobalScopeOnStart, |
| 83 adoptPtr(new Vector<CSPHeaderAndType>()), | 110 adoptPtr(new Vector<CSPHeaderAndType>()), |
| 84 m_securityOrigin.get(), | 111 m_securityOrigin.get(), |
| 85 WorkerClients::create(), | 112 clients.release(), |
| 86 V8CacheOptionsDefault)); | 113 V8CacheOptionsDefault)); |
| 87 return adoptRef(workerThread); | 114 return adoptRef(workerThread); |
| 88 } | 115 } |
| 89 | 116 |
| 90 void createWorkerAdapter(RefPtr<CompositorWorkerThread>* workerThread, WebWa
itableEvent* creationEvent) | 117 void createWorkerAdapter(RefPtr<CompositorWorkerThread>* workerThread, WebWa
itableEvent* creationEvent) |
| 91 { | 118 { |
| 92 *workerThread = createCompositorWorker(creationEvent); | 119 *workerThread = createCompositorWorker(creationEvent); |
| 93 } | 120 } |
| 94 | 121 |
| 95 // Attempts to run some simple script for |worker|. | 122 // Attempts to run some simple script for |worker|. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 v8::Isolate* secondIsolate = secondWorker->isolate(); | 250 v8::Isolate* secondIsolate = secondWorker->isolate(); |
| 224 ASSERT(secondIsolate); | 251 ASSERT(secondIsolate); |
| 225 EXPECT_EQ(firstIsolate, secondIsolate); | 252 EXPECT_EQ(firstIsolate, secondIsolate); |
| 226 | 253 |
| 227 // Verify that the isolate can run some scripts correctly in the second work
er. | 254 // Verify that the isolate can run some scripts correctly in the second work
er. |
| 228 checkWorkerCanExecuteScript(secondWorker.get()); | 255 checkWorkerCanExecuteScript(secondWorker.get()); |
| 229 secondWorker->terminateAndWait(); | 256 secondWorker->terminateAndWait(); |
| 230 } | 257 } |
| 231 | 258 |
| 232 } // namespace blink | 259 } // namespace blink |
| OLD | NEW |