Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/inspector/ConsoleMessage.h" | 9 #include "core/inspector/ConsoleMessage.h" |
| 10 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 OwnPtr<WebThread> m_thread; | 75 OwnPtr<WebThread> m_thread; |
| 76 TestingCompositorSupport m_compositorSupport; | 76 TestingCompositorSupport m_compositorSupport; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 class CompositorWorkerThreadTest : public ::testing::Test { | 81 class CompositorWorkerThreadTest : public ::testing::Test { |
| 82 public: | 82 public: |
| 83 void SetUp() override | 83 void SetUp() override |
| 84 { | 84 { |
| 85 CompositorWorkerThread::resetSharedBackingThreadForTest(); | 85 CompositorWorkerThread::resetSharedBackingThreadForTest(); |
|
yhirano
2016/05/19 05:35:37
ASSERT_EQ(0, compositorWorker->workerBackingThread
| |
| 86 m_page = DummyPageHolder::create(); | 86 m_page = DummyPageHolder::create(); |
| 87 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen t()); | 87 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen t()); |
| 88 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http:// fake.url/")); | 88 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http:// fake.url/")); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void TearDown() override | 91 void TearDown() override |
| 92 { | 92 { |
| 93 m_page.clear(); | 93 m_page.clear(); |
| 94 CompositorWorkerThread::resetSharedBackingThreadForTest(); | 94 CompositorWorkerThread::clearSharedBackingThread(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 PassOwnPtr<CompositorWorkerThread> createCompositorWorker() | 97 PassOwnPtr<CompositorWorkerThread> createCompositorWorker() |
| 98 { | 98 { |
| 99 OwnPtr<CompositorWorkerThread> workerThread = CompositorWorkerThread::cr eate(nullptr, *m_objectProxy, 0); | 99 OwnPtr<CompositorWorkerThread> workerThread = CompositorWorkerThread::cr eate(nullptr, *m_objectProxy, 0); |
| 100 WorkerClients* clients = nullptr; | 100 WorkerClients* clients = nullptr; |
| 101 workerThread->start(WorkerThreadStartupData::create( | 101 workerThread->start(WorkerThreadStartupData::create( |
| 102 KURL(ParsedURLString, "http://fake.url/"), | 102 KURL(ParsedURLString, "http://fake.url/"), |
| 103 "fake user agent", | 103 "fake user agent", |
| 104 "//fake source code", | 104 "//fake source code", |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 | 176 |
| 177 // Tests that a new WebThread is created if all existing workers are terminated before a new worker is created. | 177 // Tests that a new WebThread is created if all existing workers are terminated before a new worker is created. |
| 178 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) | 178 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) |
| 179 { | 179 { |
| 180 // Create the first worker, wait until it is initialized, and terminate it. | 180 // Create the first worker, wait until it is initialized, and terminate it. |
| 181 OwnPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(); | 181 OwnPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(); |
| 182 WorkerBackingThread* workerBackingThread = &compositorWorker->workerBackingT hread(); | 182 WorkerBackingThread* workerBackingThread = &compositorWorker->workerBackingT hread(); |
| 183 WebThreadSupportingGC* firstThread = &compositorWorker->workerBackingThread( ).backingThread(); | 183 WebThreadSupportingGC* firstThread = &compositorWorker->workerBackingThread( ).backingThread(); |
| 184 checkWorkerCanExecuteScript(compositorWorker.get()); | 184 checkWorkerCanExecuteScript(compositorWorker.get()); |
| 185 | 185 |
| 186 ASSERT_EQ(1u, workerBackingThread->workerScriptCount()); | 186 ASSERT_EQ(2u, workerBackingThread->workerScriptCount()); |
| 187 compositorWorker->terminateAndWait(); | 187 compositorWorker->terminateAndWait(); |
| 188 | 188 |
| 189 ASSERT_EQ(0u, workerBackingThread->workerScriptCount()); | 189 ASSERT_EQ(1u, workerBackingThread->workerScriptCount()); |
| 190 | 190 |
| 191 // Create the second worker. The backing thread is same. | 191 // Create the second worker. The backing thread is same. |
| 192 compositorWorker = createCompositorWorker(); | 192 compositorWorker = createCompositorWorker(); |
| 193 WebThreadSupportingGC* secondThread = &compositorWorker->workerBackingThread ().backingThread(); | 193 WebThreadSupportingGC* secondThread = &compositorWorker->workerBackingThread ().backingThread(); |
| 194 EXPECT_EQ(firstThread, secondThread); | 194 EXPECT_EQ(firstThread, secondThread); |
| 195 checkWorkerCanExecuteScript(compositorWorker.get()); | 195 checkWorkerCanExecuteScript(compositorWorker.get()); |
| 196 ASSERT_EQ(1u, workerBackingThread->workerScriptCount()); | 196 ASSERT_EQ(2u, workerBackingThread->workerScriptCount()); |
| 197 | 197 |
| 198 compositorWorker->terminateAndWait(); | 198 compositorWorker->terminateAndWait(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea ted while another is terminating. | 201 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea ted while another is terminating. |
| 202 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) | 202 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) |
| 203 { | 203 { |
| 204 OwnPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(); | 204 OwnPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(); |
| 205 checkWorkerCanExecuteScript(firstWorker.get()); | 205 checkWorkerCanExecuteScript(firstWorker.get()); |
| 206 v8::Isolate* firstIsolate = firstWorker->isolate(); | 206 v8::Isolate* firstIsolate = firstWorker->isolate(); |
| 207 ASSERT_TRUE(firstIsolate); | 207 ASSERT_TRUE(firstIsolate); |
| 208 | 208 |
| 209 // Request termination of the first worker and create the second worker | 209 // Request termination of the first worker and create the second worker |
| 210 // as soon as possible. | 210 // as soon as possible. |
| 211 EXPECT_EQ(1u, firstWorker->workerBackingThread().workerScriptCount()); | 211 EXPECT_EQ(2u, firstWorker->workerBackingThread().workerScriptCount()); |
| 212 firstWorker->terminate(); | 212 firstWorker->terminate(); |
| 213 // We don't wait for its termination. | 213 // We don't wait for its termination. |
| 214 // Note: We rely on the assumption that the termination steps don't run | 214 // Note: We rely on the assumption that the termination steps don't run |
| 215 // on the worker thread so quickly. This could be a source of flakiness. | 215 // on the worker thread so quickly. This could be a source of flakiness. |
| 216 | 216 |
| 217 OwnPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(); | 217 OwnPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(); |
| 218 | 218 |
| 219 v8::Isolate* secondIsolate = secondWorker->isolate(); | 219 v8::Isolate* secondIsolate = secondWorker->isolate(); |
| 220 ASSERT_TRUE(secondIsolate); | 220 ASSERT_TRUE(secondIsolate); |
| 221 EXPECT_EQ(firstIsolate, secondIsolate); | 221 EXPECT_EQ(firstIsolate, secondIsolate); |
| 222 | 222 |
| 223 // Verify that the isolate can run some scripts correctly in the second work er. | 223 // Verify that the isolate can run some scripts correctly in the second work er. |
| 224 checkWorkerCanExecuteScript(secondWorker.get()); | 224 checkWorkerCanExecuteScript(secondWorker.get()); |
| 225 secondWorker->terminateAndWait(); | 225 secondWorker->terminateAndWait(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace blink | 228 } // namespace blink |
| OLD | NEW |