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::TraceConfig
trace_config(
87 "video", base::trace_event::RECORD_UNTIL_FULL
);
88 trace_config
.EnableSampling();
89 trace_log_
->SetEnabled(trace_config
,
90 base::trace_event::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::DeprecatedReadAndReturnError(
203 devices_as_json
, base::JSON_ALLOW_TRAILING_COMMAS
, &error_code
,
206 ASSERT_TRUE(value
.get() != NULL
) << error_message
;
207 EXPECT_EQ(value
->GetType(), base::Value::TYPE_LIST
);
209 base::ListValue
* values
;
210 ASSERT_TRUE(value
->GetAsList(&values
));
212 for (base::ListValue::iterator it
= values
->begin();
213 it
!= values
->end(); ++it
) {
214 const base::DictionaryValue
* dict
;
216 std::string device_id
;
217 ASSERT_TRUE((*it
)->GetAsDictionary(&dict
));
218 ASSERT_TRUE(dict
->GetString("kind", &kind
));
219 ASSERT_TRUE(dict
->GetString("id", &device_id
));
220 ASSERT_FALSE(device_id
.empty());
221 EXPECT_TRUE(kind
== "audio" || kind
== "video");
222 if (kind
== "audio") {
223 audio_ids
->push_back(device_id
);
224 } else if (kind
== "video") {
225 video_ids
->push_back(device_id
);
228 ASSERT_FALSE(audio_ids
->empty());
229 ASSERT_FALSE(video_ids
->empty());
233 base::trace_event::TraceLog
* trace_log_
;
234 scoped_refptr
<base::RefCountedString
> recorded_trace_data_
;
235 scoped_refptr
<MessageLoopRunner
> message_loop_runner_
;
238 // These tests will all make a getUserMedia call with different constraints and
239 // see that the success callback is called. If the error callback is called or
240 // none of the callbacks are called the tests will simply time out and fail.
242 // Test fails under MSan, http://crbug.com/445745
243 #if defined(MEMORY_SANITIZER)
244 #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
246 #define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
248 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
249 MAYBE_GetVideoStreamAndStop
) {
250 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
252 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
253 NavigateToURL(shell(), url
);
255 ExecuteJavascriptAndWaitForOk(
256 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop
));
259 // Test fails under MSan, http://crbug.com/445745
260 #if defined(MEMORY_SANITIZER)
261 #define MAYBE_RenderSameTrackMediastreamAndStop \
262 DISABLED_RenderSameTrackMediastreamAndStop
264 #define MAYBE_RenderSameTrackMediastreamAndStop \
265 RenderSameTrackMediastreamAndStop
267 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
268 MAYBE_RenderSameTrackMediastreamAndStop
) {
269 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
271 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
272 NavigateToURL(shell(), url
);
274 ExecuteJavascriptAndWaitForOk(
275 base::StringPrintf("%s({video: true});",
276 kRenderSameTrackMediastreamAndStop
));
279 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
280 RenderClonedMediastreamAndStop
) {
281 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
283 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
284 NavigateToURL(shell(), url
);
287 ExecuteJavascriptAndWaitForOk(
288 base::StringPrintf("%s({video: true});",
289 kRenderClonedMediastreamAndStop
));
292 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
293 kRenderClonedTrackMediastreamAndStop
) {
294 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
296 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
297 NavigateToURL(shell(), url
);
299 ExecuteJavascriptAndWaitForOk(
300 base::StringPrintf("%s({video: true});",
301 kRenderClonedTrackMediastreamAndStop
));
304 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
305 kRenderDuplicatedMediastreamAndStop
) {
306 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
308 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
309 NavigateToURL(shell(), url
);
311 ExecuteJavascriptAndWaitForOk(
312 base::StringPrintf("%s({video: true});",
313 kRenderDuplicatedMediastreamAndStop
));
316 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
317 GetAudioAndVideoStreamAndStop
) {
318 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
320 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
321 NavigateToURL(shell(), url
);
323 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
324 "%s({video: true, audio: true});", kGetUserMediaAndStop
));
327 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
328 GetAudioAndVideoStreamAndClone
) {
329 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
331 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
332 NavigateToURL(shell(), url
);
334 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
337 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
338 RenderVideoTrackInMultipleTagsAndPause
) {
339 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
341 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
342 NavigateToURL(shell(), url
);
344 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
349 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
350 GetUserMediaWithMandatorySourceID
) {
351 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
353 std::vector
<std::string
> audio_ids
;
354 std::vector
<std::string
> video_ids
;
355 GetInputDevices(&audio_ids
, &video_ids
);
357 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
359 // Test all combinations of mandatory sourceID;
360 for (std::vector
<std::string
>::const_iterator video_it
= video_ids
.begin();
361 video_it
!= video_ids
.end(); ++video_it
) {
362 for (std::vector
<std::string
>::const_iterator audio_it
= audio_ids
.begin();
363 audio_it
!= audio_ids
.end(); ++audio_it
) {
364 NavigateToURL(shell(), url
);
365 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
366 GenerateGetUserMediaWithMandatorySourceID(
367 kGetUserMediaAndStop
,
374 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
375 GetUserMediaWithInvalidMandatorySourceID
) {
376 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
378 std::vector
<std::string
> audio_ids
;
379 std::vector
<std::string
> video_ids
;
380 GetInputDevices(&audio_ids
, &video_ids
);
382 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
384 // Test with invalid mandatory audio sourceID.
385 NavigateToURL(shell(), url
);
386 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
387 GenerateGetUserMediaWithMandatorySourceID(
388 kGetUserMediaAndExpectFailure
,
392 // Test with invalid mandatory video sourceID.
393 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
394 GenerateGetUserMediaWithMandatorySourceID(
395 kGetUserMediaAndExpectFailure
,
397 "something invalid")));
399 // Test with empty mandatory audio sourceID.
400 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
401 GenerateGetUserMediaWithMandatorySourceID(
402 kGetUserMediaAndExpectFailure
,
407 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
408 GetUserMediaWithInvalidOptionalSourceID
) {
409 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
411 std::vector
<std::string
> audio_ids
;
412 std::vector
<std::string
> video_ids
;
413 GetInputDevices(&audio_ids
, &video_ids
);
415 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
417 // Test with invalid optional audio sourceID.
418 NavigateToURL(shell(), url
);
419 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
420 GenerateGetUserMediaWithOptionalSourceID(
421 kGetUserMediaAndStop
,
425 // Test with invalid optional video sourceID.
426 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
427 GenerateGetUserMediaWithOptionalSourceID(
428 kGetUserMediaAndStop
,
430 "something invalid")));
432 // Test with empty optional audio sourceID.
433 EXPECT_EQ(kOK
, ExecuteJavascriptAndReturnResult(
434 GenerateGetUserMediaWithOptionalSourceID(
435 kGetUserMediaAndStop
,
440 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
, TwoGetUserMediaAndStop
) {
441 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
443 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
444 NavigateToURL(shell(), url
);
446 ExecuteJavascriptAndWaitForOk(
447 "twoGetUserMediaAndStop({video: true, audio: true});");
450 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
451 TwoGetUserMediaWithEqualConstraints
) {
452 std::string constraints1
= "{video: true, audio: true}";
453 const std::string
& constraints2
= constraints1
;
454 std::string expected_result
= "w=640:h=480-w=640:h=480";
456 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
460 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
461 TwoGetUserMediaWithSecondVideoCropped
) {
462 std::string constraints1
= "{video: true}";
463 std::string constraints2
= "{video: {mandatory: {maxHeight: 360}}}";
464 std::string expected_result
= "w=640:h=480-w=640:h=360";
465 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
469 // Test fails under MSan, http://crbug.com/445745
470 #if defined(MEMORY_SANITIZER)
471 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
472 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
474 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
475 TwoGetUserMediaWithFirstHdSecondVga
477 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
478 MAYBE_TwoGetUserMediaWithFirstHdSecondVga
) {
479 std::string constraints1
=
480 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\
482 std::string constraints2
=
483 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
484 std::string expected_result
= "w=1280:h=720-w=640:h=480";
485 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
490 // Timing out on Winodws 7 bot: http://crbug.com/443294
491 #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
492 DISABLED_TwoGetUserMediaWithFirst1080pSecondVga
494 #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
495 TwoGetUserMediaWithFirst1080pSecondVga
498 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
499 MAYBE_TwoGetUserMediaWithFirst1080pSecondVga
) {
500 std::string constraints1
=
501 "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080,\
503 std::string constraints2
=
504 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
505 std::string expected_result
= "w=1920:h=1080-w=640:h=480";
506 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
510 // Test fails under MSan, http://crbug.com/445745
511 #if defined(MEMORY_SANITIZER)
512 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
513 DISABLED_TwoGetUserMediaAndVerifyFrameRate
515 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
516 TwoGetUserMediaAndVerifyFrameRate
518 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
519 MAYBE_TwoGetUserMediaAndVerifyFrameRate
) {
520 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
522 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
523 NavigateToURL(shell(), url
);
525 std::string constraints1
=
526 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
527 "minFrameRate : 15, maxFrameRate : 15}}}";
528 std::string constraints2
=
529 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
530 "minFrameRate : 7, maxFrameRate : 7}}}";
532 std::string command
= "twoGetUserMediaAndVerifyFrameRate(" +
533 constraints1
+ ',' + constraints2
+ ", 15, 7)";
534 ExecuteJavascriptAndWaitForOk(command
);
537 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
538 GetUserMediaWithTooHighVideoConstraintsValues
) {
539 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
541 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
543 int large_value
= 99999;
544 std::string call
= GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure
,
551 NavigateToURL(shell(), url
);
553 EXPECT_EQ("ConstraintNotSatisfiedError",
554 ExecuteJavascriptAndReturnResult(call
));
557 // This test makes two getUserMedia requests, one with impossible constraints
558 // that should trigger an error, and one with valid constraints. The test
559 // verifies getUserMedia can succeed after being given impossible constraints.
560 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
561 TwoGetUserMediaAndCheckCallbackAfterFailure
) {
562 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
564 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
565 NavigateToURL(shell(), url
);
567 int large_value
= 99999;
568 const std::string gum_with_impossible_constraints
=
569 GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure
,
576 const std::string gum_with_vga_constraints
=
577 GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop
,
578 640, 640, 480, 480, 10, 30);
580 ASSERT_EQ("ConstraintNotSatisfiedError",
581 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints
));
583 ASSERT_EQ("w=640:h=480",
584 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints
));
587 // This test will make a simple getUserMedia page, verify that video is playing
588 // in a simple local <video>, and for a couple of seconds, collect some
589 // performance traces from VideoCaptureController colorspace conversion and
590 // potential resizing.
591 IN_PROC_BROWSER_TEST_F(
592 WebRtcGetUserMediaBrowserTest
,
593 TraceVideoCaptureControllerPerformanceDuringGetUserMedia
) {
594 RunGetUserMediaAndCollectMeasures(
596 "VideoCaptureDeviceClient::OnIncomingCapturedData",
597 "VideoCaptureDeviceClient");
600 // Test fails under MSan, http://crbug.com/445745
601 #if defined(MEMORY_SANITIZER)
602 #define MAYBE_TestGetUserMediaAspectRatio4To3 \
603 DISABLED_TestGetUserMediaAspectRatio4To3
605 #define MAYBE_TestGetUserMediaAspectRatio4To3 TestGetUserMediaAspectRatio4To3
607 // This test calls getUserMedia and checks for aspect ratio behavior.
608 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
609 MAYBE_TestGetUserMediaAspectRatio4To3
) {
610 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
612 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
614 std::string constraints_4_3
= GenerateGetUserMediaCall(
615 kGetUserMediaAndAnalyseAndStop
, 640, 640, 480, 480, 10, 30);
617 NavigateToURL(shell(), url
);
618 ASSERT_EQ("w=640:h=480",
619 ExecuteJavascriptAndReturnResult(constraints_4_3
));
622 // Test fails under MSan, http://crbug.com/445745
623 #if defined(MEMORY_SANITIZER)
624 #define MAYBE_TestGetUserMediaAspectRatio16To9 \
625 DISABLED_TestGetUserMediaAspectRatio16To9
627 #define MAYBE_TestGetUserMediaAspectRatio16To9 TestGetUserMediaAspectRatio16To9
629 // This test calls getUserMedia and checks for aspect ratio behavior.
630 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
631 MAYBE_TestGetUserMediaAspectRatio16To9
) {
632 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
634 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
636 std::string constraints_16_9
= GenerateGetUserMediaCall(
637 kGetUserMediaAndAnalyseAndStop
, 640, 640, 360, 360, 10, 30);
639 NavigateToURL(shell(), url
);
640 ASSERT_EQ("w=640:h=360",
641 ExecuteJavascriptAndReturnResult(constraints_16_9
));
644 // Test fails under MSan, http://crbug.com/445745
645 #if defined(MEMORY_SANITIZER)
646 #define MAYBE_TestGetUserMediaAspectRatio1To1 \
647 DISABLED_TestGetUserMediaAspectRatio1To1
649 #define MAYBE_TestGetUserMediaAspectRatio1To1 TestGetUserMediaAspectRatio1To1
651 // This test calls getUserMedia and checks for aspect ratio behavior.
652 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
653 MAYBE_TestGetUserMediaAspectRatio1To1
) {
654 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
656 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
658 std::string constraints_1_1
= GenerateGetUserMediaCall(
659 kGetUserMediaAndAnalyseAndStop
, 320, 320, 320, 320, 10, 30);
661 NavigateToURL(shell(), url
);
662 ASSERT_EQ("w=320:h=320",
663 ExecuteJavascriptAndReturnResult(constraints_1_1
));
666 // This test calls getUserMedia in an iframe and immediately close the iframe
667 // in the scope of the success callback.
668 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
669 AudioInIFrameAndCloseInSuccessCb
) {
670 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
672 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
673 NavigateToURL(shell(), url
);
676 "getUserMediaInIframeAndCloseInSuccessCb({audio: true});";
677 ExecuteJavascriptAndWaitForOk(call
);
680 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
681 VideoInIFrameAndCloseInSuccessCb
) {
682 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
684 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
685 NavigateToURL(shell(), url
);
688 "getUserMediaInIframeAndCloseInSuccessCb({video: true});";
689 ExecuteJavascriptAndWaitForOk(call
);
692 // This test calls getUserMedia in an iframe and immediately close the iframe
693 // in the scope of the failure callback.
694 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
695 VideoWithBadConstraintsInIFrameAndCloseInFailureCb
) {
696 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
698 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
700 int large_value
= 99999;
702 GenerateGetUserMediaCall("getUserMediaInIframeAndCloseInFailureCb",
709 NavigateToURL(shell(), url
);
711 ExecuteJavascriptAndWaitForOk(call
);
714 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
715 InvalidSourceIdInIFrameAndCloseInFailureCb
) {
716 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
718 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
721 GenerateGetUserMediaWithMandatorySourceID(
722 "getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid");
723 NavigateToURL(shell(), url
);
725 ExecuteJavascriptAndWaitForOk(call
);
730 struct UserMediaSizes
{
741 class WebRtcConstraintsBrowserTest
742 : public WebRtcContentBrowserTest
,
743 public testing::WithParamInterface
<UserMediaSizes
> {
745 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {}
746 const UserMediaSizes
& user_media() const { return user_media_
; }
749 UserMediaSizes user_media_
;
752 // Test fails under MSan, http://crbug.com/445745
753 #if defined(MEMORY_SANITIZER)
754 #define MAYBE_GetUserMediaConstraints DISABLED_GetUserMediaConstraints
756 #define MAYBE_GetUserMediaConstraints GetUserMediaConstraints
758 // This test calls getUserMedia in sequence with different constraints.
759 IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest
,
760 MAYBE_GetUserMediaConstraints
) {
761 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
763 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
765 std::string call
= GenerateGetUserMediaCall(kGetUserMediaAndStop
,
766 user_media().min_width
,
767 user_media().max_width
,
768 user_media().min_height
,
769 user_media().max_height
,
770 user_media().min_frame_rate
,
771 user_media().max_frame_rate
);
772 DVLOG(1) << "Calling getUserMedia: " << call
;
773 NavigateToURL(shell(), url
);
774 ExecuteJavascriptAndWaitForOk(call
);
777 static const UserMediaSizes kAllUserMediaSizes
[] = {
778 {320, 320, 180, 180, 10, 30},
779 {320, 320, 240, 240, 10, 30},
780 {640, 640, 360, 360, 10, 30},
781 {640, 640, 480, 480, 10, 30},
782 {960, 960, 720, 720, 10, 30},
783 {1280, 1280, 720, 720, 10, 30}};
785 INSTANTIATE_TEST_CASE_P(UserMedia
,
786 WebRtcConstraintsBrowserTest
,
787 testing::ValuesIn(kAllUserMediaSizes
));
789 } // namespace content