Add a FrameHostMsg_BeginNavigation IPC
[chromium-blink-merge.git] / content / browser / media / webrtc_getusermedia_browsertest.cc
blob8821d64f458ac2e53e5f538e02e86b63b89a544a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/debug/trace_event_impl.h"
7 #include "base/json/json_reader.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/test/trace_event_analyzer.h"
10 #include "base/values.h"
11 #include "content/browser/media/webrtc_internals.h"
12 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/public/test/test_utils.h"
17 #include "content/shell/browser/shell.h"
18 #include "content/test/webrtc_content_browsertest_base.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h"
20 #include "testing/perf/perf_test.h"
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 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 + "});";
74 } // namespace
76 namespace content {
78 class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest,
79 public testing::WithParamInterface<bool> {
80 public:
81 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {}
82 virtual ~WebRtcGetUserMediaBrowserTest() {}
84 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
85 WebRtcContentBrowserTest::SetUpCommandLine(command_line);
87 bool enable_audio_track_processing = GetParam();
88 if (!enable_audio_track_processing)
89 command_line->AppendSwitch(switches::kDisableAudioTrackProcessing);
92 void StartTracing() {
93 CHECK(trace_log_ == NULL) << "Can only can start tracing once";
94 trace_log_ = base::debug::TraceLog::GetInstance();
95 trace_log_->SetEnabled(base::debug::CategoryFilter("video"),
96 base::debug::TraceLog::RECORDING_MODE,
97 base::debug::TraceLog::ENABLE_SAMPLING);
98 // Check that we are indeed recording.
99 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1);
102 void StopTracing() {
103 CHECK(message_loop_runner_ == NULL) << "Calling StopTracing more than once";
104 trace_log_->SetDisabled();
105 message_loop_runner_ = new MessageLoopRunner;
106 trace_log_->Flush(base::Bind(
107 &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected,
108 base::Unretained(this)));
109 message_loop_runner_->Run();
112 void OnTraceDataCollected(
113 const scoped_refptr<base::RefCountedString>& events_str_ptr,
114 bool has_more_events) {
115 CHECK(!has_more_events);
116 recorded_trace_data_ = events_str_ptr;
117 message_loop_runner_->Quit();
120 TraceAnalyzer* CreateTraceAnalyzer() {
121 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
124 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs,
125 const std::string& measure_filter,
126 const std::string& graph_name) {
127 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
129 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
130 NavigateToURL(shell(), url);
132 // Put getUserMedia to work and let it run for a couple of seconds.
133 DCHECK(time_to_sample_secs);
134 ExecuteJavascriptAndWaitForOk(
135 base::StringPrintf("%s({video: true});",
136 kGetUserMediaAndGetStreamUp));
138 // Now the stream is up and running, start collecting traces.
139 StartTracing();
141 // Let the stream run for a while in javascript.
142 ExecuteJavascriptAndWaitForOk(
143 base::StringPrintf("waitAndStopVideoTrack(%d);", time_to_sample_secs));
145 // Wait until the page title changes to "OK". Do not sleep() here since that
146 // would stop both this code and the browser underneath.
147 StopTracing();
149 scoped_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer());
150 analyzer->AssociateBeginEndEvents();
151 trace_analyzer::TraceEventVector events;
152 DCHECK(measure_filter.size());
153 analyzer->FindEvents(
154 Query::EventNameIs(measure_filter),
155 &events);
156 ASSERT_GT(events.size(), 0u)
157 << "Could not collect any samples during test, this is bad";
159 std::string duration_us;
160 std::string interarrival_us;
161 for (size_t i = 0; i != events.size(); ++i) {
162 duration_us.append(
163 base::StringPrintf("%d,", static_cast<int>(events[i]->duration)));
166 for (size_t i = 1; i < events.size(); ++i) {
167 // The event |timestamp| comes in ns, divide to get us like |duration|.
168 interarrival_us.append(base::StringPrintf("%d,",
169 static_cast<int>((events[i]->timestamp - events[i - 1]->timestamp) /
170 base::Time::kNanosecondsPerMicrosecond)));
173 perf_test::PrintResultList(
174 graph_name, "", "sample_duration", duration_us, "us", true);
176 perf_test::PrintResultList(
177 graph_name, "", "interarrival_time", interarrival_us, "us", true);
180 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
181 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
182 const std::string& constraints1,
183 const std::string& constraints2,
184 const std::string& expected_result) {
185 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
187 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
188 NavigateToURL(shell(), url);
190 std::string command = "twoGetUserMedia(" + constraints1 + ',' +
191 constraints2 + ')';
193 EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command));
196 void GetInputDevices(std::vector<std::string>* audio_ids,
197 std::vector<std::string>* video_ids) {
198 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
199 NavigateToURL(shell(), url);
201 std::string devices_as_json = ExecuteJavascriptAndReturnResult(
202 "getSources()");
203 EXPECT_FALSE(devices_as_json.empty());
205 int error_code;
206 std::string error_message;
207 scoped_ptr<base::Value> value(
208 base::JSONReader::ReadAndReturnError(devices_as_json,
209 base::JSON_ALLOW_TRAILING_COMMAS,
210 &error_code,
211 &error_message));
213 ASSERT_TRUE(value.get() != NULL) << error_message;
214 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
216 base::ListValue* values;
217 ASSERT_TRUE(value->GetAsList(&values));
219 for (base::ListValue::iterator it = values->begin();
220 it != values->end(); ++it) {
221 const base::DictionaryValue* dict;
222 std::string kind;
223 std::string device_id;
224 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
225 ASSERT_TRUE(dict->GetString("kind", &kind));
226 ASSERT_TRUE(dict->GetString("id", &device_id));
227 ASSERT_FALSE(device_id.empty());
228 EXPECT_TRUE(kind == "audio" || kind == "video");
229 if (kind == "audio") {
230 audio_ids->push_back(device_id);
231 } else if (kind == "video") {
232 video_ids->push_back(device_id);
235 ASSERT_FALSE(audio_ids->empty());
236 ASSERT_FALSE(video_ids->empty());
239 private:
240 base::debug::TraceLog* trace_log_;
241 scoped_refptr<base::RefCountedString> recorded_trace_data_;
242 scoped_refptr<MessageLoopRunner> message_loop_runner_;
245 static const bool kRunTestsWithFlag[] = { false, true };
246 INSTANTIATE_TEST_CASE_P(WebRtcGetUserMediaBrowserTests,
247 WebRtcGetUserMediaBrowserTest,
248 testing::ValuesIn(kRunTestsWithFlag));
250 // These tests will all make a getUserMedia call with different constraints and
251 // see that the success callback is called. If the error callback is called or
252 // none of the callbacks are called the tests will simply time out and fail.
253 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, GetVideoStreamAndStop) {
254 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
256 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
257 NavigateToURL(shell(), url);
259 ExecuteJavascriptAndWaitForOk(
260 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
263 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
264 RenderSameTrackMediastreamAndStop) {
265 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
267 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
268 NavigateToURL(shell(), url);
270 ExecuteJavascriptAndWaitForOk(
271 base::StringPrintf("%s({video: true});",
272 kRenderSameTrackMediastreamAndStop));
275 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
276 RenderClonedMediastreamAndStop) {
277 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
279 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
280 NavigateToURL(shell(), url);
283 ExecuteJavascriptAndWaitForOk(
284 base::StringPrintf("%s({video: true});",
285 kRenderClonedMediastreamAndStop));
288 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
289 kRenderClonedTrackMediastreamAndStop) {
290 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
292 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
293 NavigateToURL(shell(), url);
295 ExecuteJavascriptAndWaitForOk(
296 base::StringPrintf("%s({video: true});",
297 kRenderClonedTrackMediastreamAndStop));
300 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
301 kRenderDuplicatedMediastreamAndStop) {
302 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
304 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
305 NavigateToURL(shell(), url);
307 ExecuteJavascriptAndWaitForOk(
308 base::StringPrintf("%s({video: true});",
309 kRenderDuplicatedMediastreamAndStop));
312 // Flaky on Android. http://crbug.com/387895
313 #if defined(OS_ANDROID)
314 #define MAYBE_GetAudioAndVideoStreamAndStop DISABLED_GetAudioAndVideoStreamAndStop
315 #else
316 #define MAYBE_GetAudioAndVideoStreamAndStop GetAudioAndVideoStreamAndStop
317 #endif
319 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
320 MAYBE_GetAudioAndVideoStreamAndStop) {
321 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
323 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
324 NavigateToURL(shell(), url);
326 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
327 "%s({video: true, audio: true});", kGetUserMediaAndStop));
330 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
331 GetAudioAndVideoStreamAndClone) {
332 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
334 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
335 NavigateToURL(shell(), url);
337 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
340 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
341 RenderVideoTrackInMultipleTagsAndPause) {
342 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
344 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
345 NavigateToURL(shell(), url);
347 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
352 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
353 GetUserMediaWithMandatorySourceID) {
354 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
356 std::vector<std::string> audio_ids;
357 std::vector<std::string> video_ids;
358 GetInputDevices(&audio_ids, &video_ids);
360 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
362 // Test all combinations of mandatory sourceID;
363 for (std::vector<std::string>::const_iterator video_it = video_ids.begin();
364 video_it != video_ids.end(); ++video_it) {
365 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin();
366 audio_it != audio_ids.end(); ++audio_it) {
367 NavigateToURL(shell(), url);
368 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
369 GenerateGetUserMediaWithMandatorySourceID(
370 kGetUserMediaAndStop,
371 *audio_it,
372 *video_it)));
377 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
378 GetUserMediaWithInvalidMandatorySourceID) {
379 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
381 std::vector<std::string> audio_ids;
382 std::vector<std::string> video_ids;
383 GetInputDevices(&audio_ids, &video_ids);
385 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
387 // Test with invalid mandatory audio sourceID.
388 NavigateToURL(shell(), url);
389 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
390 GenerateGetUserMediaWithMandatorySourceID(
391 kGetUserMediaAndExpectFailure,
392 "something invalid",
393 video_ids[0])));
395 // Test with invalid mandatory video sourceID.
396 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
397 GenerateGetUserMediaWithMandatorySourceID(
398 kGetUserMediaAndExpectFailure,
399 audio_ids[0],
400 "something invalid")));
402 // Test with empty mandatory audio sourceID.
403 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
404 GenerateGetUserMediaWithMandatorySourceID(
405 kGetUserMediaAndExpectFailure,
407 video_ids[0])));
410 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
411 GetUserMediaWithInvalidOptionalSourceID) {
412 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
414 std::vector<std::string> audio_ids;
415 std::vector<std::string> video_ids;
416 GetInputDevices(&audio_ids, &video_ids);
418 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
420 // Test with invalid optional audio sourceID.
421 NavigateToURL(shell(), url);
422 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
423 GenerateGetUserMediaWithOptionalSourceID(
424 kGetUserMediaAndStop,
425 "something invalid",
426 video_ids[0])));
428 // Test with invalid optional video sourceID.
429 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
430 GenerateGetUserMediaWithOptionalSourceID(
431 kGetUserMediaAndStop,
432 audio_ids[0],
433 "something invalid")));
435 // Test with empty optional audio sourceID.
436 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
437 GenerateGetUserMediaWithOptionalSourceID(
438 kGetUserMediaAndStop,
440 video_ids[0])));
443 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, TwoGetUserMediaAndStop) {
444 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
446 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
447 NavigateToURL(shell(), url);
449 ExecuteJavascriptAndWaitForOk(
450 "twoGetUserMediaAndStop({video: true, audio: true});");
453 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
454 TwoGetUserMediaWithEqualConstraints) {
455 std::string constraints1 = "{video: true, audio: true}";
456 const std::string& constraints2 = constraints1;
457 std::string expected_result = "w=640:h=480-w=640:h=480";
459 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
460 expected_result);
463 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
464 TwoGetUserMediaWithSecondVideoCropped) {
465 std::string constraints1 = "{video: true}";
466 std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}";
467 std::string expected_result = "w=640:h=480-w=640:h=360";
468 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
469 expected_result);
472 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
473 TwoGetUserMediaWithFirstHdSecondVga) {
474 std::string constraints1 =
475 "{video: {mandatory: {minWidth:1280 , minHeight: 720}}}";
476 std::string constraints2 =
477 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
478 std::string expected_result = "w=1280:h=720-w=640:h=480";
479 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
480 expected_result);
483 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
484 TwoGetUserMediaAndVerifyFrameRate) {
485 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
487 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
488 NavigateToURL(shell(), url);
490 std::string constraints1 =
491 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
492 "minFrameRate : 15, maxFrameRate : 15}}}";
493 std::string constraints2 =
494 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
495 "minFrameRate : 7, maxFrameRate : 7}}}";
497 std::string command = "twoGetUserMediaAndVerifyFrameRate(" +
498 constraints1 + ',' + constraints2 + ", 15, 7)";
499 ExecuteJavascriptAndWaitForOk(command);
502 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
503 GetUserMediaWithTooHighVideoConstraintsValues) {
504 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
506 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
508 int large_value = 99999;
509 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
510 large_value,
511 large_value,
512 large_value,
513 large_value,
514 large_value,
515 large_value);
516 NavigateToURL(shell(), url);
518 // TODO(perkj): A proper error code should be returned by gUM.
519 EXPECT_EQ("TrackStartError", ExecuteJavascriptAndReturnResult(call));
522 // This test will make a simple getUserMedia page, verify that video is playing
523 // in a simple local <video>, and for a couple of seconds, collect some
524 // performance traces from VideoCaptureController colorspace conversion and
525 // potential resizing.
526 IN_PROC_BROWSER_TEST_P(
527 WebRtcGetUserMediaBrowserTest,
528 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
529 RunGetUserMediaAndCollectMeasures(
531 "VideoCaptureController::OnIncomingCapturedData",
532 "VideoCaptureController");
535 // This test calls getUserMedia and checks for aspect ratio behavior.
536 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
537 TestGetUserMediaAspectRatio4To3) {
538 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
540 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
542 std::string constraints_4_3 = GenerateGetUserMediaCall(
543 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
545 NavigateToURL(shell(), url);
546 ASSERT_EQ("w=640:h=480",
547 ExecuteJavascriptAndReturnResult(constraints_4_3));
550 // This test calls getUserMedia and checks for aspect ratio behavior.
551 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
552 TestGetUserMediaAspectRatio16To9) {
553 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
555 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
557 std::string constraints_16_9 = GenerateGetUserMediaCall(
558 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
560 NavigateToURL(shell(), url);
561 ASSERT_EQ("w=640:h=360",
562 ExecuteJavascriptAndReturnResult(constraints_16_9));
565 // This test calls getUserMedia and checks for aspect ratio behavior.
566 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
567 TestGetUserMediaAspectRatio1To1) {
568 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
570 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
572 std::string constraints_1_1 = GenerateGetUserMediaCall(
573 kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
575 NavigateToURL(shell(), url);
576 ASSERT_EQ("w=320:h=320",
577 ExecuteJavascriptAndReturnResult(constraints_1_1));
580 namespace {
582 struct UserMediaSizes {
583 int min_width;
584 int max_width;
585 int min_height;
586 int max_height;
587 int min_frame_rate;
588 int max_frame_rate;
591 } // namespace
593 class WebRtcConstraintsBrowserTest
594 : public WebRtcContentBrowserTest,
595 public testing::WithParamInterface<UserMediaSizes> {
596 public:
597 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {}
598 const UserMediaSizes& user_media() const { return user_media_; }
600 private:
601 UserMediaSizes user_media_;
604 // This test calls getUserMedia in sequence with different constraints.
605 IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest, GetUserMediaConstraints) {
606 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
608 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
610 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop,
611 user_media().min_width,
612 user_media().max_width,
613 user_media().min_height,
614 user_media().max_height,
615 user_media().min_frame_rate,
616 user_media().max_frame_rate);
617 DVLOG(1) << "Calling getUserMedia: " << call;
618 NavigateToURL(shell(), url);
619 ExecuteJavascriptAndWaitForOk(call);
622 static const UserMediaSizes kAllUserMediaSizes[] = {
623 {320, 320, 180, 180, 10, 30},
624 {320, 320, 240, 240, 10, 30},
625 {640, 640, 360, 360, 10, 30},
626 {640, 640, 480, 480, 10, 30},
627 {960, 960, 720, 720, 10, 30},
628 {1280, 1280, 720, 720, 10, 30}};
630 INSTANTIATE_TEST_CASE_P(UserMedia,
631 WebRtcConstraintsBrowserTest,
632 testing::ValuesIn(kAllUserMediaSizes));
634 } // namespace content