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

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

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