| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/process/process_handle.h" | 15 #include "base/process/process_handle.h" |
| 16 #include "base/sync_socket.h" | 16 #include "base/sync_socket.h" |
| 17 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
| 18 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
| 19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 20 #include "media/audio/audio_output_device.h" | 20 #include "media/audio/audio_output_device.h" |
| 21 #include "media/audio/mock_audio_output_ipc.h" |
| 22 #include "media/audio/mock_render_callback.h" |
| 21 #include "media/audio/sample_rates.h" | 23 #include "media/audio/sample_rates.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gmock_mutant.h" | 25 #include "testing/gmock_mutant.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 27 |
| 26 using base::CancelableSyncSocket; | 28 using base::CancelableSyncSocket; |
| 27 using base::SharedMemory; | 29 using base::SharedMemory; |
| 28 using base::SyncSocket; | 30 using base::SyncSocket; |
| 29 using testing::_; | 31 using testing::_; |
| 30 using testing::DoAll; | 32 using testing::DoAll; |
| 31 using testing::Invoke; | 33 using testing::Invoke; |
| 32 using testing::Return; | 34 using testing::Return; |
| 33 using testing::WithArgs; | 35 using testing::WithArgs; |
| 34 using testing::StrictMock; | 36 using testing::StrictMock; |
| 35 using testing::Values; | 37 using testing::Values; |
| 36 | 38 |
| 37 namespace media { | 39 namespace media { |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 const char kDefaultDeviceId[] = ""; | 43 const char kDefaultDeviceId[] = ""; |
| 42 const char kNonDefaultDeviceId[] = "valid-nondefault-device-id"; | 44 const char kNonDefaultDeviceId[] = "valid-nondefault-device-id"; |
| 43 const char kUnauthorizedDeviceId[] = "unauthorized-device-id"; | 45 const char kUnauthorizedDeviceId[] = "unauthorized-device-id"; |
| 44 | 46 |
| 45 class MockRenderCallback : public AudioRendererSink::RenderCallback { | |
| 46 public: | |
| 47 MockRenderCallback() {} | |
| 48 virtual ~MockRenderCallback() {} | |
| 49 | |
| 50 MOCK_METHOD3(Render, | |
| 51 int(AudioBus* dest, | |
| 52 uint32_t audio_delay_milliseconds, | |
| 53 uint32_t frames_skipped)); | |
| 54 MOCK_METHOD0(OnRenderError, void()); | |
| 55 }; | |
| 56 | |
| 57 class MockAudioOutputIPC : public AudioOutputIPC { | |
| 58 public: | |
| 59 MockAudioOutputIPC() {} | |
| 60 virtual ~MockAudioOutputIPC() {} | |
| 61 | |
| 62 MOCK_METHOD4(RequestDeviceAuthorization, | |
| 63 void(AudioOutputIPCDelegate* delegate, | |
| 64 int session_id, | |
| 65 const std::string& device_id, | |
| 66 const url::Origin& security_origin)); | |
| 67 MOCK_METHOD2(CreateStream, | |
| 68 void(AudioOutputIPCDelegate* delegate, | |
| 69 const AudioParameters& params)); | |
| 70 MOCK_METHOD0(PlayStream, void()); | |
| 71 MOCK_METHOD0(PauseStream, void()); | |
| 72 MOCK_METHOD0(CloseStream, void()); | |
| 73 MOCK_METHOD1(SetVolume, void(double volume)); | |
| 74 }; | |
| 75 | |
| 76 ACTION_P2(SendPendingBytes, socket, pending_bytes) { | 47 ACTION_P2(SendPendingBytes, socket, pending_bytes) { |
| 77 socket->Send(&pending_bytes, sizeof(pending_bytes)); | 48 socket->Send(&pending_bytes, sizeof(pending_bytes)); |
| 78 } | 49 } |
| 79 | 50 |
| 80 // Used to terminate a loop from a different thread than the loop belongs to. | 51 // Used to terminate a loop from a different thread than the loop belongs to. |
| 81 // |task_runner| should be a SingleThreadTaskRunner. | 52 // |task_runner| should be a SingleThreadTaskRunner. |
| 82 ACTION_P(QuitLoop, task_runner) { | 53 ACTION_P(QuitLoop, task_runner) { |
| 83 task_runner->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 54 task_runner->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 84 } | 55 } |
| 85 | 56 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 283 |
| 313 TEST_P(AudioOutputDeviceTest, UnauthorizedDevice) { | 284 TEST_P(AudioOutputDeviceTest, UnauthorizedDevice) { |
| 314 SetDevice(kUnauthorizedDeviceId); | 285 SetDevice(kUnauthorizedDeviceId); |
| 315 StartAudioDevice(); | 286 StartAudioDevice(); |
| 316 StopAudioDevice(); | 287 StopAudioDevice(); |
| 317 } | 288 } |
| 318 | 289 |
| 319 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 290 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
| 320 | 291 |
| 321 } // namespace media. | 292 } // namespace media. |
| OLD | NEW |