Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: media/audio/audio_output_device_unittest.cc

Issue 10836025: Part 1: Plumb render view ID to render host (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 public: 106 public:
107 AudioOutputDeviceTest() 107 AudioOutputDeviceTest()
108 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, 108 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR,
109 CHANNEL_LAYOUT_STEREO, 109 CHANNEL_LAYOUT_STEREO,
110 48000, 16, 1024), 110 48000, 16, 1024),
111 stream_id_(-1) { 111 stream_id_(-1) {
112 } 112 }
113 113
114 ~AudioOutputDeviceTest() {} 114 ~AudioOutputDeviceTest() {}
115 115
116 AudioOutputDevice* CreateAudioDevice() {
117 return new AudioOutputDevice(
118 &audio_output_ipc_, io_loop_.message_loop_proxy());
119 }
120
121 void set_stream_id(int stream_id) { stream_id_ = stream_id; } 116 void set_stream_id(int stream_id) { stream_id_ = stream_id; }
122 117
123 protected: 118 protected:
124 // Used to clean up TLS pointers that the test(s) will initialize. 119 // Used to clean up TLS pointers that the test(s) will initialize.
125 // Must remain the first member of this class. 120 // Must remain the first member of this class.
126 base::ShadowingAtExitManager at_exit_manager_; 121 base::ShadowingAtExitManager at_exit_manager_;
127 MessageLoopForIO io_loop_; 122 MessageLoopForIO io_loop_;
128 const AudioParameters default_audio_parameters_; 123 const AudioParameters default_audio_parameters_;
129 MockRenderCallback callback_; 124 MockRenderCallback callback_;
130 MockAudioOutputIPC audio_output_ipc_;
131 int stream_id_; 125 int stream_id_;
132 }; 126 };
133 127
134 // The simplest test for AudioOutputDevice. Used to test construction of 128 // The simplest test for AudioOutputDevice. Used to test construction of
135 // AudioOutputDevice and that the runtime environment is set up correctly. 129 // AudioOutputDevice and that the runtime environment is set up correctly.
136 TEST_F(AudioOutputDeviceTest, Initialize) { 130 TEST_F(AudioOutputDeviceTest, Initialize) {
137 scoped_refptr<AudioOutputDevice> audio_device(CreateAudioDevice()); 131 MockAudioOutputIPC* audio_output_ipc = new MockAudioOutputIPC;
tommi (sloooow) - chröme 2012/07/31 10:52:41 new MockAudioOutputIPC(); (same throughout)
sail 2012/07/31 22:02:08 Done.
132 scoped_refptr<AudioOutputDevice> audio_device(
133 new AudioOutputDevice(audio_output_ipc, io_loop_.message_loop_proxy()));
138 audio_device->Initialize(default_audio_parameters_, &callback_); 134 audio_device->Initialize(default_audio_parameters_, &callback_);
139 io_loop_.RunAllPending(); 135 io_loop_.RunAllPending();
140 } 136 }
141 137
142 // Calls Start() followed by an immediate Stop() and check for the basic message 138 // Calls Start() followed by an immediate Stop() and check for the basic message
143 // filter messages being sent in that case. 139 // filter messages being sent in that case.
144 TEST_F(AudioOutputDeviceTest, StartStop) { 140 TEST_F(AudioOutputDeviceTest, StartStop) {
145 scoped_refptr<AudioOutputDevice> audio_device(CreateAudioDevice()); 141 MockAudioOutputIPC* audio_output_ipc = new MockAudioOutputIPC;
142 scoped_refptr<AudioOutputDevice> audio_device(
143 new AudioOutputDevice(audio_output_ipc, io_loop_.message_loop_proxy()));
146 audio_device->Initialize(default_audio_parameters_, &callback_); 144 audio_device->Initialize(default_audio_parameters_, &callback_);
147 145
148 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device.get())) 146 EXPECT_CALL(*audio_output_ipc, AddDelegate(audio_device.get()))
149 .WillOnce(Return(1)); 147 .WillOnce(Return(1));
150 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(1)).WillOnce(Return()); 148 EXPECT_CALL(*audio_output_ipc, RemoveDelegate(1)).WillOnce(Return());
151 149
152 audio_device->Start(); 150 audio_device->Start();
153 audio_device->Stop(); 151 audio_device->Stop();
154 152
155 EXPECT_CALL(audio_output_ipc_, CreateStream(_, _)); 153 EXPECT_CALL(*audio_output_ipc, CreateStream(_, _));
156 EXPECT_CALL(audio_output_ipc_, CloseStream(_)); 154 EXPECT_CALL(*audio_output_ipc, CloseStream(_));
157 155
158 io_loop_.RunAllPending(); 156 io_loop_.RunAllPending();
159 } 157 }
160 158
161 // Starts an audio stream, creates a shared memory section + SyncSocket pair 159 // Starts an audio stream, creates a shared memory section + SyncSocket pair
162 // that AudioOutputDevice must use for audio data. It then sends a request for 160 // that AudioOutputDevice must use for audio data. It then sends a request for
163 // a single audio packet and quits when the packet has been sent. 161 // a single audio packet and quits when the packet has been sent.
164 TEST_F(AudioOutputDeviceTest, CreateStream) { 162 TEST_F(AudioOutputDeviceTest, CreateStream) {
165 scoped_refptr<AudioOutputDevice> audio_device(CreateAudioDevice()); 163 MockAudioOutputIPC* audio_output_ipc = new MockAudioOutputIPC;
164 scoped_refptr<AudioOutputDevice> audio_device(
165 new AudioOutputDevice(audio_output_ipc, io_loop_.message_loop_proxy()));
166 audio_device->Initialize(default_audio_parameters_, &callback_); 166 audio_device->Initialize(default_audio_parameters_, &callback_);
167 167
168 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device.get())) 168 EXPECT_CALL(*audio_output_ipc, AddDelegate(audio_device.get()))
169 .WillOnce(Return(1)); 169 .WillOnce(Return(1));
170 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(1)).WillOnce(Return()); 170 EXPECT_CALL(*audio_output_ipc, RemoveDelegate(1)).WillOnce(Return());
171 171
172 audio_device->Start(); 172 audio_device->Start();
173 173
174 EXPECT_CALL(audio_output_ipc_, CreateStream(_, _)) 174 EXPECT_CALL(*audio_output_ipc, CreateStream(_, _))
175 .WillOnce(WithArgs<0>( 175 .WillOnce(WithArgs<0>(
176 Invoke(this, &AudioOutputDeviceTest::set_stream_id))); 176 Invoke(this, &AudioOutputDeviceTest::set_stream_id)));
177 177
178 178
179 EXPECT_EQ(stream_id_, -1); 179 EXPECT_EQ(stream_id_, -1);
180 io_loop_.RunAllPending(); 180 io_loop_.RunAllPending();
181 181
182 // OnCreateStream() must have been called and we should have a valid 182 // OnCreateStream() must have been called and we should have a valid
183 // stream id. 183 // stream id.
184 ASSERT_NE(stream_id_, -1); 184 ASSERT_NE(stream_id_, -1);
(...skipping 19 matching lines...) Expand all
204 ASSERT_TRUE(DuplicateSocketHandle(renderer_socket.handle(), 204 ASSERT_TRUE(DuplicateSocketHandle(renderer_socket.handle(),
205 &audio_device_socket)); 205 &audio_device_socket));
206 base::SharedMemoryHandle duplicated_memory_handle; 206 base::SharedMemoryHandle duplicated_memory_handle;
207 ASSERT_TRUE(shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), 207 ASSERT_TRUE(shared_memory.ShareToProcess(base::GetCurrentProcessHandle(),
208 &duplicated_memory_handle)); 208 &duplicated_memory_handle));
209 209
210 // We should get a 'play' notification when we call OnStreamCreated(). 210 // We should get a 'play' notification when we call OnStreamCreated().
211 // Respond by asking for some audio data. This should ask our callback 211 // Respond by asking for some audio data. This should ask our callback
212 // to provide some audio data that AudioOutputDevice then writes into the 212 // to provide some audio data that AudioOutputDevice then writes into the
213 // shared memory section. 213 // shared memory section.
214 EXPECT_CALL(audio_output_ipc_, PlayStream(stream_id_)) 214 EXPECT_CALL(*audio_output_ipc, PlayStream(stream_id_))
215 .WillOnce(SendPendingBytes(&browser_socket, memory_size)); 215 .WillOnce(SendPendingBytes(&browser_socket, memory_size));
216 216
217 // We expect calls to our audio renderer callback, which returns the number 217 // We expect calls to our audio renderer callback, which returns the number
218 // of frames written to the memory section. 218 // of frames written to the memory section.
219 // Here's the second place where it gets hacky: There's no way for us to 219 // Here's the second place where it gets hacky: There's no way for us to
220 // know (without using a sleep loop!) when the AudioOutputDevice has finished 220 // know (without using a sleep loop!) when the AudioOutputDevice has finished
221 // writing the interleaved audio data into the shared memory section. 221 // writing the interleaved audio data into the shared memory section.
222 // So, for the sake of this test, we consider the call to Render a sign 222 // So, for the sake of this test, we consider the call to Render a sign
223 // of success and quit the loop. 223 // of success and quit the loop.
224 224
(...skipping 16 matching lines...) Expand all
241 Return(kNumberOfFramesToProcess))); 241 Return(kNumberOfFramesToProcess)));
242 242
243 audio_device->OnStreamCreated(duplicated_memory_handle, audio_device_socket, 243 audio_device->OnStreamCreated(duplicated_memory_handle, audio_device_socket,
244 memory_size); 244 memory_size);
245 245
246 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), 246 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
247 TestTimeouts::action_timeout()); 247 TestTimeouts::action_timeout());
248 io_loop_.Run(); 248 io_loop_.Run();
249 249
250 // Close the stream sequence. 250 // Close the stream sequence.
251 EXPECT_CALL(audio_output_ipc_, CloseStream(stream_id_)); 251 EXPECT_CALL(*audio_output_ipc, CloseStream(stream_id_));
252 252
253 audio_device->Stop(); 253 audio_device->Stop();
254 io_loop_.RunAllPending(); 254 io_loop_.RunAllPending();
255 } 255 }
256 256
257 } // namespace media. 257 } // namespace media.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698