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

Side by Side Diff: content/browser/media/audio_output_stream_impl_unittest.cc

Issue 1930393002: Switch stream creation and closing in Chrome audio rendering from IPC to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unique_ptr for Binding Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdint.h>
6 #include <string>
7
8 #include "base/bind.h"
9 #include "base/command_line.h"
10 #include "content/browser/media/audio_output_impl.h"
11 #include "content/browser/media/audio_output_stream_impl.h"
12 #include "content/browser/media/capture/audio_mirroring_manager.h"
13 #include "content/browser/media/media_internals.h"
14 #include "content/browser/renderer_host/media/media_stream_manager.h"
15 #include "content/public/test/mock_render_process_host.h"
16 #include "content/public/test/test_browser_context.h"
17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "media/audio/audio_manager.h"
19 #include "media/base/media_switches.h"
20 #include "media/mojo/interfaces/audio_output.mojom.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 /*
24 using ::testing::_;
25 using ::testing::Return;
26
27 namespace content {
28
29 namespace {
30
31 const int kRenderProcessId = 1;
32 const int kRenderFrameId = 5;
33 const int kStreamId1 = 9;
34 const int kStreamId2 = 20;
35
36 std::string ReturnMockSalt() {
37 return std::string();
38 }
39
40 ResourceContext::SaltCallback GetMockSaltCallback() {
41 return base::Bind(&ReturnMockSalt);
42 }
43 }
44
45 class MockAudioOutputStreamAudioRendererHost : public AudioRendererHost {
46 public:
47 MockAudioOutputStreamAudioRendererHost(
48 int render_process_id,
49 media::AudioManager* audio_manager,
50 AudioMirroringManager* mirroring_manager,
51 MediaInternals* media_internals,
52 MediaStreamManager* media_stream_manager,
53 const ResourceContext::SaltCallback& salt_callback)
54 : AudioRendererHost(render_process_id,
55 audio_manager,
56 mirroring_manager,
57 media_internals,
58 media_stream_manager,
59 salt_callback) {}
60
61 MOCK_METHOD1(CloseStream, void(int stream_id));
62
63 protected:
64 FRIEND_TEST_ALL_PREFIXES(AudioOutputStreamImplTest, Close);
65 friend class AudioOutputStreamImplTest;
66 ~MockAudioOutputStreamAudioRendererHost() override {}
67
68 private:
69 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputStreamAudioRendererHost);
70 };
71
72 class MockAudioOutputImpl : public AudioOutputImpl {
73 public:
74 MockAudioOutputImpl(content::RenderProcessHost* process,
75 int render_frame_id,
76 media::mojom::AudioOutputRequest request)
77 : AudioOutputImpl(process, render_frame_id, std::move(request)) {}
78 ~MockAudioOutputImpl() {}
79 MOCK_METHOD1(RemoveStream, bool(int stream_id));
80 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputImpl);
81 };
82
83 class TestRenderProcessHost : public MockRenderProcessHost {
84 public:
85 TestRenderProcessHost(BrowserContext* context)
86 : MockRenderProcessHost(context) {}
87 scoped_refptr<AudioRendererHost> audio_renderer_host() const override {
88 return audio_renderer_host_;
89 }
90 scoped_refptr<AudioRendererHost> audio_renderer_host_;
91 };
92
93 class AudioOutputStreamImplTest : public ::testing::Test {
94 public:
95 AudioOutputStreamImplTest() {
96 browser_context_.reset(new TestBrowserContext);
97 render_process_host_.reset(
98 new TestRenderProcessHost(browser_context_.get()));
99
100 audio_manager_ = media::AudioManager::CreateForTesting(
101 base::ThreadTaskRunnerHandle::Get());
102
103 base::CommandLine::ForCurrentProcess()->AppendSwitch(
104 switches::kUseFakeDeviceForMediaStream);
105 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
106
107 // Enable caching to make enumerations run in a single thread
108 media_stream_manager_->audio_output_device_enumerator()->SetCachePolicy(
109 AudioOutputDeviceEnumerator::CACHE_POLICY_MANUAL_INVALIDATION);
110
111 audio_renderer_host_ = (new MockAudioOutputStreamAudioRendererHost(
112 kRenderProcessId, audio_manager_.get(), &mirroring_manager_,
113 MediaInternals::GetInstance(), media_stream_manager_.get(),
114 GetMockSaltCallback()));
115 render_process_host_->audio_renderer_host_ = audio_renderer_host_;
116 audio_output_impl_.reset(
117 new MockAudioOutputImpl(render_process_host_.get(), kRenderFrameId,
118 media::mojom::AudioOutputRequest()));
119 audio_renderer_host_->set_audio_output_impl(kRenderFrameId,
120 audio_output_impl_.get());
121 }
122
123 ~AudioOutputStreamImplTest() override {
124 // Avoid leaking the |audio_renderer_host_|.
125 audio_renderer_host_ = NULL;
126 }
127
128 protected:
129 std::unique_ptr<MockAudioOutputImpl> audio_output_impl_;
130 scoped_refptr<MockAudioOutputStreamAudioRendererHost> audio_renderer_host_;
131
132 private:
133 media::ScopedAudioManagerPtr audio_manager_;
134 std::unique_ptr<BrowserContext> browser_context_;
135 std::unique_ptr<MediaStreamManager> media_stream_manager_;
136 AudioMirroringManager mirroring_manager_;
137 std::unique_ptr<TestRenderProcessHost> render_process_host_;
138 TestBrowserThreadBundle thread_bundle_;
139 DISALLOW_COPY_AND_ASSIGN(AudioOutputStreamImplTest);
140 };
141
142 TEST_F(AudioOutputStreamImplTest, Close) {
143 media::mojom::AudioOutputStreamPtr stream1 =
144 media::mojom::AudioOutputStreamPtr();
145
146 std::unique_ptr<AudioOutputStreamImpl> stream_ptr1(
147 new AudioOutputStreamImpl(mojo::GetProxy(&stream1), kStreamId1,
148 kRenderFrameId, audio_renderer_host_.get()));
149
150 EXPECT_CALL(*audio_renderer_host_.get(), CloseStream(kStreamId1)).Times(1);
151 ;
152 EXPECT_CALL(*audio_output_impl_, RemoveStream(kStreamId1)).Times(1);
153
154 stream_ptr1->Close();
155
156 media::mojom::AudioOutputStreamPtr stream2 =
157 media::mojom::AudioOutputStreamPtr();
158
159 std::unique_ptr<AudioOutputStreamImpl> stream_ptr2(
160 new AudioOutputStreamImpl(mojo::GetProxy(&stream2), kStreamId2,
161 kRenderFrameId, audio_renderer_host_.get()));
162
163 EXPECT_CALL(*audio_renderer_host_.get(), CloseStream(kStreamId2)).Times(1);
164 ;
165 EXPECT_CALL(*audio_output_impl_, RemoveStream(kStreamId2)).Times(1);
166
167 stream_ptr2->Close();
168 }
169
170 } // namespace content
171 */
OLDNEW
« no previous file with comments | « content/browser/media/audio_output_stream_impl.cc ('k') | content/browser/renderer_host/media/audio_renderer_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698