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/message_loop/message_loop.h" |
12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "content/browser/browser_thread_impl.h" | |
15 #include "content/browser/media/capture/audio_mirroring_manager.h" | 14 #include "content/browser/media/capture/audio_mirroring_manager.h" |
16 #include "content/browser/media/capture/web_contents_tracker.h" | 15 #include "content/browser/media/capture/web_contents_tracker.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "media/audio/simple_sources.h" | 18 #include "media/audio/simple_sources.h" |
18 #include "media/audio/virtual_audio_input_stream.h" | 19 #include "media/audio/virtual_audio_input_stream.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using ::testing::_; | 23 using ::testing::_; |
23 using ::testing::Assign; | 24 using ::testing::Assign; |
24 using ::testing::DoAll; | 25 using ::testing::DoAll; |
25 using ::testing::Invoke; | 26 using ::testing::Invoke; |
26 using ::testing::InvokeWithoutArgs; | 27 using ::testing::InvokeWithoutArgs; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 171 |
171 private: | 172 private: |
172 DISALLOW_COPY_AND_ASSIGN(MockAudioInputCallback); | 173 DISALLOW_COPY_AND_ASSIGN(MockAudioInputCallback); |
173 }; | 174 }; |
174 | 175 |
175 } // namespace | 176 } // namespace |
176 | 177 |
177 class WebContentsAudioInputStreamTest : public testing::Test { | 178 class WebContentsAudioInputStreamTest : public testing::Test { |
178 public: | 179 public: |
179 WebContentsAudioInputStreamTest() | 180 WebContentsAudioInputStreamTest() |
180 : audio_thread_("Audio thread"), | 181 : thread_bundle_(TestBrowserThreadBundle::REAL_IO_THREAD), |
181 io_thread_(BrowserThread::IO), | 182 audio_thread_("Audio thread"), |
182 mock_mirroring_manager_(new MockAudioMirroringManager()), | 183 mock_mirroring_manager_(new MockAudioMirroringManager()), |
183 mock_tracker_(new MockWebContentsTracker()), | 184 mock_tracker_(new MockWebContentsTracker()), |
184 mock_vais_(NULL), | 185 mock_vais_(NULL), |
185 wcais_(NULL), | 186 wcais_(NULL), |
186 destination_(NULL), | 187 destination_(NULL), |
187 current_render_process_id_(kRenderProcessId), | 188 current_render_process_id_(kRenderProcessId), |
188 current_render_view_id_(kRenderViewId), | 189 current_render_view_id_(kRenderViewId), |
189 on_data_event_(false, false) { | 190 on_data_event_(false, false) { |
190 audio_thread_.Start(); | 191 audio_thread_.Start(); |
191 io_thread_.Start(); | |
192 } | 192 } |
193 | 193 |
194 virtual ~WebContentsAudioInputStreamTest() { | 194 virtual ~WebContentsAudioInputStreamTest() { |
195 audio_thread_.Stop(); | 195 audio_thread_.Stop(); |
196 io_thread_.Stop(); | |
197 | 196 |
198 DCHECK(!mock_vais_); | 197 DCHECK(!mock_vais_); |
199 DCHECK(!wcais_); | 198 DCHECK(!wcais_); |
200 EXPECT_FALSE(destination_); | 199 EXPECT_FALSE(destination_); |
201 DCHECK(streams_.empty()); | 200 DCHECK(streams_.empty()); |
202 DCHECK(sources_.empty()); | 201 DCHECK(sources_.empty()); |
203 } | 202 } |
204 | 203 |
205 void Open() { | 204 void Open() { |
206 mock_vais_ = | 205 mock_vais_ = |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // Block the calling thread until OnData() callbacks are being made. | 361 // Block the calling thread until OnData() callbacks are being made. |
363 void WaitForData() { | 362 void WaitForData() { |
364 // Note: Arbitrarily chosen, but more iterations causes tests to take | 363 // Note: Arbitrarily chosen, but more iterations causes tests to take |
365 // significantly more time. | 364 // significantly more time. |
366 static const int kNumIterations = 3; | 365 static const int kNumIterations = 3; |
367 for (int i = 0; i < kNumIterations; ++i) | 366 for (int i = 0; i < kNumIterations; ++i) |
368 on_data_event_.Wait(); | 367 on_data_event_.Wait(); |
369 } | 368 } |
370 | 369 |
371 private: | 370 private: |
| 371 TestBrowserThreadBundle thread_bundle_; |
372 base::Thread audio_thread_; | 372 base::Thread audio_thread_; |
373 BrowserThreadImpl io_thread_; | |
374 | 373 |
375 scoped_ptr<MockAudioMirroringManager> mock_mirroring_manager_; | 374 scoped_ptr<MockAudioMirroringManager> mock_mirroring_manager_; |
376 scoped_refptr<MockWebContentsTracker> mock_tracker_; | 375 scoped_refptr<MockWebContentsTracker> mock_tracker_; |
377 | 376 |
378 MockVirtualAudioInputStream* mock_vais_; // Owned by wcais_. | 377 MockVirtualAudioInputStream* mock_vais_; // Owned by wcais_. |
379 WebContentsAudioInputStream* wcais_; // Self-destructs on Close(). | 378 WebContentsAudioInputStream* wcais_; // Self-destructs on Close(). |
380 | 379 |
381 // Mock consumer of audio data. | 380 // Mock consumer of audio data. |
382 MockAudioInputCallback mock_input_callback_; | 381 MockAudioInputCallback mock_input_callback_; |
383 | 382 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 WaitForData(); | 503 WaitForData(); |
505 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); | 504 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
506 WaitForData(); | 505 WaitForData(); |
507 RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); | 506 RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); |
508 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); | 507 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
509 RUN_ON_AUDIO_THREAD(Stop); | 508 RUN_ON_AUDIO_THREAD(Stop); |
510 RUN_ON_AUDIO_THREAD(Close); | 509 RUN_ON_AUDIO_THREAD(Close); |
511 } | 510 } |
512 | 511 |
513 } // namespace content | 512 } // namespace content |
OLD | NEW |