Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: third_party/WebKit/Source/core/workers/WorkerThreadTestHelper.h

Issue 2116113002: [worklets] Make WorkerThread handle both Worker and Worklet global scopes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "bindings/core/v8/SourceLocation.h" 5 #include "bindings/core/v8/SourceLocation.h"
6 #include "bindings/core/v8/V8CacheOptions.h" 6 #include "bindings/core/v8/V8CacheOptions.h"
7 #include "bindings/core/v8/V8GCController.h" 7 #include "bindings/core/v8/V8GCController.h"
8 #include "core/frame/csp/ContentSecurityPolicy.h" 8 #include "core/frame/csp/ContentSecurityPolicy.h"
9 #include "core/inspector/ConsoleMessage.h" 9 #include "core/inspector/ConsoleMessage.h"
10 #include "core/workers/WorkerBackingThread.h" 10 #include "core/workers/WorkerBackingThread.h"
11 #include "core/workers/WorkerClients.h" 11 #include "core/workers/WorkerClients.h"
12 #include "core/workers/WorkerGlobalScope.h"
12 #include "core/workers/WorkerLoaderProxy.h" 13 #include "core/workers/WorkerLoaderProxy.h"
13 #include "core/workers/WorkerReportingProxy.h" 14 #include "core/workers/WorkerReportingProxy.h"
14 #include "core/workers/WorkerThread.h" 15 #include "core/workers/WorkerThread.h"
15 #include "core/workers/WorkerThreadLifecycleObserver.h" 16 #include "core/workers/WorkerThreadLifecycleObserver.h"
16 #include "core/workers/WorkerThreadStartupData.h" 17 #include "core/workers/WorkerThreadStartupData.h"
17 #include "platform/CrossThreadFunctional.h" 18 #include "platform/CrossThreadFunctional.h"
18 #include "platform/WaitableEvent.h" 19 #include "platform/WaitableEvent.h"
19 #include "platform/WebThreadSupportingGC.h" 20 #include "platform/WebThreadSupportingGC.h"
20 #include "platform/heap/Handle.h" 21 #include "platform/heap/Handle.h"
21 #include "platform/network/ContentSecurityPolicyParsers.h" 22 #include "platform/network/ContentSecurityPolicyParsers.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 ~MockWorkerReportingProxy() override { } 56 ~MockWorkerReportingProxy() override { }
56 57
57 MOCK_METHOD2(reportExceptionMock, void(const String& errorMessage, SourceLoc ation*)); 58 MOCK_METHOD2(reportExceptionMock, void(const String& errorMessage, SourceLoc ation*));
58 void reportException(const String& errorMessage, std::unique_ptr<SourceLocat ion> location) 59 void reportException(const String& errorMessage, std::unique_ptr<SourceLocat ion> location)
59 { 60 {
60 reportExceptionMock(errorMessage, location.get()); 61 reportExceptionMock(errorMessage, location.get());
61 } 62 }
62 MOCK_METHOD1(reportConsoleMessage, void(ConsoleMessage*)); 63 MOCK_METHOD1(reportConsoleMessage, void(ConsoleMessage*));
63 MOCK_METHOD1(postMessageToPageInspector, void(const String&)); 64 MOCK_METHOD1(postMessageToPageInspector, void(const String&));
64 MOCK_METHOD1(didEvaluateWorkerScript, void(bool success)); 65 MOCK_METHOD1(didEvaluateWorkerScript, void(bool success));
65 MOCK_METHOD1(workerGlobalScopeStarted, void(WorkerGlobalScope*)); 66 MOCK_METHOD1(workerGlobalScopeStarted, void(WorkerOrWorkletGlobalScope*));
66 MOCK_METHOD0(workerGlobalScopeClosed, void()); 67 MOCK_METHOD0(workerGlobalScopeClosed, void());
67 MOCK_METHOD0(workerThreadTerminated, void()); 68 MOCK_METHOD0(workerThreadTerminated, void());
68 MOCK_METHOD0(willDestroyWorkerGlobalScope, void()); 69 MOCK_METHOD0(willDestroyWorkerGlobalScope, void());
69 }; 70 };
70 71
71 class MockWorkerThreadLifecycleObserver final : public GarbageCollectedFinalized <MockWorkerThreadLifecycleObserver>, public WorkerThreadLifecycleObserver { 72 class MockWorkerThreadLifecycleObserver final : public GarbageCollectedFinalized <MockWorkerThreadLifecycleObserver>, public WorkerThreadLifecycleObserver {
72 USING_GARBAGE_COLLECTED_MIXIN(MockWorkerThreadLifecycleObserver); 73 USING_GARBAGE_COLLECTED_MIXIN(MockWorkerThreadLifecycleObserver);
73 WTF_MAKE_NONCOPYABLE(MockWorkerThreadLifecycleObserver); 74 WTF_MAKE_NONCOPYABLE(MockWorkerThreadLifecycleObserver);
74 public: 75 public:
75 explicit MockWorkerThreadLifecycleObserver(WorkerThreadLifecycleContext* con text) 76 explicit MockWorkerThreadLifecycleObserver(WorkerThreadLifecycleContext* con text)
76 : WorkerThreadLifecycleObserver(context) { } 77 : WorkerThreadLifecycleObserver(context) { }
77 78
78 MOCK_METHOD0(contextDestroyed, void()); 79 MOCK_METHOD0(contextDestroyed, void());
79 }; 80 };
80 81
81 class WorkerThreadForTest : public WorkerThread { 82 class WorkerThreadForTest : public WorkerThread {
82 public: 83 public:
83 WorkerThreadForTest( 84 WorkerThreadForTest(
84 WorkerLoaderProxyProvider* mockWorkerLoaderProxyProvider, 85 WorkerLoaderProxyProvider* mockWorkerLoaderProxyProvider,
85 WorkerReportingProxy& mockWorkerReportingProxy) 86 WorkerReportingProxy& mockWorkerReportingProxy)
86 : WorkerThread(WorkerLoaderProxy::create(mockWorkerLoaderProxyProvider), mockWorkerReportingProxy) 87 : WorkerThread(WorkerLoaderProxy::create(mockWorkerLoaderProxyProvider), mockWorkerReportingProxy)
87 , m_workerBackingThread(WorkerBackingThread::createForTest("Test thread" )) 88 , m_workerBackingThread(WorkerBackingThread::createForTest("Test thread" ))
88 , m_scriptLoadedEvent(wrapUnique(new WaitableEvent())) 89 , m_scriptLoadedEvent(wrapUnique(new WaitableEvent()))
89 { 90 {
90 } 91 }
91 92
92 ~WorkerThreadForTest() override { } 93 ~WorkerThreadForTest() override { }
93 94
94 WorkerBackingThread& workerBackingThread() override { return *m_workerBackin gThread; } 95 WorkerBackingThread& workerBackingThread() override { return *m_workerBackin gThread; }
96 ConsoleMessageStorage* consoleMessageStorage() final { return toWorkerGlobal Scope(globalScope())->consoleMessageStorage(); }
95 97
96 WorkerGlobalScope* createWorkerGlobalScope(std::unique_ptr<WorkerThreadStart upData>) override; 98 WorkerOrWorkletGlobalScope* createWorkerGlobalScope(std::unique_ptr<WorkerTh readStartupData>) override;
97 99
98 void waitUntilScriptLoaded() 100 void waitUntilScriptLoaded()
99 { 101 {
100 m_scriptLoadedEvent->wait(); 102 m_scriptLoadedEvent->wait();
101 } 103 }
102 104
103 void scriptLoaded() 105 void scriptLoaded()
104 { 106 {
105 m_scriptLoadedEvent->signal(); 107 m_scriptLoadedEvent->signal();
106 } 108 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 167 }
166 168
167 void exceptionThrown(const String&, std::unique_ptr<SourceLocation>) overrid e 169 void exceptionThrown(const String&, std::unique_ptr<SourceLocation>) overrid e
168 { 170 {
169 } 171 }
170 172
171 private: 173 private:
172 WorkerThreadForTest* m_thread; 174 WorkerThreadForTest* m_thread;
173 }; 175 };
174 176
175 inline WorkerGlobalScope* WorkerThreadForTest::createWorkerGlobalScope(std::uniq ue_ptr<WorkerThreadStartupData> startupData) 177 inline WorkerOrWorkletGlobalScope* WorkerThreadForTest::createWorkerGlobalScope( std::unique_ptr<WorkerThreadStartupData> startupData)
176 { 178 {
177 return new FakeWorkerGlobalScope(startupData->m_scriptURL, startupData->m_us erAgent, this, std::move(startupData->m_starterOriginPrivilegeData), std::move(s tartupData->m_workerClients)); 179 return new FakeWorkerGlobalScope(startupData->m_scriptURL, startupData->m_us erAgent, this, std::move(startupData->m_starterOriginPrivilegeData), std::move(s tartupData->m_workerClients));
178 } 180 }
179 181
180 } // namespace blink 182 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698