| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/AudioWorkletGlobalScope.h" | 5 #include "modules/webaudio/AudioWorkletGlobalScope.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptSourceCode.h" | 7 #include "bindings/core/v8/ScriptSourceCode.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "bindings/core/v8/SourceLocation.h" | 10 #include "bindings/core/v8/SourceLocation.h" |
| 11 #include "bindings/core/v8/ToV8.h" | 11 #include "bindings/core/v8/ToV8.h" |
| 12 #include "bindings/core/v8/V8Binding.h" | 12 #include "bindings/core/v8/V8Binding.h" |
| 13 #include "bindings/core/v8/V8BindingForTesting.h" | 13 #include "bindings/core/v8/V8BindingForTesting.h" |
| 14 #include "bindings/core/v8/V8BindingMacros.h" | 14 #include "bindings/core/v8/V8BindingMacros.h" |
| 15 #include "bindings/core/v8/V8GCController.h" | 15 #include "bindings/core/v8/V8GCController.h" |
| 16 #include "bindings/core/v8/V8ObjectConstructor.h" | 16 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 17 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 17 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 18 #include "core/dom/TaskRunnerHelper.h" |
| 18 #include "core/workers/WorkerBackingThread.h" | 19 #include "core/workers/WorkerBackingThread.h" |
| 19 #include "core/workers/WorkerReportingProxy.h" | 20 #include "core/workers/WorkerReportingProxy.h" |
| 20 #include "core/workers/WorkerThreadStartupData.h" | 21 #include "core/workers/WorkerThreadStartupData.h" |
| 21 #include "modules/webaudio/AudioBuffer.h" | 22 #include "modules/webaudio/AudioBuffer.h" |
| 22 #include "modules/webaudio/AudioWorkletProcessor.h" | 23 #include "modules/webaudio/AudioWorkletProcessor.h" |
| 23 #include "modules/webaudio/AudioWorkletProcessorDefinition.h" | 24 #include "modules/webaudio/AudioWorkletProcessorDefinition.h" |
| 24 #include "modules/webaudio/AudioWorkletThread.h" | 25 #include "modules/webaudio/AudioWorkletThread.h" |
| 25 #include "platform/weborigin/SecurityOrigin.h" | 26 #include "platform/weborigin/SecurityOrigin.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 55 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", "", | 56 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", "", |
| 56 nullptr, DontPauseWorkerGlobalScopeOnStart, nullptr, "", | 57 nullptr, DontPauseWorkerGlobalScopeOnStart, nullptr, "", |
| 57 m_securityOrigin.get(), nullptr, WebAddressSpaceLocal, nullptr, | 58 m_securityOrigin.get(), nullptr, WebAddressSpaceLocal, nullptr, |
| 58 nullptr, WorkerV8Settings::Default()), | 59 nullptr, WorkerV8Settings::Default()), |
| 59 ParentFrameTaskRunners::create(nullptr)); | 60 ParentFrameTaskRunners::create(nullptr)); |
| 60 return thread; | 61 return thread; |
| 61 } | 62 } |
| 62 | 63 |
| 63 void runBasicTest(WorkerThread* thread) { | 64 void runBasicTest(WorkerThread* thread) { |
| 64 WaitableEvent waitableEvent; | 65 WaitableEvent waitableEvent; |
| 65 thread->postTask( | 66 TaskRunnerHelper::get(TaskType::Unthrottled, thread) |
| 66 BLINK_FROM_HERE, | 67 ->postTask( |
| 67 crossThreadBind( | 68 BLINK_FROM_HERE, |
| 68 &AudioWorkletGlobalScopeTest::runBasicTestOnWorkletThread, | 69 crossThreadBind( |
| 69 crossThreadUnretained(this), crossThreadUnretained(thread), | 70 &AudioWorkletGlobalScopeTest::runBasicTestOnWorkletThread, |
| 70 crossThreadUnretained(&waitableEvent))); | 71 crossThreadUnretained(this), crossThreadUnretained(thread), |
| 72 crossThreadUnretained(&waitableEvent))); |
| 71 waitableEvent.wait(); | 73 waitableEvent.wait(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void runSimpleProcessTest(WorkerThread* thread) { | 76 void runSimpleProcessTest(WorkerThread* thread) { |
| 75 WaitableEvent waitableEvent; | 77 WaitableEvent waitableEvent; |
| 76 thread->postTask( | 78 TaskRunnerHelper::get(TaskType::Unthrottled, thread) |
| 77 BLINK_FROM_HERE, | 79 ->postTask(BLINK_FROM_HERE, |
| 78 crossThreadBind( | 80 crossThreadBind(&AudioWorkletGlobalScopeTest:: |
| 79 &AudioWorkletGlobalScopeTest::runSimpleProcessTestOnWorkletThread, | 81 runSimpleProcessTestOnWorkletThread, |
| 80 crossThreadUnretained(this), crossThreadUnretained(thread), | 82 crossThreadUnretained(this), |
| 81 crossThreadUnretained(&waitableEvent))); | 83 crossThreadUnretained(thread), |
| 84 crossThreadUnretained(&waitableEvent))); |
| 82 waitableEvent.wait(); | 85 waitableEvent.wait(); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void runParsingTest(WorkerThread* thread) { | 88 void runParsingTest(WorkerThread* thread) { |
| 86 WaitableEvent waitableEvent; | 89 WaitableEvent waitableEvent; |
| 87 thread->postTask( | 90 TaskRunnerHelper::get(TaskType::Unthrottled, thread) |
| 88 BLINK_FROM_HERE, | 91 ->postTask( |
| 89 crossThreadBind( | 92 BLINK_FROM_HERE, |
| 90 &AudioWorkletGlobalScopeTest::runParsingTestOnWorkletThread, | 93 crossThreadBind( |
| 91 crossThreadUnretained(this), crossThreadUnretained(thread), | 94 &AudioWorkletGlobalScopeTest::runParsingTestOnWorkletThread, |
| 92 crossThreadUnretained(&waitableEvent))); | 95 crossThreadUnretained(this), crossThreadUnretained(thread), |
| 96 crossThreadUnretained(&waitableEvent))); |
| 93 waitableEvent.wait(); | 97 waitableEvent.wait(); |
| 94 } | 98 } |
| 95 | 99 |
| 96 private: | 100 private: |
| 97 // Test if AudioWorkletGlobalScope and V8 components (ScriptState, Isolate) | 101 // Test if AudioWorkletGlobalScope and V8 components (ScriptState, Isolate) |
| 98 // are properly instantiated. Runs a simple processor registration and check | 102 // are properly instantiated. Runs a simple processor registration and check |
| 99 // if the class definition is correctly registered, then instantiate an | 103 // if the class definition is correctly registered, then instantiate an |
| 100 // AudioWorkletProcessor instance from the definition. | 104 // AudioWorkletProcessor instance from the definition. |
| 101 void runBasicTestOnWorkletThread(WorkerThread* thread, | 105 void runBasicTestOnWorkletThread(WorkerThread* thread, |
| 102 WaitableEvent* waitEvent) { | 106 WaitableEvent* waitEvent) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 thread->terminateAndWait(); | 259 thread->terminateAndWait(); |
| 256 } | 260 } |
| 257 | 261 |
| 258 TEST_F(AudioWorkletGlobalScopeTest, BufferProcessing) { | 262 TEST_F(AudioWorkletGlobalScopeTest, BufferProcessing) { |
| 259 std::unique_ptr<AudioWorkletThread> thread = createAudioWorkletThread(); | 263 std::unique_ptr<AudioWorkletThread> thread = createAudioWorkletThread(); |
| 260 runSimpleProcessTest(thread.get()); | 264 runSimpleProcessTest(thread.get()); |
| 261 thread->terminateAndWait(); | 265 thread->terminateAndWait(); |
| 262 } | 266 } |
| 263 | 267 |
| 264 } // namespace blink | 268 } // namespace blink |
| OLD | NEW |