| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED)); | 253 SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED)); |
| 254 base::RunLoop run_loop; | 254 base::RunLoop run_loop; |
| 255 mixer_input_->SwitchOutputDevice( | 255 mixer_input_->SwitchOutputDevice( |
| 256 kUnauthorizedDeviceId, url::Origin(), | 256 kUnauthorizedDeviceId, url::Origin(), |
| 257 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 257 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 258 base::Unretained(this), &run_loop)); | 258 base::Unretained(this), &run_loop)); |
| 259 run_loop.Run(); | 259 run_loop.Run(); |
| 260 mixer_input_->Stop(); | 260 mixer_input_->Stop(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 // Test that calling SwitchOutputDevice() before Start() is resolved after | 263 // Test that calling SwitchOutputDevice() before Start() succeeds. |
| 264 // a call to Start(). | |
| 265 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceBeforeStart) { | 264 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceBeforeStart) { |
| 266 base::RunLoop run_loop; | 265 base::RunLoop run_loop; |
| 266 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
| 267 mixer_input_->SwitchOutputDevice( | 267 mixer_input_->SwitchOutputDevice( |
| 268 kDefaultDeviceId, url::Origin(), | 268 kDefaultDeviceId, url::Origin(), |
| 269 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 269 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 270 base::Unretained(this), &run_loop)); | 270 base::Unretained(this), &run_loop)); |
| 271 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); | |
| 272 mixer_input_->Start(); | 271 mixer_input_->Start(); |
| 273 run_loop.Run(); | 272 run_loop.Run(); |
| 274 mixer_input_->Stop(); | 273 mixer_input_->Stop(); |
| 275 } | 274 } |
| 276 | 275 |
| 277 // Test that calling SwitchOutputDevice() without ever calling Start() fails | 276 // Test that calling SwitchOutputDevice() succeeds even if Start() is never |
| 278 // cleanly after calling Stop(). | 277 // called. |
| 279 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceWithoutStart) { | 278 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceWithoutStart) { |
| 280 base::RunLoop run_loop; | 279 base::RunLoop run_loop; |
| 280 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
| 281 mixer_input_->SwitchOutputDevice( | 281 mixer_input_->SwitchOutputDevice( |
| 282 kDefaultDeviceId, url::Origin(), | 282 kDefaultDeviceId, url::Origin(), |
| 283 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 283 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 284 base::Unretained(this), &run_loop)); | 284 base::Unretained(this), &run_loop)); |
| 285 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL)); | |
| 286 mixer_input_->Stop(); | 285 mixer_input_->Stop(); |
| 287 run_loop.Run(); | 286 run_loop.Run(); |
| 288 } | 287 } |
| 289 | 288 |
| 290 // Test creation with an invalid device. OnRenderError() should be called. | 289 // Test creation with an invalid device. OnRenderError() should be called. |
| 291 // Play() and Pause() should not cause crashes, even if they have no effect. | 290 // Play(), Pause() and SwitchOutputDevice() should not cause crashes, even if |
| 292 // SwitchOutputDevice() should fail. | 291 // they have no effect. |
| 293 TEST_F(AudioRendererMixerInputTest, CreateWithInvalidDevice) { | 292 TEST_F(AudioRendererMixerInputTest, CreateWithInvalidDevice) { |
| 294 // |mixer_input_| was initialized during construction. | 293 // |mixer_input_| was initialized during construction. |
| 295 mixer_input_->Stop(); | 294 mixer_input_->Stop(); |
| 296 | 295 |
| 297 CreateMixerInput(kNonexistentDeviceId); | 296 CreateMixerInput(kNonexistentDeviceId); |
| 298 EXPECT_CALL(*fake_callback_, OnRenderError()); | 297 EXPECT_CALL(*fake_callback_, OnRenderError()); |
| 299 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | 298 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
| 300 mixer_input_->Start(); | 299 mixer_input_->Start(); |
| 301 mixer_input_->Play(); | 300 mixer_input_->Play(); |
| 302 mixer_input_->Pause(); | 301 mixer_input_->Pause(); |
| 303 base::RunLoop run_loop; | 302 base::RunLoop run_loop; |
| 304 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL)); | 303 EXPECT_CALL(*this, SwitchCallbackCalled(testing::_)); |
| 305 mixer_input_->SwitchOutputDevice( | 304 mixer_input_->SwitchOutputDevice( |
| 306 kDefaultDeviceId, url::Origin(), | 305 kDefaultDeviceId, url::Origin(), |
| 307 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 306 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 308 base::Unretained(this), &run_loop)); | 307 base::Unretained(this), &run_loop)); |
| 309 mixer_input_->Stop(); | 308 mixer_input_->Stop(); |
| 310 run_loop.Run(); | 309 run_loop.Run(); |
| 311 } | 310 } |
| 312 | 311 |
| 312 // Test that calling SwitchOutputDevice() works after calling Stop(), and that |
| 313 // restarting works after the call to SwitchOutputDevice(). |
| 314 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceAfterStopBeforeRestart) { |
| 315 mixer_input_->Start(); |
| 316 mixer_input_->Stop(); |
| 317 |
| 318 base::RunLoop run_loop; |
| 319 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
| 320 mixer_input_->SwitchOutputDevice( |
| 321 kDefaultDeviceId, url::Origin(), |
| 322 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 323 base::Unretained(this), &run_loop)); |
| 324 run_loop.Run(); |
| 325 |
| 326 mixer_input_->Start(); |
| 327 mixer_input_->Stop(); |
| 328 } |
| 329 |
| 313 } // namespace media | 330 } // namespace media |
| OLD | NEW |