blob: ead80561bb742e640a4f88ee9b1bbf0b47f88433 [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]118c4582014-07-17 08:02:0878class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest {
[email protected]bdcc9702014-01-17 16:07:4679 public:
80 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {}
81 virtual ~WebRtcGetUserMediaBrowserTest() {}
82
83 void StartTracing() {
84 CHECK(trace_log_ == NULL) << "Can only can start tracing once";
85 trace_log_ = base::debug::TraceLog::GetInstance();
[email protected]4753b9e2014-08-04 16:30:5286 base::debug::TraceOptions trace_options(base::debug::RECORD_UNTIL_FULL);
87 trace_options.enable_sampling = true;
[email protected]bdcc9702014-01-17 16:07:4688 trace_log_->SetEnabled(base::debug::CategoryFilter("video"),
89 base::debug::TraceLog::RECORDING_MODE,
[email protected]4753b9e2014-08-04 16:30:5290 trace_options);
[email protected]bdcc9702014-01-17 16:07:4691 // Check that we are indeed recording.
92 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1);
93 }
94
95 void StopTracing() {
dcheng7707e972014-08-26 19:37:0196 CHECK(message_loop_runner_.get() == NULL)
97 << "Calling StopTracing more than once";
[email protected]bdcc9702014-01-17 16:07:4698 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();
104 }
105
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();
112 }
113
114 TraceAnalyzer* CreateTraceAnalyzer() {
115 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
116 }
117
[email protected]3fa8aa12014-01-20 19:06:54118 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());
122
123 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
124 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58125
[email protected]3fa8aa12014-01-20 19:06:54126 // Put getUserMedia to work and let it run for a couple of seconds.
127 DCHECK(time_to_sample_secs);
[email protected]1670d032014-03-20 15:01:45128 ExecuteJavascriptAndWaitForOk(
phoglund4eb75452014-10-07 15:34:07129 base::StringPrintf("%s({video: true}, 'myStreamName');",
[email protected]1670d032014-03-20 15:01:45130 kGetUserMediaAndGetStreamUp));
[email protected]3fa8aa12014-01-20 19:06:54131
[email protected]43ebe9e2014-03-08 21:00:58132 // Now the stream is up and running, start collecting traces.
[email protected]3fa8aa12014-01-20 19:06:54133 StartTracing();
134
[email protected]43ebe9e2014-03-08 21:00:58135 ExecuteJavascriptAndWaitForOk(
phoglund4eb75452014-10-07 15:34:07136 base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);",
137 time_to_sample_secs));
[email protected]43ebe9e2014-03-08 21:00:58138
[email protected]3fa8aa12014-01-20 19:06:54139 // Wait until the page title changes to "OK". Do not sleep() here since that
140 // would stop both this code and the browser underneath.
[email protected]3fa8aa12014-01-20 19:06:54141 StopTracing();
142
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),
149 &events);
150 ASSERT_GT(events.size(), 0u)
151 << "Could not collect any samples during test, this is bad";
152
153 std::string duration_us;
154 std::string interarrival_us;
155 for (size_t i = 0; i != events.size(); ++i) {
156 duration_us.append(
157 base::StringPrintf("%d,", static_cast<int>(events[i]->duration)));
158 }
159
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)));
165 }
166
167 perf_test::PrintResultList(
168 graph_name, "", "sample_duration", duration_us, "us", true);
169
170 perf_test::PrintResultList(
171 graph_name, "", "interarrival_time", interarrival_us, "us", true);
172 }
173
[email protected]697173d2014-06-26 11:52:13174 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
[email protected]ff993f92014-05-22 17:24:00175 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());
180
181 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
182 NavigateToURL(shell(), url);
183
184 std::string command = "twoGetUserMedia(" + constraints1 + ',' +
185 constraints2 + ')';
186
187 EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command));
188 }
189
[email protected]8926d5692014-06-11 05:02:22190 void GetInputDevices(std::vector<std::string>* audio_ids,
191 std::vector<std::string>* video_ids) {
[email protected]bdcc9702014-01-17 16:07:46192 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
193 NavigateToURL(shell(), url);
194
[email protected]8926d5692014-06-11 05:02:22195 std::string devices_as_json = ExecuteJavascriptAndReturnResult(
[email protected]b9ced842014-07-03 13:10:03196 "getSources()");
[email protected]8926d5692014-06-11 05:02:22197 EXPECT_FALSE(devices_as_json.empty());
[email protected]bdcc9702014-01-17 16:07:46198
199 int error_code;
200 std::string error_message;
201 scoped_ptr<base::Value> value(
[email protected]8926d5692014-06-11 05:02:22202 base::JSONReader::ReadAndReturnError(devices_as_json,
[email protected]bdcc9702014-01-17 16:07:46203 base::JSON_ALLOW_TRAILING_COMMAS,
204 &error_code,
205 &error_message));
206
207 ASSERT_TRUE(value.get() != NULL) << error_message;
208 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
209
210 base::ListValue* values;
211 ASSERT_TRUE(value->GetAsList(&values));
212
213 for (base::ListValue::iterator it = values->begin();
214 it != values->end(); ++it) {
215 const base::DictionaryValue* dict;
216 std::string kind;
[email protected]8926d5692014-06-11 05:02:22217 std::string device_id;
[email protected]bdcc9702014-01-17 16:07:46218 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
219 ASSERT_TRUE(dict->GetString("kind", &kind));
[email protected]b9ced842014-07-03 13:10:03220 ASSERT_TRUE(dict->GetString("id", &device_id));
[email protected]8926d5692014-06-11 05:02:22221 ASSERT_FALSE(device_id.empty());
[email protected]b9ced842014-07-03 13:10:03222 EXPECT_TRUE(kind == "audio" || kind == "video");
223 if (kind == "audio") {
[email protected]8926d5692014-06-11 05:02:22224 audio_ids->push_back(device_id);
[email protected]b9ced842014-07-03 13:10:03225 } else if (kind == "video") {
[email protected]8926d5692014-06-11 05:02:22226 video_ids->push_back(device_id);
[email protected]bdcc9702014-01-17 16:07:46227 }
228 }
229 ASSERT_FALSE(audio_ids->empty());
230 ASSERT_FALSE(video_ids->empty());
231 }
232
233 private:
234 base::debug::TraceLog* trace_log_;
235 scoped_refptr<base::RefCountedString> recorded_trace_data_;
236 scoped_refptr<MessageLoopRunner> message_loop_runner_;
237};
238
239// These tests will all make a getUserMedia call with different constraints and
240// see that the success callback is called. If the error callback is called or
241// none of the callbacks are called the tests will simply time out and fail.
[email protected]118c4582014-07-17 08:02:08242IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, GetVideoStreamAndStop) {
[email protected]bdcc9702014-01-17 16:07:46243 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
244
245 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
246 NavigateToURL(shell(), url);
247
[email protected]43ebe9e2014-03-08 21:00:58248 ExecuteJavascriptAndWaitForOk(
249 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46250}
251
[email protected]118c4582014-07-17 08:02:08252IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45253 RenderSameTrackMediastreamAndStop) {
254 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
255
256 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
257 NavigateToURL(shell(), url);
258
259 ExecuteJavascriptAndWaitForOk(
260 base::StringPrintf("%s({video: true});",
261 kRenderSameTrackMediastreamAndStop));
262}
263
[email protected]118c4582014-07-17 08:02:08264IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45265 RenderClonedMediastreamAndStop) {
266 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
267
268 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
269 NavigateToURL(shell(), url);
270
271
272 ExecuteJavascriptAndWaitForOk(
273 base::StringPrintf("%s({video: true});",
274 kRenderClonedMediastreamAndStop));
275}
276
[email protected]118c4582014-07-17 08:02:08277IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45278 kRenderClonedTrackMediastreamAndStop) {
279 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
280
281 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
282 NavigateToURL(shell(), url);
283
284 ExecuteJavascriptAndWaitForOk(
285 base::StringPrintf("%s({video: true});",
286 kRenderClonedTrackMediastreamAndStop));
287}
288
[email protected]118c4582014-07-17 08:02:08289IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45290 kRenderDuplicatedMediastreamAndStop) {
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 kRenderDuplicatedMediastreamAndStop));
299}
300
jam290d2cf2014-10-06 17:23:51301// Flaky on Android. http://crbug.com/387895
302#if defined(OS_ANDROID)
303#define MAYBE_GetAudioAndVideoStreamAndStop DISABLED_GetAudioAndVideoStreamAndStop
304#else
305#define MAYBE_GetAudioAndVideoStreamAndStop GetAudioAndVideoStreamAndStop
306#endif
307
[email protected]118c4582014-07-17 08:02:08308IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jam290d2cf2014-10-06 17:23:51309 MAYBE_GetAudioAndVideoStreamAndStop) {
[email protected]bdcc9702014-01-17 16:07:46310 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
311
312 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
313 NavigateToURL(shell(), url);
314
[email protected]43ebe9e2014-03-08 21:00:58315 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
316 "%s({video: true, audio: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46317}
318
[email protected]118c4582014-07-17 08:02:08319IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46320 GetAudioAndVideoStreamAndClone) {
321 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
322
323 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
324 NavigateToURL(shell(), url);
325
[email protected]43ebe9e2014-03-08 21:00:58326 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
[email protected]bdcc9702014-01-17 16:07:46327}
328
[email protected]118c4582014-07-17 08:02:08329IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]c6062872014-03-21 14:35:37330 RenderVideoTrackInMultipleTagsAndPause) {
331 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
332
333 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
334 NavigateToURL(shell(), url);
335
336 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
337}
338
339
340
[email protected]118c4582014-07-17 08:02:08341IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46342 GetUserMediaWithMandatorySourceID) {
343 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
344
345 std::vector<std::string> audio_ids;
346 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22347 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46348
349 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
350
351 // Test all combinations of mandatory sourceID;
352 for (std::vector<std::string>::const_iterator video_it = video_ids.begin();
353 video_it != video_ids.end(); ++video_it) {
354 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin();
355 audio_it != audio_ids.end(); ++audio_it) {
356 NavigateToURL(shell(), url);
357 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
358 GenerateGetUserMediaWithMandatorySourceID(
359 kGetUserMediaAndStop,
360 *audio_it,
361 *video_it)));
362 }
363 }
364}
365
[email protected]118c4582014-07-17 08:02:08366IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46367 GetUserMediaWithInvalidMandatorySourceID) {
368 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
369
370 std::vector<std::string> audio_ids;
371 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22372 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46373
374 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
375
376 // Test with invalid mandatory audio sourceID.
377 NavigateToURL(shell(), url);
[email protected]32d377412014-03-19 21:15:43378 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46379 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58380 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46381 "something invalid",
[email protected]0c7158b2014-03-17 16:46:38382 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46383
384 // Test with invalid mandatory video sourceID.
[email protected]32d377412014-03-19 21:15:43385 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46386 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58387 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46388 audio_ids[0],
[email protected]0c7158b2014-03-17 16:46:38389 "something invalid")));
[email protected]bdcc9702014-01-17 16:07:46390
391 // Test with empty mandatory audio sourceID.
[email protected]32d377412014-03-19 21:15:43392 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46393 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58394 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46395 "",
[email protected]0c7158b2014-03-17 16:46:38396 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46397}
398
[email protected]118c4582014-07-17 08:02:08399IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46400 GetUserMediaWithInvalidOptionalSourceID) {
401 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
402
403 std::vector<std::string> audio_ids;
404 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22405 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46406
407 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
408
409 // Test with invalid optional audio sourceID.
410 NavigateToURL(shell(), url);
411 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
412 GenerateGetUserMediaWithOptionalSourceID(
413 kGetUserMediaAndStop,
414 "something invalid",
415 video_ids[0])));
416
417 // Test with invalid optional video sourceID.
418 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
419 GenerateGetUserMediaWithOptionalSourceID(
420 kGetUserMediaAndStop,
421 audio_ids[0],
422 "something invalid")));
423
424 // Test with empty optional audio sourceID.
425 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
426 GenerateGetUserMediaWithOptionalSourceID(
427 kGetUserMediaAndStop,
428 "",
429 video_ids[0])));
430}
431
[email protected]118c4582014-07-17 08:02:08432IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, TwoGetUserMediaAndStop) {
[email protected]bdcc9702014-01-17 16:07:46433 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
434
435 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
436 NavigateToURL(shell(), url);
437
[email protected]43ebe9e2014-03-08 21:00:58438 ExecuteJavascriptAndWaitForOk(
439 "twoGetUserMediaAndStop({video: true, audio: true});");
[email protected]bdcc9702014-01-17 16:07:46440}
441
jam290d2cf2014-10-06 17:23:51442#if defined(OS_WIN) && !defined(NDEBUG)
443// Flaky on Webkit Win7 Debug bot: http://crbug.com/417756
444#define MAYBE_TwoGetUserMediaWithEqualConstraints \
445 DISABLED_TwoGetUserMediaWithEqualConstraints
446#else
447#define MAYBE_TwoGetUserMediaWithEqualConstraints \
448 TwoGetUserMediaWithEqualConstraints
449#endif
[email protected]118c4582014-07-17 08:02:08450IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jam290d2cf2014-10-06 17:23:51451 MAYBE_TwoGetUserMediaWithEqualConstraints) {
[email protected]ff993f92014-05-22 17:24:00452 std::string constraints1 = "{video: true, audio: true}";
453 const std::string& constraints2 = constraints1;
454 std::string expected_result = "w=640:h=480-w=640:h=480";
455
456 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
457 expected_result);
[email protected]744ff3e2014-06-19 19:28:01458}
[email protected]ff993f92014-05-22 17:24:00459
jam290d2cf2014-10-06 17:23:51460#if defined(OS_WIN)
461// Flaky on Windows Debug: http://crbug.com/417756
462#define MAYBE_TwoGetUserMediaWithSecondVideoCropped \
463 DISABLED_TwoGetUserMediaWithSecondVideoCropped
464#else
465#define MAYBE_TwoGetUserMediaWithSecondVideoCropped \
466 TwoGetUserMediaWithSecondVideoCropped
467#endif
[email protected]118c4582014-07-17 08:02:08468IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jam290d2cf2014-10-06 17:23:51469 MAYBE_TwoGetUserMediaWithSecondVideoCropped) {
[email protected]ff993f92014-05-22 17:24:00470 std::string constraints1 = "{video: true}";
471 std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}";
472 std::string expected_result = "w=640:h=480-w=640:h=360";
473 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
474 expected_result);
475}
476
jam290d2cf2014-10-06 17:23:51477#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(NDEBUG))
478// Flaky on Windows and on Linux Debug: http://crbug.com/417756
479#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
480 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
481#else
482#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
483 TwoGetUserMediaWithFirstHdSecondVga
484#endif
[email protected]118c4582014-07-17 08:02:08485IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jam290d2cf2014-10-06 17:23:51486 MAYBE_TwoGetUserMediaWithFirstHdSecondVga) {
[email protected]ff993f92014-05-22 17:24:00487 std::string constraints1 =
488 "{video: {mandatory: {minWidth:1280 , minHeight: 720}}}";
489 std::string constraints2 =
490 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
491 std::string expected_result = "w=1280:h=720-w=640:h=480";
492 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
493 expected_result);
494}
495
[email protected]118c4582014-07-17 08:02:08496IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]697173d2014-06-26 11:52:13497 TwoGetUserMediaAndVerifyFrameRate) {
498 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
499
500 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
501 NavigateToURL(shell(), url);
502
503 std::string constraints1 =
504 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
505 "minFrameRate : 15, maxFrameRate : 15}}}";
506 std::string constraints2 =
507 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
508 "minFrameRate : 7, maxFrameRate : 7}}}";
509
510 std::string command = "twoGetUserMediaAndVerifyFrameRate(" +
511 constraints1 + ',' + constraints2 + ", 15, 7)";
512 ExecuteJavascriptAndWaitForOk(command);
513}
514
[email protected]118c4582014-07-17 08:02:08515IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]0c7158b2014-03-17 16:46:38516 GetUserMediaWithTooHighVideoConstraintsValues) {
517 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
518
519 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
520
521 int large_value = 99999;
522 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
523 large_value,
524 large_value,
525 large_value,
526 large_value,
527 large_value,
528 large_value);
529 NavigateToURL(shell(), url);
530
[email protected]c3629aa2014-08-12 05:48:30531 EXPECT_EQ("ConstraintNotSatisfiedError",
532 ExecuteJavascriptAndReturnResult(call));
[email protected]0c7158b2014-03-17 16:46:38533}
534
[email protected]bdcc9702014-01-17 16:07:46535// This test will make a simple getUserMedia page, verify that video is playing
536// in a simple local <video>, and for a couple of seconds, collect some
[email protected]3fa8aa12014-01-20 19:06:54537// performance traces from VideoCaptureController colorspace conversion and
538// potential resizing.
[email protected]118c4582014-07-17 08:02:08539IN_PROC_BROWSER_TEST_F(
[email protected]3fa8aa12014-01-20 19:06:54540 WebRtcGetUserMediaBrowserTest,
541 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
542 RunGetUserMediaAndCollectMeasures(
543 10,
[email protected]5a642032014-02-28 15:43:28544 "VideoCaptureController::OnIncomingCapturedData",
[email protected]3fa8aa12014-01-20 19:06:54545 "VideoCaptureController");
[email protected]bdcc9702014-01-17 16:07:46546}
547
[email protected]bdcc9702014-01-17 16:07:46548// This test calls getUserMedia and checks for aspect ratio behavior.
[email protected]118c4582014-07-17 08:02:08549IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]856f7cbd2014-03-07 09:54:32550 TestGetUserMediaAspectRatio4To3) {
[email protected]bdcc9702014-01-17 16:07:46551 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
552
553 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
554
555 std::string constraints_4_3 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07556 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46557
[email protected]bdcc9702014-01-17 16:07:46558 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05559 ASSERT_EQ("w=640:h=480",
[email protected]43ebe9e2014-03-08 21:00:58560 ExecuteJavascriptAndReturnResult(constraints_4_3));
[email protected]856f7cbd2014-03-07 09:54:32561}
562
563// This test calls getUserMedia and checks for aspect ratio behavior.
[email protected]118c4582014-07-17 08:02:08564IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]599b15a22014-03-27 16:33:10565 TestGetUserMediaAspectRatio16To9) {
[email protected]856f7cbd2014-03-07 09:54:32566 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
567
568 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
569
570 std::string constraints_16_9 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07571 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46572
573 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05574 ASSERT_EQ("w=640:h=360",
[email protected]43ebe9e2014-03-08 21:00:58575 ExecuteJavascriptAndReturnResult(constraints_16_9));
[email protected]bdcc9702014-01-17 16:07:46576}
577
[email protected]b5d213b2014-03-27 11:45:05578// This test calls getUserMedia and checks for aspect ratio behavior.
[email protected]118c4582014-07-17 08:02:08579IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]599b15a22014-03-27 16:33:10580 TestGetUserMediaAspectRatio1To1) {
[email protected]b5d213b2014-03-27 11:45:05581 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
582
583 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
584
585 std::string constraints_1_1 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07586 kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
[email protected]b5d213b2014-03-27 11:45:05587
588 NavigateToURL(shell(), url);
589 ASSERT_EQ("w=320:h=320",
590 ExecuteJavascriptAndReturnResult(constraints_1_1));
591}
592
[email protected]bdcc9702014-01-17 16:07:46593namespace {
594
595struct UserMediaSizes {
596 int min_width;
597 int max_width;
598 int min_height;
599 int max_height;
600 int min_frame_rate;
601 int max_frame_rate;
602};
603
604} // namespace
605
606class WebRtcConstraintsBrowserTest
[email protected]99063682014-03-13 15:15:30607 : public WebRtcContentBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46608 public testing::WithParamInterface<UserMediaSizes> {
609 public:
610 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {}
611 const UserMediaSizes& user_media() const { return user_media_; }
612
613 private:
614 UserMediaSizes user_media_;
615};
616
617// This test calls getUserMedia in sequence with different constraints.
618IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest, GetUserMediaConstraints) {
619 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
620
621 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
622
623 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop,
624 user_media().min_width,
625 user_media().max_width,
626 user_media().min_height,
627 user_media().max_height,
628 user_media().min_frame_rate,
629 user_media().max_frame_rate);
630 DVLOG(1) << "Calling getUserMedia: " << call;
631 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58632 ExecuteJavascriptAndWaitForOk(call);
[email protected]bdcc9702014-01-17 16:07:46633}
634
635static const UserMediaSizes kAllUserMediaSizes[] = {
[email protected]cbc7d672014-04-04 09:27:07636 {320, 320, 180, 180, 10, 30},
637 {320, 320, 240, 240, 10, 30},
638 {640, 640, 360, 360, 10, 30},
639 {640, 640, 480, 480, 10, 30},
640 {960, 960, 720, 720, 10, 30},
641 {1280, 1280, 720, 720, 10, 30}};
[email protected]bdcc9702014-01-17 16:07:46642
[email protected]33afb892014-07-11 08:17:30643INSTANTIATE_TEST_CASE_P(UserMedia,
[email protected]bdcc9702014-01-17 16:07:46644 WebRtcConstraintsBrowserTest,
645 testing::ValuesIn(kAllUserMediaSizes));
646
647} // namespace content