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
= base::JSONReader::ReadAndReturnError(
202 devices_as_json
, base::JSON_ALLOW_TRAILING_COMMAS
, &error_code
,
205 ASSERT_TRUE(value
.get() != NULL
) << error_message
;
206 EXPECT_EQ(value
->GetType(), base::Value::TYPE_LIST
);
208 base::ListValue
* values
;
209 ASSERT_TRUE(value
->GetAsList(&values
));
211 for (base::ListValue::iterator it
= values
->begin();
212 it
!= values
->end(); ++it
) {
213 const base::DictionaryValue
* dict
;
215 std::string device_id
;
216 ASSERT_TRUE((*it
)->GetAsDictionary(&dict
));
217 ASSERT_TRUE(dict
->GetString("kind", &kind
));
218 ASSERT_TRUE(dict
->GetString("id", &device_id
));
219 ASSERT_FALSE(device_id
.empty());
220 EXPECT_TRUE(kind
== "audio" || kind
== "video");
221 if (kind
== "audio") {
222 audio_ids
->push_back(device_id
);
223 } else if (kind
== "video") {
224 video_ids
->push_back(device_id
);
227 ASSERT_FALSE(audio_ids
->empty());
228 ASSERT_FALSE(video_ids
->empty());
232 base::trace_event::TraceLog
* trace_log_
;
233 scoped_refptr
<base::RefCountedString
> recorded_trace_data_
;
234 scoped_refptr
<MessageLoopRunner
> message_loop_runner_
;
237 // These tests will all make a getUserMedia call with different constraints and
238 // see that the success callback is called. If the error callback is called or
239 // none of the callbacks are called the tests will simply time out and fail.
241 // Test fails under MSan, http://crbug.com/445745
242 #if defined(MEMORY_SANITIZER)
243 #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
245 #define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
247 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
248 MAYBE_GetVideoStreamAndStop
) {
249 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
251 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
252 NavigateToURL(shell(), url
);
254 ExecuteJavascriptAndWaitForOk(
255 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop
));
258 // Test fails under MSan, http://crbug.com/445745
259 #if defined(MEMORY_SANITIZER)
260 #define MAYBE_RenderSameTrackMediastreamAndStop \
261 DISABLED_RenderSameTrackMediastreamAndStop
263 #define MAYBE_RenderSameTrackMediastreamAndStop \
264 RenderSameTrackMediastreamAndStop
266 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
267 MAYBE_RenderSameTrackMediastreamAndStop
) {
268 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
270 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
271 NavigateToURL(shell(), url
);
273 ExecuteJavascriptAndWaitForOk(
274 base::StringPrintf("%s({video: true});",
275 kRenderSameTrackMediastreamAndStop
));
278 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
279 RenderClonedMediastreamAndStop
) {
280 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
282 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
283 NavigateToURL(shell(), url
);
286 ExecuteJavascriptAndWaitForOk(
287 base::StringPrintf("%s({video: true});",
288 kRenderClonedMediastreamAndStop
));
291 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
292 kRenderClonedTrackMediastreamAndStop
) {
293 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
295 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
296 NavigateToURL(shell(), url
);
298 ExecuteJavascriptAndWaitForOk(
299 base::StringPrintf("%s({video: true});",
300 kRenderClonedTrackMediastreamAndStop
));
303 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
304 kRenderDuplicatedMediastreamAndStop
) {
305 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
307 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
308 NavigateToURL(shell(), url
);
310 ExecuteJavascriptAndWaitForOk(
311 base::StringPrintf("%s({video: true});",
312 kRenderDuplicatedMediastreamAndStop
));
315 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
316 GetAudioAndVideoStreamAndStop
) {
317 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
319 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
320 NavigateToURL(shell(), url
);
322 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
323 "%s({video: true, audio: true});", kGetUserMediaAndStop
));
326 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
327 GetAudioAndVideoStreamAndClone
) {
328 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
330 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
331 NavigateToURL(shell(), url
);
333 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
336 // Test fails under Android, http://crbug.com/524388
337 // Test fails under MSan
338 // Flaky everywhere else: http://crbug.com/523152
339 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
340 DISABLED_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();");
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
,
441 TwoGetUserMediaAndStop
) {
442 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
444 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
445 NavigateToURL(shell(), url
);
447 ExecuteJavascriptAndWaitForOk(
448 "twoGetUserMediaAndStop({video: true, audio: true});");
451 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
452 TwoGetUserMediaWithEqualConstraints
) {
453 std::string constraints1
= "{video: true, audio: true}";
454 const std::string
& constraints2
= constraints1
;
455 std::string expected_result
= "w=640:h=480-w=640:h=480";
457 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
461 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
462 TwoGetUserMediaWithSecondVideoCropped
) {
463 std::string constraints1
= "{video: true}";
464 std::string constraints2
= "{video: {mandatory: {maxHeight: 360}}}";
465 std::string expected_result
= "w=640:h=480-w=640:h=360";
466 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
470 // Test fails under MSan, http://crbug.com/445745
471 #if defined(MEMORY_SANITIZER)
472 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
473 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
475 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
476 TwoGetUserMediaWithFirstHdSecondVga
478 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
479 MAYBE_TwoGetUserMediaWithFirstHdSecondVga
) {
480 std::string constraints1
=
481 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\
483 std::string constraints2
=
484 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
485 std::string expected_result
= "w=1280:h=720-w=640:h=480";
486 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
491 // Timing out on Winodws 7 bot: http://crbug.com/443294
492 #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
493 DISABLED_TwoGetUserMediaWithFirst1080pSecondVga
495 #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
496 TwoGetUserMediaWithFirst1080pSecondVga
499 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
500 MAYBE_TwoGetUserMediaWithFirst1080pSecondVga
) {
501 std::string constraints1
=
502 "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080,\
504 std::string constraints2
=
505 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
506 std::string expected_result
= "w=1920:h=1080-w=640:h=480";
507 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1
, constraints2
,
511 // Test fails under MSan, http://crbug.com/445745
512 #if defined(MEMORY_SANITIZER)
513 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
514 DISABLED_TwoGetUserMediaAndVerifyFrameRate
516 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
517 TwoGetUserMediaAndVerifyFrameRate
519 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
520 MAYBE_TwoGetUserMediaAndVerifyFrameRate
) {
521 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
523 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
524 NavigateToURL(shell(), url
);
526 std::string constraints1
=
527 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
528 "minFrameRate : 15, maxFrameRate : 15}}}";
529 std::string constraints2
=
530 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
531 "minFrameRate : 7, maxFrameRate : 7}}}";
533 std::string command
= "twoGetUserMediaAndVerifyFrameRate(" +
534 constraints1
+ ',' + constraints2
+ ", 15, 7)";
535 ExecuteJavascriptAndWaitForOk(command
);
538 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
539 GetUserMediaWithTooHighVideoConstraintsValues
) {
540 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
542 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
544 int large_value
= 99999;
545 std::string call
= GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure
,
552 NavigateToURL(shell(), url
);
554 EXPECT_EQ("ConstraintNotSatisfiedError",
555 ExecuteJavascriptAndReturnResult(call
));
558 // This test makes two getUserMedia requests, one with impossible constraints
559 // that should trigger an error, and one with valid constraints. The test
560 // verifies getUserMedia can succeed after being given impossible constraints.
561 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
562 TwoGetUserMediaAndCheckCallbackAfterFailure
) {
563 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
565 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
566 NavigateToURL(shell(), url
);
568 int large_value
= 99999;
569 const std::string gum_with_impossible_constraints
=
570 GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure
,
577 const std::string gum_with_vga_constraints
=
578 GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop
,
579 640, 640, 480, 480, 10, 30);
581 ASSERT_EQ("ConstraintNotSatisfiedError",
582 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints
));
584 ASSERT_EQ("w=640:h=480",
585 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints
));
588 // This test will make a simple getUserMedia page, verify that video is playing
589 // in a simple local <video>, and for a couple of seconds, collect some
590 // performance traces from VideoCaptureController colorspace conversion and
591 // potential resizing.
592 IN_PROC_BROWSER_TEST_F(
593 WebRtcGetUserMediaBrowserTest
,
594 TraceVideoCaptureControllerPerformanceDuringGetUserMedia
) {
595 RunGetUserMediaAndCollectMeasures(
597 "VideoCaptureDeviceClient::OnIncomingCapturedData",
598 "VideoCaptureDeviceClient");
601 // Test fails under MSan, http://crbug.com/445745
602 #if defined(MEMORY_SANITIZER)
603 #define MAYBE_TestGetUserMediaAspectRatio4To3 \
604 DISABLED_TestGetUserMediaAspectRatio4To3
606 #define MAYBE_TestGetUserMediaAspectRatio4To3 TestGetUserMediaAspectRatio4To3
608 // This test calls getUserMedia and checks for aspect ratio behavior.
609 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
610 MAYBE_TestGetUserMediaAspectRatio4To3
) {
611 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
613 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
615 std::string constraints_4_3
= GenerateGetUserMediaCall(
616 kGetUserMediaAndAnalyseAndStop
, 640, 640, 480, 480, 10, 30);
618 NavigateToURL(shell(), url
);
619 ASSERT_EQ("w=640:h=480",
620 ExecuteJavascriptAndReturnResult(constraints_4_3
));
623 // Test fails under MSan, http://crbug.com/445745
624 #if defined(MEMORY_SANITIZER)
625 #define MAYBE_TestGetUserMediaAspectRatio16To9 \
626 DISABLED_TestGetUserMediaAspectRatio16To9
628 #define MAYBE_TestGetUserMediaAspectRatio16To9 TestGetUserMediaAspectRatio16To9
630 // This test calls getUserMedia and checks for aspect ratio behavior.
631 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
632 MAYBE_TestGetUserMediaAspectRatio16To9
) {
633 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
635 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
637 std::string constraints_16_9
= GenerateGetUserMediaCall(
638 kGetUserMediaAndAnalyseAndStop
, 640, 640, 360, 360, 10, 30);
640 NavigateToURL(shell(), url
);
641 ASSERT_EQ("w=640:h=360",
642 ExecuteJavascriptAndReturnResult(constraints_16_9
));
645 // Test fails under MSan, http://crbug.com/445745
646 #if defined(MEMORY_SANITIZER)
647 #define MAYBE_TestGetUserMediaAspectRatio1To1 \
648 DISABLED_TestGetUserMediaAspectRatio1To1
650 #define MAYBE_TestGetUserMediaAspectRatio1To1 TestGetUserMediaAspectRatio1To1
652 // This test calls getUserMedia and checks for aspect ratio behavior.
653 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
654 MAYBE_TestGetUserMediaAspectRatio1To1
) {
655 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
657 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
659 std::string constraints_1_1
= GenerateGetUserMediaCall(
660 kGetUserMediaAndAnalyseAndStop
, 320, 320, 320, 320, 10, 30);
662 NavigateToURL(shell(), url
);
663 ASSERT_EQ("w=320:h=320",
664 ExecuteJavascriptAndReturnResult(constraints_1_1
));
667 // This test calls getUserMedia in an iframe and immediately close the iframe
668 // in the scope of the success callback.
669 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
670 AudioInIFrameAndCloseInSuccessCb
) {
671 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
673 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
674 NavigateToURL(shell(), url
);
677 "getUserMediaInIframeAndCloseInSuccessCb({audio: true});";
678 ExecuteJavascriptAndWaitForOk(call
);
681 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
682 VideoInIFrameAndCloseInSuccessCb
) {
683 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
685 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
686 NavigateToURL(shell(), url
);
689 "getUserMediaInIframeAndCloseInSuccessCb({video: true});";
690 ExecuteJavascriptAndWaitForOk(call
);
693 // This test calls getUserMedia in an iframe and immediately close the iframe
694 // in the scope of the failure callback.
695 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
696 VideoWithBadConstraintsInIFrameAndCloseInFailureCb
) {
697 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
699 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
701 int large_value
= 99999;
703 GenerateGetUserMediaCall("getUserMediaInIframeAndCloseInFailureCb",
710 NavigateToURL(shell(), url
);
712 ExecuteJavascriptAndWaitForOk(call
);
715 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest
,
716 InvalidSourceIdInIFrameAndCloseInFailureCb
) {
717 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
719 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
722 GenerateGetUserMediaWithMandatorySourceID(
723 "getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid");
724 NavigateToURL(shell(), url
);
726 ExecuteJavascriptAndWaitForOk(call
);
731 struct UserMediaSizes
{
742 class WebRtcConstraintsBrowserTest
743 : public WebRtcContentBrowserTest
,
744 public testing::WithParamInterface
<UserMediaSizes
> {
746 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {}
747 const UserMediaSizes
& user_media() const { return user_media_
; }
750 UserMediaSizes user_media_
;
753 // Test fails under MSan, http://crbug.com/445745
754 #if defined(MEMORY_SANITIZER)
755 #define MAYBE_GetUserMediaConstraints DISABLED_GetUserMediaConstraints
757 #define MAYBE_GetUserMediaConstraints GetUserMediaConstraints
759 // This test calls getUserMedia in sequence with different constraints.
760 IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest
,
761 MAYBE_GetUserMediaConstraints
) {
762 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
764 GURL
url(embedded_test_server()->GetURL("/media/getusermedia.html"));
766 std::string call
= GenerateGetUserMediaCall(kGetUserMediaAndStop
,
767 user_media().min_width
,
768 user_media().max_width
,
769 user_media().min_height
,
770 user_media().max_height
,
771 user_media().min_frame_rate
,
772 user_media().max_frame_rate
);
773 DVLOG(1) << "Calling getUserMedia: " << call
;
774 NavigateToURL(shell(), url
);
775 ExecuteJavascriptAndWaitForOk(call
);
778 static const UserMediaSizes kAllUserMediaSizes
[] = {
779 {320, 320, 180, 180, 10, 30},
780 {320, 320, 240, 240, 10, 30},
781 {640, 640, 360, 360, 10, 30},
782 {640, 640, 480, 480, 10, 30},
783 {960, 960, 720, 720, 10, 30},
784 {1280, 1280, 720, 720, 10, 30}};
786 INSTANTIATE_TEST_CASE_P(UserMedia
,
787 WebRtcConstraintsBrowserTest
,
788 testing::ValuesIn(kAllUserMediaSizes
));
790 } // namespace content