| 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 // CopyAudioCB. Added forwarder method due to GMock troubles with scoped_ptr. |
| 92 MOCK_METHOD3(DoCopyAudioCB, |
| 93 void(AudioBus*, uint32_t delay_milliseconds, int sample_rate)); |
| 94 void OnAudioBus(scoped_ptr<AudioBus> bus, |
| 95 uint32_t delay_milliseconds, |
| 96 int sample_rate) { |
| 97 DoCopyAudioCB(bus.get(), delay_milliseconds, sample_rate); |
| 98 } |
| 99 |
| 100 int Render(AudioBus* audio_bus) { |
| 101 return wasp_impl_->RenderForTesting(audio_bus); |
| 102 } |
| 103 |
| 88 protected: | 104 protected: |
| 89 AudioParameters params_; | 105 AudioParameters params_; |
| 90 FakeAudioRenderCallback fake_callback_; | 106 FakeAudioRenderCallback fake_callback_; |
| 91 scoped_refptr<MockAudioRendererSink> mock_sink_; | 107 scoped_refptr<MockAudioRendererSink> mock_sink_; |
| 92 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; | 108 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; |
| 93 base::MessageLoop message_loop_; | 109 base::MessageLoop message_loop_; |
| 94 | 110 |
| 95 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); | 111 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); |
| 96 }; | 112 }; |
| 97 | 113 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 110 base::RunLoop().RunUntilIdle(); | 126 base::RunLoop().RunUntilIdle(); |
| 111 | 127 |
| 112 // setClient() with the same client should do nothing. | 128 // setClient() with the same client should do nothing. |
| 113 wasp_impl_->setClient(this); | 129 wasp_impl_->setClient(this); |
| 114 base::RunLoop().RunUntilIdle(); | 130 base::RunLoop().RunUntilIdle(); |
| 115 } | 131 } |
| 116 | 132 |
| 117 // Verify AudioRendererSink functionality w/ and w/o a client. | 133 // Verify AudioRendererSink functionality w/ and w/o a client. |
| 118 TEST_F(WebAudioSourceProviderImplTest, SinkMethods) { | 134 TEST_F(WebAudioSourceProviderImplTest, SinkMethods) { |
| 119 wasp_impl_->Initialize(params_, &fake_callback_); | 135 wasp_impl_->Initialize(params_, &fake_callback_); |
| 120 ASSERT_EQ(mock_sink_->callback(), &fake_callback_); | |
| 121 | 136 |
| 122 // Without a client all WASP calls should fall through to the underlying sink. | 137 // Without a client all WASP calls should fall through to the underlying sink. |
| 123 CallAllSinkMethodsAndVerify(true); | 138 CallAllSinkMethodsAndVerify(true); |
| 124 | 139 |
| 125 // With a client no calls should reach the Stop()'d sink. Also, setClient() | 140 // With a client no calls should reach the Stop()'d sink. Also, setClient() |
| 126 // should propagate the params provided during Initialize() at call time. | 141 // should propagate the params provided during Initialize() at call time. |
| 127 SetClient(this); | 142 SetClient(this); |
| 128 CallAllSinkMethodsAndVerify(false); | 143 CallAllSinkMethodsAndVerify(false); |
| 129 | 144 |
| 130 // Removing the client should cause WASP to revert to the underlying sink. | 145 // 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())); | 248 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); |
| 234 | 249 |
| 235 // Stop() should return silence. | 250 // Stop() should return silence. |
| 236 wasp_impl_->Stop(); | 251 wasp_impl_->Stop(); |
| 237 bus1->channel(0)[0] = 1; | 252 bus1->channel(0)[0] = 1; |
| 238 bus2->Zero(); | 253 bus2->Zero(); |
| 239 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); | 254 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); |
| 240 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); | 255 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); |
| 241 } | 256 } |
| 242 | 257 |
| 258 // Verify CopyAudioCB is called if registered. |
| 259 TEST_F(WebAudioSourceProviderImplTest, CopyAudioCB) { |
| 260 testing::InSequence s; |
| 261 wasp_impl_->Initialize(params_, &fake_callback_); |
| 262 wasp_impl_->SetCopyAudioCallback(base::Bind( |
| 263 &WebAudioSourceProviderImplTest::OnAudioBus, base::Unretained(this))); |
| 264 |
| 265 const scoped_ptr<AudioBus> bus1 = AudioBus::Create(params_); |
| 266 EXPECT_CALL(*this, DoCopyAudioCB(_, 0, params_.sample_rate())).Times(1); |
| 267 Render(bus1.get()); |
| 268 |
| 269 wasp_impl_->ClearCopyAudioCallback(); |
| 270 EXPECT_CALL(*this, DoCopyAudioCB(_, _, _)).Times(0); |
| 271 Render(bus1.get()); |
| 272 |
| 273 testing::Mock::VerifyAndClear(mock_sink_.get()); |
| 274 } |
| 275 |
| 243 } // namespace media | 276 } // namespace media |
| OLD | NEW |