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

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

Issue 1955693003: compositor-worker: Keep worker backing thread alive for the lifetime of the compositor thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use the constructed WorkerBackingThread to post tasks. 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/V8GCController.h" 8 #include "bindings/core/v8/V8GCController.h"
9 #include "core/dom/CompositorProxyClient.h" 9 #include "core/dom/CompositorProxyClient.h"
10 #include "core/inspector/ConsoleMessage.h" 10 #include "core/inspector/ConsoleMessage.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 OwnPtr<WebThread> m_thread; 87 OwnPtr<WebThread> m_thread;
88 TestingCompositorSupport m_compositorSupport; 88 TestingCompositorSupport m_compositorSupport;
89 }; 89 };
90 90
91 } // namespace 91 } // namespace
92 92
93 class CompositorWorkerThreadTest : public ::testing::Test { 93 class CompositorWorkerThreadTest : public ::testing::Test {
94 public: 94 public:
95 void SetUp() override 95 void SetUp() override
96 { 96 {
97 CompositorWorkerThread::resetSharedBackingThreadForTest(); 97 CompositorWorkerThread::createSharedBackingThreadForTest();
98 m_page = DummyPageHolder::create(); 98 m_page = DummyPageHolder::create();
99 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen t()); 99 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen t());
100 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http:// fake.url/")); 100 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http:// fake.url/"));
101 } 101 }
102 102
103 void TearDown() override 103 void TearDown() override
104 { 104 {
105 m_page.reset(); 105 m_page.reset();
106 CompositorWorkerThread::resetSharedBackingThreadForTest(); 106 CompositorWorkerThread::terminateExecution();
107 CompositorWorkerThread::clearSharedBackingThread();
107 } 108 }
108 109
109 PassOwnPtr<CompositorWorkerThread> createCompositorWorker() 110 PassOwnPtr<CompositorWorkerThread> createCompositorWorker()
110 { 111 {
111 OwnPtr<CompositorWorkerThread> workerThread = CompositorWorkerThread::cr eate(nullptr, *m_objectProxy, 0); 112 OwnPtr<CompositorWorkerThread> workerThread = CompositorWorkerThread::cr eate(nullptr, *m_objectProxy, 0);
112 WorkerClients* clients = WorkerClients::create(); 113 WorkerClients* clients = WorkerClients::create();
113 provideCompositorProxyClientTo(clients, new TestCompositorProxyClient); 114 provideCompositorProxyClientTo(clients, new TestCompositorProxyClient);
114 workerThread->start(WorkerThreadStartupData::create( 115 workerThread->start(WorkerThreadStartupData::create(
115 KURL(ParsedURLString, "http://fake.url/"), 116 KURL(ParsedURLString, "http://fake.url/"),
116 "fake user agent", 117 "fake user agent",
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 190
190 // Tests that a new WebThread is created if all existing workers are terminated before a new worker is created. 191 // Tests that a new WebThread is created if all existing workers are terminated before a new worker is created.
191 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) 192 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond)
192 { 193 {
193 // Create the first worker, wait until it is initialized, and terminate it. 194 // Create the first worker, wait until it is initialized, and terminate it.
194 OwnPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(); 195 OwnPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker();
195 WorkerBackingThread* workerBackingThread = &compositorWorker->workerBackingT hread(); 196 WorkerBackingThread* workerBackingThread = &compositorWorker->workerBackingT hread();
196 WebThreadSupportingGC* firstThread = &compositorWorker->workerBackingThread( ).backingThread(); 197 WebThreadSupportingGC* firstThread = &compositorWorker->workerBackingThread( ).backingThread();
197 checkWorkerCanExecuteScript(compositorWorker.get()); 198 checkWorkerCanExecuteScript(compositorWorker.get());
198 199
199 ASSERT_EQ(1u, workerBackingThread->workerScriptCount()); 200 ASSERT_EQ(2u, workerBackingThread->workerScriptCount());
200 compositorWorker->terminateAndWait(); 201 compositorWorker->terminateAndWait();
201 202
202 ASSERT_EQ(0u, workerBackingThread->workerScriptCount()); 203 ASSERT_EQ(1u, workerBackingThread->workerScriptCount());
203 204
204 // Create the second worker. The backing thread is same. 205 // Create the second worker. The backing thread is same.
205 compositorWorker = createCompositorWorker(); 206 compositorWorker = createCompositorWorker();
206 WebThreadSupportingGC* secondThread = &compositorWorker->workerBackingThread ().backingThread(); 207 WebThreadSupportingGC* secondThread = &compositorWorker->workerBackingThread ().backingThread();
207 EXPECT_EQ(firstThread, secondThread); 208 EXPECT_EQ(firstThread, secondThread);
208 checkWorkerCanExecuteScript(compositorWorker.get()); 209 checkWorkerCanExecuteScript(compositorWorker.get());
209 ASSERT_EQ(1u, workerBackingThread->workerScriptCount()); 210 ASSERT_EQ(2u, workerBackingThread->workerScriptCount());
210 211
211 compositorWorker->terminateAndWait(); 212 compositorWorker->terminateAndWait();
212 } 213 }
213 214
214 // 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.
215 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) 216 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst)
216 { 217 {
217 OwnPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(); 218 OwnPtr<CompositorWorkerThread> firstWorker = createCompositorWorker();
218 checkWorkerCanExecuteScript(firstWorker.get()); 219 checkWorkerCanExecuteScript(firstWorker.get());
219 v8::Isolate* firstIsolate = firstWorker->isolate(); 220 v8::Isolate* firstIsolate = firstWorker->isolate();
220 ASSERT_TRUE(firstIsolate); 221 ASSERT_TRUE(firstIsolate);
221 222
222 // Request termination of the first worker and create the second worker 223 // Request termination of the first worker and create the second worker
223 // as soon as possible. 224 // as soon as possible.
224 EXPECT_EQ(1u, firstWorker->workerBackingThread().workerScriptCount()); 225 EXPECT_EQ(2u, firstWorker->workerBackingThread().workerScriptCount());
225 firstWorker->terminate(); 226 firstWorker->terminate();
226 // We don't wait for its termination. 227 // We don't wait for its termination.
227 // Note: We rely on the assumption that the termination steps don't run 228 // Note: We rely on the assumption that the termination steps don't run
228 // on the worker thread so quickly. This could be a source of flakiness. 229 // on the worker thread so quickly. This could be a source of flakiness.
229 230
230 OwnPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(); 231 OwnPtr<CompositorWorkerThread> secondWorker = createCompositorWorker();
231 232
232 v8::Isolate* secondIsolate = secondWorker->isolate(); 233 v8::Isolate* secondIsolate = secondWorker->isolate();
233 ASSERT_TRUE(secondIsolate); 234 ASSERT_TRUE(secondIsolate);
234 EXPECT_EQ(firstIsolate, secondIsolate); 235 EXPECT_EQ(firstIsolate, secondIsolate);
235 236
236 // Verify that the isolate can run some scripts correctly in the second work er. 237 // Verify that the isolate can run some scripts correctly in the second work er.
237 checkWorkerCanExecuteScript(secondWorker.get()); 238 checkWorkerCanExecuteScript(secondWorker.get());
238 secondWorker->terminateAndWait(); 239 secondWorker->terminateAndWait();
239 } 240 }
240 241
241 } // namespace blink 242 } // 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