| 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 "base/sync_socket.h" | 17 #include "base/sync_socket.h" |
| 18 #include "content/browser/audio_manager_thread.h" | |
| 19 #include "content/browser/media/capture/audio_mirroring_manager.h" | 18 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/media_observer.h" | 20 #include "content/public/browser/media_observer.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "media/audio/audio_output_controller.h" | 22 #include "media/audio/audio_output_controller.h" |
| 23 #include "media/audio/audio_thread_impl.h" |
| 24 #include "media/audio/fake_audio_log_factory.h" | 24 #include "media/audio/fake_audio_log_factory.h" |
| 25 #include "media/audio/fake_audio_manager.h" | 25 #include "media/audio/fake_audio_manager.h" |
| 26 #include "media/base/media_switches.h" | 26 #include "media/base/media_switches.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 29 |
| 30 using ::testing::_; | 30 using ::testing::_; |
| 31 using ::testing::InSequence; | 31 using ::testing::InSequence; |
| 32 using ::testing::NotNull; | 32 using ::testing::NotNull; |
| 33 using ::testing::StrictMock; | 33 using ::testing::StrictMock; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 AudioOutputDelegateTest() { | 103 AudioOutputDelegateTest() { |
| 104 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 104 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 105 switches::kUseFakeDeviceForMediaStream); | 105 switches::kUseFakeDeviceForMediaStream); |
| 106 | 106 |
| 107 // This test uses real UI, IO and audio threads. | 107 // This test uses real UI, IO and audio threads. |
| 108 // AudioOutputDelegate mainly interacts with the IO and audio threads, | 108 // AudioOutputDelegate mainly interacts with the IO and audio threads, |
| 109 // but interacts with UI for bad messages, so using these threads should | 109 // but interacts with UI for bad messages, so using these threads should |
| 110 // approximate the real conditions of AudioOutputDelegate well. | 110 // approximate the real conditions of AudioOutputDelegate well. |
| 111 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( | 111 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( |
| 112 TestBrowserThreadBundle::Options::REAL_IO_THREAD); | 112 TestBrowserThreadBundle::Options::REAL_IO_THREAD); |
| 113 audio_thread_ = base::MakeUnique<AudioManagerThread>(); | |
| 114 | 113 |
| 115 audio_manager_.reset(new media::FakeAudioManager( | 114 audio_manager_.reset(new media::FakeAudioManager( |
| 116 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), | 115 base::MakeUnique<media::AudioThreadImpl>(), &log_factory_)); |
| 117 &log_factory_)); | |
| 118 } | 116 } |
| 117 ~AudioOutputDelegateTest() { audio_manager_->Shutdown(); } |
| 119 | 118 |
| 120 // Test bodies are here, so that we can run them on the IO thread. | 119 // Test bodies are here, so that we can run them on the IO thread. |
| 121 void CreateTest(base::Closure done) { | 120 void CreateTest(base::Closure done) { |
| 122 EXPECT_CALL(media_observer_, | 121 EXPECT_CALL(media_observer_, |
| 123 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId)); | 122 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId)); |
| 124 EXPECT_CALL(event_handler_, GotOnStreamCreated()); | 123 EXPECT_CALL(event_handler_, GotOnStreamCreated()); |
| 125 EXPECT_CALL(mirroring_manager_, | 124 EXPECT_CALL(mirroring_manager_, |
| 126 AddDiverter(kRenderProcessId, kRenderFrameId, NotNull())); | 125 AddDiverter(kRenderProcessId, kRenderFrameId, NotNull())); |
| 127 | 126 |
| 128 { | 127 { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 SyncWithAllThreads(); | 424 SyncWithAllThreads(); |
| 426 | 425 |
| 427 delegate.GetControllerForTesting()->OnError(nullptr); | 426 delegate.GetControllerForTesting()->OnError(nullptr); |
| 428 } | 427 } |
| 429 SyncWithAllThreads(); | 428 SyncWithAllThreads(); |
| 430 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done); | 429 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done); |
| 431 } | 430 } |
| 432 | 431 |
| 433 protected: | 432 protected: |
| 434 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; | 433 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; |
| 435 std::unique_ptr<AudioManagerThread> audio_thread_; | 434 std::unique_ptr<media::AudioManager> audio_manager_; |
| 436 media::ScopedAudioManagerPtr audio_manager_; | |
| 437 StrictMock<MockAudioMirroringManager> mirroring_manager_; | 435 StrictMock<MockAudioMirroringManager> mirroring_manager_; |
| 438 StrictMock<MockEventHandler> event_handler_; | 436 StrictMock<MockEventHandler> event_handler_; |
| 439 StrictMock<MockObserver> media_observer_; | 437 StrictMock<MockObserver> media_observer_; |
| 440 media::FakeAudioLogFactory log_factory_; | 438 media::FakeAudioLogFactory log_factory_; |
| 441 | 439 |
| 442 private: | 440 private: |
| 443 void SyncWithAllThreads() { | 441 void SyncWithAllThreads() { |
| 444 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 442 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 445 // New tasks might be posted while we are syncing, but in every iteration at | 443 // New tasks might be posted while we are syncing, but in every iteration at |
| 446 // least one task will be run. 20 iterations should be enough for our code. | 444 // 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... |
| 554 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) { | 552 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) { |
| 555 base::RunLoop l; | 553 base::RunLoop l; |
| 556 BrowserThread::PostTask( | 554 BrowserThread::PostTask( |
| 557 BrowserThread::IO, FROM_HERE, | 555 BrowserThread::IO, FROM_HERE, |
| 558 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest, | 556 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest, |
| 559 base::Unretained(this), l.QuitClosure())); | 557 base::Unretained(this), l.QuitClosure())); |
| 560 l.Run(); | 558 l.Run(); |
| 561 } | 559 } |
| 562 | 560 |
| 563 } // namespace content | 561 } // namespace content |
| OLD | NEW |