| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/audio_output_delegate_impl.h" | 5 #include "content/browser/renderer_host/media/audio_output_delegate_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "content/browser/audio_manager_thread.h" | 17 #include "content/browser/audio_manager_thread.h" |
| 18 #include "content/browser/media/capture/audio_mirroring_manager.h" | 18 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 19 #include "content/browser/renderer_host/media/media_stream_manager.h" | 19 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/media_observer.h" | 21 #include "content/public/browser/media_observer.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "media/audio/audio_output_controller.h" | 23 #include "media/audio/audio_output_controller.h" |
| 24 #include "media/audio/audio_system_impl.h" |
| 24 #include "media/audio/fake_audio_log_factory.h" | 25 #include "media/audio/fake_audio_log_factory.h" |
| 25 #include "media/audio/fake_audio_manager.h" | 26 #include "media/audio/fake_audio_manager.h" |
| 26 #include "media/base/media_switches.h" | 27 #include "media/base/media_switches.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 using ::testing::_; | 31 using ::testing::_; |
| 31 using ::testing::InSequence; | 32 using ::testing::InSequence; |
| 32 using ::testing::NotNull; | 33 using ::testing::NotNull; |
| 33 using ::testing::StrictMock; | 34 using ::testing::StrictMock; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // AudioOutputDelegate mainly interacts with the IO and audio threads, | 109 // AudioOutputDelegate mainly interacts with the IO and audio threads, |
| 109 // but interacts with UI for bad messages, so using these threads should | 110 // but interacts with UI for bad messages, so using these threads should |
| 110 // approximate the real conditions of AudioOutputDelegate well. | 111 // approximate the real conditions of AudioOutputDelegate well. |
| 111 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( | 112 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( |
| 112 TestBrowserThreadBundle::Options::REAL_IO_THREAD); | 113 TestBrowserThreadBundle::Options::REAL_IO_THREAD); |
| 113 audio_thread_ = base::MakeUnique<AudioManagerThread>(); | 114 audio_thread_ = base::MakeUnique<AudioManagerThread>(); |
| 114 | 115 |
| 115 audio_manager_.reset(new media::FakeAudioManager( | 116 audio_manager_.reset(new media::FakeAudioManager( |
| 116 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), | 117 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), |
| 117 &log_factory_)); | 118 &log_factory_)); |
| 119 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
| 118 media_stream_manager_ = | 120 media_stream_manager_ = |
| 119 base::MakeUnique<MediaStreamManager>(audio_manager_.get()); | 121 base::MakeUnique<MediaStreamManager>(audio_system_.get()); |
| 120 } | 122 } |
| 121 | 123 |
| 122 // Test bodies are here, so that we can run them on the IO thread. | 124 // Test bodies are here, so that we can run them on the IO thread. |
| 123 void CreateTest(base::Closure done) { | 125 void CreateTest(base::Closure done) { |
| 124 EXPECT_CALL(media_observer_, | 126 EXPECT_CALL(media_observer_, |
| 125 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId)); | 127 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId)); |
| 126 EXPECT_CALL(event_handler_, | 128 EXPECT_CALL(event_handler_, |
| 127 OnStreamCreated(kStreamId, NotNull(), NotNull())); | 129 OnStreamCreated(kStreamId, NotNull(), NotNull())); |
| 128 EXPECT_CALL(mirroring_manager_, | 130 EXPECT_CALL(mirroring_manager_, |
| 129 AddDiverter(kRenderProcessId, kRenderFrameId, NotNull())); | 131 AddDiverter(kRenderProcessId, kRenderFrameId, NotNull())); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done); | 445 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done); |
| 444 } | 446 } |
| 445 | 447 |
| 446 protected: | 448 protected: |
| 447 // MediaStreamManager uses a DestructionObserver, so it must outlive the | 449 // MediaStreamManager uses a DestructionObserver, so it must outlive the |
| 448 // TestBrowserThreadBundle. | 450 // TestBrowserThreadBundle. |
| 449 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 451 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
| 450 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; | 452 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; |
| 451 std::unique_ptr<AudioManagerThread> audio_thread_; | 453 std::unique_ptr<AudioManagerThread> audio_thread_; |
| 452 media::ScopedAudioManagerPtr audio_manager_; | 454 media::ScopedAudioManagerPtr audio_manager_; |
| 455 std::unique_ptr<media::AudioSystem> audio_system_; |
| 453 StrictMock<MockAudioMirroringManager> mirroring_manager_; | 456 StrictMock<MockAudioMirroringManager> mirroring_manager_; |
| 454 StrictMock<MockEventHandler> event_handler_; | 457 StrictMock<MockEventHandler> event_handler_; |
| 455 StrictMock<MockObserver> media_observer_; | 458 StrictMock<MockObserver> media_observer_; |
| 456 media::FakeAudioLogFactory log_factory_; | 459 media::FakeAudioLogFactory log_factory_; |
| 457 | 460 |
| 458 private: | 461 private: |
| 459 void SyncWithAllThreads() { | 462 void SyncWithAllThreads() { |
| 460 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 463 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 461 // New tasks might be posted while we are syncing, but in every iteration at | 464 // New tasks might be posted while we are syncing, but in every iteration at |
| 462 // least one task will be run. 20 iterations should be enough for our code. | 465 // least one task will be run. 20 iterations should be enough for our code. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) { | 573 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) { |
| 571 base::RunLoop l; | 574 base::RunLoop l; |
| 572 BrowserThread::PostTask( | 575 BrowserThread::PostTask( |
| 573 BrowserThread::IO, FROM_HERE, | 576 BrowserThread::IO, FROM_HERE, |
| 574 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest, | 577 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest, |
| 575 base::Unretained(this), l.QuitClosure())); | 578 base::Unretained(this), l.QuitClosure())); |
| 576 l.Run(); | 579 l.Run(); |
| 577 } | 580 } |
| 578 | 581 |
| 579 } // namespace content | 582 } // namespace content |
| OLD | NEW |