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/json/json_reader.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/test/trace_event_analyzer.h"
9 #include "base/trace_event/trace_event_impl.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 ~WebRtcGetUserMediaBrowserTest() override
{}
84 CHECK(trace_log_
== NULL
) << "Can only can start tracing once";
85 trace_log_
= base::trace_event::TraceLog::GetInstance();
86 base::trace_event::TraceOptions
trace_options(
87 base::trace_event::RECORD_UNTIL_FULL
);
88 trace_options
.enable_sampling
= true;
89 trace_log_
->SetEnabled(base::trace_event::CategoryFilter("video"),
90 base::trace_event::TraceLog::RECORDING_MODE
,
92 // Check that we are indeed recording.
93 EXPECT_EQ(trace_log_
->GetNumTracesRecorded(), 1);
97 CHECK(message_loop_runner_
.get() == NULL
)
98 << "Calling StopTracing more than once";
99 trace_log_
->SetDisabled();
100 message_loop_runner_
= new MessageLoopRunner
;
101 trace_log_
->Flush(base::Bind(
102 &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected
,
103 base::Unretained(this)));
104 message_loop_runner_
->Run();
107 void OnTraceDataCollected(
108 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
,
109 bool has_more_events
) {
110 CHECK(!has_more_events
);
111 recorded_trace_data_
= events_str_ptr
;
112 message_loop_runner_
->Quit();
115 TraceAnalyzer
* CreateTraceAnalyzer() {
116 return TraceAnalyzer::Create("[" + recorded_trace_data_
->data() + "]");
119 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs
,
120 const std::string
& measure_filter
,
121 const std::string
& graph_name
) {
122 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
124 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
125 NavigateToURL(shell(), url
);
127 // Put getUserMedia to work and let it run for a couple of seconds.
128 DCHECK(time_to_sample_secs
);
129 ExecuteJavascriptAndWaitForOk(
130 base::StringPrintf("%s({video: true}, 'myStreamName');",
131 kGetUserMediaAndGetStreamUp
));
133 // Now the stream is up and running, start collecting traces.
136 ExecuteJavascriptAndWaitForOk(
137 base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);",
138 time_to_sample_secs
));
140 // Wait until the page title changes to "OK". Do not sleep() here since that
141 // would stop both this code and the browser underneath.
144 scoped_ptr
<TraceAnalyzer
> analyzer(CreateTraceAnalyzer());
145 analyzer
->AssociateBeginEndEvents();
146 trace_analyzer::TraceEventVector events
;
147 DCHECK(measure_filter
.size());
148 analyzer
->FindEvents(
149 Query::EventNameIs(measure_filter
),
151 ASSERT_GT(events
.size(), 0u)
152 << "Could not collect any samples during test, this is bad";
154 std::string duration_us
;
155 std::string interarrival_us
;
156 for (size_t i
= 0; i
!= events
.size(); ++i
) {
158 base::StringPrintf("%d,", static_cast<int>(events
[i
]->duration
)));
161 for (size_t i
= 1; i
< events
.size(); ++i
) {
162 // The event |timestamp| comes in ns, divide to get us like |duration|.
163 interarrival_us
.append(base::StringPrintf("%d,",
164 static_cast<int>((events
[i
]->timestamp
- events
[i
- 1]->timestamp
) /
165 base::Time::kNanosecondsPerMicrosecond
)));
168 perf_test::PrintResultList(
169 graph_name
, "", "sample_duration", duration_us
, "us", true);
171 perf_test::PrintResultList(
172 graph_name
, "", "interarrival_time", interarrival_us
, "us", true);
175 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
176 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
177 const std::string
& constraints1
,
178 const std::string
& constraints2
,
179 const std::string
& expected_result
) {
180 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
182 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
183 NavigateToURL(shell(), url
);
185 std::string command
= "twoGetUserMedia(" + constraints1
+ ',' +
188 EXPECT_EQ(expected_result
, ExecuteJavascriptAndReturnResult(command
));
191 void GetInputDevices(std::vector
<std::string
>* audio_ids
,
192 std::vector
<std::string
>* video_ids
) {
193 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
194 NavigateToURL(shell(), url
);
196 std::string devices_as_json
= ExecuteJavascriptAndReturnResult(
198 EXPECT_FALSE(devices_as_json
.empty());
201 std::string error_message
;
202 scoped_ptr
<base::Value
> value(
203 base::JSONReader::ReadAndReturnError(devices_as_json
,
204 base::JSON_ALLOW_TRAILING_COMMAS
,
208 ASSERT_TRUE(value
.get() != NULL
) << error_message
;
209 EXPECT_EQ(value
->GetType(), base::Value::TYPE_LIST
);
211 base::ListValue
* values
;
212 ASSERT_TRUE(value
->GetAsList(&values
));
214 for (base::ListValue::iterator it
= values
->begin();
215 it
!= values
->end(); ++it
) {
216 const base::DictionaryValue
* dict
;
218 std::string device_id
;
219 ASSERT_TRUE((*it
)->GetAsDictionary(&dict
));
220 ASSERT_TRUE(dict
->GetString("kind", &kind
));
221 ASSERT_TRUE(dict
->GetString("id", &device_id
));
222 ASSERT_FALSE(device_id
.empty());
223 EXPECT_TRUE(kind
== "audio" || kind
== "video");
224 if (kind
== "audio") {
225 audio_ids
->push_back(device_id
);
226 } else if (kind
== "video") {
227 video_ids
->push_back(device_id
);
230 ASSERT_FALSE(audio_ids
->empty());
231 ASSERT_FALSE(video_ids
->empty());
235 base::trace_event::TraceLog
* trace_log_
;
236 scoped_refptr
<base::RefCountedString
> recorded_trace_data_
;
237 scoped_refptr
<MessageLoopRunner
> message_loop_runner_
;
240 // These tests will all make a getUserMedia call with different constraints and
241 // see that the success callback is called. If the error callback is called or
242 // none of the callbacks are called the tests will simply time out and fail.
244 // Test fails under MSan, http://crbug.com/445745
245 #if defined(MEMORY_SANITIZER)
246 #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
248 #define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
250 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
251 MAYBE_GetVideoStreamAndStop
) {
252 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
254 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
255 NavigateToURL(shell(), url
);
257 ExecuteJavascriptAndWaitForOk(
258 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop
));
261 // Test fails under MSan, http://crbug.com/445745
262 #if defined(MEMORY_SANITIZER)
263 #define MAYBE_RenderSameTrackMediastreamAndStop \
264 DISABLED_RenderSameTrackMediastreamAndStop
266 #define MAYBE_RenderSameTrackMediastreamAndStop \
267 RenderSameTrackMediastreamAndStop
269 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
270 MAYBE_RenderSameTrackMediastreamAndStop
) {
271 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
273 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
274 NavigateToURL(shell(), url
);
276 ExecuteJavascriptAndWaitForOk(
277 base::StringPrintf("%s({video: true});",
278 kRenderSameTrackMediastreamAndStop
));
281 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
282 RenderClonedMediastreamAndStop
) {
283 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
285 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
286 NavigateToURL(shell(), url
);
289 ExecuteJavascriptAndWaitForOk(
290 base::StringPrintf("%s({video: true});",
291 kRenderClonedMediastreamAndStop
));
294 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
295 kRenderClonedTrackMediastreamAndStop
) {
296 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
298 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
299 NavigateToURL(shell(), url
);
301 ExecuteJavascriptAndWaitForOk(
302 base::StringPrintf("%s({video: true});",
303 kRenderClonedTrackMediastreamAndStop
));
306 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
307 kRenderDuplicatedMediastreamAndStop
) {
308 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
310 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
311 NavigateToURL(shell(), url
);
313 ExecuteJavascriptAndWaitForOk(
314 base::StringPrintf("%s({video: true});",
315 kRenderDuplicatedMediastreamAndStop
));
318 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
319 GetAudioAndVideoStreamAndStop
) {
320 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
322 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
323 NavigateToURL(shell(), url
);
325 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
326 "%s({video: true, audio: true});", kGetUserMediaAndStop
));
329 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
330 GetAudioAndVideoStreamAndClone
) {
331 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
333 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
334 NavigateToURL(shell(), url
);
336 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
339 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
340 RenderVideoTrackInMultipleTagsAndPause
) {
341 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
343 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
344 NavigateToURL(shell(), url
);
346 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
351 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
352 GetUserMediaWithMandatorySourceID
) {
353 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
355 std::vector
<std::string
> audio_ids
;
356 std::vector
<std::string
> video_ids
;
357 GetInputDevices(&audio_ids
, &video_ids
);
359 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
361 // Test all combinations of mandatory sourceID;
362 for (std::vector
<std::string
>::const_iterator video_it
= video_ids
.begin();
363 video_it
!= video_ids
.end(); ++video_it
) {
364 for (std::vector
<std::string
>::const_iterator audio_it
= audio_ids
.begin();
365 audio_it
!= audio_ids
.end(); ++audio_it
) {
366 NavigateToURL(shell(), url
);
367 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
368 GenerateGetUserMediaWithMandatorySourceID(
369 kGetUserMediaAndStop
,
376 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
377 GetUserMediaWithInvalidMandatorySourceID
) {
378 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
380 std::vector
<std::string
> audio_ids
;
381 std::vector
<std::string
> video_ids
;
382 GetInputDevices(&audio_ids
, &video_ids
);
384 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
386 // Test with invalid mandatory audio sourceID.
387 NavigateToURL(shell(), url
);
388 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
389 GenerateGetUserMediaWithMandatorySourceID(
390 kGetUserMediaAndExpectFailure
,
394 // Test with invalid mandatory video sourceID.
395 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
396 GenerateGetUserMediaWithMandatorySourceID(
397 kGetUserMediaAndExpectFailure
,
399 "something invalid")));
401 // Test with empty mandatory audio sourceID.
402 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
403 GenerateGetUserMediaWithMandatorySourceID(
404 kGetUserMediaAndExpectFailure
,
409 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
410 GetUserMediaWithInvalidOptionalSourceID
) {
411 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
413 std::vector
<std::string
> audio_ids
;
414 std::vector
<std::string
> video_ids
;
415 GetInputDevices(&audio_ids
, &video_ids
);
417 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
419 // Test with invalid optional audio sourceID.
420 NavigateToURL(shell(), url
);
421 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
422 GenerateGetUserMediaWithOptionalSourceID(
423 kGetUserMediaAndStop
,
427 // Test with invalid optional video sourceID.
428 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
429 GenerateGetUserMediaWithOptionalSourceID(
430 kGetUserMediaAndStop
,
432 "something invalid")));
434 // Test with empty optional audio sourceID.
435 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
436 GenerateGetUserMediaWithOptionalSourceID(
437 kGetUserMediaAndStop
,
442 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
, TwoGetUserMediaAndStop
) {
443 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
445 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
446 NavigateToURL(shell(), url
);
448 ExecuteJavascriptAndWaitForOk(
449 "twoGetUserMediaAndStop({video: true, audio: true});");
452 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
453 TwoGetUserMediaWithEqualConstraints
) {
454 std::string constraints1
= "{video: true, audio: true}";
455 const std::string
& constraints2
= constraints1
;
456 std::string expected_result
= "w=640:h=480-w=640:h=480";
458 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
462 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
463 TwoGetUserMediaWithSecondVideoCropped
) {
464 std::string constraints1
= "{video: true}";
465 std::string constraints2
= "{video: {mandatory: {maxHeight: 360}}}";
466 std::string expected_result
= "w=640:h=480-w=640:h=360";
467 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
471 // Test fails under MSan, http://crbug.com/445745
472 #if defined(MEMORY_SANITIZER)
473 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
474 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
476 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
477 TwoGetUserMediaWithFirstHdSecondVga
479 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
480 MAYBE_TwoGetUserMediaWithFirstHdSecondVga
) {
481 std::string constraints1
=
482 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\
484 std::string constraints2
=
485 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
486 std::string expected_result
= "w=1280:h=720-w=640:h=480";
487 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
492 // Timing out on Winodws 7 bot: http://crbug.com/443294
493 #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
494 DISABLED_TwoGetUserMediaWithFirst1080pSecondVga
496 #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
497 TwoGetUserMediaWithFirst1080pSecondVga
500 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
501 MAYBE_TwoGetUserMediaWithFirst1080pSecondVga
) {
502 std::string constraints1
=
503 "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080,\
505 std::string constraints2
=
506 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
507 std::string expected_result
= "w=1920:h=1080-w=640:h=480";
508 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
512 // Test fails under MSan, http://crbug.com/445745
513 #if defined(MEMORY_SANITIZER)
514 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
515 DISABLED_TwoGetUserMediaAndVerifyFrameRate
517 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
518 TwoGetUserMediaAndVerifyFrameRate
520 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
521 MAYBE_TwoGetUserMediaAndVerifyFrameRate
) {
522 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
524 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
525 NavigateToURL(shell(), url
);
527 std::string constraints1
=
528 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
529 "minFrameRate : 15, maxFrameRate : 15}}}";
530 std::string constraints2
=
531 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
532 "minFrameRate : 7, maxFrameRate : 7}}}";
534 std::string command
= "twoGetUserMediaAndVerifyFrameRate(" +
535 constraints1
+ ',' + constraints2
+ ", 15, 7)";
536 ExecuteJavascriptAndWaitForOk(command
);
539 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
540 GetUserMediaWithTooHighVideoConstraintsValues
) {
541 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
543 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
545 int large_value
= 99999;
546 std::string call
= GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure
,
553 NavigateToURL(shell(), url
);
555 EXPECT_EQ("ConstraintNotSatisfiedError",
556 ExecuteJavascriptAndReturnResult(call
));
559 // This test makes two getUserMedia requests, one with impossible constraints
560 // that should trigger an error, and one with valid constraints. The test
561 // verifies getUserMedia can succeed after being given impossible constraints.
562 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
563 TwoGetUserMediaAndCheckCallbackAfterFailure
) {
564 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
566 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
567 NavigateToURL(shell(), url
);
569 int large_value
= 99999;
570 const std::string gum_with_impossible_constraints
=
571 GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure
,
578 const std::string gum_with_vga_constraints
=
579 GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop
,
580 640, 640, 480, 480, 10, 30);
582 ASSERT_EQ("ConstraintNotSatisfiedError",
583 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints
));
585 ASSERT_EQ("w=640:h=480",
586 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints
));
589 // This test will make a simple getUserMedia page, verify that video is playing
590 // in a simple local <video>, and for a couple of seconds, collect some
591 // performance traces from VideoCaptureController colorspace conversion and
592 // potential resizing.
593 IN_PROC_BROWSER_TEST_F(
594 WebRtcGetUserMediaBrowserTest
,
595 TraceVideoCaptureControllerPerformanceDuringGetUserMedia
) {
596 RunGetUserMediaAndCollectMeasures(
598 "VideoCaptureDeviceClient::OnIncomingCapturedData",
599 "VideoCaptureDeviceClient");
602 // Test fails under MSan, http://crbug.com/445745
603 #if defined(MEMORY_SANITIZER)
604 #define MAYBE_TestGetUserMediaAspectRatio4To3 \
605 DISABLED_TestGetUserMediaAspectRatio4To3
607 #define MAYBE_TestGetUserMediaAspectRatio4To3 TestGetUserMediaAspectRatio4To3
609 // This test calls getUserMedia and checks for aspect ratio behavior.
610 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
611 MAYBE_TestGetUserMediaAspectRatio4To3
) {
612 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
614 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
616 std::string constraints_4_3
= GenerateGetUserMediaCall(
617 kGetUserMediaAndAnalyseAndStop
, 640, 640, 480, 480, 10, 30);
619 NavigateToURL(shell(), url
);
620 ASSERT_EQ("w=640:h=480",
621 ExecuteJavascriptAndReturnResult(constraints_4_3
));
624 // Test fails under MSan, http://crbug.com/445745
625 #if defined(MEMORY_SANITIZER)
626 #define MAYBE_TestGetUserMediaAspectRatio16To9 \
627 DISABLED_TestGetUserMediaAspectRatio16To9
629 #define MAYBE_TestGetUserMediaAspectRatio16To9 TestGetUserMediaAspectRatio16To9
631 // This test calls getUserMedia and checks for aspect ratio behavior.
632 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
633 MAYBE_TestGetUserMediaAspectRatio16To9
) {
634 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
636 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
638 std::string constraints_16_9
= GenerateGetUserMediaCall(
639 kGetUserMediaAndAnalyseAndStop
, 640, 640, 360, 360, 10, 30);
641 NavigateToURL(shell(), url
);
642 ASSERT_EQ("w=640:h=360",
643 ExecuteJavascriptAndReturnResult(constraints_16_9
));
646 // Test fails under MSan, http://crbug.com/445745
647 #if defined(MEMORY_SANITIZER)
648 #define MAYBE_TestGetUserMediaAspectRatio1To1 \
649 DISABLED_TestGetUserMediaAspectRatio1To1
651 #define MAYBE_TestGetUserMediaAspectRatio1To1 TestGetUserMediaAspectRatio1To1
653 // This test calls getUserMedia and checks for aspect ratio behavior.
654 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
655 MAYBE_TestGetUserMediaAspectRatio1To1
) {
656 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
658 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
660 std::string constraints_1_1
= GenerateGetUserMediaCall(
661 kGetUserMediaAndAnalyseAndStop
, 320, 320, 320, 320, 10, 30);
663 NavigateToURL(shell(), url
);
664 ASSERT_EQ("w=320:h=320",
665 ExecuteJavascriptAndReturnResult(constraints_1_1
));
670 struct UserMediaSizes
{
681 class WebRtcConstraintsBrowserTest
682 : public WebRtcContentBrowserTest
,
683 public testing::WithParamInterface
<UserMediaSizes
> {
685 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {}
686 const UserMediaSizes
& user_media() const { return user_media_
; }
689 UserMediaSizes user_media_
;
692 // Test fails under MSan, http://crbug.com/445745
693 #if defined(MEMORY_SANITIZER)
694 #define MAYBE_GetUserMediaConstraints DISABLED_GetUserMediaConstraints
696 #define MAYBE_GetUserMediaConstraints GetUserMediaConstraints
698 // This test calls getUserMedia in sequence with different constraints.
699 IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest
,
700 MAYBE_GetUserMediaConstraints
) {
701 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
703 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
705 std::string call
= GenerateGetUserMediaCall(kGetUserMediaAndStop
,
706 user_media().min_width
,
707 user_media().max_width
,
708 user_media().min_height
,
709 user_media().max_height
,
710 user_media().min_frame_rate
,
711 user_media().max_frame_rate
);
712 DVLOG(1) << "Calling getUserMedia: " << call
;
713 NavigateToURL(shell(), url
);
714 ExecuteJavascriptAndWaitForOk(call
);
717 static const UserMediaSizes kAllUserMediaSizes
[] = {
718 {320, 320, 180, 180, 10, 30},
719 {320, 320, 240, 240, 10, 30},
720 {640, 640, 360, 360, 10, 30},
721 {640, 640, 480, 480, 10, 30},
722 {960, 960, 720, 720, 10, 30},
723 {1280, 1280, 720, 720, 10, 30}};
725 INSTANTIATE_TEST_CASE_P(UserMedia
,
726 WebRtcConstraintsBrowserTest
,
727 testing::ValuesIn(kAllUserMediaSizes
));
729 } // namespace content