Update broken references to image assets
[chromium-blink-merge.git] / content / browser / media / webrtc_getusermedia_browsertest.cc
blob3763c0b7bd0e77a8592e8102c59e24341f247a1f
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"
22 #if defined(OS_WIN)
23 #include "base/win/windows_version.h"
24 #endif
26 using trace_analyzer::TraceAnalyzer;
27 using trace_analyzer::Query;
28 using trace_analyzer::TraceEventVector;
30 namespace {
32 // TODO(phoglund): hackhackhack: work around error with result reporting.
33 // Remove this when http://crbug.com/517977 is solved.
35 class WebRtcHack : public content::WebRtcContentBrowserTest {
38 IN_PROC_BROWSER_TEST_F(WebRtcHack, PrintSomeResults) {
39 printf("*RESULT VideoCaptureDeviceClient: sample_duration= [0, 0,] us\n");
40 printf("*RESULT VideoCaptureDeviceClient: interarrival_time= [0, 0,] us\n");
43 // TODO(phoglund): end hackhackhack.
45 static const char kGetUserMediaAndStop[] = "getUserMediaAndStop";
46 static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp";
47 static const char kGetUserMediaAndAnalyseAndStop[] =
48 "getUserMediaAndAnalyseAndStop";
49 static const char kGetUserMediaAndExpectFailure[] =
50 "getUserMediaAndExpectFailure";
51 static const char kRenderSameTrackMediastreamAndStop[] =
52 "renderSameTrackMediastreamAndStop";
53 static const char kRenderClonedMediastreamAndStop[] =
54 "renderClonedMediastreamAndStop";
55 static const char kRenderClonedTrackMediastreamAndStop[] =
56 "renderClonedTrackMediastreamAndStop";
57 static const char kRenderDuplicatedMediastreamAndStop[] =
58 "renderDuplicatedMediastreamAndStop";
60 // Results returned by JS.
61 static const char kOK[] = "OK";
63 std::string GenerateGetUserMediaWithMandatorySourceID(
64 const std::string& function_name,
65 const std::string& audio_source_id,
66 const std::string& video_source_id) {
67 const std::string audio_constraint =
68 "audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, ";
70 const std::string video_constraint =
71 "video: {mandatory: { sourceId:\"" + video_source_id + "\"}}";
72 return function_name + "({" + audio_constraint + video_constraint + "});";
75 std::string GenerateGetUserMediaWithOptionalSourceID(
76 const std::string& function_name,
77 const std::string& audio_source_id,
78 const std::string& video_source_id) {
79 const std::string audio_constraint =
80 "audio: {optional: [{sourceId:\"" + audio_source_id + "\"}]}, ";
82 const std::string video_constraint =
83 "video: {optional: [{ sourceId:\"" + video_source_id + "\"}]}";
84 return function_name + "({" + audio_constraint + video_constraint + "});";
87 } // namespace
89 namespace content {
91 #if DCHECK_IS_ON() && defined(OS_WIN)
92 // Flaky under win debug configs: http://crbug.com/517977.
93 #define MAYBE_WebRtcGetUserMediaBrowserTest DISABLED_WebRtcGetUserMediaBrowserTest
94 #else
95 #define MAYBE_WebRtcGetUserMediaBrowserTest WebRtcGetUserMediaBrowserTest
96 #endif
98 class MAYBE_WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest {
99 public:
100 MAYBE_WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {}
101 ~MAYBE_WebRtcGetUserMediaBrowserTest() override {}
103 void StartTracing() {
104 CHECK(trace_log_ == NULL) << "Can only can start tracing once";
105 trace_log_ = base::trace_event::TraceLog::GetInstance();
106 base::trace_event::TraceConfig trace_config(
107 "video", base::trace_event::RECORD_UNTIL_FULL);
108 trace_config.EnableSampling();
109 trace_log_->SetEnabled(trace_config,
110 base::trace_event::TraceLog::RECORDING_MODE);
111 // Check that we are indeed recording.
112 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1);
115 void StopTracing() {
116 CHECK(message_loop_runner_.get() == NULL)
117 << "Calling StopTracing more than once";
118 trace_log_->SetDisabled();
119 message_loop_runner_ = new MessageLoopRunner;
120 trace_log_->Flush(base::Bind(
121 &MAYBE_WebRtcGetUserMediaBrowserTest::OnTraceDataCollected,
122 base::Unretained(this)));
123 message_loop_runner_->Run();
126 void OnTraceDataCollected(
127 const scoped_refptr<base::RefCountedString>& events_str_ptr,
128 bool has_more_events) {
129 CHECK(!has_more_events);
130 recorded_trace_data_ = events_str_ptr;
131 message_loop_runner_->Quit();
134 TraceAnalyzer* CreateTraceAnalyzer() {
135 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
138 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs,
139 const std::string& measure_filter,
140 const std::string& graph_name) {
141 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
143 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
144 NavigateToURL(shell(), url);
146 // Put getUserMedia to work and let it run for a couple of seconds.
147 DCHECK(time_to_sample_secs);
148 ExecuteJavascriptAndWaitForOk(
149 base::StringPrintf("%s({video: true}, 'myStreamName');",
150 kGetUserMediaAndGetStreamUp));
152 // Now the stream is up and running, start collecting traces.
153 StartTracing();
155 ExecuteJavascriptAndWaitForOk(
156 base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);",
157 time_to_sample_secs));
159 // Wait until the page title changes to "OK". Do not sleep() here since that
160 // would stop both this code and the browser underneath.
161 StopTracing();
163 scoped_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer());
164 analyzer->AssociateBeginEndEvents();
165 trace_analyzer::TraceEventVector events;
166 DCHECK(measure_filter.size());
167 analyzer->FindEvents(
168 Query::EventNameIs(measure_filter),
169 &events);
170 ASSERT_GT(events.size(), 0u)
171 << "Could not collect any samples during test, this is bad";
173 std::string duration_us;
174 std::string interarrival_us;
175 for (size_t i = 0; i != events.size(); ++i) {
176 duration_us.append(
177 base::StringPrintf("%d,", static_cast<int>(events[i]->duration)));
180 for (size_t i = 1; i < events.size(); ++i) {
181 // The event |timestamp| comes in ns, divide to get us like |duration|.
182 interarrival_us.append(base::StringPrintf("%d,",
183 static_cast<int>((events[i]->timestamp - events[i - 1]->timestamp) /
184 base::Time::kNanosecondsPerMicrosecond)));
187 perf_test::PrintResultList(
188 graph_name, "", "sample_duration", duration_us, "us", true);
190 perf_test::PrintResultList(
191 graph_name, "", "interarrival_time", interarrival_us, "us", true);
194 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
195 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
196 const std::string& constraints1,
197 const std::string& constraints2,
198 const std::string& expected_result) {
199 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
201 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
202 NavigateToURL(shell(), url);
204 std::string command = "twoGetUserMedia(" + constraints1 + ',' +
205 constraints2 + ')';
207 EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command));
210 void GetInputDevices(std::vector<std::string>* audio_ids,
211 std::vector<std::string>* video_ids) {
212 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
213 NavigateToURL(shell(), url);
215 std::string devices_as_json = ExecuteJavascriptAndReturnResult(
216 "getSources()");
217 EXPECT_FALSE(devices_as_json.empty());
219 int error_code;
220 std::string error_message;
221 scoped_ptr<base::Value> value(
222 base::JSONReader::DeprecatedReadAndReturnError(
223 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code,
224 &error_message));
226 ASSERT_TRUE(value.get() != NULL) << error_message;
227 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
229 base::ListValue* values;
230 ASSERT_TRUE(value->GetAsList(&values));
232 for (base::ListValue::iterator it = values->begin();
233 it != values->end(); ++it) {
234 const base::DictionaryValue* dict;
235 std::string kind;
236 std::string device_id;
237 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
238 ASSERT_TRUE(dict->GetString("kind", &kind));
239 ASSERT_TRUE(dict->GetString("id", &device_id));
240 ASSERT_FALSE(device_id.empty());
241 EXPECT_TRUE(kind == "audio" || kind == "video");
242 if (kind == "audio") {
243 audio_ids->push_back(device_id);
244 } else if (kind == "video") {
245 video_ids->push_back(device_id);
248 ASSERT_FALSE(audio_ids->empty());
249 ASSERT_FALSE(video_ids->empty());
252 private:
253 base::trace_event::TraceLog* trace_log_;
254 scoped_refptr<base::RefCountedString> recorded_trace_data_;
255 scoped_refptr<MessageLoopRunner> message_loop_runner_;
258 // These tests will all make a getUserMedia call with different constraints and
259 // see that the success callback is called. If the error callback is called or
260 // none of the callbacks are called the tests will simply time out and fail.
262 // Test fails under MSan, http://crbug.com/445745
263 #if defined(MEMORY_SANITIZER)
264 #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
265 #else
266 #define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
267 #endif
268 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
269 MAYBE_GetVideoStreamAndStop) {
270 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
272 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
273 NavigateToURL(shell(), url);
275 ExecuteJavascriptAndWaitForOk(
276 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
279 // Test fails under MSan, http://crbug.com/445745
280 #if defined(MEMORY_SANITIZER)
281 #define MAYBE_RenderSameTrackMediastreamAndStop \
282 DISABLED_RenderSameTrackMediastreamAndStop
283 #else
284 #define MAYBE_RenderSameTrackMediastreamAndStop \
285 RenderSameTrackMediastreamAndStop
286 #endif
287 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
288 MAYBE_RenderSameTrackMediastreamAndStop) {
289 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
291 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
292 NavigateToURL(shell(), url);
294 ExecuteJavascriptAndWaitForOk(
295 base::StringPrintf("%s({video: true});",
296 kRenderSameTrackMediastreamAndStop));
299 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
300 RenderClonedMediastreamAndStop) {
301 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
303 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
304 NavigateToURL(shell(), url);
307 ExecuteJavascriptAndWaitForOk(
308 base::StringPrintf("%s({video: true});",
309 kRenderClonedMediastreamAndStop));
312 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
313 kRenderClonedTrackMediastreamAndStop) {
314 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
316 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
317 NavigateToURL(shell(), url);
319 ExecuteJavascriptAndWaitForOk(
320 base::StringPrintf("%s({video: true});",
321 kRenderClonedTrackMediastreamAndStop));
324 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
325 kRenderDuplicatedMediastreamAndStop) {
326 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
328 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
329 NavigateToURL(shell(), url);
331 ExecuteJavascriptAndWaitForOk(
332 base::StringPrintf("%s({video: true});",
333 kRenderDuplicatedMediastreamAndStop));
336 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
337 GetAudioAndVideoStreamAndStop) {
338 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
340 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
341 NavigateToURL(shell(), url);
343 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
344 "%s({video: true, audio: true});", kGetUserMediaAndStop));
347 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
348 GetAudioAndVideoStreamAndClone) {
349 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
351 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
352 NavigateToURL(shell(), url);
354 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
357 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
358 RenderVideoTrackInMultipleTagsAndPause) {
359 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
361 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
362 NavigateToURL(shell(), url);
364 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
369 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
370 GetUserMediaWithMandatorySourceID) {
371 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
373 std::vector<std::string> audio_ids;
374 std::vector<std::string> video_ids;
375 GetInputDevices(&audio_ids, &video_ids);
377 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
379 // Test all combinations of mandatory sourceID;
380 for (std::vector<std::string>::const_iterator video_it = video_ids.begin();
381 video_it != video_ids.end(); ++video_it) {
382 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin();
383 audio_it != audio_ids.end(); ++audio_it) {
384 NavigateToURL(shell(), url);
385 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
386 GenerateGetUserMediaWithMandatorySourceID(
387 kGetUserMediaAndStop,
388 *audio_it,
389 *video_it)));
394 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
395 GetUserMediaWithInvalidMandatorySourceID) {
396 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
398 std::vector<std::string> audio_ids;
399 std::vector<std::string> video_ids;
400 GetInputDevices(&audio_ids, &video_ids);
402 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
404 // Test with invalid mandatory audio sourceID.
405 NavigateToURL(shell(), url);
406 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
407 GenerateGetUserMediaWithMandatorySourceID(
408 kGetUserMediaAndExpectFailure,
409 "something invalid",
410 video_ids[0])));
412 // Test with invalid mandatory video sourceID.
413 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
414 GenerateGetUserMediaWithMandatorySourceID(
415 kGetUserMediaAndExpectFailure,
416 audio_ids[0],
417 "something invalid")));
419 // Test with empty mandatory audio sourceID.
420 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
421 GenerateGetUserMediaWithMandatorySourceID(
422 kGetUserMediaAndExpectFailure,
424 video_ids[0])));
427 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
428 GetUserMediaWithInvalidOptionalSourceID) {
429 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
431 std::vector<std::string> audio_ids;
432 std::vector<std::string> video_ids;
433 GetInputDevices(&audio_ids, &video_ids);
435 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
437 // Test with invalid optional audio sourceID.
438 NavigateToURL(shell(), url);
439 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
440 GenerateGetUserMediaWithOptionalSourceID(
441 kGetUserMediaAndStop,
442 "something invalid",
443 video_ids[0])));
445 // Test with invalid optional video sourceID.
446 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
447 GenerateGetUserMediaWithOptionalSourceID(
448 kGetUserMediaAndStop,
449 audio_ids[0],
450 "something invalid")));
452 // Test with empty optional audio sourceID.
453 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
454 GenerateGetUserMediaWithOptionalSourceID(
455 kGetUserMediaAndStop,
457 video_ids[0])));
460 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
461 TwoGetUserMediaAndStop) {
462 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
464 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
465 NavigateToURL(shell(), url);
467 ExecuteJavascriptAndWaitForOk(
468 "twoGetUserMediaAndStop({video: true, audio: true});");
471 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
472 TwoGetUserMediaWithEqualConstraints) {
473 std::string constraints1 = "{video: true, audio: true}";
474 const std::string& constraints2 = constraints1;
475 std::string expected_result = "w=640:h=480-w=640:h=480";
477 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
478 expected_result);
481 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
482 TwoGetUserMediaWithSecondVideoCropped) {
483 std::string constraints1 = "{video: true}";
484 std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}";
485 std::string expected_result = "w=640:h=480-w=640:h=360";
486 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
487 expected_result);
490 // Test fails under MSan, http://crbug.com/445745
491 #if defined(MEMORY_SANITIZER)
492 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
493 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
494 #else
495 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
496 TwoGetUserMediaWithFirstHdSecondVga
497 #endif
498 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
499 MAYBE_TwoGetUserMediaWithFirstHdSecondVga) {
500 std::string constraints1 =
501 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\
502 minHeight: 720}}}";
503 std::string constraints2 =
504 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
505 std::string expected_result = "w=1280:h=720-w=640:h=480";
506 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
507 expected_result);
510 #if defined(OS_WIN)
511 // Timing out on Winodws 7 bot: http://crbug.com/443294
512 #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
513 DISABLED_TwoGetUserMediaWithFirst1080pSecondVga
514 #else
515 #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
516 TwoGetUserMediaWithFirst1080pSecondVga
517 #endif
519 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
520 MAYBE_TwoGetUserMediaWithFirst1080pSecondVga) {
521 std::string constraints1 =
522 "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080,\
523 minHeight: 1080}}}";
524 std::string constraints2 =
525 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
526 std::string expected_result = "w=1920:h=1080-w=640:h=480";
527 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
528 expected_result);
531 // Test fails under MSan, http://crbug.com/445745
532 #if defined(MEMORY_SANITIZER)
533 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
534 DISABLED_TwoGetUserMediaAndVerifyFrameRate
535 #else
536 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
537 TwoGetUserMediaAndVerifyFrameRate
538 #endif
539 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
540 MAYBE_TwoGetUserMediaAndVerifyFrameRate) {
541 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
543 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
544 NavigateToURL(shell(), url);
546 std::string constraints1 =
547 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
548 "minFrameRate : 15, maxFrameRate : 15}}}";
549 std::string constraints2 =
550 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
551 "minFrameRate : 7, maxFrameRate : 7}}}";
553 std::string command = "twoGetUserMediaAndVerifyFrameRate(" +
554 constraints1 + ',' + constraints2 + ", 15, 7)";
555 ExecuteJavascriptAndWaitForOk(command);
558 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
559 GetUserMediaWithTooHighVideoConstraintsValues) {
560 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
562 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
564 int large_value = 99999;
565 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
566 large_value,
567 large_value,
568 large_value,
569 large_value,
570 large_value,
571 large_value);
572 NavigateToURL(shell(), url);
574 EXPECT_EQ("ConstraintNotSatisfiedError",
575 ExecuteJavascriptAndReturnResult(call));
578 // This test makes two getUserMedia requests, one with impossible constraints
579 // that should trigger an error, and one with valid constraints. The test
580 // verifies getUserMedia can succeed after being given impossible constraints.
581 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
582 TwoGetUserMediaAndCheckCallbackAfterFailure) {
583 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
585 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
586 NavigateToURL(shell(), url);
588 int large_value = 99999;
589 const std::string gum_with_impossible_constraints =
590 GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
591 large_value,
592 large_value,
593 large_value,
594 large_value,
595 large_value,
596 large_value);
597 const std::string gum_with_vga_constraints =
598 GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop,
599 640, 640, 480, 480, 10, 30);
601 ASSERT_EQ("ConstraintNotSatisfiedError",
602 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints));
604 ASSERT_EQ("w=640:h=480",
605 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints));
608 // This test will make a simple getUserMedia page, verify that video is playing
609 // in a simple local <video>, and for a couple of seconds, collect some
610 // performance traces from VideoCaptureController colorspace conversion and
611 // potential resizing.
612 IN_PROC_BROWSER_TEST_F(
613 MAYBE_WebRtcGetUserMediaBrowserTest,
614 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
615 RunGetUserMediaAndCollectMeasures(
617 "VideoCaptureDeviceClient::OnIncomingCapturedData",
618 "VideoCaptureDeviceClient");
621 // Test fails under MSan, http://crbug.com/445745
622 #if defined(MEMORY_SANITIZER)
623 #define MAYBE_TestGetUserMediaAspectRatio4To3 \
624 DISABLED_TestGetUserMediaAspectRatio4To3
625 #else
626 #define MAYBE_TestGetUserMediaAspectRatio4To3 TestGetUserMediaAspectRatio4To3
627 #endif
628 // This test calls getUserMedia and checks for aspect ratio behavior.
629 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
630 MAYBE_TestGetUserMediaAspectRatio4To3) {
631 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
633 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
635 std::string constraints_4_3 = GenerateGetUserMediaCall(
636 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
638 NavigateToURL(shell(), url);
639 ASSERT_EQ("w=640:h=480",
640 ExecuteJavascriptAndReturnResult(constraints_4_3));
643 // Test fails under MSan, http://crbug.com/445745
644 #if defined(MEMORY_SANITIZER)
645 #define MAYBE_TestGetUserMediaAspectRatio16To9 \
646 DISABLED_TestGetUserMediaAspectRatio16To9
647 #else
648 #define MAYBE_TestGetUserMediaAspectRatio16To9 TestGetUserMediaAspectRatio16To9
649 #endif
650 // This test calls getUserMedia and checks for aspect ratio behavior.
651 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
652 MAYBE_TestGetUserMediaAspectRatio16To9) {
653 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
655 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
657 std::string constraints_16_9 = GenerateGetUserMediaCall(
658 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
660 NavigateToURL(shell(), url);
661 ASSERT_EQ("w=640:h=360",
662 ExecuteJavascriptAndReturnResult(constraints_16_9));
665 // Test fails under MSan, http://crbug.com/445745
666 #if defined(MEMORY_SANITIZER)
667 #define MAYBE_TestGetUserMediaAspectRatio1To1 \
668 DISABLED_TestGetUserMediaAspectRatio1To1
669 #else
670 #define MAYBE_TestGetUserMediaAspectRatio1To1 TestGetUserMediaAspectRatio1To1
671 #endif
672 // This test calls getUserMedia and checks for aspect ratio behavior.
673 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
674 MAYBE_TestGetUserMediaAspectRatio1To1) {
675 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
677 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
679 std::string constraints_1_1 = GenerateGetUserMediaCall(
680 kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
682 NavigateToURL(shell(), url);
683 ASSERT_EQ("w=320:h=320",
684 ExecuteJavascriptAndReturnResult(constraints_1_1));
687 // This test calls getUserMedia in an iframe and immediately close the iframe
688 // in the scope of the success callback.
689 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
690 AudioInIFrameAndCloseInSuccessCb) {
691 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
693 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
694 NavigateToURL(shell(), url);
696 std::string call =
697 "getUserMediaInIframeAndCloseInSuccessCb({audio: true});";
698 ExecuteJavascriptAndWaitForOk(call);
701 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
702 VideoInIFrameAndCloseInSuccessCb) {
703 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
705 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
706 NavigateToURL(shell(), url);
708 std::string call =
709 "getUserMediaInIframeAndCloseInSuccessCb({video: true});";
710 ExecuteJavascriptAndWaitForOk(call);
713 // This test calls getUserMedia in an iframe and immediately close the iframe
714 // in the scope of the failure callback.
715 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
716 VideoWithBadConstraintsInIFrameAndCloseInFailureCb) {
717 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
719 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
721 int large_value = 99999;
722 std::string call =
723 GenerateGetUserMediaCall("getUserMediaInIframeAndCloseInFailureCb",
724 large_value,
725 large_value,
726 large_value,
727 large_value,
728 large_value,
729 large_value);
730 NavigateToURL(shell(), url);
732 ExecuteJavascriptAndWaitForOk(call);
735 IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcGetUserMediaBrowserTest,
736 InvalidSourceIdInIFrameAndCloseInFailureCb) {
737 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
739 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
741 std::string call =
742 GenerateGetUserMediaWithMandatorySourceID(
743 "getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid");
744 NavigateToURL(shell(), url);
746 ExecuteJavascriptAndWaitForOk(call);
749 namespace {
751 struct UserMediaSizes {
752 int min_width;
753 int max_width;
754 int min_height;
755 int max_height;
756 int min_frame_rate;
757 int max_frame_rate;
760 } // namespace
762 class WebRtcConstraintsBrowserTest
763 : public WebRtcContentBrowserTest,
764 public testing::WithParamInterface<UserMediaSizes> {
765 public:
766 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {}
767 const UserMediaSizes& user_media() const { return user_media_; }
769 private:
770 UserMediaSizes user_media_;
773 // Test fails under MSan, http://crbug.com/445745
774 #if defined(MEMORY_SANITIZER)
775 #define MAYBE_GetUserMediaConstraints DISABLED_GetUserMediaConstraints
776 #else
777 #define MAYBE_GetUserMediaConstraints GetUserMediaConstraints
778 #endif
779 // This test calls getUserMedia in sequence with different constraints.
780 IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest,
781 MAYBE_GetUserMediaConstraints) {
782 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
784 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
786 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop,
787 user_media().min_width,
788 user_media().max_width,
789 user_media().min_height,
790 user_media().max_height,
791 user_media().min_frame_rate,
792 user_media().max_frame_rate);
793 DVLOG(1) << "Calling getUserMedia: " << call;
794 NavigateToURL(shell(), url);
795 ExecuteJavascriptAndWaitForOk(call);
798 static const UserMediaSizes kAllUserMediaSizes[] = {
799 {320, 320, 180, 180, 10, 30},
800 {320, 320, 240, 240, 10, 30},
801 {640, 640, 360, 360, 10, 30},
802 {640, 640, 480, 480, 10, 30},
803 {960, 960, 720, 720, 10, 30},
804 {1280, 1280, 720, 720, 10, 30}};
806 INSTANTIATE_TEST_CASE_P(UserMedia,
807 WebRtcConstraintsBrowserTest,
808 testing::ValuesIn(kAllUserMediaSizes));
810 } // namespace content