| 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/ToV8ForCore.h" | 11 #include "bindings/core/v8/ToV8ForCore.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(kParsedURLString, "http://fake.url/"), "fake user agent", "", | 56 KURL(kParsedURLString, "http://fake.url/"), "fake user agent", "", |
| 56 nullptr, kDontPauseWorkerGlobalScopeOnStart, nullptr, "", | 57 nullptr, kDontPauseWorkerGlobalScopeOnStart, nullptr, "", |
| 57 security_origin_.Get(), nullptr, kWebAddressSpaceLocal, nullptr, | 58 security_origin_.Get(), nullptr, kWebAddressSpaceLocal, 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 waitable_event; | 65 WaitableEvent waitable_event; |
| 65 thread->PostTask( | 66 TaskRunnerHelper::Get(TaskType::kUnthrottled, 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(&waitable_event))); | 71 CrossThreadUnretained(this), CrossThreadUnretained(thread), |
| 72 CrossThreadUnretained(&waitable_event))); |
| 71 waitable_event.Wait(); | 73 waitable_event.Wait(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void RunSimpleProcessTest(WorkerThread* thread) { | 76 void RunSimpleProcessTest(WorkerThread* thread) { |
| 75 WaitableEvent waitable_event; | 77 WaitableEvent waitable_event; |
| 76 thread->PostTask( | 78 TaskRunnerHelper::Get(TaskType::kUnthrottled, 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(&waitable_event))); | 83 CrossThreadUnretained(thread), |
| 84 CrossThreadUnretained(&waitable_event))); |
| 82 waitable_event.Wait(); | 85 waitable_event.Wait(); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void RunParsingTest(WorkerThread* thread) { | 88 void RunParsingTest(WorkerThread* thread) { |
| 86 WaitableEvent waitable_event; | 89 WaitableEvent waitable_event; |
| 87 thread->PostTask( | 90 TaskRunnerHelper::Get(TaskType::kUnthrottled, 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(&waitable_event))); | 95 CrossThreadUnretained(this), CrossThreadUnretained(thread), |
| 96 CrossThreadUnretained(&waitable_event))); |
| 93 waitable_event.Wait(); | 97 waitable_event.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* wait_event) { | 106 WaitableEvent* wait_event) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 thread->TerminateAndWait(); | 261 thread->TerminateAndWait(); |
| 258 } | 262 } |
| 259 | 263 |
| 260 TEST_F(AudioWorkletGlobalScopeTest, BufferProcessing) { | 264 TEST_F(AudioWorkletGlobalScopeTest, BufferProcessing) { |
| 261 std::unique_ptr<AudioWorkletThread> thread = CreateAudioWorkletThread(); | 265 std::unique_ptr<AudioWorkletThread> thread = CreateAudioWorkletThread(); |
| 262 RunSimpleProcessTest(thread.get()); | 266 RunSimpleProcessTest(thread.get()); |
| 263 thread->TerminateAndWait(); | 267 thread->TerminateAndWait(); |
| 264 } | 268 } |
| 265 | 269 |
| 266 } // namespace blink | 270 } // namespace blink |
| OLD | NEW |