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

Side by Side Diff: content/renderer/media/user_media_client_impl_unittest.cc

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE + Workaround to ensure MediaStreamAudioProcessor is destroyed on the main thread. Created 4 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/media/user_media_client_impl.h" 5 #include "content/renderer/media/user_media_client_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 UserMediaClientImplUnderTest( 55 UserMediaClientImplUnderTest(
56 PeerConnectionDependencyFactory* dependency_factory, 56 PeerConnectionDependencyFactory* dependency_factory,
57 std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher) 57 std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher)
58 : UserMediaClientImpl(NULL, 58 : UserMediaClientImpl(NULL,
59 dependency_factory, 59 dependency_factory,
60 std::move(media_stream_dispatcher)), 60 std::move(media_stream_dispatcher)),
61 state_(REQUEST_NOT_STARTED), 61 state_(REQUEST_NOT_STARTED),
62 result_(NUM_MEDIA_REQUEST_RESULTS), 62 result_(NUM_MEDIA_REQUEST_RESULTS),
63 result_name_(""), 63 result_name_(""),
64 factory_(dependency_factory), 64 factory_(dependency_factory),
65 create_source_that_fails_(false),
65 video_source_(NULL) {} 66 video_source_(NULL) {}
66 67
67 void RequestUserMedia(const blink::WebUserMediaRequest& user_media_request) { 68 void RequestUserMedia(const blink::WebUserMediaRequest& user_media_request) {
68 state_ = REQUEST_NOT_COMPLETE; 69 state_ = REQUEST_NOT_COMPLETE;
69 requestUserMedia(user_media_request); 70 requestUserMedia(user_media_request);
70 } 71 }
71 72
72 void RequestUserMedia() { 73 void RequestUserMedia() {
73 blink::WebUserMediaRequest user_media_request; 74 blink::WebUserMediaRequest user_media_request;
74 RequestUserMedia(user_media_request); 75 RequestUserMedia(user_media_request);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 last_devices_ = devices; 120 last_devices_ = devices;
120 } 121 }
121 122
122 void EnumerateSourcesSucceded( 123 void EnumerateSourcesSucceded(
123 blink::WebMediaStreamTrackSourcesRequest* request, 124 blink::WebMediaStreamTrackSourcesRequest* request,
124 blink::WebVector<blink::WebSourceInfo>& sources) override { 125 blink::WebVector<blink::WebSourceInfo>& sources) override {
125 state_ = REQUEST_SUCCEEDED; 126 state_ = REQUEST_SUCCEEDED;
126 last_sources_ = sources; 127 last_sources_ = sources;
127 } 128 }
128 129
130 void SetCreateSourceThatFails(bool should_fail) {
131 create_source_that_fails_ = should_fail;
132 }
133
134 MediaStreamAudioSource* CreateAudioSource(
135 const StreamDeviceInfo& device,
136 const blink::WebMediaConstraints& constraints) override {
137 MediaStreamAudioSource* source;
138 if (create_source_that_fails_) {
139 class FailedAtLifeAudioSource : public MediaStreamAudioSource {
140 public:
141 FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {}
142 ~FailedAtLifeAudioSource() override {}
143 protected:
144 bool EnsureSourceIsStarted() override {
145 return false;
146 }
147 };
148 source = new FailedAtLifeAudioSource();
149 } else {
150 source = new MediaStreamAudioSource(true);
151 }
152 source->SetDeviceInfo(device);
153 return source;
154 }
155
129 MediaStreamVideoSource* CreateVideoSource( 156 MediaStreamVideoSource* CreateVideoSource(
130 const StreamDeviceInfo& device, 157 const StreamDeviceInfo& device,
131 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { 158 const MediaStreamSource::SourceStoppedCallback& stop_callback) override {
132 video_source_ = new MockMediaStreamVideoCapturerSource(device, 159 video_source_ = new MockMediaStreamVideoCapturerSource(device,
133 stop_callback, 160 stop_callback,
134 factory_); 161 factory_);
135 return video_source_; 162 return video_source_;
136 } 163 }
137 164
138 const blink::WebMediaStream& last_generated_stream() { 165 const blink::WebMediaStream& last_generated_stream() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 199 }
173 200
174 private: 201 private:
175 blink::WebMediaStream last_generated_stream_; 202 blink::WebMediaStream last_generated_stream_;
176 RequestState state_; 203 RequestState state_;
177 content::MediaStreamRequestResult result_; 204 content::MediaStreamRequestResult result_;
178 blink::WebString result_name_; 205 blink::WebString result_name_;
179 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; 206 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_;
180 blink::WebVector<blink::WebSourceInfo> last_sources_; 207 blink::WebVector<blink::WebSourceInfo> last_sources_;
181 PeerConnectionDependencyFactory* factory_; 208 PeerConnectionDependencyFactory* factory_;
209 bool create_source_that_fails_;
182 MockMediaStreamVideoCapturerSource* video_source_; 210 MockMediaStreamVideoCapturerSource* video_source_;
183 }; 211 };
184 212
185 class UserMediaClientImplTest : public ::testing::Test { 213 class UserMediaClientImplTest : public ::testing::Test {
186 public: 214 public:
187 void SetUp() override { 215 void SetUp() override {
188 // Create our test object. 216 // Create our test object.
189 child_process_.reset(new ChildProcess()); 217 child_process_.reset(new ChildProcess());
190 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); 218 dependency_factory_.reset(new MockPeerConnectionDependencyFactory());
191 ms_dispatcher_ = new MockMediaStreamDispatcher(); 219 ms_dispatcher_ = new MockMediaStreamDispatcher();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 292 }
265 293
266 void FailToStartMockedVideoSource() { 294 void FailToStartMockedVideoSource() {
267 MockMediaStreamVideoCapturerSource* video_source = 295 MockMediaStreamVideoCapturerSource* video_source =
268 used_media_impl_->last_created_video_source(); 296 used_media_impl_->last_created_video_source();
269 if (video_source->SourceHasAttemptedToStart()) 297 if (video_source->SourceHasAttemptedToStart())
270 video_source->FailToStartMockedSource(); 298 video_source->FailToStartMockedSource();
271 blink::WebHeap::collectGarbageForTesting(); 299 blink::WebHeap::collectGarbageForTesting();
272 } 300 }
273 301
274 void FailToCreateNextAudioCapturer() {
275 dependency_factory_->FailToCreateNextAudioCapturer();
276 blink::WebHeap::collectGarbageForTesting();
277 }
278
279 bool AudioRequestHasAutomaticDeviceSelection( 302 bool AudioRequestHasAutomaticDeviceSelection(
280 const blink::WebMediaConstraints& audio_constraints) { 303 const blink::WebMediaConstraints& audio_constraints) {
281 blink::WebMediaConstraints null_constraints; 304 blink::WebMediaConstraints null_constraints;
282 blink::WebUserMediaRequest request = 305 blink::WebUserMediaRequest request =
283 blink::WebUserMediaRequest::createForTesting(audio_constraints, 306 blink::WebUserMediaRequest::createForTesting(audio_constraints,
284 null_constraints); 307 null_constraints);
285 used_media_impl_->RequestUserMedia(request); 308 used_media_impl_->RequestUserMedia(request);
286 bool result = used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection( 309 bool result = used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection(
287 ms_dispatcher_->audio_input_request_id()); 310 ms_dispatcher_->audio_input_request_id());
288 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id()); 311 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id());
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, 468 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
446 used_media_impl_->error_reason()); 469 used_media_impl_->error_reason());
447 blink::WebHeap::collectAllGarbageForTesting(); 470 blink::WebHeap::collectAllGarbageForTesting();
448 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 471 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
449 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 472 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
450 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 473 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
451 } 474 }
452 475
453 // This test what happens if an audio source fail to initialize. 476 // This test what happens if an audio source fail to initialize.
454 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) { 477 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) {
455 FailToCreateNextAudioCapturer(); 478 used_media_impl_->SetCreateSourceThatFails(true);
456 used_media_impl_->RequestUserMedia(); 479 used_media_impl_->RequestUserMedia();
457 FakeMediaStreamDispatcherRequestUserMediaComplete(); 480 FakeMediaStreamDispatcherRequestUserMediaComplete();
458 StartMockedVideoSource(); 481 StartMockedVideoSource();
459 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED, 482 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED,
460 used_media_impl_->request_state()); 483 used_media_impl_->request_state());
461 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, 484 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
462 used_media_impl_->error_reason()); 485 used_media_impl_->error_reason());
463 blink::WebHeap::collectAllGarbageForTesting(); 486 blink::WebHeap::collectAllGarbageForTesting();
464 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 487 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
465 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 488 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // Now we close the web frame, if in the above Stop() call, 704 // Now we close the web frame, if in the above Stop() call,
682 // UserMediaClientImpl accidentally removed audio track, then video track will 705 // UserMediaClientImpl accidentally removed audio track, then video track will
683 // be removed again here, which is incorrect. 706 // be removed again here, which is incorrect.
684 used_media_impl_->FrameWillClose(); 707 used_media_impl_->FrameWillClose();
685 blink::WebHeap::collectAllGarbageForTesting(); 708 blink::WebHeap::collectAllGarbageForTesting();
686 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 709 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
687 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 710 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
688 } 711 }
689 712
690 } // namespace content 713 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/user_media_client_impl.cc ('k') | content/renderer/media/webaudio_capturer_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698