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 "config.h" | 5 #include "config.h" |
6 #include "modules/webaudio/AudioBasicProcessorHandler.h" | 6 #include "modules/webaudio/AudioBasicProcessorHandler.h" |
7 | 7 |
8 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
9 #include "modules/webaudio/OfflineAudioContext.h" | 9 #include "modules/webaudio/OfflineAudioContext.h" |
10 #include "platform/audio/AudioProcessor.h" | 10 #include "platform/audio/AudioProcessor.h" |
11 #include <gtest/gtest.h> | 11 #include <gtest/gtest.h> |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 class MockAudioProcessor final : public AudioProcessor { | 15 class MockAudioProcessor final : public AudioProcessor { |
16 public: | 16 public: |
17 MockAudioProcessor() : AudioProcessor(48000, 2) { } | 17 MockAudioProcessor() : AudioProcessor(48000, 2) { } |
18 void initialize() override { m_initialized = true; } | 18 void initialize() override { m_initialized = true; } |
19 void uninitialize() override { m_initialized = false; } | 19 void uninitialize() override { m_initialized = false; } |
20 void process(const AudioBus*, AudioBus*, size_t) override { } | 20 void process(const AudioBus*, AudioBus*, size_t) override { } |
21 void reset() override { } | 21 void reset() override { } |
22 void setNumberOfChannels(unsigned) override { } | 22 void setNumberOfChannels(unsigned) override { } |
23 unsigned numberOfChannels() const override { return m_numberOfChannels; } | 23 unsigned numberOfChannels() const override { return m_numberOfChannels; } |
24 double tailTime() const override { return 0; } | 24 double tailTime() const override { return 0; } |
25 double latencyTime() const override { return 0; } | 25 double latencyTime() const override { return 0; } |
26 }; | 26 }; |
27 | 27 |
28 class MockProcessorNode final : public AudioNode { | 28 class MockProcessorNode final : public AudioNode { |
29 public: | 29 public: |
30 MockProcessorNode(AudioContext& context) | 30 MockProcessorNode(AbstractAudioContext& context) |
31 : AudioNode(context) | 31 : AudioNode(context) |
32 { | 32 { |
33 setHandler(AudioBasicProcessorHandler::create(AudioHandler::NodeTypeWave
Shaper, *this, 48000, adoptPtr(new MockAudioProcessor()))); | 33 setHandler(AudioBasicProcessorHandler::create(AudioHandler::NodeTypeWave
Shaper, *this, 48000, adoptPtr(new MockAudioProcessor()))); |
34 handler().initialize(); | 34 handler().initialize(); |
35 } | 35 } |
36 }; | 36 }; |
37 | 37 |
38 TEST(AudioBasicProcessorHandlerTest, ProcessorFinalization) | 38 TEST(AudioBasicProcessorHandlerTest, ProcessorFinalization) |
39 { | 39 { |
40 OwnPtr<DummyPageHolder> page = DummyPageHolder::create(); | 40 OwnPtr<DummyPageHolder> page = DummyPageHolder::create(); |
41 OfflineAudioContext* context = OfflineAudioContext::create(&page->document()
, 2, 1, 48000, ASSERT_NO_EXCEPTION); | 41 OfflineAudioContext* context = OfflineAudioContext::create(&page->document()
, 2, 1, 48000, ASSERT_NO_EXCEPTION); |
42 MockProcessorNode* node = new MockProcessorNode(*context); | 42 MockProcessorNode* node = new MockProcessorNode(*context); |
43 AudioBasicProcessorHandler& handler = static_cast<AudioBasicProcessorHandler
&>(node->handler()); | 43 AudioBasicProcessorHandler& handler = static_cast<AudioBasicProcessorHandler
&>(node->handler()); |
44 EXPECT_TRUE(handler.processor()); | 44 EXPECT_TRUE(handler.processor()); |
45 EXPECT_TRUE(handler.processor()->isInitialized()); | 45 EXPECT_TRUE(handler.processor()->isInitialized()); |
46 AudioContext::AutoLocker locker(context); | 46 AbstractAudioContext::AutoLocker locker(context); |
47 handler.dispose(); | 47 handler.dispose(); |
48 // The AudioProcessor should live after dispose() and should not be | 48 // The AudioProcessor should live after dispose() and should not be |
49 // finalized because an audio thread is using it. | 49 // finalized because an audio thread is using it. |
50 EXPECT_TRUE(handler.processor()); | 50 EXPECT_TRUE(handler.processor()); |
51 EXPECT_TRUE(handler.processor()->isInitialized()); | 51 EXPECT_TRUE(handler.processor()->isInitialized()); |
52 } | 52 } |
53 | 53 |
54 } // namespace blink | 54 } // namespace blink |
OLD | NEW |