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

Side by Side Diff: content/renderer/media/webrtc/processed_local_audio_source_unittest.cc

Issue 2626533002: Revert of Fix getUserMedia so that failure is reported for invalid audio sources. (Closed)
Patch Set: Created 3 years, 11 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
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 blink::WebHeap::collectAllGarbageForTesting(); 95 blink::WebHeap::collectAllGarbageForTesting();
96 } 96 }
97 97
98 void CreateProcessedLocalAudioSource( 98 void CreateProcessedLocalAudioSource(
99 const blink::WebMediaConstraints& constraints) { 99 const blink::WebMediaConstraints& constraints) {
100 ProcessedLocalAudioSource* const source = new ProcessedLocalAudioSource( 100 ProcessedLocalAudioSource* const source = new ProcessedLocalAudioSource(
101 -1 /* consumer_render_frame_id is N/A for non-browser tests */, 101 -1 /* consumer_render_frame_id is N/A for non-browser tests */,
102 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", 102 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device",
103 "mock_audio_device_id", kSampleRate, kChannelLayout, 103 "mock_audio_device_id", kSampleRate, kChannelLayout,
104 kRequestedBufferSize), 104 kRequestedBufferSize),
105 constraints,
106 base::Bind(&ProcessedLocalAudioSourceTest::OnAudioSourceStarted,
107 base::Unretained(this)),
108 &mock_dependency_factory_); 105 &mock_dependency_factory_);
109 source->SetAllowInvalidRenderFrameIdForTesting(true); 106 source->SetAllowInvalidRenderFrameIdForTesting(true);
107 source->SetSourceConstraints(constraints);
110 blink_audio_source_.setExtraData(source); // Takes ownership. 108 blink_audio_source_.setExtraData(source); // Takes ownership.
111 } 109 }
112 110
113 void CheckSourceFormatMatches(const media::AudioParameters& params) { 111 void CheckSourceFormatMatches(const media::AudioParameters& params) {
114 EXPECT_EQ(kSampleRate, params.sample_rate()); 112 EXPECT_EQ(kSampleRate, params.sample_rate());
115 EXPECT_EQ(kChannelLayout, params.channel_layout()); 113 EXPECT_EQ(kChannelLayout, params.channel_layout());
116 EXPECT_EQ(kExpectedSourceBufferSize, params.frames_per_buffer()); 114 EXPECT_EQ(kExpectedSourceBufferSize, params.frames_per_buffer());
117 } 115 }
118 116
119 void CheckOutputFormatMatches(const media::AudioParameters& params) { 117 void CheckOutputFormatMatches(const media::AudioParameters& params) {
(...skipping 12 matching lines...) Expand all
132 } 130 }
133 131
134 MediaStreamAudioSource* audio_source() const { 132 MediaStreamAudioSource* audio_source() const {
135 return MediaStreamAudioSource::From(blink_audio_source_); 133 return MediaStreamAudioSource::From(blink_audio_source_);
136 } 134 }
137 135
138 const blink::WebMediaStreamTrack& blink_audio_track() { 136 const blink::WebMediaStreamTrack& blink_audio_track() {
139 return blink_audio_track_; 137 return blink_audio_track_;
140 } 138 }
141 139
142 void OnAudioSourceStarted(MediaStreamSource* source,
143 MediaStreamRequestResult result,
144 const blink::WebString& result_name) {}
145
146 private: 140 private:
147 base::MessageLoop main_thread_message_loop_; // Needed for MSAudioProcessor. 141 base::MessageLoop main_thread_message_loop_; // Needed for MSAudioProcessor.
148 MockAudioDeviceFactory mock_audio_device_factory_; 142 MockAudioDeviceFactory mock_audio_device_factory_;
149 MockPeerConnectionDependencyFactory mock_dependency_factory_; 143 MockPeerConnectionDependencyFactory mock_dependency_factory_;
150 blink::WebMediaStreamSource blink_audio_source_; 144 blink::WebMediaStreamSource blink_audio_source_;
151 blink::WebMediaStreamTrack blink_audio_track_; 145 blink::WebMediaStreamTrack blink_audio_track_;
152 }; 146 };
153 147
154 // Tests a basic end-to-end start-up, track+sink connections, audio flow, and 148 // Tests a basic end-to-end start-up, track+sink connections, audio flow, and
155 // shut-down. The unit tests in media_stream_audio_unittest.cc provide more 149 // shut-down. The unit tests in media_stream_audio_unittest.cc provide more
(...skipping 11 matching lines...) Expand all
167 CreateProcessedLocalAudioSource( 161 CreateProcessedLocalAudioSource(
168 constraint_factory.CreateWebMediaConstraints()); 162 constraint_factory.CreateWebMediaConstraints());
169 163
170 // Connect the track, and expect the MockCapturerSource to be initialized and 164 // Connect the track, and expect the MockCapturerSource to be initialized and
171 // started by ProcessedLocalAudioSource. 165 // started by ProcessedLocalAudioSource.
172 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), 166 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(),
173 Initialize(_, capture_source_callback(), -1)) 167 Initialize(_, capture_source_callback(), -1))
174 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); 168 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches)));
175 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), 169 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(),
176 SetAutomaticGainControl(true)); 170 SetAutomaticGainControl(true));
177 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) 171 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start());
178 .WillOnce(Invoke(
179 capture_source_callback(),
180 &media::AudioCapturerSource::CaptureCallback::OnCaptureStarted));
181 ASSERT_TRUE(audio_source()->ConnectToTrack(blink_audio_track())); 172 ASSERT_TRUE(audio_source()->ConnectToTrack(blink_audio_track()));
182 CheckOutputFormatMatches(audio_source()->GetAudioParameters()); 173 CheckOutputFormatMatches(audio_source()->GetAudioParameters());
183 174
184 // Connect a sink to the track. 175 // Connect a sink to the track.
185 std::unique_ptr<MockMediaStreamAudioSink> sink( 176 std::unique_ptr<MockMediaStreamAudioSink> sink(
186 new MockMediaStreamAudioSink()); 177 new MockMediaStreamAudioSink());
187 EXPECT_CALL(*sink, FormatIsSet(_)) 178 EXPECT_CALL(*sink, FormatIsSet(_))
188 .WillOnce(Invoke(this, &ThisTest::CheckOutputFormatMatches)); 179 .WillOnce(Invoke(this, &ThisTest::CheckOutputFormatMatches));
189 MediaStreamAudioTrack::From(blink_audio_track())->AddSink(sink.get()); 180 MediaStreamAudioTrack::From(blink_audio_track())->AddSink(sink.get());
190 181
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // Even though ConnectToTrack() failed, there should still have been a new 222 // Even though ConnectToTrack() failed, there should still have been a new
232 // MediaStreamAudioTrack instance created, owned by the 223 // MediaStreamAudioTrack instance created, owned by the
233 // blink::WebMediaStreamTrack. 224 // blink::WebMediaStreamTrack.
234 EXPECT_TRUE(MediaStreamAudioTrack::From(blink_audio_track())); 225 EXPECT_TRUE(MediaStreamAudioTrack::From(blink_audio_track()));
235 } 226 }
236 227
237 // TODO(miu): There's a lot of logic in ProcessedLocalAudioSource around 228 // TODO(miu): There's a lot of logic in ProcessedLocalAudioSource around
238 // constraints processing and validation that should have unit testing. 229 // constraints processing and validation that should have unit testing.
239 230
240 } // namespace content 231 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698