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

Side by Side Diff: content/browser/renderer_host/audio_renderer_host_unittest.cc

Issue 6717001: Move audio messages to their own file. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 9 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
« no previous file with comments | « content/browser/renderer_host/audio_renderer_host.cc ('k') | content/common/audio_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/environment.h" 5 #include "base/environment.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/process_util.h" 7 #include "base/process_util.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/sync_socket.h" 9 #include "base/sync_socket.h"
10 #include "chrome/common/render_messages.h"
11 #include "chrome/common/render_messages_params.h"
12 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
13 #include "content/browser/renderer_host/audio_renderer_host.h" 11 #include "content/browser/renderer_host/audio_renderer_host.h"
12 #include "content/common/audio_messages.h"
14 #include "ipc/ipc_message_utils.h" 13 #include "ipc/ipc_message_utils.h"
15 #include "media/audio/audio_manager.h" 14 #include "media/audio/audio_manager.h"
16 #include "media/audio/fake_audio_output_stream.h" 15 #include "media/audio/fake_audio_output_stream.h"
17 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 using ::testing::_; 19 using ::testing::_;
21 using ::testing::DoAll; 20 using ::testing::DoAll;
22 using ::testing::InSequence; 21 using ::testing::InSequence;
23 using ::testing::InvokeWithoutArgs; 22 using ::testing::InvokeWithoutArgs;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // This method is used to dispatch IPC messages to the renderer. We intercept 66 // This method is used to dispatch IPC messages to the renderer. We intercept
68 // these messages here and dispatch to our mock methods to verify the 67 // these messages here and dispatch to our mock methods to verify the
69 // conversation between this object and the renderer. 68 // conversation between this object and the renderer.
70 virtual bool Send(IPC::Message* message) { 69 virtual bool Send(IPC::Message* message) {
71 CHECK(message); 70 CHECK(message);
72 71
73 // In this method we dispatch the messages to the according handlers as if 72 // In this method we dispatch the messages to the according handlers as if
74 // we are the renderer. 73 // we are the renderer.
75 bool handled = true; 74 bool handled = true;
76 IPC_BEGIN_MESSAGE_MAP(MockAudioRendererHost, *message) 75 IPC_BEGIN_MESSAGE_MAP(MockAudioRendererHost, *message)
77 IPC_MESSAGE_HANDLER(ViewMsg_RequestAudioPacket, OnRequestPacket) 76 IPC_MESSAGE_HANDLER(AudioMsg_RequestPacket, OnRequestPacket)
78 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamCreated, OnStreamCreated) 77 IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamCreated, OnStreamCreated)
79 IPC_MESSAGE_HANDLER(ViewMsg_NotifyLowLatencyAudioStreamCreated, 78 IPC_MESSAGE_HANDLER(AudioMsg_NotifyLowLatencyStreamCreated,
80 OnLowLatencyStreamCreated) 79 OnLowLatencyStreamCreated)
81 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamStateChanged, 80 IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamStateChanged,
82 OnStreamStateChanged) 81 OnStreamStateChanged)
83 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamVolume, OnStreamVolume) 82 IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamVolume, OnStreamVolume)
84 IPC_MESSAGE_UNHANDLED(handled = false) 83 IPC_MESSAGE_UNHANDLED(handled = false)
85 IPC_END_MESSAGE_MAP() 84 IPC_END_MESSAGE_MAP()
86 EXPECT_TRUE(handled); 85 EXPECT_TRUE(handled);
87 86
88 delete message; 87 delete message;
89 return true; 88 return true;
90 } 89 }
91 90
92 // These handler methods do minimal things and delegate to the mock methods. 91 // These handler methods do minimal things and delegate to the mock methods.
93 void OnRequestPacket(const IPC::Message& msg, int stream_id, 92 void OnRequestPacket(const IPC::Message& msg, int stream_id,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 #else 127 #else
129 sync_socket_handle = socket_descriptor.fd; 128 sync_socket_handle = socket_descriptor.fd;
130 #endif 129 #endif
131 sync_socket_.reset(new base::SyncSocket(sync_socket_handle)); 130 sync_socket_.reset(new base::SyncSocket(sync_socket_handle));
132 131
133 // And then delegate the call to the mock method. 132 // And then delegate the call to the mock method.
134 OnLowLatencyStreamCreated(msg.routing_id(), stream_id, length); 133 OnLowLatencyStreamCreated(msg.routing_id(), stream_id, length);
135 } 134 }
136 135
137 void OnStreamStateChanged(const IPC::Message& msg, int stream_id, 136 void OnStreamStateChanged(const IPC::Message& msg, int stream_id,
138 const ViewMsg_AudioStreamState_Params& params) { 137 AudioStreamState state) {
139 if (params.state == ViewMsg_AudioStreamState_Params::kPlaying) { 138 if (state == kAudioStreamPlaying) {
140 OnStreamPlaying(msg.routing_id(), stream_id); 139 OnStreamPlaying(msg.routing_id(), stream_id);
141 } else if (params.state == ViewMsg_AudioStreamState_Params::kPaused) { 140 } else if (state == kAudioStreamPaused) {
142 OnStreamPaused(msg.routing_id(), stream_id); 141 OnStreamPaused(msg.routing_id(), stream_id);
143 } else if (params.state == ViewMsg_AudioStreamState_Params::kError) { 142 } else if (state == kAudioStreamError) {
144 OnStreamError(msg.routing_id(), stream_id); 143 OnStreamError(msg.routing_id(), stream_id);
145 } else { 144 } else {
146 FAIL() << "Unknown stream state"; 145 FAIL() << "Unknown stream state";
147 } 146 }
148 } 147 }
149 148
150 void OnStreamVolume(const IPC::Message& msg, int stream_id, double volume) { 149 void OnStreamVolume(const IPC::Message& msg, int stream_id, double volume) {
151 OnStreamVolume(msg.routing_id(), stream_id, volume); 150 OnStreamVolume(msg.routing_id(), stream_id, volume);
152 } 151 }
153 152
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 EXPECT_CALL(*host_, 198 EXPECT_CALL(*host_,
200 OnStreamCreated(kRouteId, kStreamId, _)); 199 OnStreamCreated(kRouteId, kStreamId, _));
201 200
202 // 2. First packet request will arrive. 201 // 2. First packet request will arrive.
203 EXPECT_CALL(*host_, OnRequestPacket(kRouteId, kStreamId, _)) 202 EXPECT_CALL(*host_, OnRequestPacket(kRouteId, kStreamId, _))
204 .WillOnce(QuitMessageLoop(message_loop_.get())); 203 .WillOnce(QuitMessageLoop(message_loop_.get()));
205 204
206 IPC::Message msg; 205 IPC::Message msg;
207 msg.set_routing_id(kRouteId); 206 msg.set_routing_id(kRouteId);
208 207
209 ViewHostMsg_Audio_CreateStream_Params params; 208 AudioParameters params;
210 if (mock_stream_) 209 if (mock_stream_)
211 params.params.format = AudioParameters::AUDIO_MOCK; 210 params.format = AudioParameters::AUDIO_MOCK;
212 else 211 else
213 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; 212 params.format = AudioParameters::AUDIO_PCM_LINEAR;
214 params.params.channels = 2; 213 params.channels = 2;
215 params.params.sample_rate = AudioParameters::kAudioCDSampleRate; 214 params.sample_rate = AudioParameters::kAudioCDSampleRate;
216 params.params.bits_per_sample = 16; 215 params.bits_per_sample = 16;
217 params.params.samples_per_packet = 0; 216 params.samples_per_packet = 0;
218 217
219 // Send a create stream message to the audio output stream and wait until 218 // Send a create stream message to the audio output stream and wait until
220 // we receive the created message. 219 // we receive the created message.
221 host_->OnCreateStream(msg, kStreamId, params, false); 220 host_->OnCreateStream(msg, kStreamId, params, false);
222 message_loop_->Run(); 221 message_loop_->Run();
223 } 222 }
224 223
225 void CreateLowLatency() { 224 void CreateLowLatency() {
226 InSequence s; 225 InSequence s;
227 // We will first receive a OnLowLatencyStreamCreated() signal. 226 // We will first receive a OnLowLatencyStreamCreated() signal.
228 EXPECT_CALL(*host_, 227 EXPECT_CALL(*host_,
229 OnLowLatencyStreamCreated(kRouteId, kStreamId, _)) 228 OnLowLatencyStreamCreated(kRouteId, kStreamId, _))
230 .WillOnce(QuitMessageLoop(message_loop_.get())); 229 .WillOnce(QuitMessageLoop(message_loop_.get()));
231 230
232 IPC::Message msg; 231 IPC::Message msg;
233 msg.set_routing_id(kRouteId); 232 msg.set_routing_id(kRouteId);
234 233
235 ViewHostMsg_Audio_CreateStream_Params params; 234 AudioParameters params;
236 if (mock_stream_) 235 if (mock_stream_)
237 params.params.format = AudioParameters::AUDIO_MOCK; 236 params.format = AudioParameters::AUDIO_MOCK;
238 else 237 else
239 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; 238 params.format = AudioParameters::AUDIO_PCM_LINEAR;
240 params.params.channels = 2; 239 params.channels = 2;
241 params.params.sample_rate = AudioParameters::kAudioCDSampleRate; 240 params.sample_rate = AudioParameters::kAudioCDSampleRate;
242 params.params.bits_per_sample = 16; 241 params.bits_per_sample = 16;
243 params.params.samples_per_packet = 0; 242 params.samples_per_packet = 0;
244 243
245 // Send a create stream message to the audio output stream and wait until 244 // Send a create stream message to the audio output stream and wait until
246 // we receive the created message. 245 // we receive the created message.
247 host_->OnCreateStream(msg, kStreamId, params, true); 246 host_->OnCreateStream(msg, kStreamId, params, true);
248 message_loop_->Run(); 247 message_loop_->Run();
249 } 248 }
250 249
251 void Close() { 250 void Close() {
252 // Send a message to AudioRendererHost to tell it we want to close the 251 // Send a message to AudioRendererHost to tell it we want to close the
253 // stream. 252 // stream.
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 478
480 // Simulate the case where a stream is not properly closed. 479 // Simulate the case where a stream is not properly closed.
481 TEST_F(AudioRendererHostTest, CreateLowLatencyAndShutdown) { 480 TEST_F(AudioRendererHostTest, CreateLowLatencyAndShutdown) {
482 if (!IsRunningHeadless()) 481 if (!IsRunningHeadless())
483 EnableRealDevice(); 482 EnableRealDevice();
484 483
485 CreateLowLatency(); 484 CreateLowLatency();
486 } 485 }
487 486
488 // TODO(hclam): Add tests for data conversation in low latency mode. 487 // TODO(hclam): Add tests for data conversation in low latency mode.
OLDNEW
« no previous file with comments | « content/browser/renderer_host/audio_renderer_host.cc ('k') | content/common/audio_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698