Index: media/base/audio_renderer_mixer_input_unittest.cc |
diff --git a/media/base/audio_renderer_mixer_input_unittest.cc b/media/base/audio_renderer_mixer_input_unittest.cc |
index 814b8ede316c5c1e13a5c26722f3406477b35539..d9d33de3fbb6aece1804c17a2670c0cf6013fdf8 100644 |
--- a/media/base/audio_renderer_mixer_input_unittest.cc |
+++ b/media/base/audio_renderer_mixer_input_unittest.cc |
@@ -22,7 +22,7 @@ static const int kBitsPerChannel = 16; |
static const int kSampleRate = 48000; |
static const int kBufferSize = 8192; |
static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
-static const char kDefaultDeviceId[] = ""; |
+static const char kDefaultDeviceId[] = "default"; |
static const char kUnauthorizedDeviceId[] = "unauthorized"; |
static const char kNonexistentDeviceId[] = "nonexistent"; |
@@ -45,6 +45,8 @@ class AudioRendererMixerInputTest : public testing::Test { |
base::Unretained(this)), |
base::Bind(&AudioRendererMixerInputTest::RemoveMixer, |
base::Unretained(this)), |
+ base::Bind(&AudioRendererMixerInputTest::GetOutputDeviceInfo, |
+ base::Unretained(this)), |
device_id, url::Origin()); |
} |
@@ -64,15 +66,20 @@ class AudioRendererMixerInputTest : public testing::Test { |
return nullptr; |
} |
- size_t idx = device_id.empty() ? 0 : 1; |
+ size_t idx = (device_id == kDefaultDeviceId) ? 0 : 1; |
if (!mixers_[idx]) { |
- scoped_refptr<MockAudioRendererSink> sink = new MockAudioRendererSink(); |
- EXPECT_CALL(*sink.get(), Start()); |
- EXPECT_CALL(*sink.get(), Stop()); |
- |
- mixers_[idx].reset(new AudioRendererMixer(audio_parameters_, sink)); |
+ sinks_[idx] = |
+ new MockAudioRendererSink(device_id, OUTPUT_DEVICE_STATUS_OK); |
+ EXPECT_CALL(*(sinks_[idx].get()), Start()); |
+ EXPECT_CALL(*(sinks_[idx].get()), Stop()); |
+ |
+ mixers_[idx].reset(new AudioRendererMixer( |
+ audio_parameters_, sinks_[idx].get(), |
+ base::Bind(&AudioRendererMixerInputTest::ReleaseSink, |
+ base::Unretained(this)))); |
} |
EXPECT_CALL(*this, RemoveMixer(testing::_, device_id, testing::_)); |
+ EXPECT_CALL(*this, ReleaseSink(sinks_[idx].get())); |
if (device_status) |
*device_status = OUTPUT_DEVICE_STATUS_OK; |
@@ -88,7 +95,13 @@ class AudioRendererMixerInputTest : public testing::Test { |
const std::string&, |
const url::Origin&)); |
+ MOCK_METHOD2(GetOutputDeviceInfo, |
+ OutputDeviceInfo(const std::string&, const url::Origin&)); |
+ |
+ MOCK_METHOD1(ReleaseSink, void(AudioRendererSink*)); |
+ |
MOCK_METHOD1(SwitchCallbackCalled, void(OutputDeviceStatus)); |
+ |
void SwitchCallback(base::RunLoop* loop, OutputDeviceStatus result) { |
SwitchCallbackCalled(result); |
loop->Quit(); |
@@ -100,6 +113,7 @@ class AudioRendererMixerInputTest : public testing::Test { |
virtual ~AudioRendererMixerInputTest() {} |
AudioParameters audio_parameters_; |
+ scoped_refptr<MockAudioRendererSink> sinks_[2]; // Must outlive mixers. |
std::unique_ptr<AudioRendererMixer> mixers_[2]; |
scoped_refptr<AudioRendererMixerInput> mixer_input_; |
std::unique_ptr<FakeAudioRenderCallback> fake_callback_; |
@@ -109,6 +123,25 @@ class AudioRendererMixerInputTest : public testing::Test { |
DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInputTest); |
}; |
+TEST_F(AudioRendererMixerInputTest, GetDeviceInfo) { |
+ ON_CALL(*this, GetOutputDeviceInfo(testing::_, testing::_)) |
+ .WillByDefault(testing::Return(OutputDeviceInfo())); |
+ EXPECT_CALL(*this, GetOutputDeviceInfo(kDefaultDeviceId, testing::_)) |
+ .Times(testing::Exactly(1)); |
+ |
+ // Calling GetOutputDeviceInfo() should result in the mock call, since there |
+ // is no mixer created yet for mixer input. |
+ mixer_input_->GetOutputDeviceInfo(); |
+ mixer_input_->Start(); |
+ |
+ // This call should be directed to the mixer and should not result in the mock |
+ // call. |
+ EXPECT_STREQ(kDefaultDeviceId, |
+ mixer_input_->GetOutputDeviceInfo().device_id().c_str()); |
+ |
+ mixer_input_->Stop(); |
+} |
+ |
// Test that getting and setting the volume work as expected. The volume is |
// returned from ProvideInput() only when playing. |
TEST_F(AudioRendererMixerInputTest, GetSetVolume) { |