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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/debug/trace_event_impl.h"
7 #include "base/json/json_reader.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/test/trace_event_analyzer.h"
10 #include "base/values.h"
11 #include "content/browser/media/webrtc_internals.h"
12 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/public/test/test_utils.h"
17 #include "content/shell/browser/shell.h"
18 #include "content/test/webrtc_content_browsertest_base.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h"
20 #include "testing/perf/perf_test.h"
23 #include "base/win/windows_version.h"
26 using trace_analyzer::TraceAnalyzer
;
27 using trace_analyzer::Query
;
28 using trace_analyzer::TraceEventVector
;
32 static const char kGetUserMediaAndStop
[] = "getUserMediaAndStop";
33 static const char kGetUserMediaAndGetStreamUp
[] = "getUserMediaAndGetStreamUp";
34 static const char kGetUserMediaAndAnalyseAndStop
[] =
35 "getUserMediaAndAnalyseAndStop";
36 static const char kGetUserMediaAndExpectFailure
[] =
37 "getUserMediaAndExpectFailure";
38 static const char kRenderSameTrackMediastreamAndStop
[] =
39 "renderSameTrackMediastreamAndStop";
40 static const char kRenderClonedMediastreamAndStop
[] =
41 "renderClonedMediastreamAndStop";
42 static const char kRenderClonedTrackMediastreamAndStop
[] =
43 "renderClonedTrackMediastreamAndStop";
44 static const char kRenderDuplicatedMediastreamAndStop
[] =
45 "renderDuplicatedMediastreamAndStop";
47 // Results returned by JS.
48 static const char kOK
[] = "OK";
50 std::string
GenerateGetUserMediaWithMandatorySourceID(
51 const std::string
& function_name
,
52 const std::string
& audio_source_id
,
53 const std::string
& video_source_id
) {
54 const std::string audio_constraint
=
55 "audio: {mandatory: { sourceId:\"" + audio_source_id
+ "\"}}, ";
57 const std::string video_constraint
=
58 "video: {mandatory: { sourceId:\"" + video_source_id
+ "\"}}";
59 return function_name
+ "({" + audio_constraint
+ video_constraint
+ "});";
62 std::string
GenerateGetUserMediaWithOptionalSourceID(
63 const std::string
& function_name
,
64 const std::string
& audio_source_id
,
65 const std::string
& video_source_id
) {
66 const std::string audio_constraint
=
67 "audio: {optional: [{sourceId:\"" + audio_source_id
+ "\"}]}, ";
69 const std::string video_constraint
=
70 "video: {optional: [{ sourceId:\"" + video_source_id
+ "\"}]}";
71 return function_name
+ "({" + audio_constraint
+ video_constraint
+ "});";
78 class WebRtcGetUserMediaBrowserTest
: public WebRtcContentBrowserTest
{
80 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL
) {}
81 virtual ~WebRtcGetUserMediaBrowserTest() {}
84 CHECK(trace_log_
== NULL
) << "Can only can start tracing once";
85 trace_log_
= base::debug::TraceLog::GetInstance();
86 base::debug::TraceOptions
trace_options(base::debug::RECORD_UNTIL_FULL
);
87 trace_options
.enable_sampling
= true;
88 trace_log_
->SetEnabled(base::debug::CategoryFilter("video"),
89 base::debug::TraceLog::RECORDING_MODE
,
91 // Check that we are indeed recording.
92 EXPECT_EQ(trace_log_
->GetNumTracesRecorded(), 1);
96 CHECK(message_loop_runner_
.get() == NULL
)
97 << "Calling StopTracing more than once";
98 trace_log_
->SetDisabled();
99 message_loop_runner_
= new MessageLoopRunner
;
100 trace_log_
->Flush(base::Bind(
101 &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected
,
102 base::Unretained(this)));
103 message_loop_runner_
->Run();
106 void OnTraceDataCollected(
107 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
,
108 bool has_more_events
) {
109 CHECK(!has_more_events
);
110 recorded_trace_data_
= events_str_ptr
;
111 message_loop_runner_
->Quit();
114 TraceAnalyzer
* CreateTraceAnalyzer() {
115 return TraceAnalyzer::Create("[" + recorded_trace_data_
->data() + "]");
118 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs
,
119 const std::string
& measure_filter
,
120 const std::string
& graph_name
) {
121 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
123 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
124 NavigateToURL(shell(), url
);
126 // Put getUserMedia to work and let it run for a couple of seconds.
127 DCHECK(time_to_sample_secs
);
128 ExecuteJavascriptAndWaitForOk(
129 base::StringPrintf("%s({video: true}, 'myStreamName');",
130 kGetUserMediaAndGetStreamUp
));
132 // Now the stream is up and running, start collecting traces.
135 ExecuteJavascriptAndWaitForOk(
136 base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);",
137 time_to_sample_secs
));
139 // Wait until the page title changes to "OK". Do not sleep() here since that
140 // would stop both this code and the browser underneath.
143 scoped_ptr
<TraceAnalyzer
> analyzer(CreateTraceAnalyzer());
144 analyzer
->AssociateBeginEndEvents();
145 trace_analyzer::TraceEventVector events
;
146 DCHECK(measure_filter
.size());
147 analyzer
->FindEvents(
148 Query::EventNameIs(measure_filter
),
150 ASSERT_GT(events
.size(), 0u)
151 << "Could not collect any samples during test, this is bad";
153 std::string duration_us
;
154 std::string interarrival_us
;
155 for (size_t i
= 0; i
!= events
.size(); ++i
) {
157 base::StringPrintf("%d,", static_cast<int>(events
[i
]->duration
)));
160 for (size_t i
= 1; i
< events
.size(); ++i
) {
161 // The event |timestamp| comes in ns, divide to get us like |duration|.
162 interarrival_us
.append(base::StringPrintf("%d,",
163 static_cast<int>((events
[i
]->timestamp
- events
[i
- 1]->timestamp
) /
164 base::Time::kNanosecondsPerMicrosecond
)));
167 perf_test::PrintResultList(
168 graph_name
, "", "sample_duration", duration_us
, "us", true);
170 perf_test::PrintResultList(
171 graph_name
, "", "interarrival_time", interarrival_us
, "us", true);
174 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
175 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
176 const std::string
& constraints1
,
177 const std::string
& constraints2
,
178 const std::string
& expected_result
) {
179 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
181 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
182 NavigateToURL(shell(), url
);
184 std::string command
= "twoGetUserMedia(" + constraints1
+ ',' +
187 EXPECT_EQ(expected_result
, ExecuteJavascriptAndReturnResult(command
));
190 void GetInputDevices(std::vector
<std::string
>* audio_ids
,
191 std::vector
<std::string
>* video_ids
) {
192 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
193 NavigateToURL(shell(), url
);
195 std::string devices_as_json
= ExecuteJavascriptAndReturnResult(
197 EXPECT_FALSE(devices_as_json
.empty());
200 std::string error_message
;
201 scoped_ptr
<base::Value
> value(
202 base::JSONReader::ReadAndReturnError(devices_as_json
,
203 base::JSON_ALLOW_TRAILING_COMMAS
,
207 ASSERT_TRUE(value
.get() != NULL
) << error_message
;
208 EXPECT_EQ(value
->GetType(), base::Value::TYPE_LIST
);
210 base::ListValue
* values
;
211 ASSERT_TRUE(value
->GetAsList(&values
));
213 for (base::ListValue::iterator it
= values
->begin();
214 it
!= values
->end(); ++it
) {
215 const base::DictionaryValue
* dict
;
217 std::string device_id
;
218 ASSERT_TRUE((*it
)->GetAsDictionary(&dict
));
219 ASSERT_TRUE(dict
->GetString("kind", &kind
));
220 ASSERT_TRUE(dict
->GetString("id", &device_id
));
221 ASSERT_FALSE(device_id
.empty());
222 EXPECT_TRUE(kind
== "audio" || kind
== "video");
223 if (kind
== "audio") {
224 audio_ids
->push_back(device_id
);
225 } else if (kind
== "video") {
226 video_ids
->push_back(device_id
);
229 ASSERT_FALSE(audio_ids
->empty());
230 ASSERT_FALSE(video_ids
->empty());
234 base::debug::TraceLog
* trace_log_
;
235 scoped_refptr
<base::RefCountedString
> recorded_trace_data_
;
236 scoped_refptr
<MessageLoopRunner
> message_loop_runner_
;
239 // These tests will all make a getUserMedia call with different constraints and
240 // see that the success callback is called. If the error callback is called or
241 // none of the callbacks are called the tests will simply time out and fail.
242 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
, GetVideoStreamAndStop
) {
243 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
245 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
246 NavigateToURL(shell(), url
);
248 ExecuteJavascriptAndWaitForOk(
249 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop
));
252 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
253 RenderSameTrackMediastreamAndStop
) {
254 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
256 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
257 NavigateToURL(shell(), url
);
259 ExecuteJavascriptAndWaitForOk(
260 base::StringPrintf("%s({video: true});",
261 kRenderSameTrackMediastreamAndStop
));
264 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
265 RenderClonedMediastreamAndStop
) {
266 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
268 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
269 NavigateToURL(shell(), url
);
272 ExecuteJavascriptAndWaitForOk(
273 base::StringPrintf("%s({video: true});",
274 kRenderClonedMediastreamAndStop
));
277 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
278 kRenderClonedTrackMediastreamAndStop
) {
279 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
281 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
282 NavigateToURL(shell(), url
);
284 ExecuteJavascriptAndWaitForOk(
285 base::StringPrintf("%s({video: true});",
286 kRenderClonedTrackMediastreamAndStop
));
289 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
290 kRenderDuplicatedMediastreamAndStop
) {
291 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
293 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
294 NavigateToURL(shell(), url
);
296 ExecuteJavascriptAndWaitForOk(
297 base::StringPrintf("%s({video: true});",
298 kRenderDuplicatedMediastreamAndStop
));
301 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
302 GetAudioAndVideoStreamAndStop
) {
303 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
305 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
306 NavigateToURL(shell(), url
);
308 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
309 "%s({video: true, audio: true});", kGetUserMediaAndStop
));
312 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
313 GetAudioAndVideoStreamAndClone
) {
314 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
316 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
317 NavigateToURL(shell(), url
);
319 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
322 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
323 RenderVideoTrackInMultipleTagsAndPause
) {
324 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
326 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
327 NavigateToURL(shell(), url
);
329 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
334 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
335 GetUserMediaWithMandatorySourceID
) {
336 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
338 std::vector
<std::string
> audio_ids
;
339 std::vector
<std::string
> video_ids
;
340 GetInputDevices(&audio_ids
, &video_ids
);
342 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
344 // Test all combinations of mandatory sourceID;
345 for (std::vector
<std::string
>::const_iterator video_it
= video_ids
.begin();
346 video_it
!= video_ids
.end(); ++video_it
) {
347 for (std::vector
<std::string
>::const_iterator audio_it
= audio_ids
.begin();
348 audio_it
!= audio_ids
.end(); ++audio_it
) {
349 NavigateToURL(shell(), url
);
350 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
351 GenerateGetUserMediaWithMandatorySourceID(
352 kGetUserMediaAndStop
,
359 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
360 GetUserMediaWithInvalidMandatorySourceID
) {
361 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
363 std::vector
<std::string
> audio_ids
;
364 std::vector
<std::string
> video_ids
;
365 GetInputDevices(&audio_ids
, &video_ids
);
367 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
369 // Test with invalid mandatory audio sourceID.
370 NavigateToURL(shell(), url
);
371 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
372 GenerateGetUserMediaWithMandatorySourceID(
373 kGetUserMediaAndExpectFailure
,
377 // Test with invalid mandatory video sourceID.
378 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
379 GenerateGetUserMediaWithMandatorySourceID(
380 kGetUserMediaAndExpectFailure
,
382 "something invalid")));
384 // Test with empty mandatory audio sourceID.
385 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
386 GenerateGetUserMediaWithMandatorySourceID(
387 kGetUserMediaAndExpectFailure
,
392 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
393 GetUserMediaWithInvalidOptionalSourceID
) {
394 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
396 std::vector
<std::string
> audio_ids
;
397 std::vector
<std::string
> video_ids
;
398 GetInputDevices(&audio_ids
, &video_ids
);
400 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
402 // Test with invalid optional audio sourceID.
403 NavigateToURL(shell(), url
);
404 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
405 GenerateGetUserMediaWithOptionalSourceID(
406 kGetUserMediaAndStop
,
410 // Test with invalid optional video sourceID.
411 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
412 GenerateGetUserMediaWithOptionalSourceID(
413 kGetUserMediaAndStop
,
415 "something invalid")));
417 // Test with empty optional audio sourceID.
418 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
419 GenerateGetUserMediaWithOptionalSourceID(
420 kGetUserMediaAndStop
,
425 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
, TwoGetUserMediaAndStop
) {
426 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
428 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
429 NavigateToURL(shell(), url
);
431 ExecuteJavascriptAndWaitForOk(
432 "twoGetUserMediaAndStop({video: true, audio: true});");
435 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
436 TwoGetUserMediaWithEqualConstraints
) {
437 std::string constraints1
= "{video: true, audio: true}";
438 const std::string
& constraints2
= constraints1
;
439 std::string expected_result
= "w=640:h=480-w=640:h=480";
441 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
445 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
446 TwoGetUserMediaWithSecondVideoCropped
) {
447 std::string constraints1
= "{video: true}";
448 std::string constraints2
= "{video: {mandatory: {maxHeight: 360}}}";
449 std::string expected_result
= "w=640:h=480-w=640:h=360";
450 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
454 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
455 TwoGetUserMediaWithFirstHdSecondVga
) {
456 std::string constraints1
=
457 "{video: {mandatory: {minWidth:1280 , minHeight: 720}}}";
458 std::string constraints2
=
459 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
460 std::string expected_result
= "w=1280:h=720-w=640:h=480";
461 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
465 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
466 TwoGetUserMediaAndVerifyFrameRate
) {
467 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
469 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
470 NavigateToURL(shell(), url
);
472 std::string constraints1
=
473 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
474 "minFrameRate : 15, maxFrameRate : 15}}}";
475 std::string constraints2
=
476 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
477 "minFrameRate : 7, maxFrameRate : 7}}}";
479 std::string command
= "twoGetUserMediaAndVerifyFrameRate(" +
480 constraints1
+ ',' + constraints2
+ ", 15, 7)";
481 ExecuteJavascriptAndWaitForOk(command
);
484 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
485 GetUserMediaWithTooHighVideoConstraintsValues
) {
486 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
488 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
490 int large_value
= 99999;
491 std::string call
= GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure
,
498 NavigateToURL(shell(), url
);
500 EXPECT_EQ("ConstraintNotSatisfiedError",
501 ExecuteJavascriptAndReturnResult(call
));
504 // This test makes two getUserMedia requests, one with impossible constraints
505 // that should trigger an error, and one with valid constraints. The test
506 // verifies getUserMedia can succeed after being given impossible constraints.
507 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
508 TwoGetUserMediaAndCheckCallbackAfterFailure
) {
509 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
511 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
512 NavigateToURL(shell(), url
);
514 int large_value
= 99999;
515 const std::string gum_with_impossible_constraints
=
516 GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure
,
523 const std::string gum_with_vga_constraints
=
524 GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop
,
525 640, 640, 480, 480, 10, 30);
527 ASSERT_EQ("ConstraintNotSatisfiedError",
528 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints
));
530 ASSERT_EQ("w=640:h=480",
531 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints
));
534 // This test will make a simple getUserMedia page, verify that video is playing
535 // in a simple local <video>, and for a couple of seconds, collect some
536 // performance traces from VideoCaptureController colorspace conversion and
537 // potential resizing.
538 IN_PROC_BROWSER_TEST_F(
539 WebRtcGetUserMediaBrowserTest
,
540 TraceVideoCaptureControllerPerformanceDuringGetUserMedia
) {
541 RunGetUserMediaAndCollectMeasures(
543 "VideoCaptureController::OnIncomingCapturedData",
544 "VideoCaptureController");
547 // This test calls getUserMedia and checks for aspect ratio behavior.
548 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
549 TestGetUserMediaAspectRatio4To3
) {
550 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
552 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
554 std::string constraints_4_3
= GenerateGetUserMediaCall(
555 kGetUserMediaAndAnalyseAndStop
, 640, 640, 480, 480, 10, 30);
557 NavigateToURL(shell(), url
);
558 ASSERT_EQ("w=640:h=480",
559 ExecuteJavascriptAndReturnResult(constraints_4_3
));
562 // This test calls getUserMedia and checks for aspect ratio behavior.
563 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
564 TestGetUserMediaAspectRatio16To9
) {
565 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
567 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
569 std::string constraints_16_9
= GenerateGetUserMediaCall(
570 kGetUserMediaAndAnalyseAndStop
, 640, 640, 360, 360, 10, 30);
572 NavigateToURL(shell(), url
);
573 ASSERT_EQ("w=640:h=360",
574 ExecuteJavascriptAndReturnResult(constraints_16_9
));
577 // This test calls getUserMedia and checks for aspect ratio behavior.
578 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
579 TestGetUserMediaAspectRatio1To1
) {
580 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
582 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
584 std::string constraints_1_1
= GenerateGetUserMediaCall(
585 kGetUserMediaAndAnalyseAndStop
, 320, 320, 320, 320, 10, 30);
587 NavigateToURL(shell(), url
);
588 ASSERT_EQ("w=320:h=320",
589 ExecuteJavascriptAndReturnResult(constraints_1_1
));
594 struct UserMediaSizes
{
605 class WebRtcConstraintsBrowserTest
606 : public WebRtcContentBrowserTest
,
607 public testing::WithParamInterface
<UserMediaSizes
> {
609 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {}
610 const UserMediaSizes
& user_media() const { return user_media_
; }
613 UserMediaSizes user_media_
;
616 // This test calls getUserMedia in sequence with different constraints.
617 IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest
, GetUserMediaConstraints
) {
618 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
620 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
622 std::string call
= GenerateGetUserMediaCall(kGetUserMediaAndStop
,
623 user_media().min_width
,
624 user_media().max_width
,
625 user_media().min_height
,
626 user_media().max_height
,
627 user_media().min_frame_rate
,
628 user_media().max_frame_rate
);
629 DVLOG(1) << "Calling getUserMedia: " << call
;
630 NavigateToURL(shell(), url
);
631 ExecuteJavascriptAndWaitForOk(call
);
634 static const UserMediaSizes kAllUserMediaSizes
[] = {
635 {320, 320, 180, 180, 10, 30},
636 {320, 320, 240, 240, 10, 30},
637 {640, 640, 360, 360, 10, 30},
638 {640, 640, 480, 480, 10, 30},
639 {960, 960, 720, 720, 10, 30},
640 {1280, 1280, 720, 720, 10, 30}};
642 INSTANTIATE_TEST_CASE_P(UserMedia
,
643 WebRtcConstraintsBrowserTest
,
644 testing::ValuesIn(kAllUserMediaSizes
));
646 } // namespace content