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

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

Issue 2471803002: Remove MediaStreamTrack.getSources(). (Closed)
Patch Set: Fix platform-specific expectations file Created 4 years, 1 month 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 10 matching lines...) Expand all
21 #include "content/renderer/media/mock_constraint_factory.h" 21 #include "content/renderer/media/mock_constraint_factory.h"
22 #include "content/renderer/media/mock_media_stream_dispatcher.h" 22 #include "content/renderer/media/mock_media_stream_dispatcher.h"
23 #include "content/renderer/media/mock_media_stream_video_source.h" 23 #include "content/renderer/media/mock_media_stream_video_source.h"
24 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h" 24 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h"
25 #include "mojo/public/cpp/bindings/binding.h" 25 #include "mojo/public/cpp/bindings/binding.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" 27 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h"
28 #include "third_party/WebKit/public/platform/WebMediaStream.h" 28 #include "third_party/WebKit/public/platform/WebMediaStream.h"
29 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 29 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
30 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 30 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
31 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h "
32 #include "third_party/WebKit/public/platform/WebString.h" 31 #include "third_party/WebKit/public/platform/WebString.h"
33 #include "third_party/WebKit/public/platform/WebVector.h" 32 #include "third_party/WebKit/public/platform/WebVector.h"
34 #include "third_party/WebKit/public/web/WebHeap.h" 33 #include "third_party/WebKit/public/web/WebHeap.h"
35 34
36 namespace content { 35 namespace content {
37 36
38 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource { 37 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource {
39 public: 38 public:
40 MockMediaStreamVideoCapturerSource( 39 MockMediaStreamVideoCapturerSource(
41 const StreamDeviceInfo& device, 40 const StreamDeviceInfo& device,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 blink::WebUserMediaRequest user_media_request; 114 blink::WebUserMediaRequest user_media_request;
116 RequestUserMedia(user_media_request); 115 RequestUserMedia(user_media_request);
117 } 116 }
118 117
119 void RequestMediaDevices() { 118 void RequestMediaDevices() {
120 blink::WebMediaDevicesRequest media_devices_request; 119 blink::WebMediaDevicesRequest media_devices_request;
121 state_ = REQUEST_NOT_COMPLETE; 120 state_ = REQUEST_NOT_COMPLETE;
122 requestMediaDevices(media_devices_request); 121 requestMediaDevices(media_devices_request);
123 } 122 }
124 123
125 void RequestSources() {
126 blink::WebMediaStreamTrackSourcesRequest sources_request;
127 state_ = REQUEST_NOT_COMPLETE;
128 requestSources(sources_request);
129 }
130
131 void SetMediaDeviceChangeObserver() { 124 void SetMediaDeviceChangeObserver() {
132 blink::WebMediaDeviceChangeObserver observer(true); 125 blink::WebMediaDeviceChangeObserver observer(true);
133 setMediaDeviceChangeObserver(observer); 126 setMediaDeviceChangeObserver(observer);
134 } 127 }
135 128
136 void RemoveMediaDeviceChangeObserver() { 129 void RemoveMediaDeviceChangeObserver() {
137 setMediaDeviceChangeObserver(blink::WebMediaDeviceChangeObserver()); 130 setMediaDeviceChangeObserver(blink::WebMediaDeviceChangeObserver());
138 } 131 }
139 132
140 void GetUserMediaRequestSucceeded( 133 void GetUserMediaRequestSucceeded(
(...skipping 13 matching lines...) Expand all
154 result_name_ = result_name; 147 result_name_ = result_name;
155 } 148 }
156 149
157 void EnumerateDevicesSucceded( 150 void EnumerateDevicesSucceded(
158 blink::WebMediaDevicesRequest* request, 151 blink::WebMediaDevicesRequest* request,
159 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override { 152 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override {
160 state_ = REQUEST_SUCCEEDED; 153 state_ = REQUEST_SUCCEEDED;
161 last_devices_ = devices; 154 last_devices_ = devices;
162 } 155 }
163 156
164 void EnumerateSourcesSucceded(
165 blink::WebMediaStreamTrackSourcesRequest* request,
166 blink::WebVector<blink::WebSourceInfo>& sources) override {
167 state_ = REQUEST_SUCCEEDED;
168 last_sources_ = sources;
169 }
170
171 void SetCreateSourceThatFails(bool should_fail) { 157 void SetCreateSourceThatFails(bool should_fail) {
172 create_source_that_fails_ = should_fail; 158 create_source_that_fails_ = should_fail;
173 } 159 }
174 160
175 MediaStreamAudioSource* CreateAudioSource( 161 MediaStreamAudioSource* CreateAudioSource(
176 const StreamDeviceInfo& device, 162 const StreamDeviceInfo& device,
177 const blink::WebMediaConstraints& constraints) override { 163 const blink::WebMediaConstraints& constraints) override {
178 MediaStreamAudioSource* source; 164 MediaStreamAudioSource* source;
179 if (create_source_that_fails_) { 165 if (create_source_that_fails_) {
180 class FailedAtLifeAudioSource : public MediaStreamAudioSource { 166 class FailedAtLifeAudioSource : public MediaStreamAudioSource {
(...skipping 23 matching lines...) Expand all
204 } 190 }
205 191
206 const blink::WebMediaStream& last_generated_stream() { 192 const blink::WebMediaStream& last_generated_stream() {
207 return last_generated_stream_; 193 return last_generated_stream_;
208 } 194 }
209 195
210 const blink::WebVector<blink::WebMediaDeviceInfo>& last_devices() { 196 const blink::WebVector<blink::WebMediaDeviceInfo>& last_devices() {
211 return last_devices_; 197 return last_devices_;
212 } 198 }
213 199
214 const blink::WebVector<blink::WebSourceInfo>& last_sources() {
215 return last_sources_;
216 }
217
218 void ClearLastGeneratedStream() { 200 void ClearLastGeneratedStream() {
219 last_generated_stream_.reset(); 201 last_generated_stream_.reset();
220 } 202 }
221 203
222 MockMediaStreamVideoCapturerSource* last_created_video_source() const { 204 MockMediaStreamVideoCapturerSource* last_created_video_source() const {
223 return video_source_; 205 return video_source_;
224 } 206 }
225 207
226 RequestState request_state() const { return state_; } 208 RequestState request_state() const { return state_; }
227 content::MediaStreamRequestResult error_reason() const { return result_; } 209 content::MediaStreamRequestResult error_reason() const { return result_; }
(...skipping 10 matching lines...) Expand all
238 auto* request = FindUserMediaRequestInfo(request_id); 220 auto* request = FindUserMediaRequestInfo(request_id);
239 DeleteUserMediaRequestInfo(request); 221 DeleteUserMediaRequestInfo(request);
240 } 222 }
241 223
242 private: 224 private:
243 blink::WebMediaStream last_generated_stream_; 225 blink::WebMediaStream last_generated_stream_;
244 RequestState state_; 226 RequestState state_;
245 content::MediaStreamRequestResult result_; 227 content::MediaStreamRequestResult result_;
246 blink::WebString result_name_; 228 blink::WebString result_name_;
247 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; 229 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_;
248 blink::WebVector<blink::WebSourceInfo> last_sources_;
249 PeerConnectionDependencyFactory* factory_; 230 PeerConnectionDependencyFactory* factory_;
250 bool create_source_that_fails_; 231 bool create_source_that_fails_;
251 MockMediaStreamVideoCapturerSource* video_source_; 232 MockMediaStreamVideoCapturerSource* video_source_;
252 }; 233 };
253 234
254 class UserMediaClientImplTest : public ::testing::Test { 235 class UserMediaClientImplTest : public ::testing::Test {
255 public: 236 public:
256 void SetUp() override { 237 void SetUp() override {
257 // Create our test object. 238 // Create our test object.
258 child_process_.reset(new ChildProcess()); 239 child_process_.reset(new ChildProcess());
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 EXPECT_FALSE(device->label().isEmpty()); 604 EXPECT_FALSE(device->label().isEmpty());
624 EXPECT_FALSE(device->groupId().isEmpty()); 605 EXPECT_FALSE(device->groupId().isEmpty());
625 606
626 // Verfify group IDs. 607 // Verfify group IDs.
627 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals( 608 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals(
628 used_media_impl_->last_devices()[4].groupId())); 609 used_media_impl_->last_devices()[4].groupId()));
629 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals( 610 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals(
630 used_media_impl_->last_devices()[4].groupId())); 611 used_media_impl_->last_devices()[4].groupId()));
631 } 612 }
632 613
633 TEST_F(UserMediaClientImplTest, EnumerateSources) {
634 used_media_impl_->RequestSources();
635 base::RunLoop().RunUntilIdle();
636
637 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED,
638 used_media_impl_->request_state());
639 EXPECT_EQ(static_cast<size_t>(4), used_media_impl_->last_sources().size());
640
641 // Audio input devices.
642 const blink::WebSourceInfo* source = &used_media_impl_->last_sources()[0];
643 EXPECT_FALSE(source->id().isEmpty());
644 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio, source->kind());
645 EXPECT_FALSE(source->label().isEmpty());
646 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
647
648 source = &used_media_impl_->last_sources()[1];
649 EXPECT_FALSE(source->id().isEmpty());
650 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio, source->kind());
651 EXPECT_FALSE(source->label().isEmpty());
652 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
653
654 // Video input device user facing.
655 source = &used_media_impl_->last_sources()[2];
656 EXPECT_FALSE(source->id().isEmpty());
657 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind());
658 EXPECT_FALSE(source->label().isEmpty());
659 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
660
661 // Video input device environment facing.
662 source = &used_media_impl_->last_sources()[3];
663 EXPECT_FALSE(source->id().isEmpty());
664 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind());
665 EXPECT_FALSE(source->label().isEmpty());
666 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
667 }
668
669 TEST_F(UserMediaClientImplTest, RenderToAssociatedSinkConstraint) { 614 TEST_F(UserMediaClientImplTest, RenderToAssociatedSinkConstraint) {
670 // For a null UserMediaRequest (no audio requested), we expect false. 615 // For a null UserMediaRequest (no audio requested), we expect false.
671 used_media_impl_->RequestUserMedia(); 616 used_media_impl_->RequestUserMedia();
672 EXPECT_FALSE(used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection( 617 EXPECT_FALSE(used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection(
673 ms_dispatcher_->audio_input_request_id())); 618 ms_dispatcher_->audio_input_request_id()));
674 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id()); 619 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id());
675 620
676 // If audio is requested, but no constraint, it should be true. 621 // If audio is requested, but no constraint, it should be true.
677 // Currently we expect it to be false due to a suspected bug in the 622 // Currently we expect it to be false due to a suspected bug in the
678 // device-matching code causing issues with some sound adapters. 623 // device-matching code causing issues with some sound adapters.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 // Now we load a new document in the web frame. If in the above Stop() call, 676 // Now we load a new document in the web frame. If in the above Stop() call,
732 // UserMediaClientImpl accidentally removed audio track, then video track will 677 // UserMediaClientImpl accidentally removed audio track, then video track will
733 // be removed again here, which is incorrect. 678 // be removed again here, which is incorrect.
734 LoadNewDocumentInFrame(); 679 LoadNewDocumentInFrame();
735 blink::WebHeap::collectAllGarbageForTesting(); 680 blink::WebHeap::collectAllGarbageForTesting();
736 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 681 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
737 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 682 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
738 } 683 }
739 684
740 } // namespace content 685 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/user_media_client_impl.cc ('k') | content/test/data/media/getusermedia.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698