| 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 29 matching lines...) Expand all Loading... |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class MockAudioOutputIPC : public AudioOutputIPC { | 42 class MockAudioOutputIPC : public AudioOutputIPC { |
| 43 public: | 43 public: |
| 44 MockAudioOutputIPC() {} | 44 MockAudioOutputIPC() {} |
| 45 virtual ~MockAudioOutputIPC() {} | 45 virtual ~MockAudioOutputIPC() {} |
| 46 | 46 |
| 47 MOCK_METHOD1(AddDelegate, int(AudioOutputIPCDelegate* delegate)); | 47 MOCK_METHOD1(AddDelegate, int(AudioOutputIPCDelegate* delegate)); |
| 48 MOCK_METHOD1(RemoveDelegate, void(int stream_id)); | 48 MOCK_METHOD1(RemoveDelegate, void(int stream_id)); |
| 49 | 49 |
| 50 MOCK_METHOD2(CreateStream, | 50 MOCK_METHOD3(CreateStream, |
| 51 void(int stream_id, const AudioParameters& params)); | 51 void(int stream_id, const AudioParameters& params, int input_channels)); |
| 52 MOCK_METHOD1(PlayStream, void(int stream_id)); | 52 MOCK_METHOD1(PlayStream, void(int stream_id)); |
| 53 MOCK_METHOD1(CloseStream, void(int stream_id)); | 53 MOCK_METHOD1(CloseStream, void(int stream_id)); |
| 54 MOCK_METHOD2(SetVolume, void(int stream_id, double volume)); | 54 MOCK_METHOD2(SetVolume, void(int stream_id, double volume)); |
| 55 MOCK_METHOD1(PauseStream, void(int stream_id)); | 55 MOCK_METHOD1(PauseStream, void(int stream_id)); |
| 56 MOCK_METHOD1(FlushStream, void(int stream_id)); | 56 MOCK_METHOD1(FlushStream, void(int stream_id)); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // Creates a copy of a SyncSocket handle that we can give to AudioOutputDevice. | 59 // Creates a copy of a SyncSocket handle that we can give to AudioOutputDevice. |
| 60 // On Windows this means duplicating the pipe handle so that AudioOutputDevice | 60 // On Windows this means duplicating the pipe handle so that AudioOutputDevice |
| 61 // can call CloseHandle() (since ownership has been transferred), but on other | 61 // can call CloseHandle() (since ownership has been transferred), but on other |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 scoped_refptr<AudioOutputDevice> audio_device(CreateAudioDevice()); | 130 scoped_refptr<AudioOutputDevice> audio_device(CreateAudioDevice()); |
| 131 audio_device->Initialize(default_audio_parameters_, &callback_); | 131 audio_device->Initialize(default_audio_parameters_, &callback_); |
| 132 | 132 |
| 133 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device.get())) | 133 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device.get())) |
| 134 .WillOnce(Return(1)); | 134 .WillOnce(Return(1)); |
| 135 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(1)).WillOnce(Return()); | 135 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(1)).WillOnce(Return()); |
| 136 | 136 |
| 137 audio_device->Start(); | 137 audio_device->Start(); |
| 138 audio_device->Stop(); | 138 audio_device->Stop(); |
| 139 | 139 |
| 140 EXPECT_CALL(audio_output_ipc_, CreateStream(_, _)); | 140 EXPECT_CALL(audio_output_ipc_, CreateStream(_, _, _)); |
| 141 EXPECT_CALL(audio_output_ipc_, CloseStream(_)); | 141 EXPECT_CALL(audio_output_ipc_, CloseStream(_)); |
| 142 | 142 |
| 143 io_loop_.RunAllPending(); | 143 io_loop_.RunAllPending(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Starts an audio stream, creates a shared memory section + SyncSocket pair | 146 // Starts an audio stream, creates a shared memory section + SyncSocket pair |
| 147 // that AudioOutputDevice must use for audio data. It then sends a request for | 147 // that AudioOutputDevice must use for audio data. It then sends a request for |
| 148 // a single audio packet and quits when the packet has been sent. | 148 // a single audio packet and quits when the packet has been sent. |
| 149 TEST_F(AudioOutputDeviceTest, CreateStream) { | 149 TEST_F(AudioOutputDeviceTest, CreateStream) { |
| 150 scoped_refptr<AudioOutputDevice> audio_device(CreateAudioDevice()); | 150 scoped_refptr<AudioOutputDevice> audio_device(CreateAudioDevice()); |
| 151 audio_device->Initialize(default_audio_parameters_, &callback_); | 151 audio_device->Initialize(default_audio_parameters_, &callback_); |
| 152 | 152 |
| 153 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device.get())) | 153 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device.get())) |
| 154 .WillOnce(Return(1)); | 154 .WillOnce(Return(1)); |
| 155 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(1)).WillOnce(Return()); | 155 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(1)).WillOnce(Return()); |
| 156 | 156 |
| 157 audio_device->Start(); | 157 audio_device->Start(); |
| 158 | 158 |
| 159 EXPECT_CALL(audio_output_ipc_, CreateStream(_, _)) | 159 EXPECT_CALL(audio_output_ipc_, CreateStream(_, _, _)) |
| 160 .WillOnce(WithArgs<0>( | 160 .WillOnce(WithArgs<0>( |
| 161 Invoke(this, &AudioOutputDeviceTest::set_stream_id))); | 161 Invoke(this, &AudioOutputDeviceTest::set_stream_id))); |
| 162 | 162 |
| 163 | 163 |
| 164 EXPECT_EQ(stream_id_, -1); | 164 EXPECT_EQ(stream_id_, -1); |
| 165 io_loop_.RunAllPending(); | 165 io_loop_.RunAllPending(); |
| 166 | 166 |
| 167 // OnCreateStream() must have been called and we should have a valid | 167 // OnCreateStream() must have been called and we should have a valid |
| 168 // stream id. | 168 // stream id. |
| 169 ASSERT_NE(stream_id_, -1); | 169 ASSERT_NE(stream_id_, -1); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 io_loop_.Run(); | 222 io_loop_.Run(); |
| 223 | 223 |
| 224 // Close the stream sequence. | 224 // Close the stream sequence. |
| 225 EXPECT_CALL(audio_output_ipc_, CloseStream(stream_id_)); | 225 EXPECT_CALL(audio_output_ipc_, CloseStream(stream_id_)); |
| 226 | 226 |
| 227 audio_device->Stop(); | 227 audio_device->Stop(); |
| 228 io_loop_.RunAllPending(); | 228 io_loop_.RunAllPending(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 } // namespace media. | 231 } // namespace media. |
| OLD | NEW |