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

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

Issue 391703002: Implement ConstraintNotSatisfiedError for getusermedia (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and change the reviewers list Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 18 matching lines...) Expand all
29 closure.Run(); 29 closure.Run();
30 } 30 }
31 31
32 class MediaStreamVideoSourceTest 32 class MediaStreamVideoSourceTest
33 : public ::testing::Test { 33 : public ::testing::Test {
34 public: 34 public:
35 MediaStreamVideoSourceTest() 35 MediaStreamVideoSourceTest()
36 : child_process_(new ChildProcess()), 36 : child_process_(new ChildProcess()),
37 number_of_successful_constraints_applied_(0), 37 number_of_successful_constraints_applied_(0),
38 number_of_failed_constraints_applied_(0), 38 number_of_failed_constraints_applied_(0),
39 result_(MEDIA_DEVICE_OK),
40 result_name_(""),
39 mock_source_(new MockMediaStreamVideoSource(true)) { 41 mock_source_(new MockMediaStreamVideoSource(true)) {
40 media::VideoCaptureFormats formats; 42 media::VideoCaptureFormats formats;
41 formats.push_back(media::VideoCaptureFormat( 43 formats.push_back(media::VideoCaptureFormat(
42 gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420)); 44 gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420));
43 formats.push_back(media::VideoCaptureFormat( 45 formats.push_back(media::VideoCaptureFormat(
44 gfx::Size(640, 480), 30, media::PIXEL_FORMAT_I420)); 46 gfx::Size(640, 480), 30, media::PIXEL_FORMAT_I420));
45 formats.push_back(media::VideoCaptureFormat( 47 formats.push_back(media::VideoCaptureFormat(
46 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420)); 48 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420));
47 formats.push_back(media::VideoCaptureFormat( 49 formats.push_back(media::VideoCaptureFormat(
48 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420)); 50 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 91 }
90 92
91 int NumberOfSuccessConstraintsCallbacks() const { 93 int NumberOfSuccessConstraintsCallbacks() const {
92 return number_of_successful_constraints_applied_; 94 return number_of_successful_constraints_applied_;
93 } 95 }
94 96
95 int NumberOfFailedConstraintsCallbacks() const { 97 int NumberOfFailedConstraintsCallbacks() const {
96 return number_of_failed_constraints_applied_; 98 return number_of_failed_constraints_applied_;
97 } 99 }
98 100
101 content::MediaStreamRequestResult error_type() const { return result_; }
102 blink::WebString error_name() const { return result_name_; }
103
99 MockMediaStreamVideoSource* mock_source() { return mock_source_; } 104 MockMediaStreamVideoSource* mock_source() { return mock_source_; }
100 105
101 // Test that the source crops/scales to the requested width and 106 // Test that the source crops/scales to the requested width and
102 // height even though the camera delivers a larger frame. 107 // height even though the camera delivers a larger frame.
103 void TestSourceCropFrame(int capture_width, 108 void TestSourceCropFrame(int capture_width,
104 int capture_height, 109 int capture_height,
105 const blink::WebMediaConstraints& constraints, 110 const blink::WebMediaConstraints& constraints,
106 int expected_width, 111 int expected_width,
107 int expected_height) { 112 int expected_height) {
108 // Expect the source to start capture with the supported resolution. 113 // Expect the source to start capture with the supported resolution.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 MediaStreamVideoSink::RemoveFromVideoTrack(&sink1, track1); 197 MediaStreamVideoSink::RemoveFromVideoTrack(&sink1, track1);
193 MediaStreamVideoSink::RemoveFromVideoTrack(&sink2, track2); 198 MediaStreamVideoSink::RemoveFromVideoTrack(&sink2, track2);
194 } 199 }
195 200
196 void ReleaseTrackAndSourceOnAddTrackCallback( 201 void ReleaseTrackAndSourceOnAddTrackCallback(
197 const blink::WebMediaStreamTrack& track_to_release) { 202 const blink::WebMediaStreamTrack& track_to_release) {
198 track_to_release_ = track_to_release; 203 track_to_release_ = track_to_release;
199 } 204 }
200 205
201 private: 206 private:
202 void OnConstraintsApplied(MediaStreamSource* source, bool success) { 207 void OnConstraintsApplied(MediaStreamSource* source,
208 MediaStreamRequestResult result,
209 const blink::WebString& result_name) {
203 ASSERT_EQ(source, webkit_source_.extraData()); 210 ASSERT_EQ(source, webkit_source_.extraData());
204 211
205 if (success) 212 if (result == MEDIA_DEVICE_OK) {
206 ++number_of_successful_constraints_applied_; 213 ++number_of_successful_constraints_applied_;
207 else 214 } else {
215 result_ = result;
216 result_name_ = result_name;
208 ++number_of_failed_constraints_applied_; 217 ++number_of_failed_constraints_applied_;
218 }
209 219
210 if (!track_to_release_.isNull()) { 220 if (!track_to_release_.isNull()) {
211 mock_source_ = NULL; 221 mock_source_ = NULL;
212 webkit_source_.reset(); 222 webkit_source_.reset();
213 track_to_release_.reset(); 223 track_to_release_.reset();
214 } 224 }
215 } 225 }
216 base::MessageLoopForUI message_loop_; 226 base::MessageLoopForUI message_loop_;
217 scoped_ptr<ChildProcess> child_process_; 227 scoped_ptr<ChildProcess> child_process_;
218 blink::WebMediaStreamTrack track_to_release_; 228 blink::WebMediaStreamTrack track_to_release_;
219 int number_of_successful_constraints_applied_; 229 int number_of_successful_constraints_applied_;
220 int number_of_failed_constraints_applied_; 230 int number_of_failed_constraints_applied_;
231 content::MediaStreamRequestResult result_;
232 blink::WebString result_name_;
221 blink::WebMediaStreamSource webkit_source_; 233 blink::WebMediaStreamSource webkit_source_;
222 // |mock_source_| is owned by |webkit_source_|. 234 // |mock_source_| is owned by |webkit_source_|.
223 MockMediaStreamVideoSource* mock_source_; 235 MockMediaStreamVideoSource* mock_source_;
224 }; 236 };
225 237
226 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) { 238 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) {
227 blink::WebMediaConstraints constraints; 239 blink::WebMediaConstraints constraints;
228 constraints.initialize(); 240 constraints.initialize();
229 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); 241 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
230 mock_source()->CompleteGetSupportedFormats(); 242 mock_source()->CompleteGetSupportedFormats();
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 MediaStreamVideoSource::kDefaultHeight, 445 MediaStreamVideoSource::kDefaultHeight,
434 30); 446 30);
435 } 447 }
436 448
437 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) { 449 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) {
438 MockMediaConstraintFactory factory; 450 MockMediaConstraintFactory factory;
439 factory.AddMandatory("weird key", 640); 451 factory.AddMandatory("weird key", 640);
440 blink::WebMediaStreamTrack track = CreateTrack( 452 blink::WebMediaStreamTrack track = CreateTrack(
441 "123", factory.CreateWebMediaConstraints()); 453 "123", factory.CreateWebMediaConstraints());
442 mock_source()->CompleteGetSupportedFormats(); 454 mock_source()->CompleteGetSupportedFormats();
455 EXPECT_EQ(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, error_type());
456 EXPECT_EQ("weird key", error_name());
443 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 457 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
444 } 458 }
445 459
446 // Test that the source ignores an unknown optional constraint. 460 // Test that the source ignores an unknown optional constraint.
447 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) { 461 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) {
448 MockMediaConstraintFactory factory; 462 MockMediaConstraintFactory factory;
449 factory.AddOptional("weird key", 640); 463 factory.AddOptional("weird key", 640);
450 464
451 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 465 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(),
452 MediaStreamVideoSource::kDefaultWidth, 466 MediaStreamVideoSource::kDefaultWidth,
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // TODO(mcasas): When added, check |track|'s (WebMediaStreamTrack) Muted 815 // TODO(mcasas): When added, check |track|'s (WebMediaStreamTrack) Muted
802 // attribute, should be true. In the meantime, check the MediaStreamTrack's. 816 // attribute, should be true. In the meantime, check the MediaStreamTrack's.
803 EXPECT_EQ(MediaStreamTrack::GetTrack(track1)->GetMutedState(), true); 817 EXPECT_EQ(MediaStreamTrack::GetTrack(track1)->GetMutedState(), true);
804 EXPECT_EQ(MediaStreamTrack::GetTrack(track2)->GetMutedState(), true); 818 EXPECT_EQ(MediaStreamTrack::GetTrack(track2)->GetMutedState(), true);
805 819
806 MediaStreamVideoSink::RemoveFromVideoTrack(&sink1, track1); 820 MediaStreamVideoSink::RemoveFromVideoTrack(&sink1, track1);
807 MediaStreamVideoSink::RemoveFromVideoTrack(&sink2, track2); 821 MediaStreamVideoSink::RemoveFromVideoTrack(&sink2, track2);
808 } 822 }
809 823
810 } // namespace content 824 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_video_source.cc ('k') | content/renderer/media/mock_media_stream_video_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698