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

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

Issue 2800013003: Remove some unnecessary stuff from AudioOutputDelegateImplUnitTest. (Closed)
Patch Set: Created 3 years, 8 months 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 | « no previous file | 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_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"
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"
24 #include "media/audio/audio_system_impl.h"
25 #include "media/audio/fake_audio_log_factory.h" 23 #include "media/audio/fake_audio_log_factory.h"
26 #include "media/audio/fake_audio_manager.h" 24 #include "media/audio/fake_audio_manager.h"
27 #include "media/base/media_switches.h" 25 #include "media/base/media_switches.h"
28 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
30 28
31 using ::testing::_; 29 using ::testing::_;
32 using ::testing::InSequence; 30 using ::testing::InSequence;
33 using ::testing::NotNull; 31 using ::testing::NotNull;
34 using ::testing::StrictMock; 32 using ::testing::StrictMock;
35 33
36 // TODO(maxmorin): not yet tested:
37 // - Interactions with AudioStreamMonitor (goes through WebContentsImpl,
38 // so it's a bit tricky).
39 // - Logging (small risk of bugs, not worth the effort).
40 // - That the returned socket/memory is correctly set up.
41
42 namespace content { 34 namespace content {
43 35
44 namespace { 36 namespace {
45 37
46 const int kRenderProcessId = 1; 38 const int kRenderProcessId = 1;
47 const int kRenderFrameId = 5; 39 const int kRenderFrameId = 5;
48 const int kStreamId = 50; 40 const int kStreamId = 50;
49 const char kDefaultDeviceId[] = ""; 41 const char kDefaultDeviceId[] = "";
50 42
51 class MockAudioMirroringManager : public AudioMirroringManager { 43 class MockAudioMirroringManager : public AudioMirroringManager {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // AudioOutputDelegate mainly interacts with the IO and audio threads, 101 // AudioOutputDelegate mainly interacts with the IO and audio threads,
110 // but interacts with UI for bad messages, so using these threads should 102 // but interacts with UI for bad messages, so using these threads should
111 // approximate the real conditions of AudioOutputDelegate well. 103 // approximate the real conditions of AudioOutputDelegate well.
112 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( 104 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>(
113 TestBrowserThreadBundle::Options::REAL_IO_THREAD); 105 TestBrowserThreadBundle::Options::REAL_IO_THREAD);
114 audio_thread_ = base::MakeUnique<AudioManagerThread>(); 106 audio_thread_ = base::MakeUnique<AudioManagerThread>();
115 107
116 audio_manager_.reset(new media::FakeAudioManager( 108 audio_manager_.reset(new media::FakeAudioManager(
117 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), 109 audio_thread_->task_runner(), audio_thread_->worker_task_runner(),
118 &log_factory_)); 110 &log_factory_));
119 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
120 media_stream_manager_ =
121 base::MakeUnique<MediaStreamManager>(audio_system_.get());
122 } 111 }
123 112
124 // Test bodies are here, so that we can run them on the IO thread. 113 // Test bodies are here, so that we can run them on the IO thread.
125 void CreateTest(base::Closure done) { 114 void CreateTest(base::Closure done) {
126 EXPECT_CALL(media_observer_, 115 EXPECT_CALL(media_observer_,
127 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId)); 116 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId));
128 EXPECT_CALL(event_handler_, 117 EXPECT_CALL(event_handler_,
129 OnStreamCreated(kStreamId, NotNull(), NotNull())); 118 OnStreamCreated(kStreamId, NotNull(), NotNull()));
130 EXPECT_CALL(mirroring_manager_, 119 EXPECT_CALL(mirroring_manager_,
131 AddDiverter(kRenderProcessId, kRenderFrameId, NotNull())); 120 AddDiverter(kRenderProcessId, kRenderFrameId, NotNull()));
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 kDefaultDeviceId); 428 kDefaultDeviceId);
440 SyncWithAllThreads(); 429 SyncWithAllThreads();
441 430
442 delegate.GetController()->OnError(nullptr); 431 delegate.GetController()->OnError(nullptr);
443 } 432 }
444 SyncWithAllThreads(); 433 SyncWithAllThreads();
445 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done); 434 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done);
446 } 435 }
447 436
448 protected: 437 protected:
449 // MediaStreamManager uses a DestructionObserver, so it must outlive the
450 // TestBrowserThreadBundle.
451 std::unique_ptr<MediaStreamManager> media_stream_manager_;
452 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; 438 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_;
453 std::unique_ptr<AudioManagerThread> audio_thread_; 439 std::unique_ptr<AudioManagerThread> audio_thread_;
454 media::ScopedAudioManagerPtr audio_manager_; 440 media::ScopedAudioManagerPtr audio_manager_;
455 std::unique_ptr<media::AudioSystem> audio_system_;
456 StrictMock<MockAudioMirroringManager> mirroring_manager_; 441 StrictMock<MockAudioMirroringManager> mirroring_manager_;
457 StrictMock<MockEventHandler> event_handler_; 442 StrictMock<MockEventHandler> event_handler_;
458 StrictMock<MockObserver> media_observer_; 443 StrictMock<MockObserver> media_observer_;
459 media::FakeAudioLogFactory log_factory_; 444 media::FakeAudioLogFactory log_factory_;
460 445
461 private: 446 private:
462 void SyncWithAllThreads() { 447 void SyncWithAllThreads() {
463 DCHECK_CURRENTLY_ON(BrowserThread::IO); 448 DCHECK_CURRENTLY_ON(BrowserThread::IO);
464 // New tasks might be posted while we are syncing, but in every iteration at 449 // New tasks might be posted while we are syncing, but in every iteration at
465 // least one task will be run. 20 iterations should be enough for our code. 450 // 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
573 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) { 558 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) {
574 base::RunLoop l; 559 base::RunLoop l;
575 BrowserThread::PostTask( 560 BrowserThread::PostTask(
576 BrowserThread::IO, FROM_HERE, 561 BrowserThread::IO, FROM_HERE,
577 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest, 562 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest,
578 base::Unretained(this), l.QuitClosure())); 563 base::Unretained(this), l.QuitClosure()));
579 l.Run(); 564 l.Run();
580 } 565 }
581 566
582 } // namespace content 567 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698