blob: b2100c483483a19e2869b46c90035b44a55e8ad6 [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/json/json_reader.h"
7#include "base/strings/stringprintf.h"
8#include "base/test/trace_event_analyzer.h"
ssid3e765612015-01-28 04:03:429#include "base/trace_event/trace_event_impl.h"
[email protected]bdcc9702014-01-17 16:07:4610#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
[email protected]bdcc9702014-01-17 16:07:4632static 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
phoglunda1f6906c2015-08-27 13:57:2778class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest {
[email protected]bdcc9702014-01-17 16:07:4679 public:
guoweis8efb6d892015-10-12 18:26:1780 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {
81 // Automatically grant device permission.
82 AppendUseFakeUIForMediaStreamFlag();
83 }
phoglunda1f6906c2015-08-27 13:57:2784 ~WebRtcGetUserMediaBrowserTest() override {}
[email protected]bdcc9702014-01-17 16:07:4685
86 void StartTracing() {
87 CHECK(trace_log_ == NULL) << "Can only can start tracing once";
ssidb2e3ece2015-02-09 16:02:2088 trace_log_ = base::trace_event::TraceLog::GetInstance();
zhenwd601ddc52015-06-02 21:46:3489 base::trace_event::TraceConfig trace_config(
90 "video", base::trace_event::RECORD_UNTIL_FULL);
91 trace_config.EnableSampling();
92 trace_log_->SetEnabled(trace_config,
93 base::trace_event::TraceLog::RECORDING_MODE);
[email protected]bdcc9702014-01-17 16:07:4694 // Check that we are indeed recording.
95 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1);
96 }
97
98 void StopTracing() {
dcheng7707e972014-08-26 19:37:0199 CHECK(message_loop_runner_.get() == NULL)
100 << "Calling StopTracing more than once";
[email protected]bdcc9702014-01-17 16:07:46101 trace_log_->SetDisabled();
102 message_loop_runner_ = new MessageLoopRunner;
103 trace_log_->Flush(base::Bind(
phoglunda1f6906c2015-08-27 13:57:27104 &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected,
[email protected]bdcc9702014-01-17 16:07:46105 base::Unretained(this)));
106 message_loop_runner_->Run();
107 }
108
109 void OnTraceDataCollected(
110 const scoped_refptr<base::RefCountedString>& events_str_ptr,
111 bool has_more_events) {
112 CHECK(!has_more_events);
113 recorded_trace_data_ = events_str_ptr;
114 message_loop_runner_->Quit();
115 }
116
117 TraceAnalyzer* CreateTraceAnalyzer() {
118 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
119 }
120
[email protected]3fa8aa12014-01-20 19:06:54121 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs,
122 const std::string& measure_filter,
123 const std::string& graph_name) {
124 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
125
126 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
127 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58128
[email protected]3fa8aa12014-01-20 19:06:54129 // Put getUserMedia to work and let it run for a couple of seconds.
130 DCHECK(time_to_sample_secs);
[email protected]1670d032014-03-20 15:01:45131 ExecuteJavascriptAndWaitForOk(
phoglund4eb75452014-10-07 15:34:07132 base::StringPrintf("%s({video: true}, 'myStreamName');",
[email protected]1670d032014-03-20 15:01:45133 kGetUserMediaAndGetStreamUp));
[email protected]3fa8aa12014-01-20 19:06:54134
[email protected]43ebe9e2014-03-08 21:00:58135 // Now the stream is up and running, start collecting traces.
[email protected]3fa8aa12014-01-20 19:06:54136 StartTracing();
137
[email protected]43ebe9e2014-03-08 21:00:58138 ExecuteJavascriptAndWaitForOk(
phoglund4eb75452014-10-07 15:34:07139 base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);",
140 time_to_sample_secs));
[email protected]43ebe9e2014-03-08 21:00:58141
[email protected]3fa8aa12014-01-20 19:06:54142 // Wait until the page title changes to "OK". Do not sleep() here since that
143 // would stop both this code and the browser underneath.
[email protected]3fa8aa12014-01-20 19:06:54144 StopTracing();
145
146 scoped_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer());
147 analyzer->AssociateBeginEndEvents();
148 trace_analyzer::TraceEventVector events;
149 DCHECK(measure_filter.size());
150 analyzer->FindEvents(
151 Query::EventNameIs(measure_filter),
152 &events);
153 ASSERT_GT(events.size(), 0u)
154 << "Could not collect any samples during test, this is bad";
155
156 std::string duration_us;
157 std::string interarrival_us;
158 for (size_t i = 0; i != events.size(); ++i) {
159 duration_us.append(
160 base::StringPrintf("%d,", static_cast<int>(events[i]->duration)));
161 }
162
163 for (size_t i = 1; i < events.size(); ++i) {
164 // The event |timestamp| comes in ns, divide to get us like |duration|.
165 interarrival_us.append(base::StringPrintf("%d,",
166 static_cast<int>((events[i]->timestamp - events[i - 1]->timestamp) /
167 base::Time::kNanosecondsPerMicrosecond)));
168 }
169
170 perf_test::PrintResultList(
171 graph_name, "", "sample_duration", duration_us, "us", true);
172
173 perf_test::PrintResultList(
174 graph_name, "", "interarrival_time", interarrival_us, "us", true);
175 }
176
[email protected]697173d2014-06-26 11:52:13177 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
[email protected]ff993f92014-05-22 17:24:00178 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
179 const std::string& constraints1,
180 const std::string& constraints2,
181 const std::string& expected_result) {
182 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
183
184 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
185 NavigateToURL(shell(), url);
186
187 std::string command = "twoGetUserMedia(" + constraints1 + ',' +
188 constraints2 + ')';
189
190 EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command));
191 }
192
[email protected]8926d5692014-06-11 05:02:22193 void GetInputDevices(std::vector<std::string>* audio_ids,
194 std::vector<std::string>* video_ids) {
[email protected]bdcc9702014-01-17 16:07:46195 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
196 NavigateToURL(shell(), url);
197
[email protected]8926d5692014-06-11 05:02:22198 std::string devices_as_json = ExecuteJavascriptAndReturnResult(
[email protected]b9ced842014-07-03 13:10:03199 "getSources()");
[email protected]8926d5692014-06-11 05:02:22200 EXPECT_FALSE(devices_as_json.empty());
[email protected]bdcc9702014-01-17 16:07:46201
202 int error_code;
203 std::string error_message;
olli.raula4b5fb7932015-08-24 11:51:58204 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError(
205 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code,
206 &error_message);
[email protected]bdcc9702014-01-17 16:07:46207
208 ASSERT_TRUE(value.get() != NULL) << error_message;
209 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
210
211 base::ListValue* values;
212 ASSERT_TRUE(value->GetAsList(&values));
213
214 for (base::ListValue::iterator it = values->begin();
215 it != values->end(); ++it) {
216 const base::DictionaryValue* dict;
217 std::string kind;
[email protected]8926d5692014-06-11 05:02:22218 std::string device_id;
[email protected]bdcc9702014-01-17 16:07:46219 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
220 ASSERT_TRUE(dict->GetString("kind", &kind));
[email protected]b9ced842014-07-03 13:10:03221 ASSERT_TRUE(dict->GetString("id", &device_id));
[email protected]8926d5692014-06-11 05:02:22222 ASSERT_FALSE(device_id.empty());
[email protected]b9ced842014-07-03 13:10:03223 EXPECT_TRUE(kind == "audio" || kind == "video");
224 if (kind == "audio") {
[email protected]8926d5692014-06-11 05:02:22225 audio_ids->push_back(device_id);
[email protected]b9ced842014-07-03 13:10:03226 } else if (kind == "video") {
[email protected]8926d5692014-06-11 05:02:22227 video_ids->push_back(device_id);
[email protected]bdcc9702014-01-17 16:07:46228 }
229 }
230 ASSERT_FALSE(audio_ids->empty());
231 ASSERT_FALSE(video_ids->empty());
232 }
233
234 private:
ssidb2e3ece2015-02-09 16:02:20235 base::trace_event::TraceLog* trace_log_;
[email protected]bdcc9702014-01-17 16:07:46236 scoped_refptr<base::RefCountedString> recorded_trace_data_;
237 scoped_refptr<MessageLoopRunner> message_loop_runner_;
238};
239
240// These tests will all make a getUserMedia call with different constraints and
241// see that the success callback is called. If the error callback is called or
242// none of the callbacks are called the tests will simply time out and fail.
jyasskindc83b9a2015-01-13 03:15:03243
timurrrr2ec7e9ae2015-01-19 13:24:06244// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03245#if defined(MEMORY_SANITIZER)
246#define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
247#else
248#define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
249#endif
phoglunda1f6906c2015-08-27 13:57:27250IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03251 MAYBE_GetVideoStreamAndStop) {
[email protected]bdcc9702014-01-17 16:07:46252 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
253
254 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
255 NavigateToURL(shell(), url);
256
[email protected]43ebe9e2014-03-08 21:00:58257 ExecuteJavascriptAndWaitForOk(
258 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46259}
260
timurrrr2ec7e9ae2015-01-19 13:24:06261// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03262#if defined(MEMORY_SANITIZER)
263#define MAYBE_RenderSameTrackMediastreamAndStop \
264 DISABLED_RenderSameTrackMediastreamAndStop
265#else
266#define MAYBE_RenderSameTrackMediastreamAndStop \
267 RenderSameTrackMediastreamAndStop
268#endif
phoglunda1f6906c2015-08-27 13:57:27269IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03270 MAYBE_RenderSameTrackMediastreamAndStop) {
[email protected]1670d032014-03-20 15:01:45271 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
272
273 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
274 NavigateToURL(shell(), url);
275
276 ExecuteJavascriptAndWaitForOk(
277 base::StringPrintf("%s({video: true});",
278 kRenderSameTrackMediastreamAndStop));
279}
280
phoglunda1f6906c2015-08-27 13:57:27281IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45282 RenderClonedMediastreamAndStop) {
283 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
284
285 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
286 NavigateToURL(shell(), url);
287
288
289 ExecuteJavascriptAndWaitForOk(
290 base::StringPrintf("%s({video: true});",
291 kRenderClonedMediastreamAndStop));
292}
293
phoglunda1f6906c2015-08-27 13:57:27294IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45295 kRenderClonedTrackMediastreamAndStop) {
296 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
297
298 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
299 NavigateToURL(shell(), url);
300
301 ExecuteJavascriptAndWaitForOk(
302 base::StringPrintf("%s({video: true});",
303 kRenderClonedTrackMediastreamAndStop));
304}
305
phoglunda1f6906c2015-08-27 13:57:27306IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45307 kRenderDuplicatedMediastreamAndStop) {
308 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
309
310 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
311 NavigateToURL(shell(), url);
312
313 ExecuteJavascriptAndWaitForOk(
314 base::StringPrintf("%s({video: true});",
315 kRenderDuplicatedMediastreamAndStop));
316}
317
phoglunda1f6906c2015-08-27 13:57:27318IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12319 GetAudioAndVideoStreamAndStop) {
[email protected]bdcc9702014-01-17 16:07:46320 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
321
322 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
323 NavigateToURL(shell(), url);
324
[email protected]43ebe9e2014-03-08 21:00:58325 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
326 "%s({video: true, audio: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46327}
328
phoglunda1f6906c2015-08-27 13:57:27329IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46330 GetAudioAndVideoStreamAndClone) {
331 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
332
333 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
334 NavigateToURL(shell(), url);
335
[email protected]43ebe9e2014-03-08 21:00:58336 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
[email protected]bdcc9702014-01-17 16:07:46337}
338
battre89812d12015-08-25 12:40:09339// Test fails under Android, http://crbug.com/524388
phoglundc0556e22015-08-28 07:47:25340// Test fails under MSan
341// Flaky everywhere else: http://crbug.com/523152
phoglunda1f6906c2015-08-27 13:57:27342IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
qiangchen4819b0852015-11-02 22:53:02343 RenderVideoTrackInMultipleTagsAndPause) {
[email protected]c6062872014-03-21 14:35:37344 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
345
346 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
347 NavigateToURL(shell(), url);
348
349 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
350}
351
phoglunda1f6906c2015-08-27 13:57:27352IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46353 GetUserMediaWithMandatorySourceID) {
354 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
355
356 std::vector<std::string> audio_ids;
357 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22358 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46359
360 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
361
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)));
373 }
374 }
375}
376
phoglunda1f6906c2015-08-27 13:57:27377IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46378 GetUserMediaWithInvalidMandatorySourceID) {
379 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
380
381 std::vector<std::string> audio_ids;
382 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22383 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46384
385 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
386
387 // Test with invalid mandatory audio sourceID.
388 NavigateToURL(shell(), url);
[email protected]32d377412014-03-19 21:15:43389 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46390 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58391 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46392 "something invalid",
[email protected]0c7158b2014-03-17 16:46:38393 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46394
395 // Test with invalid mandatory video sourceID.
[email protected]32d377412014-03-19 21:15:43396 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46397 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58398 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46399 audio_ids[0],
[email protected]0c7158b2014-03-17 16:46:38400 "something invalid")));
[email protected]bdcc9702014-01-17 16:07:46401
402 // Test with empty mandatory audio sourceID.
[email protected]32d377412014-03-19 21:15:43403 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46404 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58405 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46406 "",
[email protected]0c7158b2014-03-17 16:46:38407 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46408}
409
phoglunda1f6906c2015-08-27 13:57:27410IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46411 GetUserMediaWithInvalidOptionalSourceID) {
412 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
413
414 std::vector<std::string> audio_ids;
415 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22416 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46417
418 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
419
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])));
427
428 // Test with invalid optional video sourceID.
429 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
430 GenerateGetUserMediaWithOptionalSourceID(
431 kGetUserMediaAndStop,
432 audio_ids[0],
433 "something invalid")));
434
435 // Test with empty optional audio sourceID.
436 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
437 GenerateGetUserMediaWithOptionalSourceID(
438 kGetUserMediaAndStop,
439 "",
440 video_ids[0])));
441}
442
phoglunda1f6906c2015-08-27 13:57:27443IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglundf3296cd2015-08-10 16:05:32444 TwoGetUserMediaAndStop) {
[email protected]bdcc9702014-01-17 16:07:46445 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
446
447 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
448 NavigateToURL(shell(), url);
449
[email protected]43ebe9e2014-03-08 21:00:58450 ExecuteJavascriptAndWaitForOk(
451 "twoGetUserMediaAndStop({video: true, audio: true});");
[email protected]bdcc9702014-01-17 16:07:46452}
453
phoglunda1f6906c2015-08-27 13:57:27454IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12455 TwoGetUserMediaWithEqualConstraints) {
[email protected]ff993f92014-05-22 17:24:00456 std::string constraints1 = "{video: true, audio: true}";
457 const std::string& constraints2 = constraints1;
458 std::string expected_result = "w=640:h=480-w=640:h=480";
459
460 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
461 expected_result);
[email protected]744ff3e2014-06-19 19:28:01462}
[email protected]ff993f92014-05-22 17:24:00463
phoglunda1f6906c2015-08-27 13:57:27464IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12465 TwoGetUserMediaWithSecondVideoCropped) {
[email protected]ff993f92014-05-22 17:24:00466 std::string constraints1 = "{video: true}";
467 std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}";
468 std::string expected_result = "w=640:h=480-w=640:h=360";
469 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
470 expected_result);
471}
472
timurrrr2ec7e9ae2015-01-19 13:24:06473// Test fails under MSan, http://crbug.com/445745
474#if defined(MEMORY_SANITIZER)
475#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
476 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
477#else
478#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
479 TwoGetUserMediaWithFirstHdSecondVga
480#endif
phoglunda1f6906c2015-08-27 13:57:27481IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
timurrrr2ec7e9ae2015-01-19 13:24:06482 MAYBE_TwoGetUserMediaWithFirstHdSecondVga) {
[email protected]ff993f92014-05-22 17:24:00483 std::string constraints1 =
mcasas0309b1d2014-12-03 21:06:12484 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\
485 minHeight: 720}}}";
[email protected]ff993f92014-05-22 17:24:00486 std::string constraints2 =
487 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
488 std::string expected_result = "w=1280:h=720-w=640:h=480";
489 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
490 expected_result);
491}
492
shrikantaaccc112014-12-17 23:17:08493#if defined(OS_WIN)
494// Timing out on Winodws 7 bot: http://crbug.com/443294
495#define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
496 DISABLED_TwoGetUserMediaWithFirst1080pSecondVga
497#else
498#define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
499 TwoGetUserMediaWithFirst1080pSecondVga
500#endif
501
phoglunda1f6906c2015-08-27 13:57:27502IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
shrikantaaccc112014-12-17 23:17:08503 MAYBE_TwoGetUserMediaWithFirst1080pSecondVga) {
mcasas0309b1d2014-12-03 21:06:12504 std::string constraints1 =
505 "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080,\
506 minHeight: 1080}}}";
507 std::string constraints2 =
508 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
509 std::string expected_result = "w=1920:h=1080-w=640:h=480";
510 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
511 expected_result);
512}
513
timurrrr2ec7e9ae2015-01-19 13:24:06514// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03515#if defined(MEMORY_SANITIZER)
516#define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
517 DISABLED_TwoGetUserMediaAndVerifyFrameRate
518#else
519#define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
520 TwoGetUserMediaAndVerifyFrameRate
521#endif
phoglunda1f6906c2015-08-27 13:57:27522IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03523 MAYBE_TwoGetUserMediaAndVerifyFrameRate) {
[email protected]697173d2014-06-26 11:52:13524 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
525
526 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
527 NavigateToURL(shell(), url);
528
529 std::string constraints1 =
530 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
531 "minFrameRate : 15, maxFrameRate : 15}}}";
532 std::string constraints2 =
533 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
534 "minFrameRate : 7, maxFrameRate : 7}}}";
535
536 std::string command = "twoGetUserMediaAndVerifyFrameRate(" +
537 constraints1 + ',' + constraints2 + ", 15, 7)";
538 ExecuteJavascriptAndWaitForOk(command);
539}
540
phoglunda1f6906c2015-08-27 13:57:27541IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]0c7158b2014-03-17 16:46:38542 GetUserMediaWithTooHighVideoConstraintsValues) {
543 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
544
545 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
546
547 int large_value = 99999;
548 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
549 large_value,
550 large_value,
551 large_value,
552 large_value,
553 large_value,
554 large_value);
555 NavigateToURL(shell(), url);
556
[email protected]c3629aa2014-08-12 05:48:30557 EXPECT_EQ("ConstraintNotSatisfiedError",
558 ExecuteJavascriptAndReturnResult(call));
[email protected]0c7158b2014-03-17 16:46:38559}
560
jansson1c493cf2014-10-16 07:33:32561// This test makes two getUserMedia requests, one with impossible constraints
562// that should trigger an error, and one with valid constraints. The test
563// verifies getUserMedia can succeed after being given impossible constraints.
phoglunda1f6906c2015-08-27 13:57:27564IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jansson1c493cf2014-10-16 07:33:32565 TwoGetUserMediaAndCheckCallbackAfterFailure) {
566 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
567
568 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
569 NavigateToURL(shell(), url);
570
571 int large_value = 99999;
572 const std::string gum_with_impossible_constraints =
573 GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
574 large_value,
575 large_value,
576 large_value,
577 large_value,
578 large_value,
579 large_value);
580 const std::string gum_with_vga_constraints =
581 GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop,
582 640, 640, 480, 480, 10, 30);
583
584 ASSERT_EQ("ConstraintNotSatisfiedError",
585 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints));
586
587 ASSERT_EQ("w=640:h=480",
588 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints));
589}
590
[email protected]bdcc9702014-01-17 16:07:46591// This test will make a simple getUserMedia page, verify that video is playing
592// in a simple local <video>, and for a couple of seconds, collect some
[email protected]3fa8aa12014-01-20 19:06:54593// performance traces from VideoCaptureController colorspace conversion and
594// potential resizing.
[email protected]118c4582014-07-17 08:02:08595IN_PROC_BROWSER_TEST_F(
phoglunda1f6906c2015-08-27 13:57:27596 WebRtcGetUserMediaBrowserTest,
[email protected]3fa8aa12014-01-20 19:06:54597 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
598 RunGetUserMediaAndCollectMeasures(
599 10,
qiangchen939cdf302015-04-06 21:36:33600 "VideoCaptureDeviceClient::OnIncomingCapturedData",
601 "VideoCaptureDeviceClient");
[email protected]bdcc9702014-01-17 16:07:46602}
603
timurrrr2ec7e9ae2015-01-19 13:24:06604// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03605#if defined(MEMORY_SANITIZER)
606#define MAYBE_TestGetUserMediaAspectRatio4To3 \
607 DISABLED_TestGetUserMediaAspectRatio4To3
608#else
609#define MAYBE_TestGetUserMediaAspectRatio4To3 TestGetUserMediaAspectRatio4To3
610#endif
[email protected]bdcc9702014-01-17 16:07:46611// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27612IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03613 MAYBE_TestGetUserMediaAspectRatio4To3) {
[email protected]bdcc9702014-01-17 16:07:46614 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
615
616 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
617
618 std::string constraints_4_3 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07619 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46620
[email protected]bdcc9702014-01-17 16:07:46621 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05622 ASSERT_EQ("w=640:h=480",
[email protected]43ebe9e2014-03-08 21:00:58623 ExecuteJavascriptAndReturnResult(constraints_4_3));
[email protected]856f7cbd2014-03-07 09:54:32624}
625
timurrrr2ec7e9ae2015-01-19 13:24:06626// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03627#if defined(MEMORY_SANITIZER)
628#define MAYBE_TestGetUserMediaAspectRatio16To9 \
629 DISABLED_TestGetUserMediaAspectRatio16To9
630#else
631#define MAYBE_TestGetUserMediaAspectRatio16To9 TestGetUserMediaAspectRatio16To9
632#endif
[email protected]856f7cbd2014-03-07 09:54:32633// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27634IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03635 MAYBE_TestGetUserMediaAspectRatio16To9) {
[email protected]856f7cbd2014-03-07 09:54:32636 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
637
638 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
639
640 std::string constraints_16_9 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07641 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46642
643 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05644 ASSERT_EQ("w=640:h=360",
[email protected]43ebe9e2014-03-08 21:00:58645 ExecuteJavascriptAndReturnResult(constraints_16_9));
[email protected]bdcc9702014-01-17 16:07:46646}
647
timurrrr2ec7e9ae2015-01-19 13:24:06648// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03649#if defined(MEMORY_SANITIZER)
650#define MAYBE_TestGetUserMediaAspectRatio1To1 \
651 DISABLED_TestGetUserMediaAspectRatio1To1
652#else
653#define MAYBE_TestGetUserMediaAspectRatio1To1 TestGetUserMediaAspectRatio1To1
654#endif
[email protected]b5d213b2014-03-27 11:45:05655// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27656IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03657 MAYBE_TestGetUserMediaAspectRatio1To1) {
[email protected]b5d213b2014-03-27 11:45:05658 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
659
660 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
661
662 std::string constraints_1_1 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07663 kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
[email protected]b5d213b2014-03-27 11:45:05664
665 NavigateToURL(shell(), url);
666 ASSERT_EQ("w=320:h=320",
667 ExecuteJavascriptAndReturnResult(constraints_1_1));
668}
669
perkj64aae322015-04-10 14:51:41670// This test calls getUserMedia in an iframe and immediately close the iframe
671// in the scope of the success callback.
phoglunda1f6906c2015-08-27 13:57:27672IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41673 AudioInIFrameAndCloseInSuccessCb) {
674 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
675
676 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
677 NavigateToURL(shell(), url);
678
679 std::string call =
680 "getUserMediaInIframeAndCloseInSuccessCb({audio: true});";
681 ExecuteJavascriptAndWaitForOk(call);
682}
683
phoglunda1f6906c2015-08-27 13:57:27684IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41685 VideoInIFrameAndCloseInSuccessCb) {
686 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
687
688 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
689 NavigateToURL(shell(), url);
690
691 std::string call =
692 "getUserMediaInIframeAndCloseInSuccessCb({video: true});";
693 ExecuteJavascriptAndWaitForOk(call);
694}
695
696// This test calls getUserMedia in an iframe and immediately close the iframe
697// in the scope of the failure callback.
phoglunda1f6906c2015-08-27 13:57:27698IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41699 VideoWithBadConstraintsInIFrameAndCloseInFailureCb) {
700 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
701
702 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
703
704 int large_value = 99999;
705 std::string call =
706 GenerateGetUserMediaCall("getUserMediaInIframeAndCloseInFailureCb",
707 large_value,
708 large_value,
709 large_value,
710 large_value,
711 large_value,
712 large_value);
713 NavigateToURL(shell(), url);
714
715 ExecuteJavascriptAndWaitForOk(call);
716}
717
phoglunda1f6906c2015-08-27 13:57:27718IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41719 InvalidSourceIdInIFrameAndCloseInFailureCb) {
720 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
721
722 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
723
724 std::string call =
725 GenerateGetUserMediaWithMandatorySourceID(
726 "getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid");
727 NavigateToURL(shell(), url);
728
729 ExecuteJavascriptAndWaitForOk(call);
730}
731
[email protected]bdcc9702014-01-17 16:07:46732namespace {
733
734struct UserMediaSizes {
735 int min_width;
736 int max_width;
737 int min_height;
738 int max_height;
739 int min_frame_rate;
740 int max_frame_rate;
741};
742
743} // namespace
744
745class WebRtcConstraintsBrowserTest
[email protected]99063682014-03-13 15:15:30746 : public WebRtcContentBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46747 public testing::WithParamInterface<UserMediaSizes> {
748 public:
guoweis8efb6d892015-10-12 18:26:17749 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {
750 // Automatically grant device permission.
751 AppendUseFakeUIForMediaStreamFlag();
752 }
[email protected]bdcc9702014-01-17 16:07:46753 const UserMediaSizes& user_media() const { return user_media_; }
754
755 private:
756 UserMediaSizes user_media_;
757};
758
timurrrr2ec7e9ae2015-01-19 13:24:06759// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03760#if defined(MEMORY_SANITIZER)
761#define MAYBE_GetUserMediaConstraints DISABLED_GetUserMediaConstraints
762#else
763#define MAYBE_GetUserMediaConstraints GetUserMediaConstraints
764#endif
[email protected]bdcc9702014-01-17 16:07:46765// This test calls getUserMedia in sequence with different constraints.
jyasskindc83b9a2015-01-13 03:15:03766IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest,
767 MAYBE_GetUserMediaConstraints) {
[email protected]bdcc9702014-01-17 16:07:46768 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
769
770 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
771
772 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop,
773 user_media().min_width,
774 user_media().max_width,
775 user_media().min_height,
776 user_media().max_height,
777 user_media().min_frame_rate,
778 user_media().max_frame_rate);
779 DVLOG(1) << "Calling getUserMedia: " << call;
780 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58781 ExecuteJavascriptAndWaitForOk(call);
[email protected]bdcc9702014-01-17 16:07:46782}
783
784static const UserMediaSizes kAllUserMediaSizes[] = {
[email protected]cbc7d672014-04-04 09:27:07785 {320, 320, 180, 180, 10, 30},
786 {320, 320, 240, 240, 10, 30},
787 {640, 640, 360, 360, 10, 30},
788 {640, 640, 480, 480, 10, 30},
789 {960, 960, 720, 720, 10, 30},
790 {1280, 1280, 720, 720, 10, 30}};
[email protected]bdcc9702014-01-17 16:07:46791
[email protected]33afb892014-07-11 08:17:30792INSTANTIATE_TEST_CASE_P(UserMedia,
[email protected]bdcc9702014-01-17 16:07:46793 WebRtcConstraintsBrowserTest,
794 testing::ValuesIn(kAllUserMediaSizes));
795
796} // namespace content