| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "media/audio/audio_input_device.h" | 9 #include "media/audio/audio_input_device.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } // namespace. | 57 } // namespace. |
| 58 | 58 |
| 59 // Regular construction. | 59 // Regular construction. |
| 60 TEST(AudioInputDeviceTest, Noop) { | 60 TEST(AudioInputDeviceTest, Noop) { |
| 61 base::MessageLoopForIO io_loop; | 61 base::MessageLoopForIO io_loop; |
| 62 MockAudioInputIPC* input_ipc = new MockAudioInputIPC(); | 62 MockAudioInputIPC* input_ipc = new MockAudioInputIPC(); |
| 63 scoped_refptr<AudioInputDevice> device( | 63 scoped_refptr<AudioInputDevice> device( |
| 64 new AudioInputDevice(base::WrapUnique(input_ipc), io_loop.task_runner())); | 64 new AudioInputDevice(base::WrapUnique(input_ipc), io_loop.task_runner())); |
| 65 } | 65 } |
| 66 | 66 |
| 67 ACTION_P2(ReportStateChange, device, state) { | 67 ACTION_P(ReportStateChange, device) { |
| 68 static_cast<AudioInputIPCDelegate*>(device)->OnStateChanged(state); | 68 static_cast<AudioInputIPCDelegate*>(device)->OnError(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Verify that we get an OnCaptureError() callback if CreateStream fails. | 71 // Verify that we get an OnCaptureError() callback if CreateStream fails. |
| 72 TEST(AudioInputDeviceTest, FailToCreateStream) { | 72 TEST(AudioInputDeviceTest, FailToCreateStream) { |
| 73 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 73 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 74 CHANNEL_LAYOUT_STEREO, 48000, 16, 480); | 74 CHANNEL_LAYOUT_STEREO, 48000, 16, 480); |
| 75 | 75 |
| 76 base::MessageLoopForIO io_loop; | 76 base::MessageLoopForIO io_loop; |
| 77 MockCaptureCallback callback; | 77 MockCaptureCallback callback; |
| 78 MockAudioInputIPC* input_ipc = new MockAudioInputIPC(); | 78 MockAudioInputIPC* input_ipc = new MockAudioInputIPC(); |
| 79 scoped_refptr<AudioInputDevice> device( | 79 scoped_refptr<AudioInputDevice> device( |
| 80 new AudioInputDevice(base::WrapUnique(input_ipc), io_loop.task_runner())); | 80 new AudioInputDevice(base::WrapUnique(input_ipc), io_loop.task_runner())); |
| 81 device->Initialize(params, &callback, 1); | 81 device->Initialize(params, &callback, 1); |
| 82 device->Start(); | 82 device->Start(); |
| 83 EXPECT_CALL(*input_ipc, CreateStream(_, _, _, _, _)) | 83 EXPECT_CALL(*input_ipc, CreateStream(_, _, _, _, _)) |
| 84 .WillOnce(ReportStateChange(device.get(), | 84 .WillOnce(ReportStateChange(device.get())); |
| 85 AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR)); | |
| 86 EXPECT_CALL(callback, OnCaptureError(_)) | 85 EXPECT_CALL(callback, OnCaptureError(_)) |
| 87 .WillOnce(QuitLoop(io_loop.task_runner())); | 86 .WillOnce(QuitLoop(io_loop.task_runner())); |
| 88 base::RunLoop().Run(); | 87 base::RunLoop().Run(); |
| 89 } | 88 } |
| 90 | 89 |
| 91 } // namespace media. | 90 } // namespace media. |
| OLD | NEW |