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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } // namespace. | 93 } // namespace. |
94 | 94 |
95 class AudioOutputDeviceTest | 95 class AudioOutputDeviceTest |
96 : public testing::Test, | 96 : public testing::Test, |
97 public testing::WithParamInterface<bool> { | 97 public testing::WithParamInterface<bool> { |
98 public: | 98 public: |
99 AudioOutputDeviceTest() | 99 AudioOutputDeviceTest() |
100 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, | 100 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, |
101 CHANNEL_LAYOUT_STEREO, | 101 CHANNEL_LAYOUT_STEREO, |
102 48000, 16, 1024), | 102 48000, 16, 1024), |
103 audio_device_(new AudioOutputDevice( | |
104 &audio_output_ipc_, io_loop_.message_loop_proxy())), | |
105 synchronized_io_(GetParam()), | 103 synchronized_io_(GetParam()), |
106 input_channels_(synchronized_io_ ? 2 : 0) { | 104 input_channels_(synchronized_io_ ? 2 : 0) { |
107 } | 105 } |
108 | 106 |
109 ~AudioOutputDeviceTest() {} | 107 ~AudioOutputDeviceTest() {} |
110 | 108 |
109 virtual void SetUp() OVERRIDE { | |
scherkus (not reviewing)
2012/11/28 21:55:01
this is a pet peeve of mine... if your test fixtur
miu
2012/11/28 22:20:54
History: Each TEST_F() used to call Construct(), I
DaleCurtis
2012/11/28 22:34:39
I think you should just get rid of construct/destr
scherkus (not reviewing)
2012/11/28 22:37:32
We're splitting hairs here, but I'm OK having test
| |
110 Construct(); | |
111 Initialize(); | |
112 } | |
113 | |
114 virtual void TearDown() OVERRIDE { | |
115 Destruct(); | |
116 } | |
117 | |
118 void Construct(); | |
119 void Destruct(); | |
111 void Initialize(); | 120 void Initialize(); |
112 void StartAudioDevice(); | 121 void StartAudioDevice(); |
113 void CreateStream(); | 122 void CreateStream(); |
114 void ExpectRenderCallback(); | 123 void ExpectRenderCallback(); |
115 void WaitUntilRenderCallback(); | 124 void WaitUntilRenderCallback(); |
116 void StopAudioDevice(); | 125 void StopAudioDevice(); |
117 | 126 |
118 protected: | 127 protected: |
119 // Used to clean up TLS pointers that the test(s) will initialize. | 128 // Used to clean up TLS pointers that the test(s) will initialize. |
120 // Must remain the first member of this class. | 129 // Must remain the first member of this class. |
(...skipping 29 matching lines...) Expand all Loading... | |
150 | 159 |
151 int io_buffer_size = output_memory_size + input_memory_size; | 160 int io_buffer_size = output_memory_size + input_memory_size; |
152 | 161 |
153 // This is where it gets a bit hacky. The shared memory contract between | 162 // This is where it gets a bit hacky. The shared memory contract between |
154 // AudioOutputDevice and its browser side counter part includes a bit more | 163 // AudioOutputDevice and its browser side counter part includes a bit more |
155 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() | 164 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() |
156 // to get the actual size needed to fit the audio data plus the extra data. | 165 // to get the actual size needed to fit the audio data plus the extra data. |
157 return TotalSharedMemorySizeInBytes(io_buffer_size); | 166 return TotalSharedMemorySizeInBytes(io_buffer_size); |
158 } | 167 } |
159 | 168 |
169 void AudioOutputDeviceTest::Construct() { | |
170 EXPECT_CALL(audio_output_ipc_, AddDelegate(_)) | |
171 .WillOnce(Return(kStreamId)); | |
172 | |
173 audio_device_ = new AudioOutputDevice( | |
174 &audio_output_ipc_, io_loop_.message_loop_proxy()); | |
175 } | |
176 | |
177 void AudioOutputDeviceTest::Destruct() { | |
178 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
179 | |
180 audio_device_ = NULL; | |
181 } | |
182 | |
160 void AudioOutputDeviceTest::Initialize() { | 183 void AudioOutputDeviceTest::Initialize() { |
161 if (synchronized_io_) { | 184 if (synchronized_io_) { |
162 audio_device_->InitializeIO(default_audio_parameters_, | 185 audio_device_->InitializeIO(default_audio_parameters_, |
163 input_channels_, | 186 input_channels_, |
164 &callback_); | 187 &callback_); |
165 } else { | 188 } else { |
166 audio_device_->Initialize(default_audio_parameters_, | 189 audio_device_->Initialize(default_audio_parameters_, |
167 &callback_); | 190 &callback_); |
168 } | 191 } |
169 io_loop_.RunUntilIdle(); | 192 io_loop_.RunUntilIdle(); |
170 } | 193 } |
171 | 194 |
172 void AudioOutputDeviceTest::StartAudioDevice() { | 195 void AudioOutputDeviceTest::StartAudioDevice() { |
173 audio_device_->Start(); | 196 audio_device_->Start(); |
174 | 197 |
175 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device_.get())) | |
176 .WillOnce(Return(kStreamId)); | |
177 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); | 198 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); |
178 | 199 |
179 io_loop_.RunUntilIdle(); | 200 io_loop_.RunUntilIdle(); |
180 } | 201 } |
181 | 202 |
182 void AudioOutputDeviceTest::CreateStream() { | 203 void AudioOutputDeviceTest::CreateStream() { |
183 const int kMemorySize = CalculateMemorySize(); | 204 const int kMemorySize = CalculateMemorySize(); |
184 | 205 |
185 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); | 206 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); |
186 memset(shared_memory_.memory(), 0xff, kMemorySize); | 207 memset(shared_memory_.memory(), 0xff, kMemorySize); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 // Don't hang the test if we never get the Render() callback. | 259 // Don't hang the test if we never get the Render() callback. |
239 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 260 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
240 TestTimeouts::action_timeout()); | 261 TestTimeouts::action_timeout()); |
241 io_loop_.Run(); | 262 io_loop_.Run(); |
242 } | 263 } |
243 | 264 |
244 void AudioOutputDeviceTest::StopAudioDevice() { | 265 void AudioOutputDeviceTest::StopAudioDevice() { |
245 audio_device_->Stop(); | 266 audio_device_->Stop(); |
246 | 267 |
247 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); | 268 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); |
248 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
249 | 269 |
250 io_loop_.RunUntilIdle(); | 270 io_loop_.RunUntilIdle(); |
251 } | 271 } |
252 | 272 |
253 TEST_P(AudioOutputDeviceTest, Initialize) { | 273 TEST_P(AudioOutputDeviceTest, Initialize) { |
254 Initialize(); | 274 // Tests that the object can be constructed, initialized and destructed |
275 // without having ever been started/stopped. | |
255 } | 276 } |
256 | 277 |
257 // Calls Start() followed by an immediate Stop() and check for the basic message | 278 // Calls Start() followed by an immediate Stop() and check for the basic message |
258 // filter messages being sent in that case. | 279 // filter messages being sent in that case. |
259 TEST_P(AudioOutputDeviceTest, StartStop) { | 280 TEST_P(AudioOutputDeviceTest, StartStop) { |
260 Initialize(); | |
261 StartAudioDevice(); | 281 StartAudioDevice(); |
262 StopAudioDevice(); | 282 StopAudioDevice(); |
263 } | 283 } |
264 | 284 |
265 // AudioOutputDevice supports multiple start/stop sequences. | 285 // AudioOutputDevice supports multiple start/stop sequences. |
266 TEST_P(AudioOutputDeviceTest, StartStopStartStop) { | 286 TEST_P(AudioOutputDeviceTest, StartStopStartStop) { |
267 Initialize(); | |
268 StartAudioDevice(); | 287 StartAudioDevice(); |
269 StopAudioDevice(); | 288 StopAudioDevice(); |
270 StartAudioDevice(); | 289 StartAudioDevice(); |
271 StopAudioDevice(); | 290 StopAudioDevice(); |
272 } | 291 } |
273 | 292 |
274 // Simulate receiving OnStreamCreated() prior to processing ShutDownOnIOThread() | 293 // Simulate receiving OnStreamCreated() prior to processing ShutDownOnIOThread() |
275 // on the IO loop. | 294 // on the IO loop. |
276 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { | 295 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { |
277 Initialize(); | |
278 StartAudioDevice(); | 296 StartAudioDevice(); |
279 | 297 |
280 // Call Stop() but don't run the IO loop yet. | 298 // Call Stop() but don't run the IO loop yet. |
281 audio_device_->Stop(); | 299 audio_device_->Stop(); |
282 | 300 |
283 // Expect us to shutdown IPC but not to render anything despite the stream | 301 // Expect us to shutdown IPC but not to render anything despite the stream |
284 // getting created. | 302 // getting created. |
285 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); | 303 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); |
286 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
287 CreateStream(); | 304 CreateStream(); |
288 } | 305 } |
289 | 306 |
290 // Full test with output only. | 307 // Full test with output only. |
291 TEST_P(AudioOutputDeviceTest, CreateStream) { | 308 TEST_P(AudioOutputDeviceTest, CreateStream) { |
292 Initialize(); | |
293 StartAudioDevice(); | 309 StartAudioDevice(); |
294 ExpectRenderCallback(); | 310 ExpectRenderCallback(); |
295 CreateStream(); | 311 CreateStream(); |
296 WaitUntilRenderCallback(); | 312 WaitUntilRenderCallback(); |
297 StopAudioDevice(); | 313 StopAudioDevice(); |
298 } | 314 } |
299 | 315 |
300 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 316 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
301 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); | 317 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); |
302 | 318 |
303 } // namespace media. | 319 } // namespace media. |
OLD | NEW |