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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/environment.h" | 6 #include "base/environment.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.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/sync_socket.h" | 10 #include "base/sync_socket.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class MockAudioRendererHost : public AudioRendererHost { | 44 class MockAudioRendererHost : public AudioRendererHost { |
45 public: | 45 public: |
46 explicit MockAudioRendererHost( | 46 explicit MockAudioRendererHost( |
47 content::ResourceContext* resource_context, | 47 content::ResourceContext* resource_context, |
48 AudioManager* audio_manager) | 48 AudioManager* audio_manager) |
49 : AudioRendererHost(resource_context, audio_manager), | 49 : AudioRendererHost(resource_context, audio_manager), |
50 shared_memory_length_(0) { | 50 shared_memory_length_(0) { |
51 } | 51 } |
52 | 52 |
53 virtual ~MockAudioRendererHost() { | 53 virtual ~MockAudioRendererHost() { |
| 54 // Make sure all audio streams have been deleted. |
| 55 EXPECT_EQ(0u, audio_entries_.size()); |
54 } | 56 } |
55 | 57 |
56 // A list of mock methods. | 58 // A list of mock methods. |
57 MOCK_METHOD2(OnStreamCreated, | 59 MOCK_METHOD2(OnStreamCreated, |
58 void(int stream_id, int length)); | 60 void(int stream_id, int length)); |
59 MOCK_METHOD1(OnStreamPlaying, void(int stream_id)); | 61 MOCK_METHOD1(OnStreamPlaying, void(int stream_id)); |
60 MOCK_METHOD1(OnStreamPaused, void(int stream_id)); | 62 MOCK_METHOD1(OnStreamPaused, void(int stream_id)); |
61 MOCK_METHOD1(OnStreamError, void(int stream_id)); | 63 MOCK_METHOD1(OnStreamError, void(int stream_id)); |
62 MOCK_METHOD2(OnStreamVolume, void(int stream_id, double volume)); | 64 MOCK_METHOD2(OnStreamVolume, void(int stream_id, double volume)); |
63 | 65 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 184 |
183 audio_manager_.reset(); | 185 audio_manager_.reset(); |
184 | 186 |
185 io_thread_.reset(); | 187 io_thread_.reset(); |
186 ui_thread_.reset(); | 188 ui_thread_.reset(); |
187 } | 189 } |
188 | 190 |
189 void Create() { | 191 void Create() { |
190 EXPECT_CALL(*observer_, | 192 EXPECT_CALL(*observer_, |
191 OnSetAudioStreamStatus(_, kStreamId, "created")); | 193 OnSetAudioStreamStatus(_, kStreamId, "created")); |
192 EXPECT_CALL(*observer_, OnDeleteAudioStream(_, kStreamId)); | |
193 | 194 |
194 InSequence s; | 195 InSequence s; |
195 // We will first receive an OnStreamCreated() signal. | 196 // We will first receive an OnStreamCreated() signal. |
196 EXPECT_CALL(*host_, OnStreamCreated(kStreamId, _)) | 197 EXPECT_CALL(*host_, OnStreamCreated(kStreamId, _)) |
197 .WillOnce(QuitMessageLoop(message_loop_.get())); | 198 .WillOnce(QuitMessageLoop(message_loop_.get())); |
198 | 199 |
199 AudioParameters params; | 200 AudioParameters params; |
200 if (mock_stream_) | 201 if (mock_stream_) |
201 params.format = AudioParameters::AUDIO_MOCK; | 202 params.format = AudioParameters::AUDIO_MOCK; |
202 else | 203 else |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // Find the first AudioOutputController in the AudioRendererHost. | 257 // Find the first AudioOutputController in the AudioRendererHost. |
257 CHECK(host_->audio_entries_.size()) | 258 CHECK(host_->audio_entries_.size()) |
258 << "Calls Create() before calling this method"; | 259 << "Calls Create() before calling this method"; |
259 media::AudioOutputController* controller = | 260 media::AudioOutputController* controller = |
260 host_->audio_entries_.begin()->second->controller; | 261 host_->audio_entries_.begin()->second->controller; |
261 CHECK(controller) << "AudioOutputController not found"; | 262 CHECK(controller) << "AudioOutputController not found"; |
262 | 263 |
263 // Expect an error signal sent through IPC. | 264 // Expect an error signal sent through IPC. |
264 EXPECT_CALL(*host_, OnStreamError(kStreamId)); | 265 EXPECT_CALL(*host_, OnStreamError(kStreamId)); |
265 | 266 |
| 267 // Expect the audio stream will be deleted. |
| 268 EXPECT_CALL(*observer_, OnDeleteAudioStream(_, kStreamId)); |
| 269 |
266 // Simulate an error sent from the audio device. | 270 // Simulate an error sent from the audio device. |
267 host_->OnError(controller, 0); | 271 host_->OnError(controller, 0); |
268 SyncWithAudioThread(); | 272 SyncWithAudioThread(); |
269 | 273 |
270 // Expect the audio stream record is removed. | 274 // Expect the audio stream record is removed. |
271 EXPECT_EQ(0u, host_->audio_entries_.size()); | 275 EXPECT_EQ(0u, host_->audio_entries_.size()); |
272 } | 276 } |
273 | 277 |
274 // Called on the audio thread. | 278 // Called on the audio thread. |
275 static void PostQuitMessageLoop(MessageLoop* message_loop) { | 279 static void PostQuitMessageLoop(MessageLoop* message_loop) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 EnableRealDevice(); | 405 EnableRealDevice(); |
402 | 406 |
403 Create(); | 407 Create(); |
404 Play(); | 408 Play(); |
405 SimulateError(); | 409 SimulateError(); |
406 Close(); | 410 Close(); |
407 } | 411 } |
408 | 412 |
409 | 413 |
410 // TODO(hclam): Add tests for data conversation in low latency mode. | 414 // TODO(hclam): Add tests for data conversation in low latency mode. |
OLD | NEW |