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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/macros.h" | 8 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
10 #include "media/audio/audio_parameters.h" | 11 #include "media/audio/audio_parameters.h" |
11 #include "media/base/fake_audio_render_callback.h" | 12 #include "media/base/fake_audio_render_callback.h" |
12 #include "media/base/mock_audio_renderer_sink.h" | 13 #include "media/base/mock_audio_renderer_sink.h" |
13 #include "media/blink/webaudiosourceprovider_impl.h" | 14 #include "media/blink/webaudiosourceprovider_impl.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h" | 17 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h" |
17 | 18 |
| 19 using ::testing::_; |
| 20 |
18 namespace media { | 21 namespace media { |
19 | 22 |
20 namespace { | 23 namespace { |
21 const float kTestVolume = 0.25; | 24 const float kTestVolume = 0.25; |
22 } // namespace | 25 } // namespace |
23 | 26 |
24 class WebAudioSourceProviderImplTest | 27 class WebAudioSourceProviderImplTest |
25 : public testing::Test, | 28 : public testing::Test, |
26 public blink::WebAudioSourceProviderClient { | 29 public blink::WebAudioSourceProviderClient { |
27 public: | 30 public: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) { | 81 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) { |
79 return false; | 82 return false; |
80 } | 83 } |
81 } | 84 } |
82 return true; | 85 return true; |
83 } | 86 } |
84 | 87 |
85 // blink::WebAudioSourceProviderClient implementation. | 88 // blink::WebAudioSourceProviderClient implementation. |
86 MOCK_METHOD2(setFormat, void(size_t numberOfChannels, float sampleRate)); | 89 MOCK_METHOD2(setFormat, void(size_t numberOfChannels, float sampleRate)); |
87 | 90 |
| 91 // OnAudioBusCB |
| 92 MOCK_METHOD2(DoOnAudioBusCB, void(AudioBus*, uint32_t delay_milliseconds)); |
| 93 void OnAudioBus(scoped_ptr<AudioBus> bus, uint32_t delay_milliseconds) { |
| 94 DoOnAudioBusCB(bus.get(), delay_milliseconds); |
| 95 } |
| 96 |
88 protected: | 97 protected: |
89 AudioParameters params_; | 98 AudioParameters params_; |
90 FakeAudioRenderCallback fake_callback_; | 99 FakeAudioRenderCallback fake_callback_; |
91 scoped_refptr<MockAudioRendererSink> mock_sink_; | 100 scoped_refptr<MockAudioRendererSink> mock_sink_; |
92 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; | 101 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; |
93 base::MessageLoop message_loop_; | 102 base::MessageLoop message_loop_; |
94 | 103 |
95 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); | 104 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); |
96 }; | 105 }; |
97 | 106 |
(...skipping 12 matching lines...) Expand all Loading... |
110 base::RunLoop().RunUntilIdle(); | 119 base::RunLoop().RunUntilIdle(); |
111 | 120 |
112 // setClient() with the same client should do nothing. | 121 // setClient() with the same client should do nothing. |
113 wasp_impl_->setClient(this); | 122 wasp_impl_->setClient(this); |
114 base::RunLoop().RunUntilIdle(); | 123 base::RunLoop().RunUntilIdle(); |
115 } | 124 } |
116 | 125 |
117 // Verify AudioRendererSink functionality w/ and w/o a client. | 126 // Verify AudioRendererSink functionality w/ and w/o a client. |
118 TEST_F(WebAudioSourceProviderImplTest, SinkMethods) { | 127 TEST_F(WebAudioSourceProviderImplTest, SinkMethods) { |
119 wasp_impl_->Initialize(params_, &fake_callback_); | 128 wasp_impl_->Initialize(params_, &fake_callback_); |
120 ASSERT_EQ(mock_sink_->callback(), &fake_callback_); | 129 // Callbacks: |mock_sink_| uses |wasp_impl_| that uses |fake_callback_|. |
| 130 ASSERT_EQ(mock_sink_->callback(), wasp_impl_.get()); |
121 | 131 |
122 // Without a client all WASP calls should fall through to the underlying sink. | 132 // Without a client all WASP calls should fall through to the underlying sink. |
123 CallAllSinkMethodsAndVerify(true); | 133 CallAllSinkMethodsAndVerify(true); |
124 | 134 |
125 // With a client no calls should reach the Stop()'d sink. Also, setClient() | 135 // With a client no calls should reach the Stop()'d sink. Also, setClient() |
126 // should propagate the params provided during Initialize() at call time. | 136 // should propagate the params provided during Initialize() at call time. |
127 SetClient(this); | 137 SetClient(this); |
128 CallAllSinkMethodsAndVerify(false); | 138 CallAllSinkMethodsAndVerify(false); |
129 | 139 |
130 // Removing the client should cause WASP to revert to the underlying sink. | 140 // Removing the client should cause WASP to revert to the underlying sink. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); | 243 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); |
234 | 244 |
235 // Stop() should return silence. | 245 // Stop() should return silence. |
236 wasp_impl_->Stop(); | 246 wasp_impl_->Stop(); |
237 bus1->channel(0)[0] = 1; | 247 bus1->channel(0)[0] = 1; |
238 bus2->Zero(); | 248 bus2->Zero(); |
239 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); | 249 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); |
240 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); | 250 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); |
241 } | 251 } |
242 | 252 |
| 253 // Verify OnAudioBusCB is called if registered. |
| 254 TEST_F(WebAudioSourceProviderImplTest, OnAudioBusCallback) { |
| 255 testing::InSequence s; |
| 256 wasp_impl_->Initialize(params_, &fake_callback_); |
| 257 wasp_impl_->RegisterOnAudioBusCallback(base::Bind( |
| 258 &WebAudioSourceProviderImplTest::OnAudioBus, base::Unretained(this))); |
| 259 |
| 260 const scoped_ptr<AudioBus> bus1 = AudioBus::Create(params_); |
| 261 const uint32_t kDelayMilliseconds = 3; |
| 262 EXPECT_CALL(*this, DoOnAudioBusCB(_, kDelayMilliseconds)).Times(1); |
| 263 wasp_impl_->Render(bus1.get(), kDelayMilliseconds, 0 /* frames_skipped */); |
| 264 |
| 265 wasp_impl_->ResetOnAudioBusCallback(); |
| 266 EXPECT_CALL(*this, DoOnAudioBusCB(_, _)).Times(0); |
| 267 wasp_impl_->Render(bus1.get(), 0 /* delay_milliseconds */, |
| 268 0 /* frames_skipped */); |
| 269 |
| 270 testing::Mock::VerifyAndClear(mock_sink_.get()); |
| 271 } |
| 272 |
243 } // namespace media | 273 } // namespace media |
OLD | NEW |