OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/renderer/media/audio_device_factory.h" |
9 #include "content/renderer/media/audio_renderer_mixer_manager.h" | 10 #include "content/renderer/media/audio_renderer_mixer_manager.h" |
10 #include "ipc/ipc_message.h" | 11 #include "media/audio/audio_manager_base.h" |
11 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
12 #include "media/base/audio_hardware_config.h" | 13 #include "media/base/audio_capturer_source.h" |
13 #include "media/base/audio_renderer_mixer.h" | 14 #include "media/base/audio_renderer_mixer.h" |
14 #include "media/base/audio_renderer_mixer_input.h" | 15 #include "media/base/audio_renderer_mixer_input.h" |
15 #include "media/base/fake_audio_render_callback.h" | 16 #include "media/base/fake_audio_render_callback.h" |
16 #include "media/base/mock_audio_renderer_sink.h" | 17 #include "media/base/mock_audio_renderer_sink.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "url/gurl.h" |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 static const int kBitsPerChannel = 16; | 24 static const int kBitsPerChannel = 16; |
23 static const int kSampleRate = 48000; | 25 static const int kSampleRate = 48000; |
24 static const int kBufferSize = 8192; | 26 static const int kBufferSize = 8192; |
25 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; | 27 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; |
26 static const media::ChannelLayout kAnotherChannelLayout = | 28 static const media::ChannelLayout kAnotherChannelLayout = |
27 media::CHANNEL_LAYOUT_2_1; | 29 media::CHANNEL_LAYOUT_2_1; |
28 static const std::string kDefaultDeviceId; | 30 static const char* const kDefaultDeviceId = |
29 static const url::Origin kSecurityOrigin; | 31 media::AudioManagerBase::kDefaultDeviceId; |
| 32 static const char kAnotherDeviceId[] = "another-device-id"; |
| 33 static const char kNonexistentDeviceId[] = "nonexistent-device-id"; |
30 | 34 |
31 static const int kRenderFrameId = 124; | 35 static const int kRenderFrameId = 124; |
32 static const int kAnotherRenderFrameId = 678; | 36 static const int kAnotherRenderFrameId = 678; |
33 | 37 |
34 using media::AudioParameters; | 38 using media::AudioParameters; |
35 | 39 |
36 class AudioRendererMixerManagerTest : public testing::Test { | 40 class AudioRendererMixerManagerTest : public testing::Test, |
| 41 public AudioDeviceFactory { |
37 public: | 42 public: |
38 AudioRendererMixerManagerTest() { | 43 AudioRendererMixerManagerTest() |
39 manager_.reset(new AudioRendererMixerManager()); | 44 : manager_(new AudioRendererMixerManager()), |
40 | 45 mock_sink_(new media::MockAudioRendererSink()), |
41 // We don't want to deal with instantiating a real AudioOutputDevice since | 46 mock_sink_no_device_(new media::MockAudioRendererSink( |
42 // it's not important to our testing, so we inject a mock. | 47 kNonexistentDeviceId, |
43 mock_sink_ = new media::MockAudioRendererSink(); | 48 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND)), |
44 manager_->SetAudioRendererSinkForTesting(mock_sink_.get()); | 49 kSecurityOrigin2(GURL("http://localhost")) {} |
45 } | |
46 | 50 |
47 media::AudioRendererMixer* GetMixer( | 51 media::AudioRendererMixer* GetMixer( |
48 int source_render_frame_id, | 52 int source_render_frame_id, |
49 const media::AudioParameters& params, | 53 const media::AudioParameters& params, |
50 const std::string& device_id, | 54 const std::string& device_id, |
51 const url::Origin& security_origin, | 55 const url::Origin& security_origin, |
52 media::OutputDeviceStatus* device_status) { | 56 media::OutputDeviceStatus* device_status) { |
53 return manager_->GetMixer(source_render_frame_id, params, device_id, | 57 return manager_->GetMixer(source_render_frame_id, params, device_id, |
54 security_origin, device_status); | 58 security_origin, device_status); |
55 } | 59 } |
56 | 60 |
57 void RemoveMixer(int source_render_frame_id, | 61 void RemoveMixer(int source_render_frame_id, |
58 const media::AudioParameters& params, | 62 const media::AudioParameters& params, |
59 const std::string& device_id, | 63 const std::string& device_id, |
60 const url::Origin& security_origin) { | 64 const url::Origin& security_origin) { |
61 return manager_->RemoveMixer(source_render_frame_id, params, device_id, | 65 return manager_->RemoveMixer(source_render_frame_id, params, device_id, |
62 security_origin); | 66 security_origin); |
63 } | 67 } |
64 | 68 |
65 void UseNonexistentSink() { | |
66 mock_sink_ = new media::MockAudioRendererSink( | |
67 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND); | |
68 manager_->SetAudioRendererSinkForTesting(mock_sink_.get()); | |
69 } | |
70 | |
71 // Number of instantiated mixers. | 69 // Number of instantiated mixers. |
72 int mixer_count() { | 70 int mixer_count() { |
73 return manager_->mixers_.size(); | 71 return manager_->mixers_.size(); |
74 } | 72 } |
75 | 73 |
76 protected: | 74 protected: |
| 75 MOCK_METHOD1(CreateAudioCapturerSource, |
| 76 scoped_refptr<media::AudioCapturerSource>(int)); |
| 77 MOCK_METHOD5( |
| 78 CreateSwitchableAudioRendererSink, |
| 79 scoped_refptr<media::SwitchableAudioRendererSink>(SourceType, |
| 80 int, |
| 81 int, |
| 82 const std::string&, |
| 83 const url::Origin&)); |
| 84 MOCK_METHOD5(CreateAudioRendererSink, |
| 85 scoped_refptr<media::AudioRendererSink>(SourceType, |
| 86 int, |
| 87 int, |
| 88 const std::string&, |
| 89 const url::Origin&)); |
| 90 |
| 91 scoped_refptr<media::AudioRendererSink> CreateAudioRendererMixerSink( |
| 92 int render_frame_id, |
| 93 int session_id, |
| 94 const std::string& device_id, |
| 95 const url::Origin& security_origin) { |
| 96 if ((device_id == kDefaultDeviceId) || (device_id == kAnotherDeviceId)) { |
| 97 // We don't care about separate sinks for these devices |
| 98 return mock_sink_; |
| 99 } |
| 100 if (device_id == kNonexistentDeviceId) { |
| 101 return mock_sink_no_device_; |
| 102 } |
| 103 if (device_id.empty()) { |
| 104 return mock_sink_; |
| 105 } |
| 106 |
| 107 NOTREACHED(); |
| 108 return nullptr; |
| 109 } |
| 110 |
77 scoped_ptr<AudioRendererMixerManager> manager_; | 111 scoped_ptr<AudioRendererMixerManager> manager_; |
78 scoped_refptr<media::MockAudioRendererSink> mock_sink_; | 112 scoped_refptr<media::MockAudioRendererSink> mock_sink_; |
| 113 scoped_refptr<media::MockAudioRendererSink> mock_sink_no_device_; |
| 114 |
| 115 // To avoid global/static non-POD constants. |
| 116 const url::Origin kSecurityOrigin; |
| 117 const url::Origin kSecurityOrigin2; |
79 | 118 |
80 private: | 119 private: |
81 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest); | 120 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest); |
82 }; | 121 }; |
83 | 122 |
84 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with | 123 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with |
85 // respect to the explicit ref counting done. | 124 // respect to the explicit ref counting done. |
86 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { | 125 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { |
87 // Since we're testing two different sets of parameters, we expect | 126 // Since we're testing two different sets of parameters, we expect |
88 // AudioRendererMixerManager to call Start and Stop on our mock twice. | 127 // AudioRendererMixerManager to call Start and Stop on our mock twice. |
89 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 128 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
90 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 129 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
91 | 130 |
92 // There should be no mixers outstanding to start with. | 131 // There should be no mixers outstanding to start with. |
93 EXPECT_EQ(mixer_count(), 0); | 132 EXPECT_EQ(0, mixer_count()); |
94 | 133 |
95 media::AudioParameters params1( | 134 media::AudioParameters params1( |
96 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 135 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
97 kBitsPerChannel, kBufferSize); | 136 kBitsPerChannel, kBufferSize); |
98 | 137 |
99 media::AudioRendererMixer* mixer1 = GetMixer( | 138 media::AudioRendererMixer* mixer1 = GetMixer( |
100 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); | 139 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); |
101 ASSERT_TRUE(mixer1); | 140 ASSERT_TRUE(mixer1); |
102 EXPECT_EQ(mixer_count(), 1); | 141 EXPECT_EQ(1, mixer_count()); |
103 | 142 |
104 // The same parameters should return the same mixer1. | 143 // The same parameters should return the same mixer1. |
105 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params1, kDefaultDeviceId, | 144 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params1, kDefaultDeviceId, |
106 kSecurityOrigin, nullptr)); | 145 kSecurityOrigin, nullptr)); |
107 EXPECT_EQ(mixer_count(), 1); | 146 EXPECT_EQ(1, mixer_count()); |
108 | 147 |
109 // Remove the extra mixer we just acquired. | 148 // Remove the extra mixer we just acquired. |
110 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 149 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); |
111 EXPECT_EQ(mixer_count(), 1); | 150 EXPECT_EQ(1, mixer_count()); |
112 | 151 |
113 media::AudioParameters params2( | 152 media::AudioParameters params2( |
114 AudioParameters::AUDIO_PCM_LINEAR, kAnotherChannelLayout, kSampleRate * 2, | 153 AudioParameters::AUDIO_PCM_LINEAR, kAnotherChannelLayout, kSampleRate * 2, |
115 kBitsPerChannel, kBufferSize * 2); | 154 kBitsPerChannel, kBufferSize * 2); |
116 media::AudioRendererMixer* mixer2 = GetMixer( | 155 media::AudioRendererMixer* mixer2 = GetMixer( |
117 kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin, nullptr); | 156 kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin, nullptr); |
118 ASSERT_TRUE(mixer2); | 157 ASSERT_TRUE(mixer2); |
119 EXPECT_EQ(mixer_count(), 2); | 158 EXPECT_EQ(2, mixer_count()); |
120 | 159 |
121 // Different parameters should result in a different mixer1. | 160 // Different parameters should result in a different mixer1. |
122 EXPECT_NE(mixer1, mixer2); | 161 EXPECT_NE(mixer1, mixer2); |
123 | 162 |
124 // Remove both outstanding mixers. | 163 // Remove both outstanding mixers. |
125 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 164 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); |
126 EXPECT_EQ(mixer_count(), 1); | 165 EXPECT_EQ(1, mixer_count()); |
127 RemoveMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); | 166 RemoveMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); |
128 EXPECT_EQ(mixer_count(), 0); | 167 EXPECT_EQ(0, mixer_count()); |
129 } | 168 } |
130 | 169 |
131 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter | 170 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter |
132 // differences. | 171 // differences. |
133 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { | 172 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { |
134 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 173 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
135 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 174 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
136 EXPECT_EQ(mixer_count(), 0); | 175 EXPECT_EQ(mixer_count(), 0); |
137 | 176 |
138 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, | 177 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, |
139 kChannelLayout, | 178 kChannelLayout, |
140 kSampleRate, | 179 kSampleRate, |
141 kBitsPerChannel, | 180 kBitsPerChannel, |
142 kBufferSize); | 181 kBufferSize); |
143 media::AudioRendererMixer* mixer1 = GetMixer( | 182 media::AudioRendererMixer* mixer1 = GetMixer( |
144 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); | 183 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); |
145 ASSERT_TRUE(mixer1); | 184 ASSERT_TRUE(mixer1); |
146 EXPECT_EQ(mixer_count(), 1); | 185 EXPECT_EQ(1, mixer_count()); |
147 | 186 |
148 // Different sample rates, formats, bit depths, and buffer sizes should not | 187 // Different sample rates, formats, bit depths, and buffer sizes should not |
149 // result in a different mixer. | 188 // result in a different mixer. |
150 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 189 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
151 kChannelLayout, | 190 kChannelLayout, |
152 kSampleRate * 2, | 191 kSampleRate * 2, |
153 kBitsPerChannel * 2, | 192 kBitsPerChannel * 2, |
154 kBufferSize * 2); | 193 kBufferSize * 2); |
155 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params2, kDefaultDeviceId, | 194 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params2, kDefaultDeviceId, |
156 kSecurityOrigin, nullptr)); | 195 kSecurityOrigin, nullptr)); |
157 EXPECT_EQ(mixer_count(), 1); | 196 EXPECT_EQ(1, mixer_count()); |
158 RemoveMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); | 197 RemoveMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); |
159 EXPECT_EQ(mixer_count(), 1); | 198 EXPECT_EQ(1, mixer_count()); |
160 | 199 |
161 // Modify some parameters that do matter: channel layout | 200 // Modify some parameters that do matter: channel layout |
162 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 201 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
163 kAnotherChannelLayout, | 202 kAnotherChannelLayout, |
164 kSampleRate, | 203 kSampleRate, |
165 kBitsPerChannel, | 204 kBitsPerChannel, |
166 kBufferSize); | 205 kBufferSize); |
167 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); | 206 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); |
168 | 207 |
169 EXPECT_NE(mixer1, GetMixer(kRenderFrameId, params3, kDefaultDeviceId, | 208 EXPECT_NE(mixer1, GetMixer(kRenderFrameId, params3, kDefaultDeviceId, |
170 kSecurityOrigin, nullptr)); | 209 kSecurityOrigin, nullptr)); |
171 EXPECT_EQ(mixer_count(), 2); | 210 EXPECT_EQ(2, mixer_count()); |
172 RemoveMixer(kRenderFrameId, params3, kDefaultDeviceId, kSecurityOrigin); | 211 RemoveMixer(kRenderFrameId, params3, kDefaultDeviceId, kSecurityOrigin); |
173 EXPECT_EQ(mixer_count(), 1); | 212 EXPECT_EQ(1, mixer_count()); |
174 | 213 |
175 // Remove final mixer. | 214 // Remove final mixer. |
176 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 215 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); |
177 EXPECT_EQ(mixer_count(), 0); | 216 EXPECT_EQ(0, mixer_count()); |
178 } | 217 } |
179 | 218 |
180 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate | 219 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate |
181 // callbacks and they are working as expected. Also, verify that separate | 220 // callbacks and they are working as expected. Also, verify that separate |
182 // mixers are created for separate render views, even though the AudioParameters | 221 // mixers are created for separate render views, even though the AudioParameters |
183 // are the same. | 222 // are the same. |
184 TEST_F(AudioRendererMixerManagerTest, CreateInput) { | 223 TEST_F(AudioRendererMixerManagerTest, CreateInput) { |
185 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice | 224 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice |
186 // each. Note: Under normal conditions, each mixer would get its own sink! | 225 // each. Note: Under normal conditions, each mixer would get its own sink! |
187 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 226 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
188 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 227 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
189 | 228 |
190 media::AudioParameters params( | 229 media::AudioParameters params( |
191 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 230 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
192 kBitsPerChannel, kBufferSize); | 231 kBitsPerChannel, kBufferSize); |
193 | 232 |
194 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. | 233 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. |
195 EXPECT_EQ(mixer_count(), 0); | 234 EXPECT_EQ(0, mixer_count()); |
196 media::FakeAudioRenderCallback callback(0); | 235 media::FakeAudioRenderCallback callback(0); |
197 scoped_refptr<media::AudioRendererMixerInput> input( | 236 scoped_refptr<media::AudioRendererMixerInput> input( |
198 manager_->CreateInput(kRenderFrameId, kDefaultDeviceId, kSecurityOrigin)); | 237 manager_->CreateInput(kRenderFrameId, kDefaultDeviceId, kSecurityOrigin)); |
199 input->Initialize(params, &callback); | 238 input->Initialize(params, &callback); |
200 EXPECT_EQ(mixer_count(), 0); | 239 EXPECT_EQ(0, mixer_count()); |
201 media::FakeAudioRenderCallback another_callback(1); | 240 media::FakeAudioRenderCallback another_callback(1); |
202 scoped_refptr<media::AudioRendererMixerInput> another_input( | 241 scoped_refptr<media::AudioRendererMixerInput> another_input( |
203 manager_->CreateInput(kAnotherRenderFrameId, kDefaultDeviceId, | 242 manager_->CreateInput(kAnotherRenderFrameId, kDefaultDeviceId, |
204 kSecurityOrigin)); | 243 kSecurityOrigin)); |
205 another_input->Initialize(params, &another_callback); | 244 another_input->Initialize(params, &another_callback); |
206 EXPECT_EQ(mixer_count(), 0); | 245 EXPECT_EQ(0, mixer_count()); |
207 | 246 |
208 // Implicitly test that AudioRendererMixerInput was provided with the expected | 247 // Implicitly test that AudioRendererMixerInput was provided with the expected |
209 // callbacks needed to acquire an AudioRendererMixer and remove it. | 248 // callbacks needed to acquire an AudioRendererMixer and remove it. |
210 input->Start(); | 249 input->Start(); |
211 EXPECT_EQ(mixer_count(), 1); | 250 EXPECT_EQ(1, mixer_count()); |
212 another_input->Start(); | 251 another_input->Start(); |
213 EXPECT_EQ(mixer_count(), 2); | 252 EXPECT_EQ(2, mixer_count()); |
214 | 253 |
215 // Destroying the inputs should destroy the mixers. | 254 // Destroying the inputs should destroy the mixers. |
216 input->Stop(); | 255 input->Stop(); |
217 input = NULL; | 256 input = nullptr; |
218 EXPECT_EQ(mixer_count(), 1); | 257 EXPECT_EQ(1, mixer_count()); |
219 another_input->Stop(); | 258 another_input->Stop(); |
220 another_input = NULL; | 259 another_input = nullptr; |
221 EXPECT_EQ(mixer_count(), 0); | 260 EXPECT_EQ(0, mixer_count()); |
222 } | 261 } |
223 | 262 |
224 // Verify GetMixer() correctly creates different mixers with the same | 263 // Verify GetMixer() correctly creates different mixers with the same |
225 // parameters, but different device ID and/or security origin | 264 // parameters, but different device ID and/or security origin |
226 TEST_F(AudioRendererMixerManagerTest, MixerDevices) { | 265 TEST_F(AudioRendererMixerManagerTest, MixerDevices) { |
227 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); | 266 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); |
228 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); | 267 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); |
229 EXPECT_EQ(mixer_count(), 0); | 268 EXPECT_EQ(0, mixer_count()); |
230 | 269 |
231 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 270 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
232 kChannelLayout, kSampleRate, kBitsPerChannel, | 271 kChannelLayout, kSampleRate, kBitsPerChannel, |
233 kBufferSize); | 272 kBufferSize); |
234 media::AudioRendererMixer* mixer1 = GetMixer( | 273 media::AudioRendererMixer* mixer1 = GetMixer( |
235 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin, nullptr); | 274 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin, nullptr); |
236 ASSERT_TRUE(mixer1); | 275 ASSERT_TRUE(mixer1); |
237 EXPECT_EQ(mixer_count(), 1); | 276 EXPECT_EQ(1, mixer_count()); |
238 | 277 |
239 std::string device_id2("fake-device-id"); | 278 media::AudioRendererMixer* mixer2 = GetMixer( |
240 media::AudioRendererMixer* mixer2 = | 279 kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin, nullptr); |
241 GetMixer(kRenderFrameId, params, device_id2, kSecurityOrigin, nullptr); | |
242 ASSERT_TRUE(mixer2); | 280 ASSERT_TRUE(mixer2); |
243 EXPECT_EQ(mixer_count(), 2); | 281 EXPECT_EQ(2, mixer_count()); |
244 EXPECT_NE(mixer1, mixer2); | 282 EXPECT_NE(mixer1, mixer2); |
245 | 283 |
246 url::Origin security_origin2(GURL("http://localhost")); | |
247 media::AudioRendererMixer* mixer3 = GetMixer( | 284 media::AudioRendererMixer* mixer3 = GetMixer( |
248 kRenderFrameId, params, kDefaultDeviceId, security_origin2, nullptr); | 285 kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin2, nullptr); |
249 ASSERT_TRUE(mixer3); | 286 ASSERT_TRUE(mixer3); |
250 EXPECT_EQ(mixer_count(), 3); | 287 EXPECT_EQ(3, mixer_count()); |
251 EXPECT_NE(mixer1, mixer3); | 288 EXPECT_NE(mixer1, mixer3); |
252 EXPECT_NE(mixer2, mixer3); | 289 EXPECT_NE(mixer2, mixer3); |
253 | 290 |
254 RemoveMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin); | 291 RemoveMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin); |
255 EXPECT_EQ(mixer_count(), 2); | 292 EXPECT_EQ(2, mixer_count()); |
256 RemoveMixer(kRenderFrameId, params, device_id2, kSecurityOrigin); | 293 RemoveMixer(kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin); |
257 EXPECT_EQ(mixer_count(), 1); | 294 EXPECT_EQ(1, mixer_count()); |
258 RemoveMixer(kRenderFrameId, params, kDefaultDeviceId, security_origin2); | 295 RemoveMixer(kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin2); |
259 EXPECT_EQ(mixer_count(), 0); | 296 EXPECT_EQ(0, mixer_count()); |
260 } | 297 } |
261 | 298 |
262 // Verify that GetMixer() correctly returns a null mixer and an appropriate | 299 // Verify that GetMixer() correctly returns a null mixer and an appropriate |
263 // status code when a nonexistent device is requested. | 300 // status code when a nonexistent device is requested. |
264 TEST_F(AudioRendererMixerManagerTest, NonexistentDevice) { | 301 TEST_F(AudioRendererMixerManagerTest, NonexistentDevice) { |
265 EXPECT_EQ(mixer_count(), 0); | 302 EXPECT_EQ(0, mixer_count()); |
266 UseNonexistentSink(); | |
267 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 303 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
268 kChannelLayout, kSampleRate, kBitsPerChannel, | 304 kChannelLayout, kSampleRate, kBitsPerChannel, |
269 kBufferSize); | 305 kBufferSize); |
270 std::string nonexistent_device_id("nonexistent-device-id"); | |
271 media::OutputDeviceStatus device_status = media::OUTPUT_DEVICE_STATUS_OK; | 306 media::OutputDeviceStatus device_status = media::OUTPUT_DEVICE_STATUS_OK; |
272 EXPECT_CALL(*mock_sink_.get(), Stop()); | 307 EXPECT_CALL(*mock_sink_no_device_.get(), Stop()); |
273 media::AudioRendererMixer* mixer = | 308 media::AudioRendererMixer* mixer = |
274 GetMixer(kRenderFrameId, params, nonexistent_device_id, kSecurityOrigin, | 309 GetMixer(kRenderFrameId, params, kNonexistentDeviceId, kSecurityOrigin, |
275 &device_status); | 310 &device_status); |
276 EXPECT_FALSE(mixer); | 311 EXPECT_FALSE(mixer); |
277 EXPECT_EQ(device_status, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND); | 312 EXPECT_EQ(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, device_status); |
278 EXPECT_EQ(mixer_count(), 0); | 313 EXPECT_EQ(0, mixer_count()); |
279 } | 314 } |
280 | 315 |
281 } // namespace content | 316 } // namespace content |
OLD | NEW |