Chromium Code Reviews| 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 void Construct(); | |
| 110 void Destruct(); | |
| 111 void Initialize(); | 111 void Initialize(); |
| 112 void StartAudioDevice(); | 112 void StartAudioDevice(); |
| 113 void CreateStream(); | 113 void CreateStream(); |
| 114 void ExpectRenderCallback(); | 114 void ExpectRenderCallback(); |
| 115 void WaitUntilRenderCallback(); | 115 void WaitUntilRenderCallback(); |
| 116 void StopAudioDevice(); | 116 void StopAudioDevice(); |
| 117 | 117 |
| 118 protected: | 118 protected: |
| 119 // Used to clean up TLS pointers that the test(s) will initialize. | 119 // Used to clean up TLS pointers that the test(s) will initialize. |
| 120 // Must remain the first member of this class. | 120 // Must remain the first member of this class. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 150 | 150 |
| 151 int io_buffer_size = output_memory_size + input_memory_size; | 151 int io_buffer_size = output_memory_size + input_memory_size; |
| 152 | 152 |
| 153 // This is where it gets a bit hacky. The shared memory contract between | 153 // 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 | 154 // AudioOutputDevice and its browser side counter part includes a bit more |
| 155 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() | 155 // 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. | 156 // to get the actual size needed to fit the audio data plus the extra data. |
| 157 return TotalSharedMemorySizeInBytes(io_buffer_size); | 157 return TotalSharedMemorySizeInBytes(io_buffer_size); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void AudioOutputDeviceTest::Construct() { | |
| 161 EXPECT_CALL(audio_output_ipc_, AddDelegate(_)) | |
| 162 .WillOnce(Return(kStreamId)); | |
| 163 | |
| 164 audio_device_ = new AudioOutputDevice( | |
| 165 &audio_output_ipc_, io_loop_.message_loop_proxy()); | |
| 166 } | |
| 167 | |
| 168 void AudioOutputDeviceTest::Destruct() { | |
| 169 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
| 170 | |
| 171 audio_device_ = NULL; | |
| 172 } | |
| 173 | |
| 160 void AudioOutputDeviceTest::Initialize() { | 174 void AudioOutputDeviceTest::Initialize() { |
| 161 if (synchronized_io_) { | 175 if (synchronized_io_) { |
| 162 audio_device_->InitializeIO(default_audio_parameters_, | 176 audio_device_->InitializeIO(default_audio_parameters_, |
| 163 input_channels_, | 177 input_channels_, |
| 164 &callback_); | 178 &callback_); |
| 165 } else { | 179 } else { |
| 166 audio_device_->Initialize(default_audio_parameters_, | 180 audio_device_->Initialize(default_audio_parameters_, |
| 167 &callback_); | 181 &callback_); |
| 168 } | 182 } |
| 169 io_loop_.RunUntilIdle(); | 183 io_loop_.RunUntilIdle(); |
| 170 } | 184 } |
| 171 | 185 |
| 172 void AudioOutputDeviceTest::StartAudioDevice() { | 186 void AudioOutputDeviceTest::StartAudioDevice() { |
| 173 audio_device_->Start(); | 187 audio_device_->Start(); |
| 174 | 188 |
| 175 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device_.get())) | |
| 176 .WillOnce(Return(kStreamId)); | |
| 177 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); | 189 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); |
| 178 | 190 |
| 179 io_loop_.RunUntilIdle(); | 191 io_loop_.RunUntilIdle(); |
| 180 } | 192 } |
| 181 | 193 |
| 182 void AudioOutputDeviceTest::CreateStream() { | 194 void AudioOutputDeviceTest::CreateStream() { |
| 183 const int kMemorySize = CalculateMemorySize(); | 195 const int kMemorySize = CalculateMemorySize(); |
| 184 | 196 |
| 185 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); | 197 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); |
| 186 memset(shared_memory_.memory(), 0xff, kMemorySize); | 198 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. | 250 // Don't hang the test if we never get the Render() callback. |
| 239 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 251 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 240 TestTimeouts::action_timeout()); | 252 TestTimeouts::action_timeout()); |
| 241 io_loop_.Run(); | 253 io_loop_.Run(); |
| 242 } | 254 } |
| 243 | 255 |
| 244 void AudioOutputDeviceTest::StopAudioDevice() { | 256 void AudioOutputDeviceTest::StopAudioDevice() { |
| 245 audio_device_->Stop(); | 257 audio_device_->Stop(); |
| 246 | 258 |
| 247 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); | 259 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); |
| 248 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
| 249 | 260 |
| 250 io_loop_.RunUntilIdle(); | 261 io_loop_.RunUntilIdle(); |
| 251 } | 262 } |
| 252 | 263 |
| 253 TEST_P(AudioOutputDeviceTest, Initialize) { | 264 TEST_P(AudioOutputDeviceTest, Initialize) { |
| 265 Construct(); | |
|
DaleCurtis
2012/11/28 19:29:50
just do this in setUp() and tearDown() instead of
miu
2012/11/28 20:59:03
Done. I also moved the call to Initialize() into
| |
| 254 Initialize(); | 266 Initialize(); |
| 267 Destruct(); | |
| 255 } | 268 } |
| 256 | 269 |
| 257 // Calls Start() followed by an immediate Stop() and check for the basic message | 270 // Calls Start() followed by an immediate Stop() and check for the basic message |
| 258 // filter messages being sent in that case. | 271 // filter messages being sent in that case. |
| 259 TEST_P(AudioOutputDeviceTest, StartStop) { | 272 TEST_P(AudioOutputDeviceTest, StartStop) { |
| 273 Construct(); | |
| 260 Initialize(); | 274 Initialize(); |
| 261 StartAudioDevice(); | 275 StartAudioDevice(); |
| 262 StopAudioDevice(); | 276 StopAudioDevice(); |
| 277 Destruct(); | |
| 263 } | 278 } |
| 264 | 279 |
| 265 // AudioOutputDevice supports multiple start/stop sequences. | 280 // AudioOutputDevice supports multiple start/stop sequences. |
| 266 TEST_P(AudioOutputDeviceTest, StartStopStartStop) { | 281 TEST_P(AudioOutputDeviceTest, StartStopStartStop) { |
| 282 Construct(); | |
| 267 Initialize(); | 283 Initialize(); |
| 268 StartAudioDevice(); | 284 StartAudioDevice(); |
| 269 StopAudioDevice(); | 285 StopAudioDevice(); |
| 270 StartAudioDevice(); | 286 StartAudioDevice(); |
| 271 StopAudioDevice(); | 287 StopAudioDevice(); |
| 288 Destruct(); | |
| 272 } | 289 } |
| 273 | 290 |
| 274 // Simulate receiving OnStreamCreated() prior to processing ShutDownOnIOThread() | 291 // Simulate receiving OnStreamCreated() prior to processing ShutDownOnIOThread() |
| 275 // on the IO loop. | 292 // on the IO loop. |
| 276 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { | 293 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { |
| 294 Construct(); | |
| 277 Initialize(); | 295 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(); |
| 305 | |
| 306 Destruct(); | |
| 288 } | 307 } |
| 289 | 308 |
| 290 // Full test with output only. | 309 // Full test with output only. |
| 291 TEST_P(AudioOutputDeviceTest, CreateStream) { | 310 TEST_P(AudioOutputDeviceTest, CreateStream) { |
| 311 Construct(); | |
| 292 Initialize(); | 312 Initialize(); |
| 293 StartAudioDevice(); | 313 StartAudioDevice(); |
| 294 ExpectRenderCallback(); | 314 ExpectRenderCallback(); |
| 295 CreateStream(); | 315 CreateStream(); |
| 296 WaitUntilRenderCallback(); | 316 WaitUntilRenderCallback(); |
| 297 StopAudioDevice(); | 317 StopAudioDevice(); |
| 318 Destruct(); | |
| 298 } | 319 } |
| 299 | 320 |
| 300 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 321 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
| 301 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); | 322 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); |
| 302 | 323 |
| 303 } // namespace media. | 324 } // namespace media. |
| OLD | NEW |