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