Chromium Code Reviews| Index: media/audio/audio_output_device_unittest.cc |
| diff --git a/media/audio/audio_output_device_unittest.cc b/media/audio/audio_output_device_unittest.cc |
| index 363ee3894070eb0c025520c3fa6b05091c273bb3..e3d55fadc36a97112d3249c76e2ca5dbbc7b5247 100644 |
| --- a/media/audio/audio_output_device_unittest.cc |
| +++ b/media/audio/audio_output_device_unittest.cc |
| @@ -5,11 +5,15 @@ |
| #include <vector> |
| #include "base/at_exit.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/callback.h" |
| #include "base/memory/shared_memory.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/process/process_handle.h" |
| #include "base/sync_socket.h" |
| +#include "base/task_runner.h" |
| #include "base/test/test_timeouts.h" |
| +#include "base/thread_task_runner_handle.h" |
| #include "media/audio/audio_output_device.h" |
| #include "media/audio/sample_rates.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -52,6 +56,15 @@ class MockAudioOutputIPC : public AudioOutputIPC { |
| MOCK_METHOD0(PauseStream, void()); |
| MOCK_METHOD0(CloseStream, void()); |
| MOCK_METHOD1(SetVolume, void(double volume)); |
| + MOCK_METHOD3(SwitchOutputDevice, |
| + void(const std::string& device_id, |
| + const GURL& security_origin, |
| + int request_id)); |
| +}; |
| + |
| +class MockSwitchOutputDeviceCallback { |
| + public: |
| + MOCK_METHOD1(Callback, void(media::SwitchOutputDeviceResult result)); |
| }; |
| ACTION_P2(SendPendingBytes, socket, pending_bytes) { |
| @@ -78,6 +91,7 @@ class AudioOutputDeviceTest |
| void ExpectRenderCallback(); |
| void WaitUntilRenderCallback(); |
| void StopAudioDevice(); |
| + void SwitchOutputDevice(); |
| protected: |
| // Used to clean up TLS pointers that the test(s) will initialize. |
| @@ -88,9 +102,11 @@ class AudioOutputDeviceTest |
| StrictMock<MockRenderCallback> callback_; |
| MockAudioOutputIPC* audio_output_ipc_; // owned by audio_device_ |
| scoped_refptr<AudioOutputDevice> audio_device_; |
| + MockSwitchOutputDeviceCallback switch_output_device_callback_; |
| private: |
| int CalculateMemorySize(); |
| + void SwitchOutputDeviceCallback(SwitchOutputDeviceResult result); |
| SharedMemory shared_memory_; |
| CancelableSyncSocket browser_socket_; |
| @@ -196,6 +212,28 @@ void AudioOutputDeviceTest::StopAudioDevice() { |
| io_loop_.RunUntilIdle(); |
| } |
| +void AudioOutputDeviceTest::SwitchOutputDevice() { |
| + const GURL kSecurityOrigin("http://localhost"); |
|
tommi (sloooow) - chröme
2015/06/13 06:16:04
this should just be security_origin.
the style gu
Guido Urdaneta
2015/06/13 10:45:50
Done.
|
| + const std::string kDeviceId = ""; |
|
tommi (sloooow) - chröme
2015/06/13 06:16:04
device_id
(and don't think that initialization to
Guido Urdaneta
2015/06/13 10:45:50
Done.
|
| + const int kRequestId = 1; |
|
tommi (sloooow) - chröme
2015/06/13 06:16:04
request_id
Guido Urdaneta
2015/06/13 10:45:50
Done.
|
| + |
| + // Switch the output device and check that the IPC message is sent |
| + EXPECT_CALL(*audio_output_ipc_, |
| + SwitchOutputDevice(kDeviceId, kSecurityOrigin, kRequestId)); |
| + audio_device_->SwitchOutputDevice( |
| + kDeviceId, kSecurityOrigin, |
| + base::Bind(&MockSwitchOutputDeviceCallback::Callback, |
| + base::Unretained(&switch_output_device_callback_))); |
| + io_loop_.RunUntilIdle(); |
| + |
| + // Simulate the reception of a successful response from the browser |
| + EXPECT_CALL(switch_output_device_callback_, |
| + Callback(SWITCH_OUTPUT_DEVICE_RESULT_SUCCESS)); |
| + audio_device_->OnOutputDeviceSwitched(kRequestId, |
| + SWITCH_OUTPUT_DEVICE_RESULT_SUCCESS); |
| + io_loop_.RunUntilIdle(); |
| +} |
| + |
| TEST_P(AudioOutputDeviceTest, Initialize) { |
| // Tests that the object can be constructed, initialized and destructed |
| // without having ever been started/stopped. |
| @@ -239,6 +277,13 @@ TEST_P(AudioOutputDeviceTest, CreateStream) { |
| StopAudioDevice(); |
| } |
| +// Switch the output device |
| +TEST_P(AudioOutputDeviceTest, SwitchOutputDevice) { |
| + StartAudioDevice(); |
| + SwitchOutputDevice(); |
| + StopAudioDevice(); |
| +} |
| + |
| INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
| } // namespace media. |