blob: 5229881bd23c5c33f978469a66d28d8fa56b0038 [file] [log] [blame]
[email protected]bdcc9702014-01-17 16:07:461// 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.
4
[email protected]99063682014-03-13 15:15:305#include "base/command_line.h"
[email protected]bdcc9702014-01-17 16:07:466#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"
[email protected]99063682014-03-13 15:15:3013#include "content/public/common/content_switches.h"
[email protected]bdcc9702014-01-17 16:07:4614#include "content/public/test/browser_test_utils.h"
[email protected]6e9def12014-03-27 20:23:2815#include "content/public/test/content_browser_test_utils.h"
[email protected]bdcc9702014-01-17 16:07:4616#include "content/public/test/test_utils.h"
17#include "content/shell/browser/shell.h"
[email protected]bdcc9702014-01-17 16:07:4618#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"
21
22#if defined(OS_WIN)
23#include "base/win/windows_version.h"
24#endif
25
26using trace_analyzer::TraceAnalyzer;
27using trace_analyzer::Query;
28using trace_analyzer::TraceEventVector;
29
30namespace {
31
32static const char kGetUserMediaAndStop[] = "getUserMediaAndStop";
[email protected]43ebe9e2014-03-08 21:00:5833static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp";
[email protected]bdcc9702014-01-17 16:07:4634static const char kGetUserMediaAndAnalyseAndStop[] =
35 "getUserMediaAndAnalyseAndStop";
[email protected]43ebe9e2014-03-08 21:00:5836static const char kGetUserMediaAndExpectFailure[] =
37 "getUserMediaAndExpectFailure";
[email protected]1670d032014-03-20 15:01:4538static const char kRenderSameTrackMediastreamAndStop[] =
39 "renderSameTrackMediastreamAndStop";
40static const char kRenderClonedMediastreamAndStop[] =
41 "renderClonedMediastreamAndStop";
42static const char kRenderClonedTrackMediastreamAndStop[] =
43 "renderClonedTrackMediastreamAndStop";
44static const char kRenderDuplicatedMediastreamAndStop[] =
45 "renderDuplicatedMediastreamAndStop";
[email protected]bdcc9702014-01-17 16:07:4646
47// Results returned by JS.
48static const char kOK[] = "OK";
[email protected]bdcc9702014-01-17 16:07:4649
50std::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 + "\"}}, ";
56
57 const std::string video_constraint =
58 "video: {mandatory: { sourceId:\"" + video_source_id + "\"}}";
59 return function_name + "({" + audio_constraint + video_constraint + "});";
60}
61
62std::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 + "\"}]}, ";
68
69 const std::string video_constraint =
70 "video: {optional: [{ sourceId:\"" + video_source_id + "\"}]}";
71 return function_name + "({" + audio_constraint + video_constraint + "});";
72}
73
74} // namespace
75
76namespace content {
77
[email protected]99063682014-03-13 15:15:3078class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest,
79 public testing::WithParamInterface<bool> {
[email protected]bdcc9702014-01-17 16:07:4680 public:
81 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {}
82 virtual ~WebRtcGetUserMediaBrowserTest() {}
83
[email protected]99063682014-03-13 15:15:3084 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
85 WebRtcContentBrowserTest::SetUpCommandLine(command_line);
86
87 bool enable_audio_track_processing = GetParam();
[email protected]8aa68072014-06-09 21:59:1288 if (!enable_audio_track_processing)
89 command_line->AppendSwitch(switches::kDisableAudioTrackProcessing);
[email protected]99063682014-03-13 15:15:3090 }
91
[email protected]bdcc9702014-01-17 16:07:4692 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);
100 }
101
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();
110 }
111
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();
118 }
119
120 TraceAnalyzer* CreateTraceAnalyzer() {
121 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
122 }
123
[email protected]3fa8aa12014-01-20 19:06:54124 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());
128
129 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
130 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58131
[email protected]3fa8aa12014-01-20 19:06:54132 // Put getUserMedia to work and let it run for a couple of seconds.
133 DCHECK(time_to_sample_secs);
[email protected]1670d032014-03-20 15:01:45134 ExecuteJavascriptAndWaitForOk(
135 base::StringPrintf("%s({video: true});",
136 kGetUserMediaAndGetStreamUp));
[email protected]3fa8aa12014-01-20 19:06:54137
[email protected]43ebe9e2014-03-08 21:00:58138 // Now the stream is up and running, start collecting traces.
[email protected]3fa8aa12014-01-20 19:06:54139 StartTracing();
140
[email protected]43ebe9e2014-03-08 21:00:58141 // Let the stream run for a while in javascript.
142 ExecuteJavascriptAndWaitForOk(
143 base::StringPrintf("waitAndStopVideoTrack(%d);", time_to_sample_secs));
144
[email protected]3fa8aa12014-01-20 19:06:54145 // Wait until the page title changes to "OK". Do not sleep() here since that
146 // would stop both this code and the browser underneath.
[email protected]3fa8aa12014-01-20 19:06:54147 StopTracing();
148
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";
158
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)));
164 }
165
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)));
171 }
172
173 perf_test::PrintResultList(
174 graph_name, "", "sample_duration", duration_us, "us", true);
175
176 perf_test::PrintResultList(
177 graph_name, "", "interarrival_time", interarrival_us, "us", true);
178 }
179
[email protected]ff993f92014-05-22 17:24:00180 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
181 const std::string& constraints1,
182 const std::string& constraints2,
183 const std::string& expected_result) {
184 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
185
186 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
187 NavigateToURL(shell(), url);
188
189 std::string command = "twoGetUserMedia(" + constraints1 + ',' +
190 constraints2 + ')';
191
192 EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command));
193 }
194
[email protected]8926d5692014-06-11 05:02:22195 void GetInputDevices(std::vector<std::string>* audio_ids,
196 std::vector<std::string>* video_ids) {
[email protected]bdcc9702014-01-17 16:07:46197 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
198 NavigateToURL(shell(), url);
199
[email protected]8926d5692014-06-11 05:02:22200 std::string devices_as_json = ExecuteJavascriptAndReturnResult(
201 "getMediaDevices()");
202 EXPECT_FALSE(devices_as_json.empty());
[email protected]bdcc9702014-01-17 16:07:46203
204 int error_code;
205 std::string error_message;
206 scoped_ptr<base::Value> value(
[email protected]8926d5692014-06-11 05:02:22207 base::JSONReader::ReadAndReturnError(devices_as_json,
[email protected]bdcc9702014-01-17 16:07:46208 base::JSON_ALLOW_TRAILING_COMMAS,
209 &error_code,
210 &error_message));
211
212 ASSERT_TRUE(value.get() != NULL) << error_message;
213 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
214
215 base::ListValue* values;
216 ASSERT_TRUE(value->GetAsList(&values));
217
218 for (base::ListValue::iterator it = values->begin();
219 it != values->end(); ++it) {
220 const base::DictionaryValue* dict;
221 std::string kind;
[email protected]8926d5692014-06-11 05:02:22222 std::string device_id;
[email protected]bdcc9702014-01-17 16:07:46223 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
224 ASSERT_TRUE(dict->GetString("kind", &kind));
[email protected]8926d5692014-06-11 05:02:22225 ASSERT_TRUE(dict->GetString("deviceId", &device_id));
226 ASSERT_FALSE(device_id.empty());
227 EXPECT_TRUE(kind == "audioinput" || kind == "videoinput" ||
228 kind == "audiooutput");
229 if (kind == "audioinput") {
230 audio_ids->push_back(device_id);
231 } else if (kind == "videoinput") {
232 video_ids->push_back(device_id);
[email protected]bdcc9702014-01-17 16:07:46233 }
[email protected]8926d5692014-06-11 05:02:22234 // We ignore audio output.
[email protected]bdcc9702014-01-17 16:07:46235 }
236 ASSERT_FALSE(audio_ids->empty());
237 ASSERT_FALSE(video_ids->empty());
238 }
239
240 private:
241 base::debug::TraceLog* trace_log_;
242 scoped_refptr<base::RefCountedString> recorded_trace_data_;
243 scoped_refptr<MessageLoopRunner> message_loop_runner_;
244};
245
[email protected]99063682014-03-13 15:15:30246static const bool kRunTestsWithFlag[] = { false, true };
247INSTANTIATE_TEST_CASE_P(WebRtcGetUserMediaBrowserTests,
248 WebRtcGetUserMediaBrowserTest,
249 testing::ValuesIn(kRunTestsWithFlag));
250
[email protected]bdcc9702014-01-17 16:07:46251// These tests will all make a getUserMedia call with different constraints and
252// see that the success callback is called. If the error callback is called or
253// none of the callbacks are called the tests will simply time out and fail.
[email protected]99063682014-03-13 15:15:30254IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, GetVideoStreamAndStop) {
[email protected]bdcc9702014-01-17 16:07:46255 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
256
257 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
258 NavigateToURL(shell(), url);
259
[email protected]43ebe9e2014-03-08 21:00:58260 ExecuteJavascriptAndWaitForOk(
261 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46262}
263
[email protected]99063682014-03-13 15:15:30264IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45265 RenderSameTrackMediastreamAndStop) {
266 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
267
268 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
269 NavigateToURL(shell(), url);
270
271 ExecuteJavascriptAndWaitForOk(
272 base::StringPrintf("%s({video: true});",
273 kRenderSameTrackMediastreamAndStop));
274}
275
276IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
277 RenderClonedMediastreamAndStop) {
278 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
279
280 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
281 NavigateToURL(shell(), url);
282
283
284 ExecuteJavascriptAndWaitForOk(
285 base::StringPrintf("%s({video: true});",
286 kRenderClonedMediastreamAndStop));
287}
288
289IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
290 kRenderClonedTrackMediastreamAndStop) {
291 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
292
293 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
294 NavigateToURL(shell(), url);
295
296 ExecuteJavascriptAndWaitForOk(
297 base::StringPrintf("%s({video: true});",
298 kRenderClonedTrackMediastreamAndStop));
299}
300
301IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
302 kRenderDuplicatedMediastreamAndStop) {
303 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
304
305 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
306 NavigateToURL(shell(), url);
307
308 ExecuteJavascriptAndWaitForOk(
309 base::StringPrintf("%s({video: true});",
310 kRenderDuplicatedMediastreamAndStop));
311}
312
313IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46314 GetAudioAndVideoStreamAndStop) {
315 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
316
317 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
318 NavigateToURL(shell(), url);
319
[email protected]43ebe9e2014-03-08 21:00:58320 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
321 "%s({video: true, audio: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46322}
323
[email protected]99063682014-03-13 15:15:30324IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46325 GetAudioAndVideoStreamAndClone) {
326 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
327
328 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
329 NavigateToURL(shell(), url);
330
[email protected]43ebe9e2014-03-08 21:00:58331 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
[email protected]bdcc9702014-01-17 16:07:46332}
333
[email protected]99063682014-03-13 15:15:30334IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]c6062872014-03-21 14:35:37335 RenderVideoTrackInMultipleTagsAndPause) {
336 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
337
338 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
339 NavigateToURL(shell(), url);
340
341 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
342}
343
344
345
346IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46347 GetUserMediaWithMandatorySourceID) {
348 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
349
350 std::vector<std::string> audio_ids;
351 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22352 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46353
354 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
355
356 // Test all combinations of mandatory sourceID;
357 for (std::vector<std::string>::const_iterator video_it = video_ids.begin();
358 video_it != video_ids.end(); ++video_it) {
359 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin();
360 audio_it != audio_ids.end(); ++audio_it) {
361 NavigateToURL(shell(), url);
362 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
363 GenerateGetUserMediaWithMandatorySourceID(
364 kGetUserMediaAndStop,
365 *audio_it,
366 *video_it)));
367 }
368 }
369}
370
[email protected]99063682014-03-13 15:15:30371IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46372 GetUserMediaWithInvalidMandatorySourceID) {
373 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
374
375 std::vector<std::string> audio_ids;
376 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22377 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46378
379 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
380
381 // Test with invalid mandatory audio sourceID.
382 NavigateToURL(shell(), url);
[email protected]32d377412014-03-19 21:15:43383 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46384 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58385 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46386 "something invalid",
[email protected]0c7158b2014-03-17 16:46:38387 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46388
389 // Test with invalid mandatory video sourceID.
[email protected]32d377412014-03-19 21:15:43390 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46391 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58392 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46393 audio_ids[0],
[email protected]0c7158b2014-03-17 16:46:38394 "something invalid")));
[email protected]bdcc9702014-01-17 16:07:46395
396 // Test with empty mandatory audio sourceID.
[email protected]32d377412014-03-19 21:15:43397 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46398 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58399 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46400 "",
[email protected]0c7158b2014-03-17 16:46:38401 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46402}
403
[email protected]99063682014-03-13 15:15:30404IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46405 GetUserMediaWithInvalidOptionalSourceID) {
406 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
407
408 std::vector<std::string> audio_ids;
409 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22410 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46411
412 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
413
414 // Test with invalid optional audio sourceID.
415 NavigateToURL(shell(), url);
416 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
417 GenerateGetUserMediaWithOptionalSourceID(
418 kGetUserMediaAndStop,
419 "something invalid",
420 video_ids[0])));
421
422 // Test with invalid optional video sourceID.
423 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
424 GenerateGetUserMediaWithOptionalSourceID(
425 kGetUserMediaAndStop,
426 audio_ids[0],
427 "something invalid")));
428
429 // Test with empty optional audio sourceID.
430 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
431 GenerateGetUserMediaWithOptionalSourceID(
432 kGetUserMediaAndStop,
433 "",
434 video_ids[0])));
435}
436
[email protected]99063682014-03-13 15:15:30437IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, TwoGetUserMediaAndStop) {
[email protected]bdcc9702014-01-17 16:07:46438 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
439
440 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
441 NavigateToURL(shell(), url);
442
[email protected]43ebe9e2014-03-08 21:00:58443 ExecuteJavascriptAndWaitForOk(
444 "twoGetUserMediaAndStop({video: true, audio: true});");
[email protected]bdcc9702014-01-17 16:07:46445}
446
[email protected]0c7158b2014-03-17 16:46:38447IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]ff993f92014-05-22 17:24:00448 TwoGetUserMediaWithEqualConstraints) {
449 std::string constraints1 = "{video: true, audio: true}";
450 const std::string& constraints2 = constraints1;
451 std::string expected_result = "w=640:h=480-w=640:h=480";
452
453 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
454 expected_result);
455 }
456
457IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
458 TwoGetUserMediaWithSecondVideoCropped) {
459 std::string constraints1 = "{video: true}";
460 std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}";
461 std::string expected_result = "w=640:h=480-w=640:h=360";
462 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
463 expected_result);
464}
465
466IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]8d5a3282014-06-06 22:01:28467 DISABLED_TwoGetUserMediaWithFirstHdSecondVga) {
[email protected]ff993f92014-05-22 17:24:00468 std::string constraints1 =
469 "{video: {mandatory: {minWidth:1280 , minHeight: 720}}}";
470 std::string constraints2 =
471 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
472 std::string expected_result = "w=1280:h=720-w=640:h=480";
473 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
474 expected_result);
475}
476
477IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]0c7158b2014-03-17 16:46:38478 GetUserMediaWithTooHighVideoConstraintsValues) {
479 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
480
481 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
482
483 int large_value = 99999;
484 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
485 large_value,
486 large_value,
487 large_value,
488 large_value,
489 large_value,
490 large_value);
491 NavigateToURL(shell(), url);
492
493 // TODO(perkj): A proper error code should be returned by gUM.
494 EXPECT_EQ("TrackStartError", ExecuteJavascriptAndReturnResult(call));
495}
496
[email protected]bdcc9702014-01-17 16:07:46497// This test will make a simple getUserMedia page, verify that video is playing
498// in a simple local <video>, and for a couple of seconds, collect some
[email protected]3fa8aa12014-01-20 19:06:54499// performance traces from VideoCaptureController colorspace conversion and
500// potential resizing.
[email protected]99063682014-03-13 15:15:30501IN_PROC_BROWSER_TEST_P(
[email protected]3fa8aa12014-01-20 19:06:54502 WebRtcGetUserMediaBrowserTest,
503 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
504 RunGetUserMediaAndCollectMeasures(
505 10,
[email protected]5a642032014-02-28 15:43:28506 "VideoCaptureController::OnIncomingCapturedData",
[email protected]3fa8aa12014-01-20 19:06:54507 "VideoCaptureController");
[email protected]bdcc9702014-01-17 16:07:46508}
509
[email protected]bdcc9702014-01-17 16:07:46510// This test calls getUserMedia and checks for aspect ratio behavior.
[email protected]99063682014-03-13 15:15:30511IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]856f7cbd2014-03-07 09:54:32512 TestGetUserMediaAspectRatio4To3) {
[email protected]bdcc9702014-01-17 16:07:46513 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
514
515 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
516
517 std::string constraints_4_3 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07518 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46519
[email protected]bdcc9702014-01-17 16:07:46520 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05521 ASSERT_EQ("w=640:h=480",
[email protected]43ebe9e2014-03-08 21:00:58522 ExecuteJavascriptAndReturnResult(constraints_4_3));
[email protected]856f7cbd2014-03-07 09:54:32523}
524
525// This test calls getUserMedia and checks for aspect ratio behavior.
[email protected]99063682014-03-13 15:15:30526IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
[email protected]599b15a22014-03-27 16:33:10527 TestGetUserMediaAspectRatio16To9) {
[email protected]856f7cbd2014-03-07 09:54:32528 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
529
530 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
531
532 std::string constraints_16_9 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07533 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46534
535 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05536 ASSERT_EQ("w=640:h=360",
[email protected]43ebe9e2014-03-08 21:00:58537 ExecuteJavascriptAndReturnResult(constraints_16_9));
[email protected]bdcc9702014-01-17 16:07:46538}
539
[email protected]b5d213b2014-03-27 11:45:05540// This test calls getUserMedia and checks for aspect ratio behavior.
[email protected]599b15a22014-03-27 16:33:10541IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
542 TestGetUserMediaAspectRatio1To1) {
[email protected]b5d213b2014-03-27 11:45:05543 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
544
545 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
546
547 std::string constraints_1_1 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07548 kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
[email protected]b5d213b2014-03-27 11:45:05549
550 NavigateToURL(shell(), url);
551 ASSERT_EQ("w=320:h=320",
552 ExecuteJavascriptAndReturnResult(constraints_1_1));
553}
554
[email protected]bdcc9702014-01-17 16:07:46555namespace {
556
557struct UserMediaSizes {
558 int min_width;
559 int max_width;
560 int min_height;
561 int max_height;
562 int min_frame_rate;
563 int max_frame_rate;
564};
565
566} // namespace
567
568class WebRtcConstraintsBrowserTest
[email protected]99063682014-03-13 15:15:30569 : public WebRtcContentBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46570 public testing::WithParamInterface<UserMediaSizes> {
571 public:
572 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {}
573 const UserMediaSizes& user_media() const { return user_media_; }
574
575 private:
576 UserMediaSizes user_media_;
577};
578
579// This test calls getUserMedia in sequence with different constraints.
580IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest, GetUserMediaConstraints) {
581 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
582
583 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
584
585 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop,
586 user_media().min_width,
587 user_media().max_width,
588 user_media().min_height,
589 user_media().max_height,
590 user_media().min_frame_rate,
591 user_media().max_frame_rate);
592 DVLOG(1) << "Calling getUserMedia: " << call;
593 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58594 ExecuteJavascriptAndWaitForOk(call);
[email protected]bdcc9702014-01-17 16:07:46595}
596
597static const UserMediaSizes kAllUserMediaSizes[] = {
[email protected]cbc7d672014-04-04 09:27:07598 {320, 320, 180, 180, 10, 30},
599 {320, 320, 240, 240, 10, 30},
600 {640, 640, 360, 360, 10, 30},
601 {640, 640, 480, 480, 10, 30},
602 {960, 960, 720, 720, 10, 30},
603 {1280, 1280, 720, 720, 10, 30}};
[email protected]bdcc9702014-01-17 16:07:46604
605INSTANTIATE_TEST_CASE_P(UserMedia,
606 WebRtcConstraintsBrowserTest,
607 testing::ValuesIn(kAllUserMediaSizes));
608
609} // namespace content