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

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

Issue 2805903002: Fix races in MediaStream video constraints tests. (Closed)
Patch Set: Created 3 years, 8 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 24 matching lines...) Expand all
35 } 35 }
36 36
37 class MediaStreamVideoSourceTest : public ::testing::Test { 37 class MediaStreamVideoSourceTest : public ::testing::Test {
38 public: 38 public:
39 MediaStreamVideoSourceTest() 39 MediaStreamVideoSourceTest()
40 : child_process_(new ChildProcess()), 40 : child_process_(new ChildProcess()),
41 number_of_successful_constraints_applied_(0), 41 number_of_successful_constraints_applied_(0),
42 number_of_failed_constraints_applied_(0), 42 number_of_failed_constraints_applied_(0),
43 result_(MEDIA_DEVICE_OK), 43 result_(MEDIA_DEVICE_OK),
44 result_name_(""), 44 result_name_(""),
45 mock_source_(new MockMediaStreamVideoSource(true)), 45 mock_source_(new MockMediaStreamVideoSource(
46 mock_source2_(new MockMediaStreamVideoSource(
47 media::VideoCaptureFormat(gfx::Size(1280, 720), 46 media::VideoCaptureFormat(gfx::Size(1280, 720),
48 1000.0, 47 1000.0,
49 media::PIXEL_FORMAT_I420), 48 media::PIXEL_FORMAT_I420),
50 false)) { 49 false)) {
50 scoped_feature_list_.InitAndDisableFeature(
51 features::kMediaStreamOldVideoConstraints);
52
53 media::VideoCaptureFormats formats;
54 formats.push_back(media::VideoCaptureFormat(gfx::Size(1280, 720), 30,
55 media::PIXEL_FORMAT_I420));
56 formats.push_back(media::VideoCaptureFormat(gfx::Size(640, 480), 30,
57 media::PIXEL_FORMAT_I420));
58 formats.push_back(media::VideoCaptureFormat(gfx::Size(352, 288), 30,
59 media::PIXEL_FORMAT_I420));
60 formats.push_back(media::VideoCaptureFormat(gfx::Size(320, 240), 30,
61 media::PIXEL_FORMAT_I420));
62 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"),
63 blink::WebMediaStreamSource::TypeVideo,
64 blink::WebString::fromASCII("dummy_source_name"),
65 false /* remote */);
66 webkit_source_.setExtraData(mock_source_);
67 }
68
69 void TearDown() override {
70 webkit_source_.reset();
71 blink::WebHeap::collectAllGarbageForTesting();
72 }
73
74 protected:
75 // Create a track that's associated with |webkit_source_|.
76 blink::WebMediaStreamTrack CreateTrack(const std::string& id) {
77 bool enabled = true;
78 return MediaStreamVideoTrack::CreateVideoTrack(
79 mock_source_,
80 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied,
81 base::Unretained(this)),
82 enabled);
83 }
84
85 blink::WebMediaStreamTrack CreateTrack(
86 const std::string& id,
87 const VideoTrackAdapterSettings& adapter_settings,
88 const base::Optional<bool>& noise_reduction,
89 bool is_screencast,
90 double min_frame_rate) {
91 bool enabled = true;
92 return MediaStreamVideoTrack::CreateVideoTrack(
93 mock_source_, adapter_settings, noise_reduction, is_screencast,
94 min_frame_rate,
95 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied,
96 base::Unretained(this)),
97 enabled);
98 }
99
100 blink::WebMediaStreamTrack CreateTrackAndStartSource(int width,
101 int height,
102 double frame_rate) {
103 DCHECK(!IsOldVideoConstraints());
104 blink::WebMediaStreamTrack track = CreateTrack(
105 "123",
106 VideoTrackAdapterSettings(width, height, 0.0, HUGE_VAL, frame_rate),
107 base::Optional<bool>(), false, 0.0);
108
109 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks());
110 mock_source_->StartMockedSource();
111 // Once the source has started successfully we expect that the
112 // ConstraintsCallback in MediaStreamSource::AddTrack completes.
113 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
114 return track;
115 }
116
117 int NumberOfSuccessConstraintsCallbacks() const {
118 return number_of_successful_constraints_applied_;
119 }
120
121 int NumberOfFailedConstraintsCallbacks() const {
122 return number_of_failed_constraints_applied_;
123 }
124
125 content::MediaStreamRequestResult error_type() const { return result_; }
126 blink::WebString error_name() const { return result_name_; }
127
128 MockMediaStreamVideoSource* mock_source() { return mock_source_; }
129
130 const blink::WebMediaStreamSource& webkit_source() { return webkit_source_; }
131
132 void TestSourceCropFrame(int capture_width,
133 int capture_height,
134 int expected_width,
135 int expected_height) {
136 DCHECK(!IsOldVideoConstraints());
137 // Configure the track to crop to the expected resolution.
138 blink::WebMediaStreamTrack track =
139 CreateTrackAndStartSource(expected_width, expected_height, 30.0);
140
141 // Produce frames at the capture resolution.
142 MockMediaStreamVideoSink sink;
143 sink.ConnectToTrack(track);
144 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink);
145 EXPECT_EQ(1, sink.number_of_frames());
146
147 // Expect the delivered frame to be cropped.
148 EXPECT_EQ(expected_height, sink.frame_size().height());
149 EXPECT_EQ(expected_width, sink.frame_size().width());
150 sink.DisconnectFromTrack();
151 }
152
153 void DeliverVideoFrameAndWaitForRenderer(int width,
154 int height,
155 MockMediaStreamVideoSink* sink) {
156 base::RunLoop run_loop;
157 base::Closure quit_closure = run_loop.QuitClosure();
158 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce(RunClosure(quit_closure));
159 scoped_refptr<media::VideoFrame> frame =
160 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height));
161 mock_source()->DeliverVideoFrame(frame);
162 run_loop.Run();
163 }
164
165 void DeliverVideoFrameAndWaitForTwoRenderers(
166 int width,
167 int height,
168 MockMediaStreamVideoSink* sink1,
169 MockMediaStreamVideoSink* sink2) {
170 base::RunLoop run_loop;
171 base::Closure quit_closure = run_loop.QuitClosure();
172 EXPECT_CALL(*sink1, OnVideoFrame());
173 EXPECT_CALL(*sink2, OnVideoFrame()).WillOnce(RunClosure(quit_closure));
174 scoped_refptr<media::VideoFrame> frame =
175 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height));
176 mock_source()->DeliverVideoFrame(frame);
177 run_loop.Run();
178 }
179
180 void TestTwoTracksWithDifferentSettings(int capture_width,
181 int capture_height,
182 int expected_width1,
183 int expected_height1,
184 int expected_width2,
185 int expected_height2) {
186 blink::WebMediaStreamTrack track1 =
187 CreateTrackAndStartSource(expected_width1, expected_height1,
188 MediaStreamVideoSource::kDefaultFrameRate);
189
190 blink::WebMediaStreamTrack track2 =
191 CreateTrack("dummy",
192 VideoTrackAdapterSettings(
193 expected_width2, expected_height2, 0.0, HUGE_VAL,
194 MediaStreamVideoSource::kDefaultFrameRate),
195 base::Optional<bool>(), false, 0.0);
196
197 MockMediaStreamVideoSink sink1;
198 sink1.ConnectToTrack(track1);
199 EXPECT_EQ(0, sink1.number_of_frames());
200
201 MockMediaStreamVideoSink sink2;
202 sink2.ConnectToTrack(track2);
203 EXPECT_EQ(0, sink2.number_of_frames());
204
205 DeliverVideoFrameAndWaitForTwoRenderers(capture_width, capture_height,
206 &sink1, &sink2);
207
208 EXPECT_EQ(1, sink1.number_of_frames());
209 EXPECT_EQ(expected_width1, sink1.frame_size().width());
210 EXPECT_EQ(expected_height1, sink1.frame_size().height());
211
212 EXPECT_EQ(1, sink2.number_of_frames());
213 EXPECT_EQ(expected_width2, sink2.frame_size().width());
214 EXPECT_EQ(expected_height2, sink2.frame_size().height());
215
216 sink1.DisconnectFromTrack();
217 sink2.DisconnectFromTrack();
218 }
219
220 void ReleaseTrackAndSourceOnAddTrackCallback(
221 const blink::WebMediaStreamTrack& track_to_release) {
222 track_to_release_ = track_to_release;
223 }
224
225 private:
226 void OnConstraintsApplied(MediaStreamSource* source,
227 MediaStreamRequestResult result,
228 const blink::WebString& result_name) {
229 ASSERT_EQ(source, webkit_source().getExtraData());
230
231 if (result == MEDIA_DEVICE_OK) {
232 ++number_of_successful_constraints_applied_;
233 } else {
234 result_ = result;
235 result_name_ = result_name;
236 ++number_of_failed_constraints_applied_;
237 }
238
239 if (!track_to_release_.isNull()) {
240 mock_source_ = nullptr;
241 webkit_source_.reset();
242 track_to_release_.reset();
243 }
244 }
245 const base::MessageLoopForUI message_loop_;
246 const std::unique_ptr<ChildProcess> child_process_;
247 blink::WebMediaStreamTrack track_to_release_;
248 int number_of_successful_constraints_applied_;
249 int number_of_failed_constraints_applied_;
250 content::MediaStreamRequestResult result_;
251 blink::WebString result_name_;
252 blink::WebMediaStreamSource webkit_source_;
253 // |mock_source_| is owned by |webkit_source_|.
254 MockMediaStreamVideoSource* mock_source_;
255 base::test::ScopedFeatureList scoped_feature_list_;
256 };
257
258 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) {
259 blink::WebMediaStreamTrack track = CreateTrack("123");
260 mock_source()->StartMockedSource();
261 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
262 }
263
264 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeSourceStarts) {
265 blink::WebMediaStreamTrack track1 = CreateTrack("123");
266 blink::WebMediaStreamTrack track2 = CreateTrack("123");
267 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks());
268 mock_source()->StartMockedSource();
269 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
270 }
271
272 TEST_F(MediaStreamVideoSourceTest, AddTrackAfterSourceStarts) {
273 blink::WebMediaStreamTrack track1 = CreateTrack("123");
274 mock_source()->StartMockedSource();
275 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
276 blink::WebMediaStreamTrack track2 = CreateTrack("123");
277 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
278 }
279
280 TEST_F(MediaStreamVideoSourceTest, AddTrackAndFailToStartSource) {
281 blink::WebMediaStreamTrack track = CreateTrack("123");
282 mock_source()->FailToStartMockedSource();
283 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
284 }
285
286 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) {
287 TestSourceCropFrame(1280, 720, 960, 720);
288 }
289
290 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnSuccessCallBack) {
291 blink::WebMediaStreamTrack track = CreateTrack("123");
292 ReleaseTrackAndSourceOnAddTrackCallback(track);
293 mock_source()->StartMockedSource();
294 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
295 }
296
297 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGA) {
298 TestTwoTracksWithDifferentSettings(640, 480, 640, 480, 640, 360);
299 }
300
301 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGA) {
302 TestTwoTracksWithDifferentSettings(1280, 720, 1280, 720, 640, 360);
303 }
304
305 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) {
306 MockConstraintFactory factory;
307 factory.AddAdvanced().width.setMax(800);
308 factory.AddAdvanced().height.setMax(700);
309
310 // Expect the source to start capture with the supported resolution.
311 // Disable frame-rate adjustment in spec-compliant mode to ensure no frames
312 // are dropped.
313 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(800, 700, 0.0);
314
315 MockMediaStreamVideoSink sink;
316 sink.ConnectToTrack(track);
317 EXPECT_EQ(0, sink.number_of_frames());
318 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink);
319 EXPECT_EQ(1, sink.number_of_frames());
320 // Expect the delivered frame to be passed unchanged since its smaller than
321 // max requested.
322 EXPECT_EQ(320, sink.frame_size().width());
323 EXPECT_EQ(240, sink.frame_size().height());
324
325 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink);
326 EXPECT_EQ(2, sink.number_of_frames());
327 // Expect the delivered frame to be passed unchanged since its smaller than
328 // max requested.
329 EXPECT_EQ(640, sink.frame_size().width());
330 EXPECT_EQ(480, sink.frame_size().height());
331
332 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink);
333 EXPECT_EQ(3, sink.number_of_frames());
334 // Expect a frame to be cropped since its larger than max requested.
335 EXPECT_EQ(800, sink.frame_size().width());
336 EXPECT_EQ(700, sink.frame_size().height());
337
338 sink.DisconnectFromTrack();
339 }
340
341 // Test that a source producing no frames change the source ReadyState to muted.
342 // that in a reasonable time frame the muted state turns to false.
343 TEST_F(MediaStreamVideoSourceTest, MutedSource) {
344 // Setup the source for support a frame rate of 999 fps in order to test
345 // the muted event faster. This is since the frame monitoring uses
346 // PostDelayedTask that is dependent on the source frame rate.
347 // Note that media::limits::kMaxFramesPerSecond is 1000.
348 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
349 640, 480, media::limits::kMaxFramesPerSecond - 2);
350 MockMediaStreamVideoSink sink;
351 sink.ConnectToTrack(track);
352 EXPECT_EQ(track.source().getReadyState(),
353 blink::WebMediaStreamSource::ReadyStateLive);
354
355 base::RunLoop run_loop;
356 base::Closure quit_closure = run_loop.QuitClosure();
357 bool muted_state = false;
358 EXPECT_CALL(*mock_source(), DoSetMutedState(_))
359 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure)));
360 run_loop.Run();
361 EXPECT_EQ(muted_state, true);
362
363 EXPECT_EQ(track.source().getReadyState(),
364 blink::WebMediaStreamSource::ReadyStateMuted);
365
366 base::RunLoop run_loop2;
367 base::Closure quit_closure2 = run_loop2.QuitClosure();
368 EXPECT_CALL(*mock_source(), DoSetMutedState(_))
369 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure2)));
370 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink);
371 run_loop2.Run();
372
373 EXPECT_EQ(muted_state, false);
374 EXPECT_EQ(track.source().getReadyState(),
375 blink::WebMediaStreamSource::ReadyStateLive);
376
377 sink.DisconnectFromTrack();
378 }
379
380 class MediaStreamVideoSourceOldConstraintsTest : public ::testing::Test {
381 public:
382 MediaStreamVideoSourceOldConstraintsTest()
383 : child_process_(new ChildProcess()),
384 number_of_successful_constraints_applied_(0),
385 number_of_failed_constraints_applied_(0),
386 result_(MEDIA_DEVICE_OK),
387 result_name_(""),
388 mock_source_(new MockMediaStreamVideoSource(true)) {
389 scoped_feature_list_.InitAndEnableFeature(
390 features::kMediaStreamOldVideoConstraints);
391
51 media::VideoCaptureFormats formats; 392 media::VideoCaptureFormats formats;
52 formats.push_back(media::VideoCaptureFormat( 393 formats.push_back(media::VideoCaptureFormat(
53 gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420)); 394 gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420));
54 formats.push_back(media::VideoCaptureFormat( 395 formats.push_back(media::VideoCaptureFormat(
55 gfx::Size(640, 480), 30, media::PIXEL_FORMAT_I420)); 396 gfx::Size(640, 480), 30, media::PIXEL_FORMAT_I420));
56 formats.push_back(media::VideoCaptureFormat( 397 formats.push_back(media::VideoCaptureFormat(
57 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420)); 398 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420));
58 formats.push_back(media::VideoCaptureFormat( 399 formats.push_back(media::VideoCaptureFormat(
59 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420)); 400 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420));
60 mock_source_->SetSupportedFormats(formats); 401 mock_source_->SetSupportedFormats(formats);
61 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), 402 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"),
62 blink::WebMediaStreamSource::TypeVideo, 403 blink::WebMediaStreamSource::TypeVideo,
63 blink::WebString::fromASCII("dummy_source_name"), 404 blink::WebString::fromASCII("dummy_source_name"),
64 false /* remote */); 405 false /* remote */);
65 webkit_source_.setExtraData(mock_source_); 406 webkit_source_.setExtraData(mock_source_);
66 webkit_source2_.initialize(blink::WebString::fromASCII("dummy_source_id"),
67 blink::WebMediaStreamSource::TypeVideo,
68 blink::WebString::fromASCII("dummy_source_name"),
69 false /* remote */);
70 webkit_source2_.setExtraData(mock_source2_);
71 } 407 }
72 408
73 void TearDown() override { 409 void TearDown() override {
74 webkit_source_.reset(); 410 webkit_source_.reset();
75 webkit_source2_.reset();
76 blink::WebHeap::collectAllGarbageForTesting(); 411 blink::WebHeap::collectAllGarbageForTesting();
77 } 412 }
78 413
79 protected: 414 protected:
80 // Create a track that's associated with |webkit_source_|. 415 // Create a track that's associated with |webkit_source_|.
81 blink::WebMediaStreamTrack CreateTrack( 416 blink::WebMediaStreamTrack CreateTrack(
82 const std::string& id, 417 const std::string& id,
83 const blink::WebMediaConstraints& constraints) { 418 const blink::WebMediaConstraints& constraints) {
84 bool enabled = true; 419 bool enabled = true;
85 return MediaStreamVideoTrack::CreateVideoTrack( 420 return MediaStreamVideoTrack::CreateVideoTrack(
86 mock_source_, constraints, 421 mock_source_, constraints,
87 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied, 422 base::Bind(
88 base::Unretained(this)), 423 &MediaStreamVideoSourceOldConstraintsTest::OnConstraintsApplied,
424 base::Unretained(this)),
89 enabled); 425 enabled);
90 } 426 }
91 427
92 blink::WebMediaStreamTrack CreateTrack(const std::string& id) {
93 bool enabled = true;
94 return MediaStreamVideoTrack::CreateVideoTrack(
95 mock_source2_,
96 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied,
97 base::Unretained(this)),
98 enabled);
99 }
100
101 blink::WebMediaStreamTrack CreateTrack(
102 const std::string& id,
103 const VideoTrackAdapterSettings& adapter_settings,
104 const base::Optional<bool>& noise_reduction,
105 bool is_screencast,
106 double min_frame_rate) {
107 bool enabled = true;
108 return MediaStreamVideoTrack::CreateVideoTrack(
109 mock_source2_, adapter_settings, noise_reduction, is_screencast,
110 min_frame_rate,
111 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied,
112 base::Unretained(this)),
113 enabled);
114 }
115
116 blink::WebMediaStreamTrack CreateTrackAndStartSource( 428 blink::WebMediaStreamTrack CreateTrackAndStartSource(
117 const blink::WebMediaConstraints& constraints, 429 const blink::WebMediaConstraints& constraints,
118 int expected_width, 430 int expected_width,
119 int expected_height, 431 int expected_height,
120 int expected_frame_rate) { 432 int expected_frame_rate) {
121 DCHECK(IsOldVideoConstraints()); 433 DCHECK(IsOldVideoConstraints());
122 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); 434 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
123 435
124 mock_source_->CompleteGetSupportedFormats(); 436 mock_source_->CompleteGetSupportedFormats();
125 const media::VideoCaptureFormat& format = mock_source()->start_format(); 437 const media::VideoCaptureFormat& format = mock_source()->start_format();
126 EXPECT_EQ(expected_width, format.frame_size.width()); 438 EXPECT_EQ(expected_width, format.frame_size.width());
127 EXPECT_EQ(expected_height, format.frame_size.height()); 439 EXPECT_EQ(expected_height, format.frame_size.height());
128 EXPECT_EQ(expected_frame_rate, format.frame_rate); 440 EXPECT_EQ(expected_frame_rate, format.frame_rate);
129 441
130 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); 442 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks());
131 mock_source_->StartMockedSource(); 443 mock_source_->StartMockedSource();
132 // Once the source has started successfully we expect that the 444 // Once the source has started successfully we expect that the
133 // ConstraintsCallback in MediaStreamSource::AddTrack completes. 445 // ConstraintsCallback in MediaStreamSource::AddTrack completes.
134 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 446 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
135 return track; 447 return track;
136 } 448 }
137 449
138 blink::WebMediaStreamTrack CreateTrackAndStartSource(int width,
139 int height,
140 double frame_rate) {
141 DCHECK(!IsOldVideoConstraints());
142 blink::WebMediaStreamTrack track = CreateTrack(
143 "123",
144 VideoTrackAdapterSettings(width, height, 0.0, HUGE_VAL, frame_rate),
145 base::Optional<bool>(), false, 0.0);
146
147 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks());
148 mock_source2_->StartMockedSource();
149 // Once the source has started successfully we expect that the
150 // ConstraintsCallback in MediaStreamSource::AddTrack completes.
151 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
152 return track;
153 }
154
155 int NumberOfSuccessConstraintsCallbacks() const { 450 int NumberOfSuccessConstraintsCallbacks() const {
156 return number_of_successful_constraints_applied_; 451 return number_of_successful_constraints_applied_;
157 } 452 }
158 453
159 int NumberOfFailedConstraintsCallbacks() const { 454 int NumberOfFailedConstraintsCallbacks() const {
160 return number_of_failed_constraints_applied_; 455 return number_of_failed_constraints_applied_;
161 } 456 }
162 457
163 content::MediaStreamRequestResult error_type() const { return result_; } 458 content::MediaStreamRequestResult error_type() const { return result_; }
164 blink::WebString error_name() const { return result_name_; } 459 blink::WebString error_name() const { return result_name_; }
165 460
166 MockMediaStreamVideoSource* mock_source() { 461 MockMediaStreamVideoSource* mock_source() { return mock_source_; }
167 return IsOldVideoConstraints() ? mock_source_ : mock_source2_;
168 }
169 462
170 const blink::WebMediaStreamSource& webkit_source() { 463 const blink::WebMediaStreamSource& webkit_source() { return webkit_source_; }
171 return IsOldVideoConstraints() ? webkit_source_ : webkit_source2_;
172 }
173 464
174 // Test that the source crops/scales to the requested width and 465 // Test that the source crops/scales to the requested width and
175 // height even though the camera delivers a larger frame. 466 // height even though the camera delivers a larger frame.
176 void TestSourceCropFrame(int capture_width, 467 void TestSourceCropFrame(int capture_width,
177 int capture_height, 468 int capture_height,
178 const blink::WebMediaConstraints& constraints, 469 const blink::WebMediaConstraints& constraints,
179 int expected_width, 470 int expected_width,
180 int expected_height) { 471 int expected_height) {
181 DCHECK(IsOldVideoConstraints()); 472 DCHECK(IsOldVideoConstraints());
182 // Expect the source to start capture with the supported resolution. 473 // Expect the source to start capture with the supported resolution.
183 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( 474 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
184 constraints, capture_width, capture_height, 30); 475 constraints, capture_width, capture_height, 30);
185 476
186 MockMediaStreamVideoSink sink; 477 MockMediaStreamVideoSink sink;
187 sink.ConnectToTrack(track); 478 sink.ConnectToTrack(track);
188 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink); 479 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink);
189 EXPECT_EQ(1, sink.number_of_frames()); 480 EXPECT_EQ(1, sink.number_of_frames());
190 481
191 // Expect the delivered frame to be cropped. 482 // Expect the delivered frame to be cropped.
192 EXPECT_EQ(expected_height, sink.frame_size().height()); 483 EXPECT_EQ(expected_height, sink.frame_size().height());
193 EXPECT_EQ(expected_width, sink.frame_size().width()); 484 EXPECT_EQ(expected_width, sink.frame_size().width());
194 sink.DisconnectFromTrack(); 485 sink.DisconnectFromTrack();
195 } 486 }
196 487
197 void TestSourceCropFrame(int capture_width,
198 int capture_height,
199 int expected_width,
200 int expected_height) {
201 DCHECK(!IsOldVideoConstraints());
202 // Configure the track to crop to the expected resolution.
203 blink::WebMediaStreamTrack track =
204 CreateTrackAndStartSource(expected_width, expected_height, 30.0);
205
206 // Produce frames at the capture resolution.
207 MockMediaStreamVideoSink sink;
208 sink.ConnectToTrack(track);
209 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink);
210 EXPECT_EQ(1, sink.number_of_frames());
211
212 // Expect the delivered frame to be cropped.
213 EXPECT_EQ(expected_height, sink.frame_size().height());
214 EXPECT_EQ(expected_width, sink.frame_size().width());
215 sink.DisconnectFromTrack();
216 }
217
218 void DeliverVideoFrameAndWaitForRenderer(int width, int height, 488 void DeliverVideoFrameAndWaitForRenderer(int width, int height,
219 MockMediaStreamVideoSink* sink) { 489 MockMediaStreamVideoSink* sink) {
220 base::RunLoop run_loop; 490 base::RunLoop run_loop;
221 base::Closure quit_closure = run_loop.QuitClosure(); 491 base::Closure quit_closure = run_loop.QuitClosure();
222 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce( 492 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce(
223 RunClosure(quit_closure)); 493 RunClosure(quit_closure));
224 scoped_refptr<media::VideoFrame> frame = 494 scoped_refptr<media::VideoFrame> frame =
225 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); 495 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height));
226 mock_source()->DeliverVideoFrame(frame); 496 mock_source()->DeliverVideoFrame(frame);
227 run_loop.Run(); 497 run_loop.Run();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 EXPECT_EQ(expected_height1, sink1.frame_size().height()); 546 EXPECT_EQ(expected_height1, sink1.frame_size().height());
277 547
278 EXPECT_EQ(1, sink2.number_of_frames()); 548 EXPECT_EQ(1, sink2.number_of_frames());
279 EXPECT_EQ(expected_width2, sink2.frame_size().width()); 549 EXPECT_EQ(expected_width2, sink2.frame_size().width());
280 EXPECT_EQ(expected_height2, sink2.frame_size().height()); 550 EXPECT_EQ(expected_height2, sink2.frame_size().height());
281 551
282 sink1.DisconnectFromTrack(); 552 sink1.DisconnectFromTrack();
283 sink2.DisconnectFromTrack(); 553 sink2.DisconnectFromTrack();
284 } 554 }
285 555
286 void TestTwoTracksWithDifferentSettings(int capture_width,
287 int capture_height,
288 int expected_width1,
289 int expected_height1,
290 int expected_width2,
291 int expected_height2) {
292 blink::WebMediaStreamTrack track1 =
293 CreateTrackAndStartSource(expected_width1, expected_height1,
294 MediaStreamVideoSource::kDefaultFrameRate);
295
296 blink::WebMediaStreamTrack track2 =
297 CreateTrack("dummy",
298 VideoTrackAdapterSettings(
299 expected_width2, expected_height2, 0.0, HUGE_VAL,
300 MediaStreamVideoSource::kDefaultFrameRate),
301 base::Optional<bool>(), false, 0.0);
302
303 MockMediaStreamVideoSink sink1;
304 sink1.ConnectToTrack(track1);
305 EXPECT_EQ(0, sink1.number_of_frames());
306
307 MockMediaStreamVideoSink sink2;
308 sink2.ConnectToTrack(track2);
309 EXPECT_EQ(0, sink2.number_of_frames());
310
311 DeliverVideoFrameAndWaitForTwoRenderers(capture_width, capture_height,
312 &sink1, &sink2);
313
314 EXPECT_EQ(1, sink1.number_of_frames());
315 EXPECT_EQ(expected_width1, sink1.frame_size().width());
316 EXPECT_EQ(expected_height1, sink1.frame_size().height());
317
318 EXPECT_EQ(1, sink2.number_of_frames());
319 EXPECT_EQ(expected_width2, sink2.frame_size().width());
320 EXPECT_EQ(expected_height2, sink2.frame_size().height());
321
322 sink1.DisconnectFromTrack();
323 sink2.DisconnectFromTrack();
324 }
325 void SetSourceSupportedFormats(const media::VideoCaptureFormats& formats) { 556 void SetSourceSupportedFormats(const media::VideoCaptureFormats& formats) {
326 mock_source_->SetSupportedFormats(formats); 557 mock_source_->SetSupportedFormats(formats);
327 } 558 }
328 559
329 void ReleaseTrackAndSourceOnAddTrackCallback( 560 void ReleaseTrackAndSourceOnAddTrackCallback(
330 const blink::WebMediaStreamTrack& track_to_release) { 561 const blink::WebMediaStreamTrack& track_to_release) {
331 track_to_release_ = track_to_release; 562 track_to_release_ = track_to_release;
332 } 563 }
333 564
334 private: 565 private:
335 void OnConstraintsApplied(MediaStreamSource* source, 566 void OnConstraintsApplied(MediaStreamSource* source,
336 MediaStreamRequestResult result, 567 MediaStreamRequestResult result,
337 const blink::WebString& result_name) { 568 const blink::WebString& result_name) {
338 ASSERT_EQ(source, webkit_source().getExtraData()); 569 ASSERT_EQ(source, webkit_source().getExtraData());
339 570
340 if (result == MEDIA_DEVICE_OK) { 571 if (result == MEDIA_DEVICE_OK) {
341 ++number_of_successful_constraints_applied_; 572 ++number_of_successful_constraints_applied_;
342 } else { 573 } else {
343 result_ = result; 574 result_ = result;
344 result_name_ = result_name; 575 result_name_ = result_name;
345 ++number_of_failed_constraints_applied_; 576 ++number_of_failed_constraints_applied_;
346 } 577 }
347 578
348 if (!track_to_release_.isNull()) { 579 if (!track_to_release_.isNull()) {
349 mock_source_ = nullptr; 580 mock_source_ = nullptr;
350 webkit_source_.reset(); 581 webkit_source_.reset();
351 mock_source2_ = nullptr;
352 webkit_source2_.reset();
353 track_to_release_.reset(); 582 track_to_release_.reset();
354 } 583 }
355 } 584 }
356 const base::MessageLoopForUI message_loop_; 585 const base::MessageLoopForUI message_loop_;
357 const std::unique_ptr<ChildProcess> child_process_; 586 const std::unique_ptr<ChildProcess> child_process_;
358 blink::WebMediaStreamTrack track_to_release_; 587 blink::WebMediaStreamTrack track_to_release_;
359 int number_of_successful_constraints_applied_; 588 int number_of_successful_constraints_applied_;
360 int number_of_failed_constraints_applied_; 589 int number_of_failed_constraints_applied_;
361 content::MediaStreamRequestResult result_; 590 content::MediaStreamRequestResult result_;
362 blink::WebString result_name_; 591 blink::WebString result_name_;
363 blink::WebMediaStreamSource webkit_source_; 592 blink::WebMediaStreamSource webkit_source_;
364 // |mock_source_| is owned by |webkit_source_|. 593 // |mock_source_| is owned by |webkit_source_|.
365 MockMediaStreamVideoSource* mock_source_; 594 MockMediaStreamVideoSource* mock_source_;
366 blink::WebMediaStreamSource webkit_source2_; 595 base::test::ScopedFeatureList scoped_feature_list_;
367 // |mock_source2_| is owned by |webkit_source2_|.
368 MockMediaStreamVideoSource* mock_source2_;
369 }; 596 };
370 597
371 // TODO(guidou): Remove this test. http://crbug.com/706408 598 // TODO(guidou): Remove this test. http://crbug.com/706408
372 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSourceOldConstraints) { 599 TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAndStartSource) {
373 base::test::ScopedFeatureList scoped_feature_list;
374 scoped_feature_list.InitAndEnableFeature(
375 features::kMediaStreamOldVideoConstraints);
376 blink::WebMediaConstraints constraints; 600 blink::WebMediaConstraints constraints;
377 constraints.initialize(); 601 constraints.initialize();
378 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); 602 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
379 mock_source()->CompleteGetSupportedFormats(); 603 mock_source()->CompleteGetSupportedFormats();
380 mock_source()->StartMockedSource(); 604 mock_source()->StartMockedSource();
381 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 605 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
382 } 606 }
383 607
384 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) {
385 base::test::ScopedFeatureList scoped_feature_list;
386 scoped_feature_list.InitAndDisableFeature(
387 features::kMediaStreamOldVideoConstraints);
388 blink::WebMediaStreamTrack track = CreateTrack("123");
389 mock_source()->StartMockedSource();
390 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
391 }
392
393 // TODO(guidou): Remove this test. http://crbug.com/706408 608 // TODO(guidou): Remove this test. http://crbug.com/706408
394 TEST_F(MediaStreamVideoSourceTest, 609 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
395 AddTwoTracksBeforeSourceStartsOldConstraints) { 610 AddTwoTracksBeforeSourceStarts) {
396 base::test::ScopedFeatureList scoped_feature_list;
397 scoped_feature_list.InitAndEnableFeature(
398 features::kMediaStreamOldVideoConstraints);
399 blink::WebMediaConstraints constraints; 611 blink::WebMediaConstraints constraints;
400 constraints.initialize(); 612 constraints.initialize();
401 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); 613 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
402 mock_source()->CompleteGetSupportedFormats(); 614 mock_source()->CompleteGetSupportedFormats();
403 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); 615 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
404 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); 616 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks());
405 mock_source()->StartMockedSource(); 617 mock_source()->StartMockedSource();
406 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 618 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
407 } 619 }
408 620
409 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeSourceStarts) {
410 base::test::ScopedFeatureList scoped_feature_list;
411 scoped_feature_list.InitAndDisableFeature(
412 features::kMediaStreamOldVideoConstraints);
413 blink::WebMediaStreamTrack track1 = CreateTrack("123");
414 blink::WebMediaStreamTrack track2 = CreateTrack("123");
415 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks());
416 mock_source()->StartMockedSource();
417 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
418 }
419
420 // TODO(guidou): Remove this test. http://crbug.com/706408 621 // TODO(guidou): Remove this test. http://crbug.com/706408
421 TEST_F(MediaStreamVideoSourceTest, AddTrackAfterSourceStartsOldConstraints) { 622 TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAfterSourceStarts) {
422 base::test::ScopedFeatureList scoped_feature_list;
423 scoped_feature_list.InitAndEnableFeature(
424 features::kMediaStreamOldVideoConstraints);
425 blink::WebMediaConstraints constraints; 623 blink::WebMediaConstraints constraints;
426 constraints.initialize(); 624 constraints.initialize();
427 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); 625 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
428 mock_source()->CompleteGetSupportedFormats(); 626 mock_source()->CompleteGetSupportedFormats();
429 mock_source()->StartMockedSource(); 627 mock_source()->StartMockedSource();
430 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 628 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
431 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); 629 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
432 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 630 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
433 } 631 }
434 632
435 TEST_F(MediaStreamVideoSourceTest, AddTrackAfterSourceStarts) {
436 base::test::ScopedFeatureList scoped_feature_list;
437 scoped_feature_list.InitAndDisableFeature(
438 features::kMediaStreamOldVideoConstraints);
439 blink::WebMediaStreamTrack track1 = CreateTrack("123");
440 mock_source()->StartMockedSource();
441 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
442 blink::WebMediaStreamTrack track2 = CreateTrack("123");
443 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
444 }
445
446 // TODO(guidou): Remove this test. http://crbug.com/706408 633 // TODO(guidou): Remove this test. http://crbug.com/706408
447 TEST_F(MediaStreamVideoSourceTest, AddTrackAndFailToStartSourceOldConstraints) { 634 TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAndFailToStartSource) {
448 base::test::ScopedFeatureList scoped_feature_list;
449 scoped_feature_list.InitAndEnableFeature(
450 features::kMediaStreamOldVideoConstraints);
451 blink::WebMediaConstraints constraints; 635 blink::WebMediaConstraints constraints;
452 constraints.initialize(); 636 constraints.initialize();
453 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); 637 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
454 mock_source()->CompleteGetSupportedFormats(); 638 mock_source()->CompleteGetSupportedFormats();
455 mock_source()->FailToStartMockedSource(); 639 mock_source()->FailToStartMockedSource();
456 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 640 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
457 } 641 }
458 642
459 TEST_F(MediaStreamVideoSourceTest, AddTrackAndFailToStartSource) {
460 base::test::ScopedFeatureList scoped_feature_list;
461 scoped_feature_list.InitAndDisableFeature(
462 features::kMediaStreamOldVideoConstraints);
463 blink::WebMediaStreamTrack track = CreateTrack("123");
464 mock_source()->FailToStartMockedSource();
465 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
466 }
467
468 // Does not apply with spec-compliant constraints. 643 // Does not apply with spec-compliant constraints.
469 // TODO(guidou): Remove this test. http://crbug.com/706408 644 // TODO(guidou): Remove this test. http://crbug.com/706408
470 TEST_F(MediaStreamVideoSourceTest, 645 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
471 AddTwoTracksBeforeGetSupportedFormatsOldConstraints) { 646 AddTwoTracksBeforeGetSupportedFormats) {
472 base::test::ScopedFeatureList scoped_feature_list;
473 scoped_feature_list.InitAndEnableFeature(
474 features::kMediaStreamOldVideoConstraints);
475 blink::WebMediaConstraints constraints; 647 blink::WebMediaConstraints constraints;
476 constraints.initialize(); 648 constraints.initialize();
477 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); 649 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
478 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); 650 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
479 mock_source()->CompleteGetSupportedFormats(); 651 mock_source()->CompleteGetSupportedFormats();
480 mock_source()->StartMockedSource(); 652 mock_source()->StartMockedSource();
481 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 653 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
482 } 654 }
483 655
484 // Test that the capture output is CIF if we set max constraints to CIF. 656 // Test that the capture output is CIF if we set max constraints to CIF.
485 // and the capture device support CIF. 657 // and the capture device support CIF.
486 // Does not apply with spec-compliant constraints. 658 // Does not apply with spec-compliant constraints.
487 // TODO(guidou): Remove this test. http://crbug.com/706408 659 // TODO(guidou): Remove this test. http://crbug.com/706408
488 TEST_F(MediaStreamVideoSourceTest, MandatoryConstraintCif5FpsOldConstraints) { 660 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryConstraintCif5Fps) {
489 base::test::ScopedFeatureList scoped_feature_list;
490 scoped_feature_list.InitAndEnableFeature(
491 features::kMediaStreamOldVideoConstraints);
492 MockConstraintFactory factory; 661 MockConstraintFactory factory;
493 factory.basic().width.setMax(352); 662 factory.basic().width.setMax(352);
494 factory.basic().height.setMax(288); 663 factory.basic().height.setMax(288);
495 factory.basic().frameRate.setMax(5.0); 664 factory.basic().frameRate.setMax(5.0);
496 665
497 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 352, 288, 5); 666 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 352, 288, 5);
498 } 667 }
499 668
500 // Test that the capture output is 720P if the camera support it and the 669 // Test that the capture output is 720P if the camera support it and the
501 // optional constraint is set to 720P. 670 // optional constraint is set to 720P.
502 // Does not apply with spec-compliant constraints. 671 // Does not apply with spec-compliant constraints.
503 // TODO(guidou): Remove this test. http://crbug.com/706408 672 // TODO(guidou): Remove this test. http://crbug.com/706408
504 TEST_F(MediaStreamVideoSourceTest, MandatoryMinVgaOptional720POldConstraints) { 673 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryMinVgaOptional720P) {
505 base::test::ScopedFeatureList scoped_feature_list;
506 scoped_feature_list.InitAndEnableFeature(
507 features::kMediaStreamOldVideoConstraints);
508 MockConstraintFactory factory; 674 MockConstraintFactory factory;
509 factory.basic().width.setMin(640); 675 factory.basic().width.setMin(640);
510 factory.basic().height.setMin(480); 676 factory.basic().height.setMin(480);
511 factory.AddAdvanced().width.setMin(1280); 677 factory.AddAdvanced().width.setMin(1280);
512 factory.AddAdvanced().aspectRatio.setMin(1280.0 / 720); 678 factory.AddAdvanced().aspectRatio.setMin(1280.0 / 720);
513 679
514 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); 680 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30);
515 } 681 }
516 682
517 // Test that the capture output is 720P if the camera supports it and the 683 // Test that the capture output is 720P if the camera supports it and the
518 // mandatory constraint is exactly width 1280. 684 // mandatory constraint is exactly width 1280.
519 // Does not apply with spec-compliant constraints. 685 // Does not apply with spec-compliant constraints.
520 // TODO(guidou): Remove this test. http://crbug.com/706408 686 // TODO(guidou): Remove this test. http://crbug.com/706408
521 TEST_F(MediaStreamVideoSourceTest, MandatoryExact720POldConstraints) { 687 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryExact720P) {
522 base::test::ScopedFeatureList scoped_feature_list;
523 scoped_feature_list.InitAndEnableFeature(
524 features::kMediaStreamOldVideoConstraints);
525 MockConstraintFactory factory; 688 MockConstraintFactory factory;
526 factory.basic().width.setExact(1280); 689 factory.basic().width.setExact(1280);
527 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); 690 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30);
528 } 691 }
529 692
530 // Test that the capture output have aspect ratio 4:3 if a mandatory constraint 693 // Test that the capture output have aspect ratio 4:3 if a mandatory constraint
531 // require it even if an optional constraint request a higher resolution 694 // require it even if an optional constraint request a higher resolution
532 // that don't have this aspect ratio. 695 // that don't have this aspect ratio.
533 // TODO(guidou): Remove this test. http://crbug.com/706408 696 // TODO(guidou): Remove this test. http://crbug.com/706408
534 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3OldConstraints) { 697 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryAspectRatio4To3) {
535 base::test::ScopedFeatureList scoped_feature_list;
536 scoped_feature_list.InitAndEnableFeature(
537 features::kMediaStreamOldVideoConstraints);
538 MockConstraintFactory factory; 698 MockConstraintFactory factory;
539 factory.basic().width.setMin(640); 699 factory.basic().width.setMin(640);
540 factory.basic().height.setMin(480); 700 factory.basic().height.setMin(480);
541 factory.basic().aspectRatio.setMax(640.0 / 480); 701 factory.basic().aspectRatio.setMax(640.0 / 480);
542 factory.AddAdvanced().width.setMin(1280); 702 factory.AddAdvanced().width.setMin(1280);
543 703
544 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 960, 720); 704 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 960, 720);
545 } 705 }
546 706
547 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) {
548 base::test::ScopedFeatureList scoped_feature_list;
549 scoped_feature_list.InitAndDisableFeature(
550 features::kMediaStreamOldVideoConstraints);
551 TestSourceCropFrame(1280, 720, 960, 720);
552 }
553
554 // Test that AddTrack succeeds if the mandatory min aspect ratio it set to 2. 707 // Test that AddTrack succeeds if the mandatory min aspect ratio it set to 2.
555 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio2OldConstraints) { 708 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryAspectRatio2) {
556 base::test::ScopedFeatureList scoped_feature_list;
557 scoped_feature_list.InitAndEnableFeature(
558 features::kMediaStreamOldVideoConstraints);
559 MockConstraintFactory factory; 709 MockConstraintFactory factory;
560 factory.basic().aspectRatio.setMin(2.0); 710 factory.basic().aspectRatio.setMin(2.0);
561 711
562 TestSourceCropFrame(MediaStreamVideoSource::kDefaultWidth, 712 TestSourceCropFrame(MediaStreamVideoSource::kDefaultWidth,
563 MediaStreamVideoSource::kDefaultHeight, 713 MediaStreamVideoSource::kDefaultHeight,
564 factory.CreateWebMediaConstraints(), 640, 320); 714 factory.CreateWebMediaConstraints(), 640, 320);
565 } 715 }
566 716
567 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio2) {
568 base::test::ScopedFeatureList scoped_feature_list;
569 scoped_feature_list.InitAndDisableFeature(
570 features::kMediaStreamOldVideoConstraints);
571 TestSourceCropFrame(1280, 720, 960, 720);
572 }
573
574 // Does not apply with spec-compliant constraints. 717 // Does not apply with spec-compliant constraints.
575 // TODO(guidou): Remove this test. http://crbug.com/706408 718 // TODO(guidou): Remove this test. http://crbug.com/706408
576 TEST_F(MediaStreamVideoSourceTest, 719 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
577 MinAspectRatioLargerThanMaxAspectRatioOldConstraints) { 720 MinAspectRatioLargerThanMaxAspectRatio) {
578 base::test::ScopedFeatureList scoped_feature_list;
579 scoped_feature_list.InitAndEnableFeature(
580 features::kMediaStreamOldVideoConstraints);
581 MockConstraintFactory factory; 721 MockConstraintFactory factory;
582 factory.basic().aspectRatio.setMin(2.0); 722 factory.basic().aspectRatio.setMin(2.0);
583 factory.basic().aspectRatio.setMax(1.0); 723 factory.basic().aspectRatio.setMax(1.0);
584 blink::WebMediaStreamTrack track = 724 blink::WebMediaStreamTrack track =
585 CreateTrack("123", factory.CreateWebMediaConstraints()); 725 CreateTrack("123", factory.CreateWebMediaConstraints());
586 mock_source()->CompleteGetSupportedFormats(); 726 mock_source()->CompleteGetSupportedFormats();
587 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 727 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
588 } 728 }
589 729
590 // Does not apply with spec-compliant constraints. 730 // Does not apply with spec-compliant constraints.
591 // TODO(guidou): Remove this test. http://crbug.com/706408 731 // TODO(guidou): Remove this test. http://crbug.com/706408
592 TEST_F(MediaStreamVideoSourceTest, MinWidthLargerThanMaxWidthOldConstraints) { 732 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinWidthLargerThanMaxWidth) {
593 base::test::ScopedFeatureList scoped_feature_list;
594 scoped_feature_list.InitAndEnableFeature(
595 features::kMediaStreamOldVideoConstraints);
596 MockConstraintFactory factory; 733 MockConstraintFactory factory;
597 factory.basic().width.setMin(640); 734 factory.basic().width.setMin(640);
598 factory.basic().width.setMax(320); 735 factory.basic().width.setMax(320);
599 blink::WebMediaStreamTrack track = 736 blink::WebMediaStreamTrack track =
600 CreateTrack("123", factory.CreateWebMediaConstraints()); 737 CreateTrack("123", factory.CreateWebMediaConstraints());
601 mock_source()->CompleteGetSupportedFormats(); 738 mock_source()->CompleteGetSupportedFormats();
602 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 739 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
603 } 740 }
604 741
605 // Does not apply with spec-compliant constraints. 742 // Does not apply with spec-compliant constraints.
606 // TODO(guidou): Remove this test. http://crbug.com/706408 743 // TODO(guidou): Remove this test. http://crbug.com/706408
607 TEST_F(MediaStreamVideoSourceTest, MinHeightLargerThanMaxHeightOldConstraints) { 744 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinHeightLargerThanMaxHeight) {
608 base::test::ScopedFeatureList scoped_feature_list;
609 scoped_feature_list.InitAndEnableFeature(
610 features::kMediaStreamOldVideoConstraints);
611 MockConstraintFactory factory; 745 MockConstraintFactory factory;
612 factory.basic().height.setMin(480); 746 factory.basic().height.setMin(480);
613 factory.basic().height.setMax(360); 747 factory.basic().height.setMax(360);
614 748
615 blink::WebMediaStreamTrack track = 749 blink::WebMediaStreamTrack track =
616 CreateTrack("123", factory.CreateWebMediaConstraints()); 750 CreateTrack("123", factory.CreateWebMediaConstraints());
617 mock_source()->CompleteGetSupportedFormats(); 751 mock_source()->CompleteGetSupportedFormats();
618 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 752 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
619 } 753 }
620 754
621 // Does not apply with spec-compliant constraints. 755 // Does not apply with spec-compliant constraints.
622 // TODO(guidou): Remove this test. http://crbug.com/706408 756 // TODO(guidou): Remove this test. http://crbug.com/706408
623 TEST_F(MediaStreamVideoSourceTest, 757 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
624 MinFrameRateLargerThanMaxFrameRateOldConstraints) { 758 MinFrameRateLargerThanMaxFrameRate) {
625 base::test::ScopedFeatureList scoped_feature_list;
626 scoped_feature_list.InitAndEnableFeature(
627 features::kMediaStreamOldVideoConstraints);
628 MockConstraintFactory factory; 759 MockConstraintFactory factory;
629 factory.basic().frameRate.setMin(25); 760 factory.basic().frameRate.setMin(25);
630 factory.basic().frameRate.setMax(15); 761 factory.basic().frameRate.setMax(15);
631 blink::WebMediaStreamTrack track = 762 blink::WebMediaStreamTrack track =
632 CreateTrack("123", factory.CreateWebMediaConstraints()); 763 CreateTrack("123", factory.CreateWebMediaConstraints());
633 mock_source()->CompleteGetSupportedFormats(); 764 mock_source()->CompleteGetSupportedFormats();
634 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 765 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
635 } 766 }
636 767
637 // Does not apply with spec-compliant constraints. 768 // Does not apply with spec-compliant constraints.
638 // TODO(guidou): Remove this test. http://crbug.com/706408 769 // TODO(guidou): Remove this test. http://crbug.com/706408
639 TEST_F(MediaStreamVideoSourceTest, ExactWidthNotSupportedOldConstraints) { 770 TEST_F(MediaStreamVideoSourceOldConstraintsTest, ExactWidthNotSupported) {
640 base::test::ScopedFeatureList scoped_feature_list;
641 scoped_feature_list.InitAndEnableFeature(
642 features::kMediaStreamOldVideoConstraints);
643 MockConstraintFactory factory; 771 MockConstraintFactory factory;
644 factory.basic().width.setExact(12000); 772 factory.basic().width.setExact(12000);
645 blink::WebMediaStreamTrack track = 773 blink::WebMediaStreamTrack track =
646 CreateTrack("123", factory.CreateWebMediaConstraints()); 774 CreateTrack("123", factory.CreateWebMediaConstraints());
647 mock_source()->CompleteGetSupportedFormats(); 775 mock_source()->CompleteGetSupportedFormats();
648 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 776 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
649 } 777 }
650 778
651 // Does not apply with spec-compliant constraints. 779 // Does not apply with spec-compliant constraints.
652 // TODO(guidou): Remove this test. http://crbug.com/706408 780 // TODO(guidou): Remove this test. http://crbug.com/706408
653 TEST_F(MediaStreamVideoSourceTest, MinWidthNotSupportedOldConstraints) { 781 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinWidthNotSupported) {
654 base::test::ScopedFeatureList scoped_feature_list;
655 scoped_feature_list.InitAndEnableFeature(
656 features::kMediaStreamOldVideoConstraints);
657 MockConstraintFactory factory; 782 MockConstraintFactory factory;
658 factory.basic().width.setMin(12000); 783 factory.basic().width.setMin(12000);
659 blink::WebMediaStreamTrack track = 784 blink::WebMediaStreamTrack track =
660 CreateTrack("123", factory.CreateWebMediaConstraints()); 785 CreateTrack("123", factory.CreateWebMediaConstraints());
661 mock_source()->CompleteGetSupportedFormats(); 786 mock_source()->CompleteGetSupportedFormats();
662 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 787 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
663 } 788 }
664 789
665 // Test that its safe to release the last reference of a blink track and the 790 // Test that its safe to release the last reference of a blink track and the
666 // source during the callback if adding a track succeeds. 791 // source during the callback if adding a track succeeds.
667 // TODO(guidou): Remove this test. http://crbug.com/706408 792 // TODO(guidou): Remove this test. http://crbug.com/706408
668 TEST_F(MediaStreamVideoSourceTest, 793 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
669 ReleaseTrackAndSourceOnSuccessCallBackOldConstraints) { 794 ReleaseTrackAndSourceOnSuccessCallBack) {
670 base::test::ScopedFeatureList scoped_feature_list;
671 scoped_feature_list.InitAndEnableFeature(
672 features::kMediaStreamOldVideoConstraints);
673 MockConstraintFactory factory; 795 MockConstraintFactory factory;
674 blink::WebMediaStreamTrack track = 796 blink::WebMediaStreamTrack track =
675 CreateTrack("123", factory.CreateWebMediaConstraints()); 797 CreateTrack("123", factory.CreateWebMediaConstraints());
676 ReleaseTrackAndSourceOnAddTrackCallback(track); 798 ReleaseTrackAndSourceOnAddTrackCallback(track);
677 mock_source()->CompleteGetSupportedFormats(); 799 mock_source()->CompleteGetSupportedFormats();
678 mock_source()->StartMockedSource(); 800 mock_source()->StartMockedSource();
679 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 801 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
680 } 802 }
681 803
682 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnSuccessCallBack) {
683 base::test::ScopedFeatureList scoped_feature_list;
684 scoped_feature_list.InitAndDisableFeature(
685 features::kMediaStreamOldVideoConstraints);
686 blink::WebMediaStreamTrack track = CreateTrack("123");
687 ReleaseTrackAndSourceOnAddTrackCallback(track);
688 mock_source()->StartMockedSource();
689 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
690 }
691
692 // Test that its safe to release the last reference of a blink track and the 804 // Test that its safe to release the last reference of a blink track and the
693 // source during the callback if adding a track fails. 805 // source during the callback if adding a track fails.
694 // Does not apply with spec-compliant constraints. 806 // Does not apply with spec-compliant constraints.
695 // TODO(guidou): Remove this test. http://crbug.com/706408 807 // TODO(guidou): Remove this test. http://crbug.com/706408
696 TEST_F(MediaStreamVideoSourceTest, 808 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
697 ReleaseTrackAndSourceOnFailureCallBackOldConstraints) { 809 ReleaseTrackAndSourceOnFailureCallBack) {
698 base::test::ScopedFeatureList scoped_feature_list;
699 scoped_feature_list.InitAndEnableFeature(
700 features::kMediaStreamOldVideoConstraints);
701 MockConstraintFactory factory; 810 MockConstraintFactory factory;
702 factory.basic().width.setMin(99999); 811 factory.basic().width.setMin(99999);
703 { 812 {
704 blink::WebMediaStreamTrack track = 813 blink::WebMediaStreamTrack track =
705 CreateTrack("123", factory.CreateWebMediaConstraints()); 814 CreateTrack("123", factory.CreateWebMediaConstraints());
706 ReleaseTrackAndSourceOnAddTrackCallback(track); 815 ReleaseTrackAndSourceOnAddTrackCallback(track);
707 } 816 }
708 mock_source()->CompleteGetSupportedFormats(); 817 mock_source()->CompleteGetSupportedFormats();
709 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 818 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
710 } 819 }
711 820
712 // Test that the source ignores an optional aspect ratio that is higher than 821 // Test that the source ignores an optional aspect ratio that is higher than
713 // supported. 822 // supported.
714 // Does not apply with spec-compliant constraints. 823 // Does not apply with spec-compliant constraints.
715 // TODO(guidou): Remove this test. http://crbug.com/706408 824 // TODO(guidou): Remove this test. http://crbug.com/706408
716 TEST_F(MediaStreamVideoSourceTest, OptionalAspectRatioTooHighOldConstraints) { 825 TEST_F(MediaStreamVideoSourceOldConstraintsTest, OptionalAspectRatioTooHigh) {
717 base::test::ScopedFeatureList scoped_feature_list;
718 scoped_feature_list.InitAndEnableFeature(
719 features::kMediaStreamOldVideoConstraints);
720 MockConstraintFactory factory; 826 MockConstraintFactory factory;
721 factory.AddAdvanced().aspectRatio.setMin(2.0); 827 factory.AddAdvanced().aspectRatio.setMin(2.0);
722 blink::WebMediaStreamTrack track = 828 blink::WebMediaStreamTrack track =
723 CreateTrack("123", factory.CreateWebMediaConstraints()); 829 CreateTrack("123", factory.CreateWebMediaConstraints());
724 mock_source()->CompleteGetSupportedFormats(); 830 mock_source()->CompleteGetSupportedFormats();
725 831
726 const media::VideoCaptureFormat& format = mock_source()->start_format(); 832 const media::VideoCaptureFormat& format = mock_source()->start_format();
727 const double aspect_ratio = static_cast<double>(format.frame_size.width()) / 833 const double aspect_ratio = static_cast<double>(format.frame_size.width()) /
728 format.frame_size.height(); 834 format.frame_size.height();
729 EXPECT_LT(aspect_ratio, 2); 835 EXPECT_LT(aspect_ratio, 2);
730 } 836 }
731 837
732 // Test that the source starts video with the default resolution if the 838 // Test that the source starts video with the default resolution if the
733 // that is the only supported. 839 // that is the only supported.
734 // Does not apply with spec-compliant constraints. 840 // Does not apply with spec-compliant constraints.
735 // TODO(guidou): Remove this test. http://crbug.com/706408 841 // TODO(guidou): Remove this test. http://crbug.com/706408
736 TEST_F(MediaStreamVideoSourceTest, DefaultCapabilityOldConstraints) { 842 TEST_F(MediaStreamVideoSourceOldConstraintsTest, DefaultCapability) {
737 base::test::ScopedFeatureList scoped_feature_list;
738 scoped_feature_list.InitAndEnableFeature(
739 features::kMediaStreamOldVideoConstraints);
740 media::VideoCaptureFormats formats; 843 media::VideoCaptureFormats formats;
741 formats.push_back(media::VideoCaptureFormat( 844 formats.push_back(media::VideoCaptureFormat(
742 gfx::Size(MediaStreamVideoSource::kDefaultWidth, 845 gfx::Size(MediaStreamVideoSource::kDefaultWidth,
743 MediaStreamVideoSource::kDefaultHeight), 846 MediaStreamVideoSource::kDefaultHeight),
744 MediaStreamVideoSource::kDefaultFrameRate, media::PIXEL_FORMAT_I420)); 847 MediaStreamVideoSource::kDefaultFrameRate, media::PIXEL_FORMAT_I420));
745 mock_source()->SetSupportedFormats(formats); 848 mock_source()->SetSupportedFormats(formats);
746 849
747 blink::WebMediaConstraints constraints; 850 blink::WebMediaConstraints constraints;
748 constraints.initialize(); 851 constraints.initialize();
749 CreateTrackAndStartSource(constraints, MediaStreamVideoSource::kDefaultWidth, 852 CreateTrackAndStartSource(constraints, MediaStreamVideoSource::kDefaultWidth,
750 MediaStreamVideoSource::kDefaultHeight, 30); 853 MediaStreamVideoSource::kDefaultHeight, 30);
751 } 854 }
752 855
753 // Does not apply with spec-compliant constraints. 856 // Does not apply with spec-compliant constraints.
754 // TODO(guidou): Remove this test. http://crbug.com/706408 857 // TODO(guidou): Remove this test. http://crbug.com/706408
755 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraintOldConstraints) { 858 TEST_F(MediaStreamVideoSourceOldConstraintsTest, InvalidMandatoryConstraint) {
756 base::test::ScopedFeatureList scoped_feature_list;
757 scoped_feature_list.InitAndEnableFeature(
758 features::kMediaStreamOldVideoConstraints);
759 MockConstraintFactory factory; 859 MockConstraintFactory factory;
760 // Use a constraint that is only known for audio. 860 // Use a constraint that is only known for audio.
761 factory.basic().echoCancellation.setExact(true); 861 factory.basic().echoCancellation.setExact(true);
762 blink::WebMediaStreamTrack track = 862 blink::WebMediaStreamTrack track =
763 CreateTrack("123", factory.CreateWebMediaConstraints()); 863 CreateTrack("123", factory.CreateWebMediaConstraints());
764 mock_source()->CompleteGetSupportedFormats(); 864 mock_source()->CompleteGetSupportedFormats();
765 EXPECT_EQ(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, error_type()); 865 EXPECT_EQ(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, error_type());
766 EXPECT_EQ("echoCancellation", error_name()); 866 EXPECT_EQ("echoCancellation", error_name());
767 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 867 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
768 } 868 }
769 869
770 // Test that the source ignores an unknown optional constraint. 870 // Test that the source ignores an unknown optional constraint.
771 // Does not apply with spec-compliant constraints. 871 // Does not apply with spec-compliant constraints.
772 // TODO(guidou): Remove this test. http://crbug.com/706408 872 // TODO(guidou): Remove this test. http://crbug.com/706408
773 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraintOldConstraints) { 873 TEST_F(MediaStreamVideoSourceOldConstraintsTest, InvalidOptionalConstraint) {
774 base::test::ScopedFeatureList scoped_feature_list;
775 scoped_feature_list.InitAndEnableFeature(
776 features::kMediaStreamOldVideoConstraints);
777 MockConstraintFactory factory; 874 MockConstraintFactory factory;
778 factory.AddAdvanced().echoCancellation.setExact(true); 875 factory.AddAdvanced().echoCancellation.setExact(true);
779 876
780 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 877 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(),
781 MediaStreamVideoSource::kDefaultWidth, 878 MediaStreamVideoSource::kDefaultWidth,
782 MediaStreamVideoSource::kDefaultHeight, 30); 879 MediaStreamVideoSource::kDefaultHeight, 30);
783 } 880 }
784 881
785 // Tests that the source starts video with the max width and height set by 882 // Tests that the source starts video with the max width and height set by
786 // constraints for screencast. 883 // constraints for screencast.
787 // Does not apply with spec-compliant constraints. 884 // Does not apply with spec-compliant constraints.
788 // TODO(guidou): Remove this test. http://crbug.com/706408 885 // TODO(guidou): Remove this test. http://crbug.com/706408
789 TEST_F(MediaStreamVideoSourceTest, 886 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
790 ScreencastResolutionWithConstraintOldConstraints) { 887 ScreencastResolutionWithConstraint) {
791 base::test::ScopedFeatureList scoped_feature_list;
792 scoped_feature_list.InitAndEnableFeature(
793 features::kMediaStreamOldVideoConstraints);
794 media::VideoCaptureFormats formats; 888 media::VideoCaptureFormats formats;
795 formats.push_back(media::VideoCaptureFormat(gfx::Size(480, 270), 30, 889 formats.push_back(media::VideoCaptureFormat(gfx::Size(480, 270), 30,
796 media::PIXEL_FORMAT_I420)); 890 media::PIXEL_FORMAT_I420));
797 mock_source()->SetSupportedFormats(formats); 891 mock_source()->SetSupportedFormats(formats);
798 MockConstraintFactory factory; 892 MockConstraintFactory factory;
799 factory.basic().width.setMax(480); 893 factory.basic().width.setMax(480);
800 factory.basic().height.setMax(270); 894 factory.basic().height.setMax(270);
801 895
802 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( 896 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
803 factory.CreateWebMediaConstraints(), 480, 270, 30); 897 factory.CreateWebMediaConstraints(), 480, 270, 30);
804 EXPECT_EQ(480, mock_source()->max_requested_height()); 898 EXPECT_EQ(480, mock_source()->max_requested_height());
805 EXPECT_EQ(270, mock_source()->max_requested_width()); 899 EXPECT_EQ(270, mock_source()->max_requested_width());
806 } 900 }
807 901
808 // Test that optional constraints are applied in order. 902 // Test that optional constraints are applied in order.
809 // Does not apply with spec-compliant constraints. 903 // Does not apply with spec-compliant constraints.
810 // TODO(guidou): Remove this test. http://crbug.com/706408 904 // TODO(guidou): Remove this test. http://crbug.com/706408
811 TEST_F(MediaStreamVideoSourceTest, OptionalConstraintsOldConstraints) { 905 TEST_F(MediaStreamVideoSourceOldConstraintsTest, OptionalConstraints) {
812 base::test::ScopedFeatureList scoped_feature_list;
813 scoped_feature_list.InitAndEnableFeature(
814 features::kMediaStreamOldVideoConstraints);
815 MockConstraintFactory factory; 906 MockConstraintFactory factory;
816 // Min width of 2056 pixels can not be fulfilled. 907 // Min width of 2056 pixels can not be fulfilled.
817 factory.AddAdvanced().width.setMin(2056); 908 factory.AddAdvanced().width.setMin(2056);
818 factory.AddAdvanced().width.setMin(641); 909 factory.AddAdvanced().width.setMin(641);
819 // Since min width is set to 641 pixels, max width 640 can not be fulfilled. 910 // Since min width is set to 641 pixels, max width 640 can not be fulfilled.
820 factory.AddAdvanced().width.setMax(640); 911 factory.AddAdvanced().width.setMax(640);
821 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); 912 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30);
822 } 913 }
823 914
824 // Test that the source crops to the requested max width and 915 // Test that the source crops to the requested max width and
825 // height even though the camera delivers a larger frame. 916 // height even though the camera delivers a larger frame.
826 // Redundant with spec-compliant constraints. 917 // Redundant with spec-compliant constraints.
827 // TODO(guidou): Remove this test. http://crbug.com/706408 918 // TODO(guidou): Remove this test. http://crbug.com/706408
828 TEST_F(MediaStreamVideoSourceTest, 919 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
829 DeliverCroppedVideoFrameOptional640360OldConstraints) { 920 DeliverCroppedVideoFrameOptional640360) {
830 base::test::ScopedFeatureList scoped_feature_list;
831 scoped_feature_list.InitAndEnableFeature(
832 features::kMediaStreamOldVideoConstraints);
833 MockConstraintFactory factory; 921 MockConstraintFactory factory;
834 factory.AddAdvanced().width.setMax(640); 922 factory.AddAdvanced().width.setMax(640);
835 factory.AddAdvanced().height.setMax(360); 923 factory.AddAdvanced().height.setMax(360);
836 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); 924 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360);
837 } 925 }
838 926
839 // Redundant with spec-compliant constraints. 927 // Redundant with spec-compliant constraints.
840 // TODO(guidou): Remove this test. http://crbug.com/706408 928 // TODO(guidou): Remove this test. http://crbug.com/706408
841 TEST_F(MediaStreamVideoSourceTest, 929 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
842 DeliverCroppedVideoFrameMandatory640360OldConstraints) { 930 DeliverCroppedVideoFrameMandatory640360) {
843 base::test::ScopedFeatureList scoped_feature_list;
844 scoped_feature_list.InitAndEnableFeature(
845 features::kMediaStreamOldVideoConstraints);
846 MockConstraintFactory factory; 931 MockConstraintFactory factory;
847 factory.basic().width.setMax(640); 932 factory.basic().width.setMax(640);
848 factory.basic().height.setMax(360); 933 factory.basic().height.setMax(360);
849 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); 934 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360);
850 } 935 }
851 936
852 // Redundant with spec-compliant constraints. 937 // Redundant with spec-compliant constraints.
853 // TODO(guidou): Remove this test. http://crbug.com/706408 938 // TODO(guidou): Remove this test. http://crbug.com/706408
854 TEST_F(MediaStreamVideoSourceTest, 939 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
855 DeliverCroppedVideoFrameMandatory732489OldConstraints) { 940 DeliverCroppedVideoFrameMandatory732489) {
856 base::test::ScopedFeatureList scoped_feature_list;
857 scoped_feature_list.InitAndEnableFeature(
858 features::kMediaStreamOldVideoConstraints);
859 MockConstraintFactory factory; 941 MockConstraintFactory factory;
860 factory.basic().width.setMax(732); 942 factory.basic().width.setMax(732);
861 factory.basic().height.setMax(489); 943 factory.basic().height.setMax(489);
862 factory.basic().width.setMin(732); 944 factory.basic().width.setMin(732);
863 factory.basic().height.setMin(489); 945 factory.basic().height.setMin(489);
864 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 732, 489); 946 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 732, 489);
865 } 947 }
866 948
867 // Test that the source crops to the requested max width and 949 // Test that the source crops to the requested max width and
868 // height even though the requested frame has odd size. 950 // height even though the requested frame has odd size.
869 // Redundant with spec-compliant constraints. 951 // Redundant with spec-compliant constraints.
870 // TODO(guidou): Remove this test. http://crbug.com/706408 952 // TODO(guidou): Remove this test. http://crbug.com/706408
871 TEST_F(MediaStreamVideoSourceTest, 953 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
872 DeliverCroppedVideoFrame637359OldConstraints) { 954 DeliverCroppedVideoFrame637359) {
873 base::test::ScopedFeatureList scoped_feature_list;
874 scoped_feature_list.InitAndEnableFeature(
875 features::kMediaStreamOldVideoConstraints);
876 MockConstraintFactory factory; 955 MockConstraintFactory factory;
877 factory.AddAdvanced().width.setMax(637); 956 factory.AddAdvanced().width.setMax(637);
878 factory.AddAdvanced().height.setMax(359); 957 factory.AddAdvanced().height.setMax(359);
879 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359); 958 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359);
880 } 959 }
881 960
882 // Redundant with spec-compliant constraints. 961 // Redundant with spec-compliant constraints.
883 // TODO(guidou): Remove this test. http://crbug.com/706408 962 // TODO(guidou): Remove this test. http://crbug.com/706408
884 TEST_F(MediaStreamVideoSourceTest, 963 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
885 DeliverCroppedVideoFrame320320OldConstraints) { 964 DeliverCroppedVideoFrame320320) {
886 base::test::ScopedFeatureList scoped_feature_list;
887 scoped_feature_list.InitAndEnableFeature(
888 features::kMediaStreamOldVideoConstraints);
889 MockConstraintFactory factory; 965 MockConstraintFactory factory;
890 factory.basic().width.setMax(320); 966 factory.basic().width.setMax(320);
891 factory.basic().height.setMax(320); 967 factory.basic().height.setMax(320);
892 factory.basic().height.setMin(320); 968 factory.basic().height.setMin(320);
893 factory.basic().width.setMax(320); 969 factory.basic().width.setMax(320);
894 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 320, 320); 970 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 320, 320);
895 } 971 }
896 972
897 // Redundant with spec-compliant constraints. 973 // Redundant with spec-compliant constraints.
898 // TODO(guidou): Remove this test. http://crbug.com/706408 974 // TODO(guidou): Remove this test. http://crbug.com/706408
899 TEST_F(MediaStreamVideoSourceTest, 975 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
900 DeliverSmallerSizeWhenTooLargeMaxOldConstraints) { 976 DeliverSmallerSizeWhenTooLargeMax) {
901 base::test::ScopedFeatureList scoped_feature_list;
902 scoped_feature_list.InitAndEnableFeature(
903 features::kMediaStreamOldVideoConstraints);
904 MockConstraintFactory factory; 977 MockConstraintFactory factory;
905 factory.AddAdvanced().width.setMax(1920); 978 factory.AddAdvanced().width.setMax(1920);
906 factory.AddAdvanced().height.setMax(1080); 979 factory.AddAdvanced().height.setMax(1080);
907 factory.AddAdvanced().width.setMin(1280); 980 factory.AddAdvanced().width.setMin(1280);
908 factory.AddAdvanced().height.setMin(720); 981 factory.AddAdvanced().height.setMin(720);
909 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 1280, 982 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 1280,
910 720); 983 720);
911 } 984 }
912 985
913 // TODO(guidou): Remove this test. http://crbug.com/706408 986 // TODO(guidou): Remove this test. http://crbug.com/706408
914 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGAOldConstraints) { 987 TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWithVGAAndWVGA) {
915 base::test::ScopedFeatureList scoped_feature_list;
916 scoped_feature_list.InitAndEnableFeature(
917 features::kMediaStreamOldVideoConstraints);
918 MockConstraintFactory factory1; 988 MockConstraintFactory factory1;
919 factory1.AddAdvanced().width.setMax(640); 989 factory1.AddAdvanced().width.setMax(640);
920 factory1.AddAdvanced().height.setMax(480); 990 factory1.AddAdvanced().height.setMax(480);
921 991
922 MockConstraintFactory factory2; 992 MockConstraintFactory factory2;
923 factory2.AddAdvanced().height.setMax(360); 993 factory2.AddAdvanced().height.setMax(360);
924 994
925 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), 995 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
926 factory2.CreateWebMediaConstraints(), 996 factory2.CreateWebMediaConstraints(),
927 640, 480, 640, 480, 640, 360); 997 640, 480, 640, 480, 640, 360);
928 } 998 }
929 999
930 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGA) {
931 base::test::ScopedFeatureList scoped_feature_list;
932 scoped_feature_list.InitAndDisableFeature(
933 features::kMediaStreamOldVideoConstraints);
934 TestTwoTracksWithDifferentSettings(640, 480, 640, 480, 640, 360);
935 }
936
937 // Redundant with spec-compliant constraints 1000 // Redundant with spec-compliant constraints
938 // TODO(guidou): Remove this test. http://crbug.com/706408 1001 // TODO(guidou): Remove this test. http://crbug.com/706408
939 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGAOldConstraints) { 1002 TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWith720AndWVGA) {
940 base::test::ScopedFeatureList scoped_feature_list;
941 scoped_feature_list.InitAndEnableFeature(
942 features::kMediaStreamOldVideoConstraints);
943 MockConstraintFactory factory1; 1003 MockConstraintFactory factory1;
944 factory1.AddAdvanced().width.setMin(1280); 1004 factory1.AddAdvanced().width.setMin(1280);
945 factory1.AddAdvanced().height.setMin(720); 1005 factory1.AddAdvanced().height.setMin(720);
946 1006
947 MockConstraintFactory factory2; 1007 MockConstraintFactory factory2;
948 factory2.basic().width.setMax(640); 1008 factory2.basic().width.setMax(640);
949 factory2.basic().height.setMax(360); 1009 factory2.basic().height.setMax(360);
950 1010
951 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), 1011 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
952 factory2.CreateWebMediaConstraints(), 1012 factory2.CreateWebMediaConstraints(),
953 1280, 720, 1280, 720, 640, 360); 1013 1280, 720, 1280, 720, 640, 360);
954 } 1014 }
955 1015
956 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGA) {
957 base::test::ScopedFeatureList scoped_feature_list;
958 scoped_feature_list.InitAndDisableFeature(
959 features::kMediaStreamOldVideoConstraints);
960 TestTwoTracksWithDifferentSettings(1280, 720, 1280, 720, 640, 360);
961 }
962
963 // Redundant with spec-compliant constraints 1016 // Redundant with spec-compliant constraints
964 // TODO(guidou): Remove this test. http://crbug.com/706408 1017 // TODO(guidou): Remove this test. http://crbug.com/706408
965 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndW700H700OldConstraints) { 1018 TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWith720AndW700H700) {
966 base::test::ScopedFeatureList scoped_feature_list;
967 scoped_feature_list.InitAndEnableFeature(
968 features::kMediaStreamOldVideoConstraints);
969 MockConstraintFactory factory1; 1019 MockConstraintFactory factory1;
970 factory1.AddAdvanced().width.setMin(1280); 1020 factory1.AddAdvanced().width.setMin(1280);
971 factory1.AddAdvanced().height.setMin(720); 1021 factory1.AddAdvanced().height.setMin(720);
972 1022
973 MockConstraintFactory factory2; 1023 MockConstraintFactory factory2;
974 factory2.basic().width.setMax(700); 1024 factory2.basic().width.setMax(700);
975 factory2.basic().height.setMax(700); 1025 factory2.basic().height.setMax(700);
976 1026
977 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), 1027 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
978 factory2.CreateWebMediaConstraints(), 1028 factory2.CreateWebMediaConstraints(),
979 1280, 720, 1280, 720, 700, 700); 1029 1280, 720, 1280, 720, 700, 700);
980 } 1030 }
981 1031
982 // Redundant with spec-compliant constraints 1032 // Redundant with spec-compliant constraints
983 // TODO(guidou): Remove this test. http://crbug.com/706408 1033 // TODO(guidou): Remove this test. http://crbug.com/706408
984 TEST_F(MediaStreamVideoSourceTest, 1034 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
985 TwoTracksWith720AndMaxAspectRatio4To3OldConstraints) { 1035 TwoTracksWith720AndMaxAspectRatio4To3) {
986 base::test::ScopedFeatureList scoped_feature_list;
987 scoped_feature_list.InitAndEnableFeature(
988 features::kMediaStreamOldVideoConstraints);
989 MockConstraintFactory factory1; 1036 MockConstraintFactory factory1;
990 factory1.AddAdvanced().width.setMin(1280); 1037 factory1.AddAdvanced().width.setMin(1280);
991 factory1.AddAdvanced().height.setMin(720); 1038 factory1.AddAdvanced().height.setMin(720);
992 1039
993 MockConstraintFactory factory2; 1040 MockConstraintFactory factory2;
994 factory2.basic().aspectRatio.setMax(640.0 / 480); 1041 factory2.basic().aspectRatio.setMax(640.0 / 480);
995 1042
996 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), 1043 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
997 factory2.CreateWebMediaConstraints(), 1044 factory2.CreateWebMediaConstraints(),
998 1280, 720, 1280, 720, 960, 720); 1045 1280, 720, 1280, 720, 960, 720);
999 } 1046 }
1000 1047
1001 // Redundant with spec-compliant constraints 1048 // Redundant with spec-compliant constraints
1002 // TODO(guidou): Remove this test. http://crbug.com/706408 1049 // TODO(guidou): Remove this test. http://crbug.com/706408
1003 TEST_F(MediaStreamVideoSourceTest, 1050 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
1004 TwoTracksWithVgaAndMinAspectRatioOldConstraints) { 1051 TwoTracksWithVgaAndMinAspectRatio) {
1005 base::test::ScopedFeatureList scoped_feature_list;
1006 scoped_feature_list.InitAndEnableFeature(
1007 features::kMediaStreamOldVideoConstraints);
1008 MockConstraintFactory factory1; 1052 MockConstraintFactory factory1;
1009 factory1.AddAdvanced().width.setMax(640); 1053 factory1.AddAdvanced().width.setMax(640);
1010 factory1.AddAdvanced().height.setMax(480); 1054 factory1.AddAdvanced().height.setMax(480);
1011 1055
1012 MockConstraintFactory factory2; 1056 MockConstraintFactory factory2;
1013 factory2.basic().aspectRatio.setMin(640.0 / 360); 1057 factory2.basic().aspectRatio.setMin(640.0 / 360);
1014 1058
1015 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), 1059 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
1016 factory2.CreateWebMediaConstraints(), 1060 factory2.CreateWebMediaConstraints(),
1017 640, 480, 640, 480, 640, 360); 1061 640, 480, 640, 480, 640, 360);
1018 } 1062 }
1019 1063
1020 // Does not apply with spec-compliant constraints 1064 // Does not apply with spec-compliant constraints
1021 // TODO(guidou): Remove this test. http://crbug.com/706408 1065 // TODO(guidou): Remove this test. http://crbug.com/706408
1022 TEST_F(MediaStreamVideoSourceTest, 1066 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
1023 TwoTracksWithSecondTrackFrameRateHigherThanFirstOldConstraints) { 1067 TwoTracksWithSecondTrackFrameRateHigherThanFirst) {
1024 base::test::ScopedFeatureList scoped_feature_list;
1025 scoped_feature_list.InitAndEnableFeature(
1026 features::kMediaStreamOldVideoConstraints);
1027 MockConstraintFactory factory1; 1068 MockConstraintFactory factory1;
1028 factory1.basic().frameRate.setMin(15); 1069 factory1.basic().frameRate.setMin(15);
1029 factory1.basic().frameRate.setMax(15); 1070 factory1.basic().frameRate.setMax(15);
1030 1071
1031 blink::WebMediaStreamTrack track1 = 1072 blink::WebMediaStreamTrack track1 =
1032 CreateTrackAndStartSource(factory1.CreateWebMediaConstraints(), 1073 CreateTrackAndStartSource(factory1.CreateWebMediaConstraints(),
1033 MediaStreamVideoSource::kDefaultWidth, 1074 MediaStreamVideoSource::kDefaultWidth,
1034 MediaStreamVideoSource::kDefaultHeight, 15); 1075 MediaStreamVideoSource::kDefaultHeight, 15);
1035 1076
1036 MockConstraintFactory factory2; 1077 MockConstraintFactory factory2;
1037 factory2.basic().frameRate.setMin(30); 1078 factory2.basic().frameRate.setMin(30);
1038 blink::WebMediaStreamTrack track2 = 1079 blink::WebMediaStreamTrack track2 =
1039 CreateTrack("123", factory2.CreateWebMediaConstraints()); 1080 CreateTrack("123", factory2.CreateWebMediaConstraints());
1040 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 1081 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
1041 } 1082 }
1042 1083
1043 // Test that a source can change the frame resolution on the fly and that 1084 // Test that a source can change the frame resolution on the fly and that
1044 // tracks sinks get the new frame size unless constraints force the frame to be 1085 // tracks sinks get the new frame size unless constraints force the frame to be
1045 // cropped. 1086 // cropped.
1046 // TODO(guidou): Remove this test. http://crbug.com/706408 1087 // TODO(guidou): Remove this test. http://crbug.com/706408
1047 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSizeOldConstraints) { 1088 TEST_F(MediaStreamVideoSourceOldConstraintsTest, SourceChangeFrameSize) {
1048 base::test::ScopedFeatureList scoped_feature_list;
1049 scoped_feature_list.InitAndEnableFeature(
1050 features::kMediaStreamOldVideoConstraints);
1051 MockConstraintFactory factory; 1089 MockConstraintFactory factory;
1052 factory.AddAdvanced().width.setMax(800); 1090 factory.AddAdvanced().width.setMax(800);
1053 factory.AddAdvanced().height.setMax(700); 1091 factory.AddAdvanced().height.setMax(700);
1054 1092
1055 // Expect the source to start capture with the supported resolution. 1093 // Expect the source to start capture with the supported resolution.
1056 // Disable frame-rate adjustment in spec-compliant mode to ensure no frames 1094 // Disable frame-rate adjustment in spec-compliant mode to ensure no frames
1057 // are dropped. 1095 // are dropped.
1058 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( 1096 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
1059 factory.CreateWebMediaConstraints(), 640, 480, 30); 1097 factory.CreateWebMediaConstraints(), 640, 480, 30);
1060 1098
(...skipping 16 matching lines...) Expand all
1077 1115
1078 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink); 1116 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink);
1079 EXPECT_EQ(3, sink.number_of_frames()); 1117 EXPECT_EQ(3, sink.number_of_frames());
1080 // Expect a frame to be cropped since its larger than max requested. 1118 // Expect a frame to be cropped since its larger than max requested.
1081 EXPECT_EQ(800, sink.frame_size().width()); 1119 EXPECT_EQ(800, sink.frame_size().width());
1082 EXPECT_EQ(700, sink.frame_size().height()); 1120 EXPECT_EQ(700, sink.frame_size().height());
1083 1121
1084 sink.DisconnectFromTrack(); 1122 sink.DisconnectFromTrack();
1085 } 1123 }
1086 1124
1087 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) {
1088 base::test::ScopedFeatureList scoped_feature_list;
1089 scoped_feature_list.InitAndDisableFeature(
1090 features::kMediaStreamOldVideoConstraints);
1091 MockConstraintFactory factory;
1092 factory.AddAdvanced().width.setMax(800);
1093 factory.AddAdvanced().height.setMax(700);
1094
1095 // Expect the source to start capture with the supported resolution.
1096 // Disable frame-rate adjustment in spec-compliant mode to ensure no frames
1097 // are dropped.
1098 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(800, 700, 0.0);
1099
1100 MockMediaStreamVideoSink sink;
1101 sink.ConnectToTrack(track);
1102 EXPECT_EQ(0, sink.number_of_frames());
1103 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink);
1104 EXPECT_EQ(1, sink.number_of_frames());
1105 // Expect the delivered frame to be passed unchanged since its smaller than
1106 // max requested.
1107 EXPECT_EQ(320, sink.frame_size().width());
1108 EXPECT_EQ(240, sink.frame_size().height());
1109
1110 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink);
1111 EXPECT_EQ(2, sink.number_of_frames());
1112 // Expect the delivered frame to be passed unchanged since its smaller than
1113 // max requested.
1114 EXPECT_EQ(640, sink.frame_size().width());
1115 EXPECT_EQ(480, sink.frame_size().height());
1116
1117 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink);
1118 EXPECT_EQ(3, sink.number_of_frames());
1119 // Expect a frame to be cropped since its larger than max requested.
1120 EXPECT_EQ(800, sink.frame_size().width());
1121 EXPECT_EQ(700, sink.frame_size().height());
1122
1123 sink.DisconnectFromTrack();
1124 }
1125
1126 // Test that the constraint negotiation can handle 0.0 fps as frame rate. 1125 // Test that the constraint negotiation can handle 0.0 fps as frame rate.
1127 // Does not apply to spec-compliant constraints. 1126 TEST_F(MediaStreamVideoSourceOldConstraintsTest, Use0FpsSupportedFormat) {
1128 // TODO(guidou): Remove this test. http://crbug.com/706408
1129 TEST_F(MediaStreamVideoSourceTest, Use0FpsSupportedFormatOldConstraints) {
1130 base::test::ScopedFeatureList scoped_feature_list;
1131 scoped_feature_list.InitAndEnableFeature(
1132 features::kMediaStreamOldVideoConstraints);
1133 media::VideoCaptureFormats formats; 1127 media::VideoCaptureFormats formats;
1134 formats.push_back(media::VideoCaptureFormat(gfx::Size(640, 480), 0.0f, 1128 formats.push_back(media::VideoCaptureFormat(gfx::Size(640, 480), 0.0f,
1135 media::PIXEL_FORMAT_I420)); 1129 media::PIXEL_FORMAT_I420));
1136 formats.push_back(media::VideoCaptureFormat(gfx::Size(320, 240), 0.0f, 1130 formats.push_back(media::VideoCaptureFormat(gfx::Size(320, 240), 0.0f,
1137 media::PIXEL_FORMAT_I420)); 1131 media::PIXEL_FORMAT_I420));
1138 mock_source()->SetSupportedFormats(formats); 1132 mock_source()->SetSupportedFormats(formats);
1139 1133
1140 blink::WebMediaConstraints constraints; 1134 blink::WebMediaConstraints constraints;
1141 constraints.initialize(); 1135 constraints.initialize();
1142 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); 1136 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
1143 mock_source()->CompleteGetSupportedFormats(); 1137 mock_source()->CompleteGetSupportedFormats();
1144 mock_source()->StartMockedSource(); 1138 mock_source()->StartMockedSource();
1145 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 1139 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
1146 1140
1147 MockMediaStreamVideoSink sink; 1141 MockMediaStreamVideoSink sink;
1148 sink.ConnectToTrack(track); 1142 sink.ConnectToTrack(track);
1149 EXPECT_EQ(0, sink.number_of_frames()); 1143 EXPECT_EQ(0, sink.number_of_frames());
1150 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); 1144 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink);
1151 EXPECT_EQ(1, sink.number_of_frames()); 1145 EXPECT_EQ(1, sink.number_of_frames());
1152 // Expect the delivered frame to be passed unchanged since its smaller than 1146 // Expect the delivered frame to be passed unchanged since its smaller than
1153 // max requested. 1147 // max requested.
1154 EXPECT_EQ(320, sink.frame_size().width()); 1148 EXPECT_EQ(320, sink.frame_size().width());
1155 EXPECT_EQ(240, sink.frame_size().height()); 1149 EXPECT_EQ(240, sink.frame_size().height());
1156 sink.DisconnectFromTrack(); 1150 sink.DisconnectFromTrack();
1157 } 1151 }
1158 1152
1159 // Test that a source producing no frames change the source ReadyState to muted. 1153 // Test that a source producing no frames change the source ReadyState to muted.
1160 // that in a reasonable time frame the muted state turns to false. 1154 // that in a reasonable time frame the muted state turns to false.
1161 // TODO(guidou): Remove this test. http://crbug.com/706408 1155 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MutedSource) {
1162 TEST_F(MediaStreamVideoSourceTest, MutedSourceOldConstraints) {
1163 base::test::ScopedFeatureList scoped_feature_list;
1164 scoped_feature_list.InitAndEnableFeature(
1165 features::kMediaStreamOldVideoConstraints);
1166 // Setup the source for support a frame rate of 999 fps in order to test 1156 // Setup the source for support a frame rate of 999 fps in order to test
1167 // the muted event faster. This is since the frame monitoring uses 1157 // the muted event faster. This is since the frame monitoring uses
1168 // PostDelayedTask that is dependent on the source frame rate. 1158 // PostDelayedTask that is dependent on the source frame rate.
1169 // Note that media::limits::kMaxFramesPerSecond is 1000. 1159 // Note that media::limits::kMaxFramesPerSecond is 1000.
1170 media::VideoCaptureFormats formats; 1160 media::VideoCaptureFormats formats;
1171 formats.push_back(media::VideoCaptureFormat( 1161 formats.push_back(media::VideoCaptureFormat(
1172 gfx::Size(640, 480), media::limits::kMaxFramesPerSecond - 1, 1162 gfx::Size(640, 480), media::limits::kMaxFramesPerSecond - 1,
1173 media::PIXEL_FORMAT_I420)); 1163 media::PIXEL_FORMAT_I420));
1174 SetSourceSupportedFormats(formats); 1164 SetSourceSupportedFormats(formats);
1175 1165
(...skipping 25 matching lines...) Expand all
1201 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); 1191 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink);
1202 run_loop2.Run(); 1192 run_loop2.Run();
1203 1193
1204 EXPECT_EQ(muted_state, false); 1194 EXPECT_EQ(muted_state, false);
1205 EXPECT_EQ(track.source().getReadyState(), 1195 EXPECT_EQ(track.source().getReadyState(),
1206 blink::WebMediaStreamSource::ReadyStateLive); 1196 blink::WebMediaStreamSource::ReadyStateLive);
1207 1197
1208 sink.DisconnectFromTrack(); 1198 sink.DisconnectFromTrack();
1209 } 1199 }
1210 1200
1211 // Test that a source producing no frames change the source ReadyState to muted.
1212 // that in a reasonable time frame the muted state turns to false.
1213 TEST_F(MediaStreamVideoSourceTest, MutedSource) {
1214 base::test::ScopedFeatureList scoped_feature_list;
1215 scoped_feature_list.InitAndDisableFeature(
1216 features::kMediaStreamOldVideoConstraints);
1217 // Setup the source for support a frame rate of 999 fps in order to test
1218 // the muted event faster. This is since the frame monitoring uses
1219 // PostDelayedTask that is dependent on the source frame rate.
1220 // Note that media::limits::kMaxFramesPerSecond is 1000.
1221 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
1222 640, 480, media::limits::kMaxFramesPerSecond - 2);
1223 MockMediaStreamVideoSink sink;
1224 sink.ConnectToTrack(track);
1225 EXPECT_EQ(track.source().getReadyState(),
1226 blink::WebMediaStreamSource::ReadyStateLive);
1227
1228 base::RunLoop run_loop;
1229 base::Closure quit_closure = run_loop.QuitClosure();
1230 bool muted_state = false;
1231 EXPECT_CALL(*mock_source(), DoSetMutedState(_))
1232 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure)));
1233 run_loop.Run();
1234 EXPECT_EQ(muted_state, true);
1235
1236 EXPECT_EQ(track.source().getReadyState(),
1237 blink::WebMediaStreamSource::ReadyStateMuted);
1238
1239 base::RunLoop run_loop2;
1240 base::Closure quit_closure2 = run_loop2.QuitClosure();
1241 EXPECT_CALL(*mock_source(), DoSetMutedState(_))
1242 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure2)));
1243 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink);
1244 run_loop2.Run();
1245
1246 EXPECT_EQ(muted_state, false);
1247 EXPECT_EQ(track.source().getReadyState(),
1248 blink::WebMediaStreamSource::ReadyStateLive);
1249
1250 sink.DisconnectFromTrack();
1251 }
1252
1253 // Test that an optional constraint with an invalid aspect ratio is ignored. 1201 // Test that an optional constraint with an invalid aspect ratio is ignored.
1254 // Does not apply with spec-compliant constraints. 1202 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
1255 // TODO(guidou): Remove this test. http://crbug.com/706408 1203 InvalidOptionalAspectRatioIgnored) {
1256 TEST_F(MediaStreamVideoSourceTest,
1257 InvalidOptionalAspectRatioIgnoredOldConstraints) {
1258 base::test::ScopedFeatureList scoped_feature_list;
1259 scoped_feature_list.InitAndEnableFeature(
1260 features::kMediaStreamOldVideoConstraints);
1261 MockConstraintFactory factory; 1204 MockConstraintFactory factory;
1262 factory.AddAdvanced().aspectRatio.setMax(0.0); 1205 factory.AddAdvanced().aspectRatio.setMax(0.0);
1263 blink::WebMediaStreamTrack track = 1206 blink::WebMediaStreamTrack track =
1264 CreateTrack("123", factory.CreateWebMediaConstraints()); 1207 CreateTrack("123", factory.CreateWebMediaConstraints());
1265 mock_source()->CompleteGetSupportedFormats(); 1208 mock_source()->CompleteGetSupportedFormats();
1266 EXPECT_EQ(0, NumberOfFailedConstraintsCallbacks()); 1209 EXPECT_EQ(0, NumberOfFailedConstraintsCallbacks());
1267 } 1210 }
1268 1211
1269 // Test that setting an invalid mandatory aspect ratio fails. 1212 // Test that setting an invalid mandatory aspect ratio fails.
1270 // Does not apply with spec-compliant constraints. 1213 // Does not apply with spec-compliant constraints.
1271 // TODO(guidou): Remove this test. http://crbug.com/706408 1214 TEST_F(MediaStreamVideoSourceOldConstraintsTest,
1272 TEST_F(MediaStreamVideoSourceTest, 1215 InvalidMandatoryAspectRatioFails) {
1273 InvalidMandatoryAspectRatioFailsOldConstraints) {
1274 base::test::ScopedFeatureList scoped_feature_list;
1275 scoped_feature_list.InitAndEnableFeature(
1276 features::kMediaStreamOldVideoConstraints);
1277 MockConstraintFactory factory; 1216 MockConstraintFactory factory;
1278 factory.basic().aspectRatio.setMax(0.0); 1217 factory.basic().aspectRatio.setMax(0.0);
1279 blink::WebMediaStreamTrack track = 1218 blink::WebMediaStreamTrack track =
1280 CreateTrack("123", factory.CreateWebMediaConstraints()); 1219 CreateTrack("123", factory.CreateWebMediaConstraints());
1281 mock_source()->CompleteGetSupportedFormats(); 1220 mock_source()->CompleteGetSupportedFormats();
1282 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 1221 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
1283 } 1222 }
1284 1223
1285 } // namespace content 1224 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698