OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/media/capture/web_contents_audio_input_stream.h" | 5 #include "content/browser/media/capture/web_contents_audio_input_stream.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/location.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "content/browser/media/capture/audio_mirroring_manager.h" | 15 #include "content/browser/media/capture/audio_mirroring_manager.h" |
16 #include "content/browser/media/capture/web_contents_tracker.h" | 16 #include "content/browser/media/capture/web_contents_tracker.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "media/audio/simple_sources.h" | 19 #include "media/audio/simple_sources.h" |
20 #include "media/audio/virtual_audio_input_stream.h" | 20 #include "media/audio/virtual_audio_input_stream.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 thread_bundle_.reset(); | 194 thread_bundle_.reset(); |
195 | 195 |
196 DCHECK(!mock_vais_); | 196 DCHECK(!mock_vais_); |
197 DCHECK(!wcais_); | 197 DCHECK(!wcais_); |
198 EXPECT_FALSE(destination_); | 198 EXPECT_FALSE(destination_); |
199 DCHECK(streams_.empty()); | 199 DCHECK(streams_.empty()); |
200 DCHECK(sources_.empty()); | 200 DCHECK(sources_.empty()); |
201 } | 201 } |
202 | 202 |
203 void Open() { | 203 void Open() { |
204 mock_vais_ = new MockVirtualAudioInputStream(audio_thread_.task_runner()); | 204 mock_vais_ = |
| 205 new MockVirtualAudioInputStream(audio_thread_.message_loop_proxy()); |
205 EXPECT_CALL(*mock_vais_, Open()); | 206 EXPECT_CALL(*mock_vais_, Open()); |
206 EXPECT_CALL(*mock_vais_, Close()); // At Close() time. | 207 EXPECT_CALL(*mock_vais_, Close()); // At Close() time. |
207 | 208 |
208 ASSERT_EQ(kRenderProcessId, current_render_process_id_); | 209 ASSERT_EQ(kRenderProcessId, current_render_process_id_); |
209 ASSERT_EQ(kRenderFrameId, current_render_frame_id_); | 210 ASSERT_EQ(kRenderFrameId, current_render_frame_id_); |
210 EXPECT_CALL(*mock_tracker_.get(), | 211 EXPECT_CALL(*mock_tracker_.get(), |
211 Start(kRenderProcessId, kRenderFrameId, _)) | 212 Start(kRenderProcessId, kRenderFrameId, _)) |
212 .WillOnce(DoAll( | 213 .WillOnce(DoAll( |
213 SaveArg<2>(&change_callback_), | 214 SaveArg<2>(&change_callback_), |
214 WithArgs<0, 1>(Invoke(this, | 215 WithArgs<0, 1>(Invoke(this, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 void Close() { | 334 void Close() { |
334 // WebContentsAudioInputStream self-destructs on Close(). Its internal | 335 // WebContentsAudioInputStream self-destructs on Close(). Its internal |
335 // objects hang around until they are no longer referred to (e.g., as tasks | 336 // objects hang around until they are no longer referred to (e.g., as tasks |
336 // on other threads shut things down). | 337 // on other threads shut things down). |
337 wcais_->Close(); | 338 wcais_->Close(); |
338 wcais_ = NULL; | 339 wcais_ = NULL; |
339 mock_vais_ = NULL; | 340 mock_vais_ = NULL; |
340 } | 341 } |
341 | 342 |
342 void RunOnAudioThread(const base::Closure& closure) { | 343 void RunOnAudioThread(const base::Closure& closure) { |
343 audio_thread_.task_runner()->PostTask(FROM_HERE, closure); | 344 audio_thread_.message_loop()->PostTask(FROM_HERE, closure); |
344 } | 345 } |
345 | 346 |
346 // Block the calling thread until OnData() callbacks are being made. | 347 // Block the calling thread until OnData() callbacks are being made. |
347 void WaitForData() { | 348 void WaitForData() { |
348 // Note: Arbitrarily chosen, but more iterations causes tests to take | 349 // Note: Arbitrarily chosen, but more iterations causes tests to take |
349 // significantly more time. | 350 // significantly more time. |
350 static const int kNumIterations = 3; | 351 static const int kNumIterations = 3; |
351 for (int i = 0; i < kNumIterations; ++i) | 352 for (int i = 0; i < kNumIterations; ++i) |
352 on_data_event_.Wait(); | 353 on_data_event_.Wait(); |
353 } | 354 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 WaitForData(); | 494 WaitForData(); |
494 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); | 495 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
495 WaitForData(); | 496 WaitForData(); |
496 RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); | 497 RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); |
497 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); | 498 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
498 RUN_ON_AUDIO_THREAD(Stop); | 499 RUN_ON_AUDIO_THREAD(Stop); |
499 RUN_ON_AUDIO_THREAD(Close); | 500 RUN_ON_AUDIO_THREAD(Close); |
500 } | 501 } |
501 | 502 |
502 } // namespace content | 503 } // namespace content |
OLD | NEW |