Index: content/browser/media/capture/web_contents_audio_input_stream_unittest.cc |
diff --git a/content/browser/media/capture/web_contents_audio_input_stream_unittest.cc b/content/browser/media/capture/web_contents_audio_input_stream_unittest.cc |
index 6ec220f767ae3ba09245905882090a3bbff1268a..c9dfe512deac2d6e931717075f008a0585543547 100644 |
--- a/content/browser/media/capture/web_contents_audio_input_stream_unittest.cc |
+++ b/content/browser/media/capture/web_contents_audio_input_stream_unittest.cc |
@@ -33,9 +33,11 @@ using ::testing::NotNull; |
using ::testing::SaveArg; |
using ::testing::WithArgs; |
+using media::AudioBus; |
using media::AudioInputStream; |
using media::AudioOutputStream; |
using media::AudioParameters; |
+using media::AudioPushSink; |
using media::SineWaveAudioSource; |
using media::VirtualAudioInputStream; |
using media::VirtualAudioOutputStream; |
@@ -119,12 +121,12 @@ class MockVirtualAudioInputStream : public VirtualAudioInputStream { |
ON_CALL(*this, GetAutomaticGainControl()) |
.WillByDefault( |
Invoke(&real_, &VirtualAudioInputStream::GetAutomaticGainControl)); |
- ON_CALL(*this, AddOutputStream(NotNull(), _)) |
+ ON_CALL(*this, AddInputProvider(NotNull(), _)) |
.WillByDefault( |
- Invoke(&real_, &VirtualAudioInputStream::AddOutputStream)); |
- ON_CALL(*this, RemoveOutputStream(NotNull(), _)) |
+ Invoke(&real_, &VirtualAudioInputStream::AddInputProvider)); |
+ ON_CALL(*this, RemoveInputProvider(NotNull(), _)) |
.WillByDefault( |
- Invoke(&real_, &VirtualAudioInputStream::RemoveOutputStream)); |
+ Invoke(&real_, &VirtualAudioInputStream::RemoveInputProvider)); |
} |
~MockVirtualAudioInputStream() { |
@@ -140,10 +142,12 @@ class MockVirtualAudioInputStream : public VirtualAudioInputStream { |
MOCK_METHOD0(GetVolume, double()); |
MOCK_METHOD1(SetAutomaticGainControl, bool(bool)); |
MOCK_METHOD0(GetAutomaticGainControl, bool()); |
- MOCK_METHOD2(AddOutputStream, void(VirtualAudioOutputStream*, |
- const AudioParameters&)); |
- MOCK_METHOD2(RemoveOutputStream, void(VirtualAudioOutputStream*, |
- const AudioParameters&)); |
+ MOCK_METHOD2(AddInputProvider, |
+ void(media::AudioConverter::InputCallback*, |
+ const AudioParameters&)); |
+ MOCK_METHOD2(RemoveInputProvider, |
+ void(media::AudioConverter::InputCallback*, |
+ const AudioParameters&)); |
private: |
void OnRealStreamHasClosed(VirtualAudioInputStream* stream) { |
@@ -175,7 +179,7 @@ class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { |
} // namespace |
-class WebContentsAudioInputStreamTest : public testing::Test { |
+class WebContentsAudioInputStreamTest : public testing::TestWithParam<bool> { |
public: |
WebContentsAudioInputStreamTest() |
: thread_bundle_(new TestBrowserThreadBundle( |
@@ -203,6 +207,10 @@ class WebContentsAudioInputStreamTest : public testing::Test { |
DCHECK(sources_.empty()); |
} |
+ void SetIsDuplication(bool is_duplication) { |
miu
2016/05/06 22:29:49
The is_duplication_ member (and this setter method
qiangchen
2016/05/10 22:36:53
Done.
|
+ is_duplication_ = is_duplication; |
+ } |
+ |
void Open() { |
mock_vais_ = new MockVirtualAudioInputStream(audio_thread_.task_runner()); |
EXPECT_CALL(*mock_vais_, Open()); |
@@ -222,8 +230,8 @@ class WebContentsAudioInputStreamTest : public testing::Test { |
wcais_ = new WebContentsAudioInputStream( |
current_render_process_id_, current_render_frame_id_, |
- mock_mirroring_manager_.get(), |
- mock_tracker_, mock_vais_); |
+ mock_mirroring_manager_.get(), mock_tracker_, mock_vais_, |
+ is_duplication_); |
wcais_->Open(); |
} |
@@ -277,32 +285,62 @@ class WebContentsAudioInputStreamTest : public testing::Test { |
done.Wait(); |
ASSERT_TRUE(destination_); |
- EXPECT_CALL(*mock_vais_, AddOutputStream(NotNull(), _)) |
+ EXPECT_CALL(*mock_vais_, AddInputProvider(NotNull(), _)) |
.RetiresOnSaturation(); |
// Later, when stream is closed: |
- EXPECT_CALL(*mock_vais_, RemoveOutputStream(NotNull(), _)) |
+ EXPECT_CALL(*mock_vais_, RemoveInputProvider(NotNull(), _)) |
.RetiresOnSaturation(); |
const AudioParameters& params = TestAudioParameters(); |
- AudioOutputStream* const out = destination_->AddInput(params); |
- ASSERT_TRUE(out); |
- streams_.push_back(out); |
- EXPECT_TRUE(out->Open()); |
- SineWaveAudioSource* const source = new SineWaveAudioSource( |
- params.channel_layout(), 200.0, params.sample_rate()); |
- sources_.push_back(source); |
- out->Start(source); |
+ if (is_duplication_) { |
+ media::AudioPushSink* out = destination_->AddPushInput(params); |
+ ASSERT_TRUE(out); |
+ sinks_.push_back(out); |
+ SineWaveAudioSource* const source = new SineWaveAudioSource( |
miu
2016/05/06 22:29:49
Please try to avoid duplicate code where possible:
qiangchen
2016/05/10 22:36:52
Done.
|
+ params.channel_layout(), 200.0, params.sample_rate()); |
+ sources_.push_back(source); |
+ |
+ std::unique_ptr<media::AudioBus> audio_data = AudioBus::Create(params); |
+ base::TimeTicks now = base::TimeTicks::Now(); |
+ // 20 Audio buses are enough for all test cases. |
+ const int kAudioBusesNumber = 20; |
+ for (int i = 0; i < kAudioBusesNumber; i++) { |
+ int frames = source->OnMoreData(audio_data.get(), 0, 0); |
+ out->OnData(*(audio_data.get()), now); |
+ now += base::TimeDelta::FromMillisecondsD( |
+ frames * params.GetMicrosecondsPerFrame()); |
+ } |
+ } else { |
+ AudioOutputStream* const out = destination_->AddInput(params); |
+ ASSERT_TRUE(out); |
+ streams_.push_back(out); |
+ EXPECT_TRUE(out->Open()); |
+ SineWaveAudioSource* const source = new SineWaveAudioSource( |
+ params.channel_layout(), 200.0, params.sample_rate()); |
+ sources_.push_back(source); |
+ out->Start(source); |
+ } |
} |
void RemoveOneInputInFIFOOrder() { |
- ASSERT_FALSE(streams_.empty()); |
- AudioOutputStream* const out = streams_.front(); |
- streams_.pop_front(); |
- out->Stop(); |
- out->Close(); // Self-deletes. |
- ASSERT_TRUE(!sources_.empty()); |
- delete sources_.front(); |
- sources_.pop_front(); |
+ if (is_duplication_) { |
+ ASSERT_FALSE(sinks_.empty()); |
+ AudioPushSink* const out = sinks_.front(); |
+ sinks_.pop_front(); |
+ out->Close(); // Self-deletes. |
+ ASSERT_TRUE(!sources_.empty()); |
miu
2016/05/06 22:29:50
ditto (duplicate code): The last three lines here
qiangchen
2016/05/10 22:36:53
Done.
|
+ delete sources_.front(); |
+ sources_.pop_front(); |
+ } else { |
+ ASSERT_FALSE(streams_.empty()); |
+ AudioOutputStream* const out = streams_.front(); |
+ streams_.pop_front(); |
+ out->Stop(); |
+ out->Close(); // Self-deletes. |
+ ASSERT_TRUE(!sources_.empty()); |
+ delete sources_.front(); |
+ sources_.pop_front(); |
+ } |
} |
void ChangeMirroringTarget() { |
@@ -390,8 +428,15 @@ class WebContentsAudioInputStreamTest : public testing::Test { |
// Streams provided by calls to WebContentsAudioInputStream::AddInput(). Each |
// is started with a simulated source of audio data. |
std::list<AudioOutputStream*> streams_; |
+ std::list<media::AudioPushSink*> sinks_; |
std::list<SineWaveAudioSource*> sources_; // 1:1 with elements in streams_. |
+ // Set this value to true to test a WebContentsAudioInputStream instance, |
+ // which requests duplicate audio. |
+ // Otherwise, we are testing a WebContentsAudioInputStream instance, which |
+ // requests diverting audio. |
+ bool is_duplication_; |
+ |
base::WaitableEvent on_data_event_; |
DISALLOW_COPY_AND_ASSIGN(WebContentsAudioInputStreamTest); |
@@ -401,12 +446,14 @@ class WebContentsAudioInputStreamTest : public testing::Test { |
RunOnAudioThread(base::Bind(&WebContentsAudioInputStreamTest::method, \ |
base::Unretained(this))) |
-TEST_F(WebContentsAudioInputStreamTest, OpenedButNeverStarted) { |
+TEST_P(WebContentsAudioInputStreamTest, OpenedButNeverStarted) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Close); |
} |
-TEST_F(WebContentsAudioInputStreamTest, MirroringNothing) { |
+TEST_P(WebContentsAudioInputStreamTest, MirroringNothing) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Start); |
WaitForData(); |
@@ -414,7 +461,8 @@ TEST_F(WebContentsAudioInputStreamTest, MirroringNothing) { |
RUN_ON_AUDIO_THREAD(Close); |
} |
-TEST_F(WebContentsAudioInputStreamTest, MirroringOutputOutlivesSession) { |
+TEST_P(WebContentsAudioInputStreamTest, MirroringOutputOutlivesSession) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Start); |
RUN_ON_AUDIO_THREAD(AddAnotherInput); |
@@ -424,7 +472,8 @@ TEST_F(WebContentsAudioInputStreamTest, MirroringOutputOutlivesSession) { |
RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
} |
-TEST_F(WebContentsAudioInputStreamTest, MirroringOutputWithinSession) { |
+TEST_P(WebContentsAudioInputStreamTest, MirroringOutputWithinSession) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Start); |
RUN_ON_AUDIO_THREAD(AddAnotherInput); |
@@ -434,7 +483,8 @@ TEST_F(WebContentsAudioInputStreamTest, MirroringOutputWithinSession) { |
RUN_ON_AUDIO_THREAD(Close); |
} |
-TEST_F(WebContentsAudioInputStreamTest, MirroringNothingWithTargetChange) { |
+TEST_P(WebContentsAudioInputStreamTest, MirroringNothingWithTargetChange) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Start); |
RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); |
@@ -442,7 +492,8 @@ TEST_F(WebContentsAudioInputStreamTest, MirroringNothingWithTargetChange) { |
RUN_ON_AUDIO_THREAD(Close); |
} |
-TEST_F(WebContentsAudioInputStreamTest, MirroringOneStreamAfterTargetChange) { |
+TEST_P(WebContentsAudioInputStreamTest, MirroringOneStreamAfterTargetChange) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Start); |
RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); |
@@ -453,7 +504,8 @@ TEST_F(WebContentsAudioInputStreamTest, MirroringOneStreamAfterTargetChange) { |
RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
} |
-TEST_F(WebContentsAudioInputStreamTest, MirroringOneStreamWithTargetChange) { |
+TEST_P(WebContentsAudioInputStreamTest, MirroringOneStreamWithTargetChange) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Start); |
RUN_ON_AUDIO_THREAD(AddAnotherInput); |
@@ -467,7 +519,8 @@ TEST_F(WebContentsAudioInputStreamTest, MirroringOneStreamWithTargetChange) { |
RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
} |
-TEST_F(WebContentsAudioInputStreamTest, MirroringLostTarget) { |
+TEST_P(WebContentsAudioInputStreamTest, MirroringLostTarget) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Start); |
RUN_ON_AUDIO_THREAD(AddAnotherInput); |
@@ -478,7 +531,8 @@ TEST_F(WebContentsAudioInputStreamTest, MirroringLostTarget) { |
RUN_ON_AUDIO_THREAD(Close); |
} |
-TEST_F(WebContentsAudioInputStreamTest, MirroringMultipleStreamsAndTargets) { |
+TEST_P(WebContentsAudioInputStreamTest, MirroringMultipleStreamsAndTargets) { |
+ SetIsDuplication(GetParam()); |
RUN_ON_AUDIO_THREAD(Open); |
RUN_ON_AUDIO_THREAD(Start); |
RUN_ON_AUDIO_THREAD(AddAnotherInput); |
@@ -502,4 +556,6 @@ TEST_F(WebContentsAudioInputStreamTest, MirroringMultipleStreamsAndTargets) { |
RUN_ON_AUDIO_THREAD(Close); |
} |
+INSTANTIATE_TEST_CASE_P(, WebContentsAudioInputStreamTest, ::testing::Bool()); |
miu
2016/05/06 22:29:49
Great idea here! (to just run all the tests when
qiangchen
2016/05/10 22:36:52
Acknowledged.
|
+ |
} // namespace content |