blob: 56a54ec109d796af0839e020e8574b86c732ecbf [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
avi7f277562015-12-25 02:41:265#include <stddef.h>
6
[email protected]99063682014-03-13 15:15:307#include "base/command_line.h"
[email protected]bdcc9702014-01-17 16:07:468#include "base/json/json_reader.h"
primiano30c5afa2016-02-22 14:37:089#include "base/memory/ref_counted_memory.h"
[email protected]bdcc9702014-01-17 16:07:4610#include "base/strings/stringprintf.h"
11#include "base/test/trace_event_analyzer.h"
lukasza7947ccd2016-07-28 21:56:2512#include "base/threading/thread_restrictions.h"
ssid3e765612015-01-28 04:03:4213#include "base/trace_event/trace_event_impl.h"
[email protected]bdcc9702014-01-17 16:07:4614#include "base/values.h"
avi7f277562015-12-25 02:41:2615#include "build/build_config.h"
qiangchenf6ca1ed2016-10-13 22:25:0016#include "content/browser/browser_main_loop.h"
17#include "content/browser/renderer_host/media/media_stream_manager.h"
[email protected]bdcc9702014-01-17 16:07:4618#include "content/browser/web_contents/web_contents_impl.h"
mcasas6b8c0c82016-07-29 23:04:3519#include "content/browser/webrtc/webrtc_content_browsertest_base.h"
20#include "content/browser/webrtc/webrtc_internals.h"
[email protected]99063682014-03-13 15:15:3021#include "content/public/common/content_switches.h"
[email protected]bdcc9702014-01-17 16:07:4622#include "content/public/test/browser_test_utils.h"
[email protected]6e9def12014-03-27 20:23:2823#include "content/public/test/content_browser_test_utils.h"
[email protected]bdcc9702014-01-17 16:07:4624#include "content/public/test/test_utils.h"
25#include "content/shell/browser/shell.h"
[email protected]bdcc9702014-01-17 16:07:4626#include "net/test/embedded_test_server/embedded_test_server.h"
27#include "testing/perf/perf_test.h"
28
29#if defined(OS_WIN)
30#include "base/win/windows_version.h"
31#endif
32
33using trace_analyzer::TraceAnalyzer;
34using trace_analyzer::Query;
35using trace_analyzer::TraceEventVector;
36
37namespace {
38
39static const char kGetUserMediaAndStop[] = "getUserMediaAndStop";
[email protected]43ebe9e2014-03-08 21:00:5840static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp";
[email protected]bdcc9702014-01-17 16:07:4641static const char kGetUserMediaAndAnalyseAndStop[] =
42 "getUserMediaAndAnalyseAndStop";
[email protected]43ebe9e2014-03-08 21:00:5843static const char kGetUserMediaAndExpectFailure[] =
44 "getUserMediaAndExpectFailure";
[email protected]1670d032014-03-20 15:01:4545static const char kRenderSameTrackMediastreamAndStop[] =
46 "renderSameTrackMediastreamAndStop";
47static const char kRenderClonedMediastreamAndStop[] =
48 "renderClonedMediastreamAndStop";
49static const char kRenderClonedTrackMediastreamAndStop[] =
50 "renderClonedTrackMediastreamAndStop";
51static const char kRenderDuplicatedMediastreamAndStop[] =
52 "renderDuplicatedMediastreamAndStop";
[email protected]bdcc9702014-01-17 16:07:4653
54// Results returned by JS.
55static const char kOK[] = "OK";
[email protected]bdcc9702014-01-17 16:07:4656
57std::string GenerateGetUserMediaWithMandatorySourceID(
58 const std::string& function_name,
59 const std::string& audio_source_id,
60 const std::string& video_source_id) {
61 const std::string audio_constraint =
62 "audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, ";
63
64 const std::string video_constraint =
65 "video: {mandatory: { sourceId:\"" + video_source_id + "\"}}";
66 return function_name + "({" + audio_constraint + video_constraint + "});";
67}
68
69std::string GenerateGetUserMediaWithOptionalSourceID(
70 const std::string& function_name,
71 const std::string& audio_source_id,
72 const std::string& video_source_id) {
73 const std::string audio_constraint =
74 "audio: {optional: [{sourceId:\"" + audio_source_id + "\"}]}, ";
75
76 const std::string video_constraint =
77 "video: {optional: [{ sourceId:\"" + video_source_id + "\"}]}";
78 return function_name + "({" + audio_constraint + video_constraint + "});";
79}
80
qiangchenf6ca1ed2016-10-13 22:25:0081std::string GenerateGetUserMediaWithDisableLocalEcho(
82 const std::string& function_name,
83 const std::string& disable_local_echo) {
84 const std::string audio_constraint =
85 "audio:{mandatory: { chromeMediaSource : 'system', disableLocalEcho : " +
86 disable_local_echo + " }},";
87
88 const std::string video_constraint =
89 "video: { mandatory: { chromeMediaSource:'screen' }}";
90 return function_name + "({" + audio_constraint + video_constraint + "});";
91}
92
93bool VerifyDisableLocalEcho(bool expect_value,
94 const content::StreamControls& controls) {
95 return expect_value == controls.disable_local_echo;
96}
97
[email protected]bdcc9702014-01-17 16:07:4698} // namespace
99
100namespace content {
101
mcasas41f5b702016-08-03 20:19:41102class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase {
[email protected]bdcc9702014-01-17 16:07:46103 public:
guoweis8efb6d892015-10-12 18:26:17104 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {
105 // Automatically grant device permission.
106 AppendUseFakeUIForMediaStreamFlag();
107 }
phoglunda1f6906c2015-08-27 13:57:27108 ~WebRtcGetUserMediaBrowserTest() override {}
[email protected]bdcc9702014-01-17 16:07:46109
110 void StartTracing() {
111 CHECK(trace_log_ == NULL) << "Can only can start tracing once";
ssidb2e3ece2015-02-09 16:02:20112 trace_log_ = base::trace_event::TraceLog::GetInstance();
zhenwd601ddc52015-06-02 21:46:34113 base::trace_event::TraceConfig trace_config(
114 "video", base::trace_event::RECORD_UNTIL_FULL);
zhenwd601ddc52015-06-02 21:46:34115 trace_log_->SetEnabled(trace_config,
116 base::trace_event::TraceLog::RECORDING_MODE);
[email protected]bdcc9702014-01-17 16:07:46117 // Check that we are indeed recording.
118 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1);
119 }
120
121 void StopTracing() {
dcheng7707e972014-08-26 19:37:01122 CHECK(message_loop_runner_.get() == NULL)
123 << "Calling StopTracing more than once";
lukasza7947ccd2016-07-28 21:56:25124
125 {
126 base::ThreadRestrictions::ScopedAllowIO allow_thread_join_caused_by_test;
127 trace_log_->SetDisabled();
128 }
129
[email protected]bdcc9702014-01-17 16:07:46130 message_loop_runner_ = new MessageLoopRunner;
131 trace_log_->Flush(base::Bind(
phoglunda1f6906c2015-08-27 13:57:27132 &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected,
[email protected]bdcc9702014-01-17 16:07:46133 base::Unretained(this)));
134 message_loop_runner_->Run();
135 }
136
137 void OnTraceDataCollected(
138 const scoped_refptr<base::RefCountedString>& events_str_ptr,
139 bool has_more_events) {
140 CHECK(!has_more_events);
141 recorded_trace_data_ = events_str_ptr;
142 message_loop_runner_->Quit();
143 }
144
145 TraceAnalyzer* CreateTraceAnalyzer() {
146 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
147 }
148
[email protected]3fa8aa12014-01-20 19:06:54149 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs,
150 const std::string& measure_filter,
151 const std::string& graph_name) {
svaldezc3a9a172015-11-03 22:01:33152 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]3fa8aa12014-01-20 19:06:54153
154 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
155 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58156
[email protected]3fa8aa12014-01-20 19:06:54157 // Put getUserMedia to work and let it run for a couple of seconds.
158 DCHECK(time_to_sample_secs);
[email protected]1670d032014-03-20 15:01:45159 ExecuteJavascriptAndWaitForOk(
phoglund4eb75452014-10-07 15:34:07160 base::StringPrintf("%s({video: true}, 'myStreamName');",
[email protected]1670d032014-03-20 15:01:45161 kGetUserMediaAndGetStreamUp));
[email protected]3fa8aa12014-01-20 19:06:54162
[email protected]43ebe9e2014-03-08 21:00:58163 // Now the stream is up and running, start collecting traces.
[email protected]3fa8aa12014-01-20 19:06:54164 StartTracing();
165
[email protected]43ebe9e2014-03-08 21:00:58166 ExecuteJavascriptAndWaitForOk(
phoglund4eb75452014-10-07 15:34:07167 base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);",
168 time_to_sample_secs));
[email protected]43ebe9e2014-03-08 21:00:58169
[email protected]3fa8aa12014-01-20 19:06:54170 // Wait until the page title changes to "OK". Do not sleep() here since that
171 // would stop both this code and the browser underneath.
[email protected]3fa8aa12014-01-20 19:06:54172 StopTracing();
173
dcheng3b4fe472016-04-08 23:45:13174 std::unique_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer());
[email protected]3fa8aa12014-01-20 19:06:54175 analyzer->AssociateBeginEndEvents();
176 trace_analyzer::TraceEventVector events;
177 DCHECK(measure_filter.size());
178 analyzer->FindEvents(
179 Query::EventNameIs(measure_filter),
180 &events);
181 ASSERT_GT(events.size(), 0u)
182 << "Could not collect any samples during test, this is bad";
183
184 std::string duration_us;
185 std::string interarrival_us;
186 for (size_t i = 0; i != events.size(); ++i) {
187 duration_us.append(
188 base::StringPrintf("%d,", static_cast<int>(events[i]->duration)));
189 }
190
191 for (size_t i = 1; i < events.size(); ++i) {
192 // The event |timestamp| comes in ns, divide to get us like |duration|.
193 interarrival_us.append(base::StringPrintf("%d,",
194 static_cast<int>((events[i]->timestamp - events[i - 1]->timestamp) /
195 base::Time::kNanosecondsPerMicrosecond)));
196 }
197
198 perf_test::PrintResultList(
199 graph_name, "", "sample_duration", duration_us, "us", true);
200
201 perf_test::PrintResultList(
202 graph_name, "", "interarrival_time", interarrival_us, "us", true);
203 }
204
[email protected]697173d2014-06-26 11:52:13205 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
[email protected]ff993f92014-05-22 17:24:00206 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
207 const std::string& constraints1,
208 const std::string& constraints2,
209 const std::string& expected_result) {
svaldezc3a9a172015-11-03 22:01:33210 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]ff993f92014-05-22 17:24:00211
212 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
213 NavigateToURL(shell(), url);
214
215 std::string command = "twoGetUserMedia(" + constraints1 + ',' +
216 constraints2 + ')';
217
218 EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command));
219 }
220
[email protected]8926d5692014-06-11 05:02:22221 void GetInputDevices(std::vector<std::string>* audio_ids,
222 std::vector<std::string>* video_ids) {
[email protected]bdcc9702014-01-17 16:07:46223 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
224 NavigateToURL(shell(), url);
225
[email protected]8926d5692014-06-11 05:02:22226 std::string devices_as_json = ExecuteJavascriptAndReturnResult(
[email protected]b9ced842014-07-03 13:10:03227 "getSources()");
[email protected]8926d5692014-06-11 05:02:22228 EXPECT_FALSE(devices_as_json.empty());
[email protected]bdcc9702014-01-17 16:07:46229
230 int error_code;
231 std::string error_message;
dcheng3b4fe472016-04-08 23:45:13232 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError(
olli.raula4b5fb7932015-08-24 11:51:58233 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code,
234 &error_message);
[email protected]bdcc9702014-01-17 16:07:46235
236 ASSERT_TRUE(value.get() != NULL) << error_message;
237 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
238
239 base::ListValue* values;
240 ASSERT_TRUE(value->GetAsList(&values));
241
242 for (base::ListValue::iterator it = values->begin();
243 it != values->end(); ++it) {
244 const base::DictionaryValue* dict;
245 std::string kind;
[email protected]8926d5692014-06-11 05:02:22246 std::string device_id;
[email protected]bdcc9702014-01-17 16:07:46247 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
248 ASSERT_TRUE(dict->GetString("kind", &kind));
[email protected]b9ced842014-07-03 13:10:03249 ASSERT_TRUE(dict->GetString("id", &device_id));
[email protected]8926d5692014-06-11 05:02:22250 ASSERT_FALSE(device_id.empty());
[email protected]b9ced842014-07-03 13:10:03251 EXPECT_TRUE(kind == "audio" || kind == "video");
252 if (kind == "audio") {
[email protected]8926d5692014-06-11 05:02:22253 audio_ids->push_back(device_id);
[email protected]b9ced842014-07-03 13:10:03254 } else if (kind == "video") {
[email protected]8926d5692014-06-11 05:02:22255 video_ids->push_back(device_id);
[email protected]bdcc9702014-01-17 16:07:46256 }
257 }
258 ASSERT_FALSE(audio_ids->empty());
259 ASSERT_FALSE(video_ids->empty());
260 }
261
262 private:
ssidb2e3ece2015-02-09 16:02:20263 base::trace_event::TraceLog* trace_log_;
[email protected]bdcc9702014-01-17 16:07:46264 scoped_refptr<base::RefCountedString> recorded_trace_data_;
265 scoped_refptr<MessageLoopRunner> message_loop_runner_;
266};
267
268// These tests will all make a getUserMedia call with different constraints and
269// see that the success callback is called. If the error callback is called or
270// none of the callbacks are called the tests will simply time out and fail.
jyasskindc83b9a2015-01-13 03:15:03271
timurrrr2ec7e9ae2015-01-19 13:24:06272// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03273#if defined(MEMORY_SANITIZER)
274#define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
275#else
276#define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
277#endif
phoglunda1f6906c2015-08-27 13:57:27278IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03279 MAYBE_GetVideoStreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33280 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46281
282 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
283 NavigateToURL(shell(), url);
284
[email protected]43ebe9e2014-03-08 21:00:58285 ExecuteJavascriptAndWaitForOk(
286 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46287}
288
timurrrr2ec7e9ae2015-01-19 13:24:06289// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03290#if defined(MEMORY_SANITIZER)
291#define MAYBE_RenderSameTrackMediastreamAndStop \
292 DISABLED_RenderSameTrackMediastreamAndStop
293#else
294#define MAYBE_RenderSameTrackMediastreamAndStop \
295 RenderSameTrackMediastreamAndStop
296#endif
phoglunda1f6906c2015-08-27 13:57:27297IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03298 MAYBE_RenderSameTrackMediastreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33299 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]1670d032014-03-20 15:01:45300
301 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
302 NavigateToURL(shell(), url);
303
304 ExecuteJavascriptAndWaitForOk(
305 base::StringPrintf("%s({video: true});",
306 kRenderSameTrackMediastreamAndStop));
307}
308
phoglunda1f6906c2015-08-27 13:57:27309IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45310 RenderClonedMediastreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33311 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]1670d032014-03-20 15:01:45312
313 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
314 NavigateToURL(shell(), url);
315
316
317 ExecuteJavascriptAndWaitForOk(
318 base::StringPrintf("%s({video: true});",
319 kRenderClonedMediastreamAndStop));
320}
321
phoglunda1f6906c2015-08-27 13:57:27322IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45323 kRenderClonedTrackMediastreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33324 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]1670d032014-03-20 15:01:45325
326 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
327 NavigateToURL(shell(), url);
328
329 ExecuteJavascriptAndWaitForOk(
330 base::StringPrintf("%s({video: true});",
331 kRenderClonedTrackMediastreamAndStop));
332}
333
phoglunda1f6906c2015-08-27 13:57:27334IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45335 kRenderDuplicatedMediastreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33336 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]1670d032014-03-20 15:01:45337
338 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
339 NavigateToURL(shell(), url);
340
341 ExecuteJavascriptAndWaitForOk(
342 base::StringPrintf("%s({video: true});",
343 kRenderDuplicatedMediastreamAndStop));
344}
345
phoglunda1f6906c2015-08-27 13:57:27346IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12347 GetAudioAndVideoStreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33348 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46349
350 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
351 NavigateToURL(shell(), url);
352
[email protected]43ebe9e2014-03-08 21:00:58353 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
354 "%s({video: true, audio: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46355}
356
phoglunda1f6906c2015-08-27 13:57:27357IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46358 GetAudioAndVideoStreamAndClone) {
svaldezc3a9a172015-11-03 22:01:33359 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46360
361 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
362 NavigateToURL(shell(), url);
363
[email protected]43ebe9e2014-03-08 21:00:58364 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
[email protected]bdcc9702014-01-17 16:07:46365}
366
battre89812d12015-08-25 12:40:09367// Test fails under Android, http://crbug.com/524388
phoglundc0556e22015-08-28 07:47:25368// Test fails under MSan
369// Flaky everywhere else: http://crbug.com/523152
phoglunda1f6906c2015-08-27 13:57:27370IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
qiangchen4819b0852015-11-02 22:53:02371 RenderVideoTrackInMultipleTagsAndPause) {
svaldezc3a9a172015-11-03 22:01:33372 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]c6062872014-03-21 14:35:37373
374 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
375 NavigateToURL(shell(), url);
376
377 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
378}
379
phoglunda1f6906c2015-08-27 13:57:27380IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46381 GetUserMediaWithMandatorySourceID) {
svaldezc3a9a172015-11-03 22:01:33382 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46383
384 std::vector<std::string> audio_ids;
385 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22386 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46387
388 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
perkj52255332016-07-06 14:22:40389 NavigateToURL(shell(), url);
[email protected]bdcc9702014-01-17 16:07:46390
391 // Test all combinations of mandatory sourceID;
392 for (std::vector<std::string>::const_iterator video_it = video_ids.begin();
393 video_it != video_ids.end(); ++video_it) {
394 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin();
395 audio_it != audio_ids.end(); ++audio_it) {
[email protected]bdcc9702014-01-17 16:07:46396 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
397 GenerateGetUserMediaWithMandatorySourceID(
398 kGetUserMediaAndStop,
399 *audio_it,
400 *video_it)));
401 }
402 }
403}
404
phoglunda1f6906c2015-08-27 13:57:27405IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46406 GetUserMediaWithInvalidMandatorySourceID) {
svaldezc3a9a172015-11-03 22:01:33407 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46408
409 std::vector<std::string> audio_ids;
410 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22411 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46412
413 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
414
415 // Test with invalid mandatory audio sourceID.
416 NavigateToURL(shell(), url);
[email protected]32d377412014-03-19 21:15:43417 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46418 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58419 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46420 "something invalid",
[email protected]0c7158b2014-03-17 16:46:38421 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46422
423 // Test with invalid mandatory video sourceID.
[email protected]32d377412014-03-19 21:15:43424 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46425 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58426 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46427 audio_ids[0],
[email protected]0c7158b2014-03-17 16:46:38428 "something invalid")));
[email protected]bdcc9702014-01-17 16:07:46429
430 // Test with empty mandatory audio sourceID.
[email protected]32d377412014-03-19 21:15:43431 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46432 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58433 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46434 "",
[email protected]0c7158b2014-03-17 16:46:38435 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46436}
437
phoglunda1f6906c2015-08-27 13:57:27438IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46439 GetUserMediaWithInvalidOptionalSourceID) {
svaldezc3a9a172015-11-03 22:01:33440 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46441
442 std::vector<std::string> audio_ids;
443 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22444 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46445
446 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
447
448 // Test with invalid optional audio sourceID.
449 NavigateToURL(shell(), url);
450 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
451 GenerateGetUserMediaWithOptionalSourceID(
452 kGetUserMediaAndStop,
453 "something invalid",
454 video_ids[0])));
455
456 // Test with invalid optional video sourceID.
457 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
458 GenerateGetUserMediaWithOptionalSourceID(
459 kGetUserMediaAndStop,
460 audio_ids[0],
461 "something invalid")));
462
463 // Test with empty optional audio sourceID.
464 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
465 GenerateGetUserMediaWithOptionalSourceID(
466 kGetUserMediaAndStop,
467 "",
468 video_ids[0])));
469}
470
phoglunda1f6906c2015-08-27 13:57:27471IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglundf3296cd2015-08-10 16:05:32472 TwoGetUserMediaAndStop) {
svaldezc3a9a172015-11-03 22:01:33473 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46474
475 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
476 NavigateToURL(shell(), url);
477
[email protected]43ebe9e2014-03-08 21:00:58478 ExecuteJavascriptAndWaitForOk(
479 "twoGetUserMediaAndStop({video: true, audio: true});");
[email protected]bdcc9702014-01-17 16:07:46480}
481
phoglunda1f6906c2015-08-27 13:57:27482IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12483 TwoGetUserMediaWithEqualConstraints) {
[email protected]ff993f92014-05-22 17:24:00484 std::string constraints1 = "{video: true, audio: true}";
485 const std::string& constraints2 = constraints1;
486 std::string expected_result = "w=640:h=480-w=640:h=480";
487
488 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
489 expected_result);
[email protected]744ff3e2014-06-19 19:28:01490}
[email protected]ff993f92014-05-22 17:24:00491
phoglunda1f6906c2015-08-27 13:57:27492IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12493 TwoGetUserMediaWithSecondVideoCropped) {
[email protected]ff993f92014-05-22 17:24:00494 std::string constraints1 = "{video: true}";
495 std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}";
496 std::string expected_result = "w=640:h=480-w=640:h=360";
497 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
498 expected_result);
499}
500
timurrrr2ec7e9ae2015-01-19 13:24:06501// Test fails under MSan, http://crbug.com/445745
502#if defined(MEMORY_SANITIZER)
503#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
504 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
505#else
506#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
507 TwoGetUserMediaWithFirstHdSecondVga
508#endif
phoglunda1f6906c2015-08-27 13:57:27509IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
timurrrr2ec7e9ae2015-01-19 13:24:06510 MAYBE_TwoGetUserMediaWithFirstHdSecondVga) {
[email protected]ff993f92014-05-22 17:24:00511 std::string constraints1 =
mcasas0309b1d2014-12-03 21:06:12512 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\
513 minHeight: 720}}}";
[email protected]ff993f92014-05-22 17:24:00514 std::string constraints2 =
515 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
516 std::string expected_result = "w=1280:h=720-w=640:h=480";
517 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
518 expected_result);
519}
520
phoglund311334d062016-10-31 10:50:19521// Timing out on Windows 7 bot: http://crbug.com/443294
522// Flaky: http://crbug.com/660656; possible the test is too perf sensitive.
phoglunda1f6906c2015-08-27 13:57:27523IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund311334d062016-10-31 10:50:19524 DISABLED_TwoGetUserMediaWithFirst1080pSecondVga) {
mcasas0309b1d2014-12-03 21:06:12525 std::string constraints1 =
526 "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080,\
527 minHeight: 1080}}}";
528 std::string constraints2 =
529 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
530 std::string expected_result = "w=1920:h=1080-w=640:h=480";
531 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
532 expected_result);
533}
534
timurrrr2ec7e9ae2015-01-19 13:24:06535// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03536#if defined(MEMORY_SANITIZER)
537#define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
538 DISABLED_TwoGetUserMediaAndVerifyFrameRate
539#else
540#define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
541 TwoGetUserMediaAndVerifyFrameRate
542#endif
phoglunda1f6906c2015-08-27 13:57:27543IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03544 MAYBE_TwoGetUserMediaAndVerifyFrameRate) {
svaldezc3a9a172015-11-03 22:01:33545 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]697173d2014-06-26 11:52:13546
547 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
548 NavigateToURL(shell(), url);
549
550 std::string constraints1 =
551 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
552 "minFrameRate : 15, maxFrameRate : 15}}}";
553 std::string constraints2 =
554 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
555 "minFrameRate : 7, maxFrameRate : 7}}}";
556
557 std::string command = "twoGetUserMediaAndVerifyFrameRate(" +
558 constraints1 + ',' + constraints2 + ", 15, 7)";
559 ExecuteJavascriptAndWaitForOk(command);
560}
561
phoglunda1f6906c2015-08-27 13:57:27562IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]0c7158b2014-03-17 16:46:38563 GetUserMediaWithTooHighVideoConstraintsValues) {
svaldezc3a9a172015-11-03 22:01:33564 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]0c7158b2014-03-17 16:46:38565
566 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
567
568 int large_value = 99999;
569 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
570 large_value,
571 large_value,
572 large_value,
573 large_value,
574 large_value,
575 large_value);
576 NavigateToURL(shell(), url);
577
[email protected]c3629aa2014-08-12 05:48:30578 EXPECT_EQ("ConstraintNotSatisfiedError",
579 ExecuteJavascriptAndReturnResult(call));
[email protected]0c7158b2014-03-17 16:46:38580}
581
jansson1c493cf2014-10-16 07:33:32582// This test makes two getUserMedia requests, one with impossible constraints
583// that should trigger an error, and one with valid constraints. The test
584// verifies getUserMedia can succeed after being given impossible constraints.
phoglunda1f6906c2015-08-27 13:57:27585IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jansson1c493cf2014-10-16 07:33:32586 TwoGetUserMediaAndCheckCallbackAfterFailure) {
svaldezc3a9a172015-11-03 22:01:33587 ASSERT_TRUE(embedded_test_server()->Start());
jansson1c493cf2014-10-16 07:33:32588
589 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
590 NavigateToURL(shell(), url);
591
592 int large_value = 99999;
593 const std::string gum_with_impossible_constraints =
594 GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
595 large_value,
596 large_value,
597 large_value,
598 large_value,
599 large_value,
600 large_value);
601 const std::string gum_with_vga_constraints =
602 GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop,
603 640, 640, 480, 480, 10, 30);
604
605 ASSERT_EQ("ConstraintNotSatisfiedError",
606 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints));
607
608 ASSERT_EQ("w=640:h=480",
609 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints));
610}
611
aboxhall68ab1892016-08-04 22:43:36612#if defined(OS_ANDROID) && defined(NDEBUG)
613#define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia DISABLED_TraceVideoCaptureControllerPerformanceDuringGetUserMedia
614#else
615#define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia TraceVideoCaptureControllerPerformanceDuringGetUserMedia
616#endif
617
[email protected]bdcc9702014-01-17 16:07:46618// This test will make a simple getUserMedia page, verify that video is playing
619// in a simple local <video>, and for a couple of seconds, collect some
[email protected]3fa8aa12014-01-20 19:06:54620// performance traces from VideoCaptureController colorspace conversion and
621// potential resizing.
[email protected]118c4582014-07-17 08:02:08622IN_PROC_BROWSER_TEST_F(
phoglunda1f6906c2015-08-27 13:57:27623 WebRtcGetUserMediaBrowserTest,
aboxhall68ab1892016-08-04 22:43:36624 MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
[email protected]3fa8aa12014-01-20 19:06:54625 RunGetUserMediaAndCollectMeasures(
626 10,
qiangchen939cdf302015-04-06 21:36:33627 "VideoCaptureDeviceClient::OnIncomingCapturedData",
628 "VideoCaptureDeviceClient");
[email protected]bdcc9702014-01-17 16:07:46629}
630
[email protected]bdcc9702014-01-17 16:07:46631// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27632IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund3619c422016-01-11 10:13:57633 TestGetUserMediaAspectRatio4To3) {
svaldezc3a9a172015-11-03 22:01:33634 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46635
636 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
637
638 std::string constraints_4_3 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07639 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46640
[email protected]bdcc9702014-01-17 16:07:46641 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05642 ASSERT_EQ("w=640:h=480",
[email protected]43ebe9e2014-03-08 21:00:58643 ExecuteJavascriptAndReturnResult(constraints_4_3));
[email protected]856f7cbd2014-03-07 09:54:32644}
645
[email protected]856f7cbd2014-03-07 09:54:32646// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27647IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund3619c422016-01-11 10:13:57648 TestGetUserMediaAspectRatio16To9) {
svaldezc3a9a172015-11-03 22:01:33649 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]856f7cbd2014-03-07 09:54:32650
651 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
652
653 std::string constraints_16_9 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07654 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46655
656 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05657 ASSERT_EQ("w=640:h=360",
[email protected]43ebe9e2014-03-08 21:00:58658 ExecuteJavascriptAndReturnResult(constraints_16_9));
[email protected]bdcc9702014-01-17 16:07:46659}
660
[email protected]b5d213b2014-03-27 11:45:05661// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27662IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund3619c422016-01-11 10:13:57663 TestGetUserMediaAspectRatio1To1) {
svaldezc3a9a172015-11-03 22:01:33664 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]b5d213b2014-03-27 11:45:05665
666 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
667
668 std::string constraints_1_1 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07669 kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
[email protected]b5d213b2014-03-27 11:45:05670
671 NavigateToURL(shell(), url);
672 ASSERT_EQ("w=320:h=320",
673 ExecuteJavascriptAndReturnResult(constraints_1_1));
674}
675
perkj64aae322015-04-10 14:51:41676// This test calls getUserMedia in an iframe and immediately close the iframe
677// in the scope of the success callback.
phoglunda1f6906c2015-08-27 13:57:27678IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41679 AudioInIFrameAndCloseInSuccessCb) {
svaldezc3a9a172015-11-03 22:01:33680 ASSERT_TRUE(embedded_test_server()->Start());
perkj64aae322015-04-10 14:51:41681
682 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
683 NavigateToURL(shell(), url);
684
685 std::string call =
686 "getUserMediaInIframeAndCloseInSuccessCb({audio: true});";
687 ExecuteJavascriptAndWaitForOk(call);
688}
689
phoglunda1f6906c2015-08-27 13:57:27690IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41691 VideoInIFrameAndCloseInSuccessCb) {
svaldezc3a9a172015-11-03 22:01:33692 ASSERT_TRUE(embedded_test_server()->Start());
perkj64aae322015-04-10 14:51:41693
694 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
695 NavigateToURL(shell(), url);
696
697 std::string call =
698 "getUserMediaInIframeAndCloseInSuccessCb({video: true});";
699 ExecuteJavascriptAndWaitForOk(call);
700}
701
702// This test calls getUserMedia in an iframe and immediately close the iframe
703// in the scope of the failure callback.
phoglunda1f6906c2015-08-27 13:57:27704IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41705 VideoWithBadConstraintsInIFrameAndCloseInFailureCb) {
svaldezc3a9a172015-11-03 22:01:33706 ASSERT_TRUE(embedded_test_server()->Start());
perkj64aae322015-04-10 14:51:41707
708 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
709
710 int large_value = 99999;
711 std::string call =
712 GenerateGetUserMediaCall("getUserMediaInIframeAndCloseInFailureCb",
713 large_value,
714 large_value,
715 large_value,
716 large_value,
717 large_value,
718 large_value);
719 NavigateToURL(shell(), url);
720
721 ExecuteJavascriptAndWaitForOk(call);
722}
723
phoglunda1f6906c2015-08-27 13:57:27724IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41725 InvalidSourceIdInIFrameAndCloseInFailureCb) {
svaldezc3a9a172015-11-03 22:01:33726 ASSERT_TRUE(embedded_test_server()->Start());
perkj64aae322015-04-10 14:51:41727
728 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
729
730 std::string call =
731 GenerateGetUserMediaWithMandatorySourceID(
732 "getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid");
733 NavigateToURL(shell(), url);
734
735 ExecuteJavascriptAndWaitForOk(call);
736}
737
qiangchenf6ca1ed2016-10-13 22:25:00738IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
739 DisableLocalEchoParameter) {
740 base::CommandLine::ForCurrentProcess()->AppendSwitch(
741 switches::kEnableExperimentalWebPlatformFeatures);
742 ASSERT_TRUE(embedded_test_server()->Start());
743
744 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
745 NavigateToURL(shell(), url);
746
747 MediaStreamManager* manager =
748 BrowserMainLoop::GetInstance()->media_stream_manager();
749
750 manager->SetGenerateStreamCallbackForTesting(
751 base::Bind(&VerifyDisableLocalEcho, false));
752 std::string call = GenerateGetUserMediaWithDisableLocalEcho(
753 "getUserMediaAndExpectSuccess", "false");
754 ExecuteJavascriptAndWaitForOk(call);
755
756 manager->SetGenerateStreamCallbackForTesting(
757 base::Bind(&VerifyDisableLocalEcho, true));
758 call = GenerateGetUserMediaWithDisableLocalEcho(
759 "getUserMediaAndExpectSuccess", "true");
760 ExecuteJavascriptAndWaitForOk(call);
761
762 manager->SetGenerateStreamCallbackForTesting(
763 MediaStreamManager::GenerateStreamTestCallback());
764}
765
[email protected]bdcc9702014-01-17 16:07:46766} // namespace content