Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: content/browser/renderer_host/media/audio_output_delegate_unittest.cc

Issue 2558303004: Cleanup AudioDeviceThread to avoid accidental misuse. (Closed)
Patch Set: Rename to AudioManagerThread. Fix tests. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/media/audio_output_authorization_handler_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "content/browser/renderer_host/media/audio_output_delegate.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/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "content/browser/audio_device_thread.h" 16 #include "content/browser/audio_manager_thread.h"
17 #include "content/browser/media/capture/audio_mirroring_manager.h" 17 #include "content/browser/media/capture/audio_mirroring_manager.h"
18 #include "content/browser/renderer_host/media/media_stream_manager.h" 18 #include "content/browser/renderer_host/media/media_stream_manager.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/media_observer.h" 20 #include "content/public/browser/media_observer.h"
21 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "media/audio/fake_audio_log_factory.h" 22 #include "media/audio/fake_audio_log_factory.h"
23 #include "media/audio/fake_audio_manager.h" 23 #include "media/audio/fake_audio_manager.h"
24 #include "media/base/media_switches.h" 24 #include "media/base/media_switches.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 AudioOutputDelegateTest() { 102 AudioOutputDelegateTest() {
103 base::CommandLine::ForCurrentProcess()->AppendSwitch( 103 base::CommandLine::ForCurrentProcess()->AppendSwitch(
104 switches::kUseFakeDeviceForMediaStream); 104 switches::kUseFakeDeviceForMediaStream);
105 105
106 // This test uses real UI, IO and audio threads. 106 // This test uses real UI, IO and audio threads.
107 // AudioOutputDelegate mainly interacts with the IO and audio threads, 107 // AudioOutputDelegate mainly interacts with the IO and audio threads,
108 // but interacts with UI for bad messages, so using these threads should 108 // but interacts with UI for bad messages, so using these threads should
109 // approximate the real conditions of AudioOutputDelegate well. 109 // approximate the real conditions of AudioOutputDelegate well.
110 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( 110 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>(
111 TestBrowserThreadBundle::Options::REAL_IO_THREAD); 111 TestBrowserThreadBundle::Options::REAL_IO_THREAD);
112 audio_thread_ = base::MakeUnique<AudioDeviceThread>(); 112 audio_thread_ = base::MakeUnique<AudioManagerThread>();
113 113
114 audio_manager_.reset(new media::FakeAudioManager( 114 audio_manager_.reset(new media::FakeAudioManager(
115 audio_thread_->GetTaskRunner(), audio_thread_->worker_task_runner(), 115 audio_thread_->task_runner(), audio_thread_->worker_task_runner(),
116 &log_factory_)); 116 &log_factory_));
117 media_stream_manager_ = 117 media_stream_manager_ =
118 base::MakeUnique<MediaStreamManager>(audio_manager_.get()); 118 base::MakeUnique<MediaStreamManager>(audio_manager_.get());
119 } 119 }
120 120
121 // Test bodies are here, so that we can run them on the IO thread. 121 // Test bodies are here, so that we can run them on the IO thread.
122 void CreateTest(base::Closure done) { 122 void CreateTest(base::Closure done) {
123 EXPECT_CALL(media_observer_, 123 EXPECT_CALL(media_observer_,
124 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId)); 124 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId));
125 EXPECT_CALL(event_handler_, 125 EXPECT_CALL(event_handler_,
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 delegate.reset(); 451 delegate.reset();
452 SyncWithAllThreads(); 452 SyncWithAllThreads();
453 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done); 453 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done);
454 } 454 }
455 455
456 protected: 456 protected:
457 // MediaStreamManager uses a DestructionObserver, so it must outlive the 457 // MediaStreamManager uses a DestructionObserver, so it must outlive the
458 // TestBrowserThreadBundle. 458 // TestBrowserThreadBundle.
459 std::unique_ptr<MediaStreamManager> media_stream_manager_; 459 std::unique_ptr<MediaStreamManager> media_stream_manager_;
460 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; 460 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_;
461 std::unique_ptr<AudioDeviceThread> audio_thread_; 461 std::unique_ptr<AudioManagerThread> audio_thread_;
462 media::ScopedAudioManagerPtr audio_manager_; 462 media::ScopedAudioManagerPtr audio_manager_;
463 StrictMock<MockAudioMirroringManager> mirroring_manager_; 463 StrictMock<MockAudioMirroringManager> mirroring_manager_;
464 StrictMock<MockEventHandler> event_handler_; 464 StrictMock<MockEventHandler> event_handler_;
465 StrictMock<MockObserver> media_observer_; 465 StrictMock<MockObserver> media_observer_;
466 media::FakeAudioLogFactory log_factory_; 466 media::FakeAudioLogFactory log_factory_;
467 467
468 private: 468 private:
469 void SyncWithAllThreads() { 469 void SyncWithAllThreads() {
470 DCHECK_CURRENTLY_ON(BrowserThread::IO); 470 DCHECK_CURRENTLY_ON(BrowserThread::IO);
471 // New tasks might be posted while we are syncing, but in every iteration at 471 // New tasks might be posted while we are syncing, but in every iteration at
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) { 580 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) {
581 base::RunLoop l; 581 base::RunLoop l;
582 BrowserThread::PostTask( 582 BrowserThread::PostTask(
583 BrowserThread::IO, FROM_HERE, 583 BrowserThread::IO, FROM_HERE,
584 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest, 584 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest,
585 base::Unretained(this), l.QuitClosure())); 585 base::Unretained(this), l.QuitClosure()));
586 l.Run(); 586 l.Run();
587 } 587 }
588 588
589 } // namespace content 589 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_output_authorization_handler_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698