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

Side by Side Diff: third_party/WebKit/Source/core/workers/ThreadedWorkletTest.cpp

Issue 2718643002: Worker: Pass ParentFrameTaskRunners via WorkerThread::start() instead of the ctor (Closed)
Patch Set: Created 3 years, 9 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 "core/inspector/ConsoleMessageStorage.h" 5 #include "core/inspector/ConsoleMessageStorage.h"
6 #include "core/testing/DummyPageHolder.h" 6 #include "core/testing/DummyPageHolder.h"
7 #include "core/workers/ThreadedWorkletGlobalScope.h" 7 #include "core/workers/ThreadedWorkletGlobalScope.h"
8 #include "core/workers/ThreadedWorkletMessagingProxy.h" 8 #include "core/workers/ThreadedWorkletMessagingProxy.h"
9 #include "core/workers/ThreadedWorkletObjectProxy.h" 9 #include "core/workers/ThreadedWorkletObjectProxy.h"
10 #include "core/workers/WorkerInspectorProxy.h" 10 #include "core/workers/WorkerInspectorProxy.h"
11 #include "core/workers/WorkerThread.h" 11 #include "core/workers/WorkerThread.h"
12 #include "core/workers/WorkerThreadStartupData.h" 12 #include "core/workers/WorkerThreadStartupData.h"
13 #include "core/workers/WorkerThreadTestHelper.h" 13 #include "core/workers/WorkerThreadTestHelper.h"
14 #include "core/workers/WorkletThreadHolder.h" 14 #include "core/workers/WorkletThreadHolder.h"
15 #include "platform/CrossThreadFunctional.h" 15 #include "platform/CrossThreadFunctional.h"
16 #include "platform/testing/UnitTestHelpers.h" 16 #include "platform/testing/UnitTestHelpers.h"
17 #include "platform/weborigin/SecurityOrigin.h" 17 #include "platform/weborigin/SecurityOrigin.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace blink { 20 namespace blink {
21 21
22 class ThreadedWorkletThreadForTest : public WorkerThread { 22 class ThreadedWorkletThreadForTest : public WorkerThread {
23 public: 23 public:
24 ThreadedWorkletThreadForTest( 24 ThreadedWorkletThreadForTest(
25 WorkerLoaderProxyProvider* workerLoaderProxyProvider, 25 WorkerLoaderProxyProvider* workerLoaderProxyProvider,
26 WorkerReportingProxy& workerReportingProxy, 26 WorkerReportingProxy& workerReportingProxy)
27 ParentFrameTaskRunners* parentFrameTaskRunners)
28 : WorkerThread(WorkerLoaderProxy::create(workerLoaderProxyProvider), 27 : WorkerThread(WorkerLoaderProxy::create(workerLoaderProxyProvider),
29 workerReportingProxy, 28 workerReportingProxy) {}
30 parentFrameTaskRunners) {}
31 ~ThreadedWorkletThreadForTest() override{}; 29 ~ThreadedWorkletThreadForTest() override{};
32 30
33 WorkerBackingThread& workerBackingThread() override { 31 WorkerBackingThread& workerBackingThread() override {
34 auto workletThreadHolder = 32 auto workletThreadHolder =
35 WorkletThreadHolder<ThreadedWorkletThreadForTest>::getInstance(); 33 WorkletThreadHolder<ThreadedWorkletThreadForTest>::getInstance();
36 DCHECK(workletThreadHolder); 34 DCHECK(workletThreadHolder);
37 return *workletThreadHolder->thread(); 35 return *workletThreadHolder->thread();
38 } 36 }
39 37
40 void clearWorkerBackingThread() override {} 38 void clearWorkerBackingThread() override {}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 }; 86 };
89 87
90 class ThreadedWorkletMessagingProxyForTest 88 class ThreadedWorkletMessagingProxyForTest
91 : public ThreadedWorkletMessagingProxy { 89 : public ThreadedWorkletMessagingProxy {
92 public: 90 public:
93 ThreadedWorkletMessagingProxyForTest(ExecutionContext* executionContext) 91 ThreadedWorkletMessagingProxyForTest(ExecutionContext* executionContext)
94 : ThreadedWorkletMessagingProxy(executionContext) { 92 : ThreadedWorkletMessagingProxy(executionContext) {
95 m_mockWorkerLoaderProxyProvider = 93 m_mockWorkerLoaderProxyProvider =
96 WTF::makeUnique<MockWorkerLoaderProxyProvider>(); 94 WTF::makeUnique<MockWorkerLoaderProxyProvider>();
97 m_workerThread = WTF::makeUnique<ThreadedWorkletThreadForTest>( 95 m_workerThread = WTF::makeUnique<ThreadedWorkletThreadForTest>(
98 m_mockWorkerLoaderProxyProvider.get(), workletObjectProxy(), 96 m_mockWorkerLoaderProxyProvider.get(), workletObjectProxy());
99 getParentFrameTaskRunners());
100 ThreadedWorkletThreadForTest::ensureSharedBackingThread(); 97 ThreadedWorkletThreadForTest::ensureSharedBackingThread();
101 } 98 }
102 99
103 ~ThreadedWorkletMessagingProxyForTest() override { 100 ~ThreadedWorkletMessagingProxyForTest() override {
104 m_workerThread->workerLoaderProxy()->detachProvider( 101 m_workerThread->workerLoaderProxy()->detachProvider(
105 m_mockWorkerLoaderProxyProvider.get()); 102 m_mockWorkerLoaderProxyProvider.get());
106 m_workerThread->terminateAndWait(); 103 m_workerThread->terminateAndWait();
107 ThreadedWorkletThreadForTest::clearSharedBackingThread(); 104 ThreadedWorkletThreadForTest::clearSharedBackingThread();
108 }; 105 };
109 106
110 void start() { 107 void start() {
111 KURL scriptURL(ParsedURLString, "http://fake.url/"); 108 KURL scriptURL(ParsedURLString, "http://fake.url/");
112 std::unique_ptr<Vector<char>> cachedMetaData = nullptr; 109 std::unique_ptr<Vector<char>> cachedMetaData = nullptr;
113 Vector<CSPHeaderAndType> contentSecurityPolicyHeaders; 110 Vector<CSPHeaderAndType> contentSecurityPolicyHeaders;
114 String referrerPolicy = ""; 111 String referrerPolicy = "";
115 m_securityOrigin = SecurityOrigin::create(scriptURL); 112 m_securityOrigin = SecurityOrigin::create(scriptURL);
116 WorkerClients* workerClients = nullptr; 113 WorkerClients* workerClients = nullptr;
117 Vector<String> originTrialTokens; 114 Vector<String> originTrialTokens;
118 std::unique_ptr<WorkerSettings> workerSettings = nullptr; 115 std::unique_ptr<WorkerSettings> workerSettings = nullptr;
119 m_workerThread->start(WorkerThreadStartupData::create( 116 m_workerThread->start(
120 scriptURL, "fake user agent", "// fake source code", 117 WorkerThreadStartupData::create(
121 std::move(cachedMetaData), DontPauseWorkerGlobalScopeOnStart, 118 scriptURL, "fake user agent", "// fake source code",
122 &contentSecurityPolicyHeaders, referrerPolicy, m_securityOrigin.get(), 119 std::move(cachedMetaData), DontPauseWorkerGlobalScopeOnStart,
123 workerClients, WebAddressSpaceLocal, &originTrialTokens, 120 &contentSecurityPolicyHeaders, referrerPolicy,
124 std::move(workerSettings), WorkerV8Settings::Default())); 121 m_securityOrigin.get(), workerClients, WebAddressSpaceLocal,
122 &originTrialTokens, std::move(workerSettings),
123 WorkerV8Settings::Default()),
124 getParentFrameTaskRunners());
125 workerInspectorProxy()->workerThreadCreated( 125 workerInspectorProxy()->workerThreadCreated(
126 toDocument(getExecutionContext()), m_workerThread.get(), scriptURL); 126 toDocument(getExecutionContext()), m_workerThread.get(), scriptURL);
127 } 127 }
128 128
129 protected: 129 protected:
130 std::unique_ptr<WorkerThread> createWorkerThread(double originTime) final { 130 std::unique_ptr<WorkerThread> createWorkerThread(double originTime) final {
131 NOTREACHED(); 131 NOTREACHED();
132 return nullptr; 132 return nullptr;
133 } 133 }
134 134
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 EXPECT_FALSE(UseCounter::isCounted(document(), feature2)); 188 EXPECT_FALSE(UseCounter::isCounted(document(), feature2));
189 workerThread()->postTask( 189 workerThread()->postTask(
190 BLINK_FROM_HERE, 190 BLINK_FROM_HERE,
191 crossThreadBind(&ThreadedWorkletThreadForTest::countDeprecation, 191 crossThreadBind(&ThreadedWorkletThreadForTest::countDeprecation,
192 crossThreadUnretained(workerThread()), feature2)); 192 crossThreadUnretained(workerThread()), feature2));
193 testing::enterRunLoop(); 193 testing::enterRunLoop();
194 EXPECT_TRUE(UseCounter::isCounted(document(), feature2)); 194 EXPECT_TRUE(UseCounter::isCounted(document(), feature2));
195 } 195 }
196 196
197 } // namespace blink 197 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698