OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "content/renderer/media/webaudiosourceprovider_impl.h" | |
8 #include "media/audio/audio_parameters.h" | 7 #include "media/audio/audio_parameters.h" |
9 #include "media/base/fake_audio_render_callback.h" | 8 #include "media/base/fake_audio_render_callback.h" |
10 #include "media/base/mock_audio_renderer_sink.h" | 9 #include "media/base/mock_audio_renderer_sink.h" |
| 10 #include "media/blink/webaudiosourceprovider_impl.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h" | 13 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h" |
14 | 14 |
15 namespace content { | 15 namespace media { |
16 | 16 |
17 namespace { | 17 namespace { |
18 const float kTestVolume = 0.25; | 18 const float kTestVolume = 0.25; |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 class WebAudioSourceProviderImplTest | 21 class WebAudioSourceProviderImplTest |
22 : public testing::Test, | 22 : public testing::Test, |
23 public blink::WebAudioSourceProviderClient { | 23 public blink::WebAudioSourceProviderClient { |
24 public: | 24 public: |
25 WebAudioSourceProviderImplTest() | 25 WebAudioSourceProviderImplTest() |
26 : params_(media::AudioParameters::AUDIO_PCM_LINEAR, | 26 : params_(AudioParameters::AUDIO_PCM_LINEAR, |
27 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 64), | 27 CHANNEL_LAYOUT_STEREO, 48000, 16, 64), |
28 fake_callback_(0.1), | 28 fake_callback_(0.1), |
29 mock_sink_(new media::MockAudioRendererSink()), | 29 mock_sink_(new MockAudioRendererSink()), |
30 wasp_impl_(new WebAudioSourceProviderImpl(mock_sink_)) { | 30 wasp_impl_(new WebAudioSourceProviderImpl(mock_sink_)) { |
31 } | 31 } |
32 | 32 |
33 virtual ~WebAudioSourceProviderImplTest() {} | 33 virtual ~WebAudioSourceProviderImplTest() {} |
34 | 34 |
35 void CallAllSinkMethodsAndVerify(bool verify) { | 35 void CallAllSinkMethodsAndVerify(bool verify) { |
36 testing::InSequence s; | 36 testing::InSequence s; |
37 | 37 |
38 EXPECT_CALL(*mock_sink_.get(), Start()).Times(verify); | 38 EXPECT_CALL(*mock_sink_.get(), Start()).Times(verify); |
39 wasp_impl_->Start(); | 39 wasp_impl_->Start(); |
(...skipping 20 matching lines...) Expand all Loading... |
60 EXPECT_CALL(*mock_sink_.get(), Stop()); | 60 EXPECT_CALL(*mock_sink_.get(), Stop()); |
61 EXPECT_CALL(*this, setFormat(params_.channels(), params_.sample_rate())); | 61 EXPECT_CALL(*this, setFormat(params_.channels(), params_.sample_rate())); |
62 } | 62 } |
63 wasp_impl_->setClient(client); | 63 wasp_impl_->setClient(client); |
64 base::RunLoop().RunUntilIdle(); | 64 base::RunLoop().RunUntilIdle(); |
65 | 65 |
66 testing::Mock::VerifyAndClear(mock_sink_.get()); | 66 testing::Mock::VerifyAndClear(mock_sink_.get()); |
67 testing::Mock::VerifyAndClear(this); | 67 testing::Mock::VerifyAndClear(this); |
68 } | 68 } |
69 | 69 |
70 bool CompareBusses(const media::AudioBus* bus1, const media::AudioBus* bus2) { | 70 bool CompareBusses(const AudioBus* bus1, const AudioBus* bus2) { |
71 EXPECT_EQ(bus1->channels(), bus2->channels()); | 71 EXPECT_EQ(bus1->channels(), bus2->channels()); |
72 EXPECT_EQ(bus1->frames(), bus2->frames()); | 72 EXPECT_EQ(bus1->frames(), bus2->frames()); |
73 for (int ch = 0; ch < bus1->channels(); ++ch) { | 73 for (int ch = 0; ch < bus1->channels(); ++ch) { |
74 if (memcmp(bus1->channel(ch), bus2->channel(ch), | 74 if (memcmp(bus1->channel(ch), bus2->channel(ch), |
75 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) { | 75 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) { |
76 return false; | 76 return false; |
77 } | 77 } |
78 } | 78 } |
79 return true; | 79 return true; |
80 } | 80 } |
81 | 81 |
82 // blink::WebAudioSourceProviderClient implementation. | 82 // blink::WebAudioSourceProviderClient implementation. |
83 MOCK_METHOD2(setFormat, void(size_t numberOfChannels, float sampleRate)); | 83 MOCK_METHOD2(setFormat, void(size_t numberOfChannels, float sampleRate)); |
84 | 84 |
85 protected: | 85 protected: |
86 media::AudioParameters params_; | 86 AudioParameters params_; |
87 media::FakeAudioRenderCallback fake_callback_; | 87 FakeAudioRenderCallback fake_callback_; |
88 scoped_refptr<media::MockAudioRendererSink> mock_sink_; | 88 scoped_refptr<MockAudioRendererSink> mock_sink_; |
89 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; | 89 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; |
90 base::MessageLoop message_loop_; | 90 base::MessageLoop message_loop_; |
91 | 91 |
92 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); | 92 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); |
93 }; | 93 }; |
94 | 94 |
95 TEST_F(WebAudioSourceProviderImplTest, SetClientBeforeInitialize) { | 95 TEST_F(WebAudioSourceProviderImplTest, SetClientBeforeInitialize) { |
96 // setClient() with a NULL client should do nothing if no client is set. | 96 // setClient() with a NULL client should do nothing if no client is set. |
97 wasp_impl_->setClient(NULL); | 97 wasp_impl_->setClient(NULL); |
98 | 98 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 wasp_impl_->SetVolume(kTestVolume); | 149 wasp_impl_->SetVolume(kTestVolume); |
150 | 150 |
151 EXPECT_CALL(*mock_sink_.get(), SetVolume(kTestVolume)); | 151 EXPECT_CALL(*mock_sink_.get(), SetVolume(kTestVolume)); |
152 EXPECT_CALL(*mock_sink_.get(), Start()); | 152 EXPECT_CALL(*mock_sink_.get(), Start()); |
153 EXPECT_CALL(*mock_sink_.get(), Play()); | 153 EXPECT_CALL(*mock_sink_.get(), Play()); |
154 SetClient(NULL); | 154 SetClient(NULL); |
155 } | 155 } |
156 | 156 |
157 // Test the AudioRendererSink state machine and its effects on provideInput(). | 157 // Test the AudioRendererSink state machine and its effects on provideInput(). |
158 TEST_F(WebAudioSourceProviderImplTest, ProvideInput) { | 158 TEST_F(WebAudioSourceProviderImplTest, ProvideInput) { |
159 scoped_ptr<media::AudioBus> bus1 = media::AudioBus::Create(params_); | 159 scoped_ptr<AudioBus> bus1 = AudioBus::Create(params_); |
160 scoped_ptr<media::AudioBus> bus2 = media::AudioBus::Create(params_); | 160 scoped_ptr<AudioBus> bus2 = AudioBus::Create(params_); |
161 | 161 |
162 // Point the WebVector into memory owned by |bus1|. | 162 // Point the WebVector into memory owned by |bus1|. |
163 blink::WebVector<float*> audio_data(static_cast<size_t>(bus1->channels())); | 163 blink::WebVector<float*> audio_data(static_cast<size_t>(bus1->channels())); |
164 for (size_t i = 0; i < audio_data.size(); ++i) | 164 for (size_t i = 0; i < audio_data.size(); ++i) |
165 audio_data[i] = bus1->channel(i); | 165 audio_data[i] = bus1->channel(i); |
166 | 166 |
167 // Verify provideInput() works before Initialize() and returns silence. | 167 // Verify provideInput() works before Initialize() and returns silence. |
168 bus1->channel(0)[0] = 1; | 168 bus1->channel(0)[0] = 1; |
169 bus2->Zero(); | 169 bus2->Zero(); |
170 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); | 170 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); | 230 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); |
231 | 231 |
232 // Stop() should return silence. | 232 // Stop() should return silence. |
233 wasp_impl_->Stop(); | 233 wasp_impl_->Stop(); |
234 bus1->channel(0)[0] = 1; | 234 bus1->channel(0)[0] = 1; |
235 bus2->Zero(); | 235 bus2->Zero(); |
236 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); | 236 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); |
237 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); | 237 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); |
238 } | 238 } |
239 | 239 |
240 } // namespace content | 240 } // namespace media |
OLD | NEW |