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/message_loop/message_loop.h" | 11 #include "base/location.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_ = | 204 mock_vais_ = new MockVirtualAudioInputStream(audio_thread_.task_runner()); |
205 new MockVirtualAudioInputStream(audio_thread_.message_loop_proxy()); | |
206 EXPECT_CALL(*mock_vais_, Open()); | 205 EXPECT_CALL(*mock_vais_, Open()); |
207 EXPECT_CALL(*mock_vais_, Close()); // At Close() time. | 206 EXPECT_CALL(*mock_vais_, Close()); // At Close() time. |
208 | 207 |
209 ASSERT_EQ(kRenderProcessId, current_render_process_id_); | 208 ASSERT_EQ(kRenderProcessId, current_render_process_id_); |
210 ASSERT_EQ(kRenderFrameId, current_render_frame_id_); | 209 ASSERT_EQ(kRenderFrameId, current_render_frame_id_); |
211 EXPECT_CALL(*mock_tracker_.get(), | 210 EXPECT_CALL(*mock_tracker_.get(), |
212 Start(kRenderProcessId, kRenderFrameId, _)) | 211 Start(kRenderProcessId, kRenderFrameId, _)) |
213 .WillOnce(DoAll( | 212 .WillOnce(DoAll( |
214 SaveArg<2>(&change_callback_), | 213 SaveArg<2>(&change_callback_), |
215 WithArgs<0, 1>(Invoke(this, | 214 WithArgs<0, 1>(Invoke(this, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 void Close() { | 333 void Close() { |
335 // WebContentsAudioInputStream self-destructs on Close(). Its internal | 334 // WebContentsAudioInputStream self-destructs on Close(). Its internal |
336 // objects hang around until they are no longer referred to (e.g., as tasks | 335 // objects hang around until they are no longer referred to (e.g., as tasks |
337 // on other threads shut things down). | 336 // on other threads shut things down). |
338 wcais_->Close(); | 337 wcais_->Close(); |
339 wcais_ = NULL; | 338 wcais_ = NULL; |
340 mock_vais_ = NULL; | 339 mock_vais_ = NULL; |
341 } | 340 } |
342 | 341 |
343 void RunOnAudioThread(const base::Closure& closure) { | 342 void RunOnAudioThread(const base::Closure& closure) { |
344 audio_thread_.message_loop()->PostTask(FROM_HERE, closure); | 343 audio_thread_.task_runner()->PostTask(FROM_HERE, closure); |
345 } | 344 } |
346 | 345 |
347 // Block the calling thread until OnData() callbacks are being made. | 346 // Block the calling thread until OnData() callbacks are being made. |
348 void WaitForData() { | 347 void WaitForData() { |
349 // Note: Arbitrarily chosen, but more iterations causes tests to take | 348 // Note: Arbitrarily chosen, but more iterations causes tests to take |
350 // significantly more time. | 349 // significantly more time. |
351 static const int kNumIterations = 3; | 350 static const int kNumIterations = 3; |
352 for (int i = 0; i < kNumIterations; ++i) | 351 for (int i = 0; i < kNumIterations; ++i) |
353 on_data_event_.Wait(); | 352 on_data_event_.Wait(); |
354 } | 353 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 WaitForData(); | 493 WaitForData(); |
495 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); | 494 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
496 WaitForData(); | 495 WaitForData(); |
497 RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); | 496 RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); |
498 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); | 497 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
499 RUN_ON_AUDIO_THREAD(Stop); | 498 RUN_ON_AUDIO_THREAD(Stop); |
500 RUN_ON_AUDIO_THREAD(Close); | 499 RUN_ON_AUDIO_THREAD(Close); |
501 } | 500 } |
502 | 501 |
503 } // namespace content | 502 } // namespace content |
OLD | NEW |