| 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/renderer_host/media/web_contents_audio_input_stream.h" | 5 #include "content/browser/renderer_host/media/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" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 virtual ~MockWebContentsTracker() {} | 82 virtual ~MockWebContentsTracker() {} |
| 83 | 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(MockWebContentsTracker); | 84 DISALLOW_COPY_AND_ASSIGN(MockWebContentsTracker); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 // A fully-functional VirtualAudioInputStream, but methods are mocked to allow | 87 // A fully-functional VirtualAudioInputStream, but methods are mocked to allow |
| 88 // tests to check how/when they are invoked. | 88 // tests to check how/when they are invoked. |
| 89 class MockVirtualAudioInputStream : public VirtualAudioInputStream { | 89 class MockVirtualAudioInputStream : public VirtualAudioInputStream { |
| 90 public: | 90 public: |
| 91 explicit MockVirtualAudioInputStream( | 91 explicit MockVirtualAudioInputStream( |
| 92 const scoped_refptr<base::MessageLoopProxy>& message_loop) | 92 const scoped_refptr<base::MessageLoopProxy>& worker_loop) |
| 93 : VirtualAudioInputStream(TestAudioParameters(), message_loop, | 93 : VirtualAudioInputStream(TestAudioParameters(), worker_loop, |
| 94 VirtualAudioInputStream::AfterCloseCallback()), | 94 VirtualAudioInputStream::AfterCloseCallback()), |
| 95 real_(TestAudioParameters(), message_loop, | 95 real_(TestAudioParameters(), worker_loop, |
| 96 base::Bind(&MockVirtualAudioInputStream::OnRealStreamHasClosed, | 96 base::Bind(&MockVirtualAudioInputStream::OnRealStreamHasClosed, |
| 97 base::Unretained(this))), | 97 base::Unretained(this))), |
| 98 real_stream_is_closed_(false) { | 98 real_stream_is_closed_(false) { |
| 99 // Set default actions of mocked methods to delegate to the concrete | 99 // Set default actions of mocked methods to delegate to the concrete |
| 100 // implementation. | 100 // implementation. |
| 101 ON_CALL(*this, Open()) | 101 ON_CALL(*this, Open()) |
| 102 .WillByDefault(Invoke(&real_, &VirtualAudioInputStream::Open)); | 102 .WillByDefault(Invoke(&real_, &VirtualAudioInputStream::Open)); |
| 103 ON_CALL(*this, Start(_)) | 103 ON_CALL(*this, Start(_)) |
| 104 .WillByDefault(Invoke(&real_, &VirtualAudioInputStream::Start)); | 104 .WillByDefault(Invoke(&real_, &VirtualAudioInputStream::Start)); |
| 105 ON_CALL(*this, Stop()) | 105 ON_CALL(*this, Stop()) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 ASSERT_EQ(kRenderViewId, current_render_view_id_); | 211 ASSERT_EQ(kRenderViewId, current_render_view_id_); |
| 212 EXPECT_CALL(*mock_tracker_.get(), Start(kRenderProcessId, kRenderViewId, _)) | 212 EXPECT_CALL(*mock_tracker_.get(), Start(kRenderProcessId, kRenderViewId, _)) |
| 213 .WillOnce(DoAll( | 213 .WillOnce(DoAll( |
| 214 SaveArg<2>(&change_callback_), | 214 SaveArg<2>(&change_callback_), |
| 215 WithArgs<0, 1>(Invoke(&change_callback_, | 215 WithArgs<0, 1>(Invoke(&change_callback_, |
| 216 &WebContentsTracker::ChangeCallback::Run)))); | 216 &WebContentsTracker::ChangeCallback::Run)))); |
| 217 EXPECT_CALL(*mock_tracker_.get(), Stop()); // At Close() time. | 217 EXPECT_CALL(*mock_tracker_.get(), Stop()); // At Close() time. |
| 218 | 218 |
| 219 wcais_ = new WebContentsAudioInputStream( | 219 wcais_ = new WebContentsAudioInputStream( |
| 220 current_render_process_id_, current_render_view_id_, | 220 current_render_process_id_, current_render_view_id_, |
| 221 audio_thread_.message_loop_proxy(), mock_mirroring_manager_.get(), | 221 mock_mirroring_manager_.get(), |
| 222 mock_tracker_, mock_vais_); | 222 mock_tracker_, mock_vais_); |
| 223 wcais_->Open(); | 223 wcais_->Open(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void Start() { | 226 void Start() { |
| 227 EXPECT_CALL(*mock_vais_, Start(&mock_input_callback_)); | 227 EXPECT_CALL(*mock_vais_, Start(&mock_input_callback_)); |
| 228 EXPECT_CALL(*mock_vais_, Stop()); // At Stop() time. | 228 EXPECT_CALL(*mock_vais_, Stop()); // At Stop() time. |
| 229 | 229 |
| 230 EXPECT_CALL(*mock_mirroring_manager_, | 230 EXPECT_CALL(*mock_mirroring_manager_, |
| 231 StartMirroring(kRenderProcessId, kRenderViewId, NotNull())) | 231 StartMirroring(kRenderProcessId, kRenderViewId, NotNull())) |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 WaitForData(); | 504 WaitForData(); |
| 505 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); | 505 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
| 506 WaitForData(); | 506 WaitForData(); |
| 507 RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); | 507 RUN_ON_AUDIO_THREAD(ChangeMirroringTarget); |
| 508 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); | 508 RUN_ON_AUDIO_THREAD(RemoveOneInputInFIFOOrder); |
| 509 RUN_ON_AUDIO_THREAD(Stop); | 509 RUN_ON_AUDIO_THREAD(Stop); |
| 510 RUN_ON_AUDIO_THREAD(Close); | 510 RUN_ON_AUDIO_THREAD(Close); |
| 511 } | 511 } |
| 512 | 512 |
| 513 } // namespace content | 513 } // namespace content |
| OLD | NEW |