OLD | NEW |
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 "modules/webaudio/AudioWorkletThread.h" | 5 #include "modules/webaudio/AudioWorkletThread.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 "bindings/core/v8/WorkerOrWorkletScriptController.h" | 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 private: | 56 private: |
57 TestAudioWorkletReportingProxy() {} | 57 TestAudioWorkletReportingProxy() {} |
58 }; | 58 }; |
59 | 59 |
60 } // namespace | 60 } // namespace |
61 | 61 |
62 class AudioWorkletThreadTest : public ::testing::Test { | 62 class AudioWorkletThreadTest : public ::testing::Test { |
63 public: | 63 public: |
64 void SetUp() override { | 64 void SetUp() override { |
65 AudioWorkletThread::createSharedBackingThreadForTest(); | 65 AudioWorkletThread::createSharedBackingThreadForTest(); |
66 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr); | |
67 m_reportingProxy = TestAudioWorkletReportingProxy::create(); | 66 m_reportingProxy = TestAudioWorkletReportingProxy::create(); |
68 m_securityOrigin = | 67 m_securityOrigin = |
69 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); | 68 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); |
70 } | 69 } |
71 | 70 |
72 void TearDown() override { AudioWorkletThread::clearSharedBackingThread(); } | 71 void TearDown() override { AudioWorkletThread::clearSharedBackingThread(); } |
73 | 72 |
74 std::unique_ptr<AudioWorkletThread> createAudioWorkletThread() { | 73 std::unique_ptr<AudioWorkletThread> createAudioWorkletThread() { |
75 std::unique_ptr<AudioWorkletThread> thread = AudioWorkletThread::create( | 74 std::unique_ptr<AudioWorkletThread> thread = |
76 nullptr, *m_reportingProxy, m_parentFrameTaskRunners.get()); | 75 AudioWorkletThread::create(nullptr, *m_reportingProxy); |
77 thread->start(WorkerThreadStartupData::create( | 76 thread->start( |
78 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", "", | 77 WorkerThreadStartupData::create( |
79 nullptr, DontPauseWorkerGlobalScopeOnStart, nullptr, "", | 78 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", "", |
80 m_securityOrigin.get(), nullptr, WebAddressSpaceLocal, nullptr, nullptr, | 79 nullptr, DontPauseWorkerGlobalScopeOnStart, nullptr, "", |
81 WorkerV8Settings::Default())); | 80 m_securityOrigin.get(), nullptr, WebAddressSpaceLocal, nullptr, |
| 81 nullptr, WorkerV8Settings::Default()), |
| 82 ParentFrameTaskRunners::create(nullptr)); |
82 return thread; | 83 return thread; |
83 } | 84 } |
84 | 85 |
85 // Attempts to run some simple script for |thread|. | 86 // Attempts to run some simple script for |thread|. |
86 void checkWorkletCanExecuteScript(WorkerThread* thread) { | 87 void checkWorkletCanExecuteScript(WorkerThread* thread) { |
87 WaitableEvent waitEvent; | 88 WaitableEvent waitEvent; |
88 thread->workerBackingThread().backingThread().postTask( | 89 thread->workerBackingThread().backingThread().postTask( |
89 BLINK_FROM_HERE, | 90 BLINK_FROM_HERE, |
90 crossThreadBind(&AudioWorkletThreadTest::executeScriptInWorklet, | 91 crossThreadBind(&AudioWorkletThreadTest::executeScriptInWorklet, |
91 crossThreadUnretained(this), | 92 crossThreadUnretained(this), |
92 crossThreadUnretained(thread), | 93 crossThreadUnretained(thread), |
93 crossThreadUnretained(&waitEvent))); | 94 crossThreadUnretained(&waitEvent))); |
94 waitEvent.wait(); | 95 waitEvent.wait(); |
95 } | 96 } |
96 | 97 |
97 private: | 98 private: |
98 void executeScriptInWorklet(WorkerThread* thread, WaitableEvent* waitEvent) { | 99 void executeScriptInWorklet(WorkerThread* thread, WaitableEvent* waitEvent) { |
99 WorkerOrWorkletScriptController* scriptController = | 100 WorkerOrWorkletScriptController* scriptController = |
100 thread->globalScope()->scriptController(); | 101 thread->globalScope()->scriptController(); |
101 scriptController->evaluate(ScriptSourceCode("var counter = 0; ++counter;")); | 102 scriptController->evaluate(ScriptSourceCode("var counter = 0; ++counter;")); |
102 waitEvent->signal(); | 103 waitEvent->signal(); |
103 } | 104 } |
104 | 105 |
105 RefPtr<SecurityOrigin> m_securityOrigin; | 106 RefPtr<SecurityOrigin> m_securityOrigin; |
106 std::unique_ptr<WorkerReportingProxy> m_reportingProxy; | 107 std::unique_ptr<WorkerReportingProxy> m_reportingProxy; |
107 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | |
108 }; | 108 }; |
109 | 109 |
110 TEST_F(AudioWorkletThreadTest, Basic) { | 110 TEST_F(AudioWorkletThreadTest, Basic) { |
111 std::unique_ptr<AudioWorkletThread> worklet = createAudioWorkletThread(); | 111 std::unique_ptr<AudioWorkletThread> worklet = createAudioWorkletThread(); |
112 checkWorkletCanExecuteScript(worklet.get()); | 112 checkWorkletCanExecuteScript(worklet.get()); |
113 worklet->terminateAndWait(); | 113 worklet->terminateAndWait(); |
114 } | 114 } |
115 | 115 |
116 // Tests that the same WebThread is used for new worklets if the WebThread is | 116 // Tests that the same WebThread is used for new worklets if the WebThread is |
117 // still alive. | 117 // still alive. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 ASSERT_TRUE(secondIsolate); | 190 ASSERT_TRUE(secondIsolate); |
191 EXPECT_EQ(firstIsolate, secondIsolate); | 191 EXPECT_EQ(firstIsolate, secondIsolate); |
192 | 192 |
193 // Verify that the isolate can run some scripts correctly in the second | 193 // Verify that the isolate can run some scripts correctly in the second |
194 // worklet. | 194 // worklet. |
195 checkWorkletCanExecuteScript(secondWorklet.get()); | 195 checkWorkletCanExecuteScript(secondWorklet.get()); |
196 secondWorklet->terminateAndWait(); | 196 secondWorklet->terminateAndWait(); |
197 } | 197 } |
198 | 198 |
199 } // namespace blink | 199 } // namespace blink |
OLD | NEW |