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

Side by Side Diff: third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThreadTest.cpp

Issue 2066403003: Revert of Remove WorkerBackingThread::scriptCount (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThread.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/dom/CompositorProxyClient.h" 10 #include "core/dom/CompositorProxyClient.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 { 97 {
98 CompositorWorkerThread::createSharedBackingThreadForTest(); 98 CompositorWorkerThread::createSharedBackingThreadForTest();
99 m_page = DummyPageHolder::create(); 99 m_page = DummyPageHolder::create();
100 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen t()); 100 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen t());
101 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http:// fake.url/")); 101 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http:// fake.url/"));
102 } 102 }
103 103
104 void TearDown() override 104 void TearDown() override
105 { 105 {
106 m_page.reset(); 106 m_page.reset();
107 CompositorWorkerThread::terminateExecution();
107 CompositorWorkerThread::clearSharedBackingThread(); 108 CompositorWorkerThread::clearSharedBackingThread();
108 } 109 }
109 110
110 PassOwnPtr<CompositorWorkerThread> createCompositorWorker() 111 PassOwnPtr<CompositorWorkerThread> createCompositorWorker()
111 { 112 {
112 OwnPtr<CompositorWorkerThread> workerThread = CompositorWorkerThread::cr eate(nullptr, *m_objectProxy, 0); 113 OwnPtr<CompositorWorkerThread> workerThread = CompositorWorkerThread::cr eate(nullptr, *m_objectProxy, 0);
113 WorkerClients* clients = WorkerClients::create(); 114 WorkerClients* clients = WorkerClients::create();
114 provideCompositorProxyClientTo(clients, new TestCompositorProxyClient); 115 provideCompositorProxyClientTo(clients, new TestCompositorProxyClient);
115 workerThread->start(WorkerThreadStartupData::create( 116 workerThread->start(WorkerThreadStartupData::create(
116 KURL(ParsedURLString, "http://fake.url/"), 117 KURL(ParsedURLString, "http://fake.url/"),
(...skipping 15 matching lines...) Expand all
132 { 133 {
133 OwnPtr<WaitableEvent> waitEvent = adoptPtr(new WaitableEvent()); 134 OwnPtr<WaitableEvent> waitEvent = adoptPtr(new WaitableEvent());
134 worker->workerBackingThread().backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&CompositorWorkerThreadTest::executeScriptInWorker, AllowCrossThr eadAccess(this), 135 worker->workerBackingThread().backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&CompositorWorkerThreadTest::executeScriptInWorker, AllowCrossThr eadAccess(this),
135 AllowCrossThreadAccess(worker), AllowCrossThreadAccess(waitEvent.get ()))); 136 AllowCrossThreadAccess(worker), AllowCrossThreadAccess(waitEvent.get ())));
136 waitEvent->wait(); 137 waitEvent->wait();
137 } 138 }
138 139
139 private: 140 private:
140 void executeScriptInWorker(WorkerThread* worker, WaitableEvent* waitEvent) 141 void executeScriptInWorker(WorkerThread* worker, WaitableEvent* waitEvent)
141 { 142 {
143 EXPECT_GT(worker->workerBackingThread().workerScriptCount(), 0u);
142 WorkerOrWorkletScriptController* scriptController = worker->workerGlobal Scope()->scriptController(); 144 WorkerOrWorkletScriptController* scriptController = worker->workerGlobal Scope()->scriptController();
143 bool evaluateResult = scriptController->evaluate(ScriptSourceCode("var c ounter = 0; ++counter;")); 145 bool evaluateResult = scriptController->evaluate(ScriptSourceCode("var c ounter = 0; ++counter;"));
144 ASSERT_UNUSED(evaluateResult, evaluateResult); 146 ASSERT_UNUSED(evaluateResult, evaluateResult);
145 waitEvent->signal(); 147 waitEvent->signal();
146 } 148 }
147 149
148 OwnPtr<DummyPageHolder> m_page; 150 OwnPtr<DummyPageHolder> m_page;
149 RefPtr<SecurityOrigin> m_securityOrigin; 151 RefPtr<SecurityOrigin> m_securityOrigin;
150 OwnPtr<InProcessWorkerObjectProxy> m_objectProxy; 152 OwnPtr<InProcessWorkerObjectProxy> m_objectProxy;
151 CompositorWorkerTestPlatform m_testPlatform; 153 CompositorWorkerTestPlatform m_testPlatform;
(...skipping 11 matching lines...) Expand all
163 { 165 {
164 // Create the first worker and wait until it is initialized. 166 // Create the first worker and wait until it is initialized.
165 OwnPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(); 167 OwnPtr<CompositorWorkerThread> firstWorker = createCompositorWorker();
166 WebThreadSupportingGC* firstThread = &firstWorker->workerBackingThread().bac kingThread(); 168 WebThreadSupportingGC* firstThread = &firstWorker->workerBackingThread().bac kingThread();
167 checkWorkerCanExecuteScript(firstWorker.get()); 169 checkWorkerCanExecuteScript(firstWorker.get());
168 v8::Isolate* firstIsolate = firstWorker->isolate(); 170 v8::Isolate* firstIsolate = firstWorker->isolate();
169 ASSERT_TRUE(firstIsolate); 171 ASSERT_TRUE(firstIsolate);
170 172
171 // Create the second worker and immediately destroy the first worker. 173 // Create the second worker and immediately destroy the first worker.
172 OwnPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(); 174 OwnPtr<CompositorWorkerThread> secondWorker = createCompositorWorker();
173 // We don't use terminateAndWait here to avoid forcible termination. 175 firstWorker->terminateAndWait();
174 firstWorker->terminate();
175 firstWorker->waitForShutdownForTesting();
176 176
177 // Wait until the second worker is initialized. Verify that the second worke r is using the same 177 // Wait until the second worker is initialized. Verify that the second worke r is using the same
178 // thread and Isolate as the first worker. 178 // thread and Isolate as the first worker.
179 WebThreadSupportingGC* secondThread = &secondWorker->workerBackingThread().b ackingThread(); 179 WebThreadSupportingGC* secondThread = &secondWorker->workerBackingThread().b ackingThread();
180 ASSERT_EQ(firstThread, secondThread); 180 ASSERT_EQ(firstThread, secondThread);
181 181
182 v8::Isolate* secondIsolate = secondWorker->isolate(); 182 v8::Isolate* secondIsolate = secondWorker->isolate();
183 ASSERT_TRUE(secondIsolate); 183 ASSERT_TRUE(secondIsolate);
184 EXPECT_EQ(firstIsolate, secondIsolate); 184 EXPECT_EQ(firstIsolate, secondIsolate);
185 185
186 // Verify that the worker can still successfully execute script. 186 // Verify that the worker can still successfully execute script.
187 checkWorkerCanExecuteScript(secondWorker.get()); 187 checkWorkerCanExecuteScript(secondWorker.get());
188 188
189 secondWorker->terminateAndWait(); 189 secondWorker->terminateAndWait();
190 } 190 }
191 191
192 // Tests that a new WebThread is created if all existing workers are terminated before a new worker is created. 192 // Tests that a new WebThread is created if all existing workers are terminated before a new worker is created.
193 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) 193 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond)
194 { 194 {
195 // Create the first worker, wait until it is initialized, and terminate it. 195 // Create the first worker, wait until it is initialized, and terminate it.
196 OwnPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(); 196 OwnPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker();
197 WorkerBackingThread* workerBackingThread = &compositorWorker->workerBackingT hread();
197 WebThreadSupportingGC* firstThread = &compositorWorker->workerBackingThread( ).backingThread(); 198 WebThreadSupportingGC* firstThread = &compositorWorker->workerBackingThread( ).backingThread();
198 checkWorkerCanExecuteScript(compositorWorker.get()); 199 checkWorkerCanExecuteScript(compositorWorker.get());
199 200
200 // We don't use terminateAndWait here to avoid forcible termination. 201 ASSERT_EQ(2u, workerBackingThread->workerScriptCount());
201 compositorWorker->terminate(); 202 compositorWorker->terminateAndWait();
202 compositorWorker->waitForShutdownForTesting(); 203
204 ASSERT_EQ(1u, workerBackingThread->workerScriptCount());
203 205
204 // Create the second worker. The backing thread is same. 206 // Create the second worker. The backing thread is same.
205 compositorWorker = createCompositorWorker(); 207 compositorWorker = createCompositorWorker();
206 WebThreadSupportingGC* secondThread = &compositorWorker->workerBackingThread ().backingThread(); 208 WebThreadSupportingGC* secondThread = &compositorWorker->workerBackingThread ().backingThread();
207 EXPECT_EQ(firstThread, secondThread); 209 EXPECT_EQ(firstThread, secondThread);
208 checkWorkerCanExecuteScript(compositorWorker.get()); 210 checkWorkerCanExecuteScript(compositorWorker.get());
211 ASSERT_EQ(2u, workerBackingThread->workerScriptCount());
209 212
210 compositorWorker->terminateAndWait(); 213 compositorWorker->terminateAndWait();
211 } 214 }
212 215
213 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea ted while another is terminating. 216 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea ted while another is terminating.
214 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) 217 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst)
215 { 218 {
216 OwnPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(); 219 OwnPtr<CompositorWorkerThread> firstWorker = createCompositorWorker();
217 checkWorkerCanExecuteScript(firstWorker.get()); 220 checkWorkerCanExecuteScript(firstWorker.get());
218 v8::Isolate* firstIsolate = firstWorker->isolate(); 221 v8::Isolate* firstIsolate = firstWorker->isolate();
219 ASSERT_TRUE(firstIsolate); 222 ASSERT_TRUE(firstIsolate);
220 223
221 // Request termination of the first worker and create the second worker 224 // Request termination of the first worker and create the second worker
222 // as soon as possible. 225 // as soon as possible.
226 EXPECT_EQ(2u, firstWorker->workerBackingThread().workerScriptCount());
223 firstWorker->terminate(); 227 firstWorker->terminate();
224 // We don't wait for its termination. 228 // We don't wait for its termination.
225 // Note: We rely on the assumption that the termination steps don't run 229 // Note: We rely on the assumption that the termination steps don't run
226 // on the worker thread so quickly. This could be a source of flakiness. 230 // on the worker thread so quickly. This could be a source of flakiness.
227 231
228 OwnPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(); 232 OwnPtr<CompositorWorkerThread> secondWorker = createCompositorWorker();
229 233
230 v8::Isolate* secondIsolate = secondWorker->isolate(); 234 v8::Isolate* secondIsolate = secondWorker->isolate();
231 ASSERT_TRUE(secondIsolate); 235 ASSERT_TRUE(secondIsolate);
232 EXPECT_EQ(firstIsolate, secondIsolate); 236 EXPECT_EQ(firstIsolate, secondIsolate);
233 237
234 // Verify that the isolate can run some scripts correctly in the second work er. 238 // Verify that the isolate can run some scripts correctly in the second work er.
235 checkWorkerCanExecuteScript(secondWorker.get()); 239 checkWorkerCanExecuteScript(secondWorker.get());
236 secondWorker->terminateAndWait(); 240 secondWorker->terminateAndWait();
237 } 241 }
238 242
239 } // namespace blink 243 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThread.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698