blob: 255778590f65c7a3e1b392c800b725faef4b83e5 [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"
ssid3e765612015-01-28 04:03:4212#include "base/trace_event/trace_event_impl.h"
[email protected]bdcc9702014-01-17 16:07:4613#include "base/values.h"
avi7f277562015-12-25 02:41:2614#include "build/build_config.h"
mcasas6c910df2016-02-23 23:27:5815#include "content/browser/media/webrtc/webrtc_internals.h"
[email protected]bdcc9702014-01-17 16:07:4616#include "content/browser/web_contents/web_contents_impl.h"
[email protected]99063682014-03-13 15:15:3017#include "content/public/common/content_switches.h"
[email protected]bdcc9702014-01-17 16:07:4618#include "content/public/test/browser_test_utils.h"
[email protected]6e9def12014-03-27 20:23:2819#include "content/public/test/content_browser_test_utils.h"
[email protected]bdcc9702014-01-17 16:07:4620#include "content/public/test/test_utils.h"
21#include "content/shell/browser/shell.h"
[email protected]bdcc9702014-01-17 16:07:4622#include "content/test/webrtc_content_browsertest_base.h"
23#include "net/test/embedded_test_server/embedded_test_server.h"
24#include "testing/perf/perf_test.h"
25
26#if defined(OS_WIN)
27#include "base/win/windows_version.h"
28#endif
29
30using trace_analyzer::TraceAnalyzer;
31using trace_analyzer::Query;
32using trace_analyzer::TraceEventVector;
33
34namespace {
35
36static const char kGetUserMediaAndStop[] = "getUserMediaAndStop";
[email protected]43ebe9e2014-03-08 21:00:5837static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp";
[email protected]bdcc9702014-01-17 16:07:4638static const char kGetUserMediaAndAnalyseAndStop[] =
39 "getUserMediaAndAnalyseAndStop";
[email protected]43ebe9e2014-03-08 21:00:5840static const char kGetUserMediaAndExpectFailure[] =
41 "getUserMediaAndExpectFailure";
[email protected]1670d032014-03-20 15:01:4542static const char kRenderSameTrackMediastreamAndStop[] =
43 "renderSameTrackMediastreamAndStop";
44static const char kRenderClonedMediastreamAndStop[] =
45 "renderClonedMediastreamAndStop";
46static const char kRenderClonedTrackMediastreamAndStop[] =
47 "renderClonedTrackMediastreamAndStop";
48static const char kRenderDuplicatedMediastreamAndStop[] =
49 "renderDuplicatedMediastreamAndStop";
[email protected]bdcc9702014-01-17 16:07:4650
51// Results returned by JS.
52static const char kOK[] = "OK";
[email protected]bdcc9702014-01-17 16:07:4653
54std::string GenerateGetUserMediaWithMandatorySourceID(
55 const std::string& function_name,
56 const std::string& audio_source_id,
57 const std::string& video_source_id) {
58 const std::string audio_constraint =
59 "audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, ";
60
61 const std::string video_constraint =
62 "video: {mandatory: { sourceId:\"" + video_source_id + "\"}}";
63 return function_name + "({" + audio_constraint + video_constraint + "});";
64}
65
66std::string GenerateGetUserMediaWithOptionalSourceID(
67 const std::string& function_name,
68 const std::string& audio_source_id,
69 const std::string& video_source_id) {
70 const std::string audio_constraint =
71 "audio: {optional: [{sourceId:\"" + audio_source_id + "\"}]}, ";
72
73 const std::string video_constraint =
74 "video: {optional: [{ sourceId:\"" + video_source_id + "\"}]}";
75 return function_name + "({" + audio_constraint + video_constraint + "});";
76}
77
78} // namespace
79
80namespace content {
81
phoglunda1f6906c2015-08-27 13:57:2782class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest {
[email protected]bdcc9702014-01-17 16:07:4683 public:
guoweis8efb6d892015-10-12 18:26:1784 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {
85 // Automatically grant device permission.
86 AppendUseFakeUIForMediaStreamFlag();
87 }
phoglunda1f6906c2015-08-27 13:57:2788 ~WebRtcGetUserMediaBrowserTest() override {}
[email protected]bdcc9702014-01-17 16:07:4689
90 void StartTracing() {
91 CHECK(trace_log_ == NULL) << "Can only can start tracing once";
ssidb2e3ece2015-02-09 16:02:2092 trace_log_ = base::trace_event::TraceLog::GetInstance();
zhenwd601ddc52015-06-02 21:46:3493 base::trace_event::TraceConfig trace_config(
94 "video", base::trace_event::RECORD_UNTIL_FULL);
95 trace_config.EnableSampling();
96 trace_log_->SetEnabled(trace_config,
97 base::trace_event::TraceLog::RECORDING_MODE);
[email protected]bdcc9702014-01-17 16:07:4698 // Check that we are indeed recording.
99 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1);
100 }
101
102 void StopTracing() {
dcheng7707e972014-08-26 19:37:01103 CHECK(message_loop_runner_.get() == NULL)
104 << "Calling StopTracing more than once";
[email protected]bdcc9702014-01-17 16:07:46105 trace_log_->SetDisabled();
106 message_loop_runner_ = new MessageLoopRunner;
107 trace_log_->Flush(base::Bind(
phoglunda1f6906c2015-08-27 13:57:27108 &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected,
[email protected]bdcc9702014-01-17 16:07:46109 base::Unretained(this)));
110 message_loop_runner_->Run();
111 }
112
113 void OnTraceDataCollected(
114 const scoped_refptr<base::RefCountedString>& events_str_ptr,
115 bool has_more_events) {
116 CHECK(!has_more_events);
117 recorded_trace_data_ = events_str_ptr;
118 message_loop_runner_->Quit();
119 }
120
121 TraceAnalyzer* CreateTraceAnalyzer() {
122 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
123 }
124
[email protected]3fa8aa12014-01-20 19:06:54125 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs,
126 const std::string& measure_filter,
127 const std::string& graph_name) {
svaldezc3a9a172015-11-03 22:01:33128 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]3fa8aa12014-01-20 19:06:54129
130 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
131 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58132
[email protected]3fa8aa12014-01-20 19:06:54133 // Put getUserMedia to work and let it run for a couple of seconds.
134 DCHECK(time_to_sample_secs);
[email protected]1670d032014-03-20 15:01:45135 ExecuteJavascriptAndWaitForOk(
phoglund4eb75452014-10-07 15:34:07136 base::StringPrintf("%s({video: true}, 'myStreamName');",
[email protected]1670d032014-03-20 15:01:45137 kGetUserMediaAndGetStreamUp));
[email protected]3fa8aa12014-01-20 19:06:54138
[email protected]43ebe9e2014-03-08 21:00:58139 // Now the stream is up and running, start collecting traces.
[email protected]3fa8aa12014-01-20 19:06:54140 StartTracing();
141
[email protected]43ebe9e2014-03-08 21:00:58142 ExecuteJavascriptAndWaitForOk(
phoglund4eb75452014-10-07 15:34:07143 base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);",
144 time_to_sample_secs));
[email protected]43ebe9e2014-03-08 21:00:58145
[email protected]3fa8aa12014-01-20 19:06:54146 // Wait until the page title changes to "OK". Do not sleep() here since that
147 // would stop both this code and the browser underneath.
[email protected]3fa8aa12014-01-20 19:06:54148 StopTracing();
149
dcheng3b4fe472016-04-08 23:45:13150 std::unique_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer());
[email protected]3fa8aa12014-01-20 19:06:54151 analyzer->AssociateBeginEndEvents();
152 trace_analyzer::TraceEventVector events;
153 DCHECK(measure_filter.size());
154 analyzer->FindEvents(
155 Query::EventNameIs(measure_filter),
156 &events);
157 ASSERT_GT(events.size(), 0u)
158 << "Could not collect any samples during test, this is bad";
159
160 std::string duration_us;
161 std::string interarrival_us;
162 for (size_t i = 0; i != events.size(); ++i) {
163 duration_us.append(
164 base::StringPrintf("%d,", static_cast<int>(events[i]->duration)));
165 }
166
167 for (size_t i = 1; i < events.size(); ++i) {
168 // The event |timestamp| comes in ns, divide to get us like |duration|.
169 interarrival_us.append(base::StringPrintf("%d,",
170 static_cast<int>((events[i]->timestamp - events[i - 1]->timestamp) /
171 base::Time::kNanosecondsPerMicrosecond)));
172 }
173
174 perf_test::PrintResultList(
175 graph_name, "", "sample_duration", duration_us, "us", true);
176
177 perf_test::PrintResultList(
178 graph_name, "", "interarrival_time", interarrival_us, "us", true);
179 }
180
[email protected]697173d2014-06-26 11:52:13181 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
[email protected]ff993f92014-05-22 17:24:00182 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
183 const std::string& constraints1,
184 const std::string& constraints2,
185 const std::string& expected_result) {
svaldezc3a9a172015-11-03 22:01:33186 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]ff993f92014-05-22 17:24:00187
188 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
189 NavigateToURL(shell(), url);
190
191 std::string command = "twoGetUserMedia(" + constraints1 + ',' +
192 constraints2 + ')';
193
194 EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command));
195 }
196
[email protected]8926d5692014-06-11 05:02:22197 void GetInputDevices(std::vector<std::string>* audio_ids,
198 std::vector<std::string>* video_ids) {
[email protected]bdcc9702014-01-17 16:07:46199 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
200 NavigateToURL(shell(), url);
201
[email protected]8926d5692014-06-11 05:02:22202 std::string devices_as_json = ExecuteJavascriptAndReturnResult(
[email protected]b9ced842014-07-03 13:10:03203 "getSources()");
[email protected]8926d5692014-06-11 05:02:22204 EXPECT_FALSE(devices_as_json.empty());
[email protected]bdcc9702014-01-17 16:07:46205
206 int error_code;
207 std::string error_message;
dcheng3b4fe472016-04-08 23:45:13208 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError(
olli.raula4b5fb7932015-08-24 11:51:58209 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code,
210 &error_message);
[email protected]bdcc9702014-01-17 16:07:46211
212 ASSERT_TRUE(value.get() != NULL) << error_message;
213 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
214
215 base::ListValue* values;
216 ASSERT_TRUE(value->GetAsList(&values));
217
218 for (base::ListValue::iterator it = values->begin();
219 it != values->end(); ++it) {
220 const base::DictionaryValue* dict;
221 std::string kind;
[email protected]8926d5692014-06-11 05:02:22222 std::string device_id;
[email protected]bdcc9702014-01-17 16:07:46223 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
224 ASSERT_TRUE(dict->GetString("kind", &kind));
[email protected]b9ced842014-07-03 13:10:03225 ASSERT_TRUE(dict->GetString("id", &device_id));
[email protected]8926d5692014-06-11 05:02:22226 ASSERT_FALSE(device_id.empty());
[email protected]b9ced842014-07-03 13:10:03227 EXPECT_TRUE(kind == "audio" || kind == "video");
228 if (kind == "audio") {
[email protected]8926d5692014-06-11 05:02:22229 audio_ids->push_back(device_id);
[email protected]b9ced842014-07-03 13:10:03230 } else if (kind == "video") {
[email protected]8926d5692014-06-11 05:02:22231 video_ids->push_back(device_id);
[email protected]bdcc9702014-01-17 16:07:46232 }
233 }
234 ASSERT_FALSE(audio_ids->empty());
235 ASSERT_FALSE(video_ids->empty());
236 }
237
238 private:
ssidb2e3ece2015-02-09 16:02:20239 base::trace_event::TraceLog* trace_log_;
[email protected]bdcc9702014-01-17 16:07:46240 scoped_refptr<base::RefCountedString> recorded_trace_data_;
241 scoped_refptr<MessageLoopRunner> message_loop_runner_;
242};
243
244// These tests will all make a getUserMedia call with different constraints and
245// see that the success callback is called. If the error callback is called or
246// none of the callbacks are called the tests will simply time out and fail.
jyasskindc83b9a2015-01-13 03:15:03247
timurrrr2ec7e9ae2015-01-19 13:24:06248// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03249#if defined(MEMORY_SANITIZER)
250#define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
251#else
252#define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
253#endif
phoglunda1f6906c2015-08-27 13:57:27254IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03255 MAYBE_GetVideoStreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33256 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46257
258 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
259 NavigateToURL(shell(), url);
260
[email protected]43ebe9e2014-03-08 21:00:58261 ExecuteJavascriptAndWaitForOk(
262 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46263}
264
timurrrr2ec7e9ae2015-01-19 13:24:06265// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03266#if defined(MEMORY_SANITIZER)
267#define MAYBE_RenderSameTrackMediastreamAndStop \
268 DISABLED_RenderSameTrackMediastreamAndStop
269#else
270#define MAYBE_RenderSameTrackMediastreamAndStop \
271 RenderSameTrackMediastreamAndStop
272#endif
phoglunda1f6906c2015-08-27 13:57:27273IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03274 MAYBE_RenderSameTrackMediastreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33275 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]1670d032014-03-20 15:01:45276
277 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
278 NavigateToURL(shell(), url);
279
280 ExecuteJavascriptAndWaitForOk(
281 base::StringPrintf("%s({video: true});",
282 kRenderSameTrackMediastreamAndStop));
283}
284
phoglunda1f6906c2015-08-27 13:57:27285IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45286 RenderClonedMediastreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33287 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]1670d032014-03-20 15:01:45288
289 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
290 NavigateToURL(shell(), url);
291
292
293 ExecuteJavascriptAndWaitForOk(
294 base::StringPrintf("%s({video: true});",
295 kRenderClonedMediastreamAndStop));
296}
297
phoglunda1f6906c2015-08-27 13:57:27298IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45299 kRenderClonedTrackMediastreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33300 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]1670d032014-03-20 15:01:45301
302 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
303 NavigateToURL(shell(), url);
304
305 ExecuteJavascriptAndWaitForOk(
306 base::StringPrintf("%s({video: true});",
307 kRenderClonedTrackMediastreamAndStop));
308}
309
phoglunda1f6906c2015-08-27 13:57:27310IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]1670d032014-03-20 15:01:45311 kRenderDuplicatedMediastreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33312 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]1670d032014-03-20 15:01:45313
314 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
315 NavigateToURL(shell(), url);
316
317 ExecuteJavascriptAndWaitForOk(
318 base::StringPrintf("%s({video: true});",
319 kRenderDuplicatedMediastreamAndStop));
320}
321
phoglunda1f6906c2015-08-27 13:57:27322IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12323 GetAudioAndVideoStreamAndStop) {
svaldezc3a9a172015-11-03 22:01:33324 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46325
326 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
327 NavigateToURL(shell(), url);
328
[email protected]43ebe9e2014-03-08 21:00:58329 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
330 "%s({video: true, audio: true});", kGetUserMediaAndStop));
[email protected]bdcc9702014-01-17 16:07:46331}
332
phoglunda1f6906c2015-08-27 13:57:27333IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46334 GetAudioAndVideoStreamAndClone) {
svaldezc3a9a172015-11-03 22:01:33335 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46336
337 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
338 NavigateToURL(shell(), url);
339
[email protected]43ebe9e2014-03-08 21:00:58340 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
[email protected]bdcc9702014-01-17 16:07:46341}
342
battre89812d12015-08-25 12:40:09343// Test fails under Android, http://crbug.com/524388
phoglundc0556e22015-08-28 07:47:25344// Test fails under MSan
345// Flaky everywhere else: http://crbug.com/523152
phoglunda1f6906c2015-08-27 13:57:27346IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
qiangchen4819b0852015-11-02 22:53:02347 RenderVideoTrackInMultipleTagsAndPause) {
svaldezc3a9a172015-11-03 22:01:33348 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]c6062872014-03-21 14:35:37349
350 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
351 NavigateToURL(shell(), url);
352
353 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
354}
355
phoglunda1f6906c2015-08-27 13:57:27356IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46357 GetUserMediaWithMandatorySourceID) {
svaldezc3a9a172015-11-03 22:01:33358 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46359
360 std::vector<std::string> audio_ids;
361 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22362 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46363
364 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
perkj52255332016-07-06 14:22:40365 NavigateToURL(shell(), url);
[email protected]bdcc9702014-01-17 16:07:46366
367 // Test all combinations of mandatory sourceID;
368 for (std::vector<std::string>::const_iterator video_it = video_ids.begin();
369 video_it != video_ids.end(); ++video_it) {
370 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin();
371 audio_it != audio_ids.end(); ++audio_it) {
[email protected]bdcc9702014-01-17 16:07:46372 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
373 GenerateGetUserMediaWithMandatorySourceID(
374 kGetUserMediaAndStop,
375 *audio_it,
376 *video_it)));
377 }
378 }
379}
380
phoglunda1f6906c2015-08-27 13:57:27381IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46382 GetUserMediaWithInvalidMandatorySourceID) {
svaldezc3a9a172015-11-03 22:01:33383 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46384
385 std::vector<std::string> audio_ids;
386 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22387 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46388
389 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
390
391 // Test with invalid mandatory audio sourceID.
392 NavigateToURL(shell(), url);
[email protected]32d377412014-03-19 21:15:43393 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46394 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58395 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46396 "something invalid",
[email protected]0c7158b2014-03-17 16:46:38397 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46398
399 // Test with invalid mandatory video sourceID.
[email protected]32d377412014-03-19 21:15:43400 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46401 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58402 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46403 audio_ids[0],
[email protected]0c7158b2014-03-17 16:46:38404 "something invalid")));
[email protected]bdcc9702014-01-17 16:07:46405
406 // Test with empty mandatory audio sourceID.
[email protected]32d377412014-03-19 21:15:43407 EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult(
[email protected]bdcc9702014-01-17 16:07:46408 GenerateGetUserMediaWithMandatorySourceID(
[email protected]43ebe9e2014-03-08 21:00:58409 kGetUserMediaAndExpectFailure,
[email protected]bdcc9702014-01-17 16:07:46410 "",
[email protected]0c7158b2014-03-17 16:46:38411 video_ids[0])));
[email protected]bdcc9702014-01-17 16:07:46412}
413
phoglunda1f6906c2015-08-27 13:57:27414IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46415 GetUserMediaWithInvalidOptionalSourceID) {
svaldezc3a9a172015-11-03 22:01:33416 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46417
418 std::vector<std::string> audio_ids;
419 std::vector<std::string> video_ids;
[email protected]8926d5692014-06-11 05:02:22420 GetInputDevices(&audio_ids, &video_ids);
[email protected]bdcc9702014-01-17 16:07:46421
422 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
423
424 // Test with invalid optional audio sourceID.
425 NavigateToURL(shell(), url);
426 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
427 GenerateGetUserMediaWithOptionalSourceID(
428 kGetUserMediaAndStop,
429 "something invalid",
430 video_ids[0])));
431
432 // Test with invalid optional video sourceID.
433 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
434 GenerateGetUserMediaWithOptionalSourceID(
435 kGetUserMediaAndStop,
436 audio_ids[0],
437 "something invalid")));
438
439 // Test with empty optional audio sourceID.
440 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
441 GenerateGetUserMediaWithOptionalSourceID(
442 kGetUserMediaAndStop,
443 "",
444 video_ids[0])));
445}
446
phoglunda1f6906c2015-08-27 13:57:27447IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglundf3296cd2015-08-10 16:05:32448 TwoGetUserMediaAndStop) {
svaldezc3a9a172015-11-03 22:01:33449 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46450
451 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
452 NavigateToURL(shell(), url);
453
[email protected]43ebe9e2014-03-08 21:00:58454 ExecuteJavascriptAndWaitForOk(
455 "twoGetUserMediaAndStop({video: true, audio: true});");
[email protected]bdcc9702014-01-17 16:07:46456}
457
phoglunda1f6906c2015-08-27 13:57:27458IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12459 TwoGetUserMediaWithEqualConstraints) {
[email protected]ff993f92014-05-22 17:24:00460 std::string constraints1 = "{video: true, audio: true}";
461 const std::string& constraints2 = constraints1;
462 std::string expected_result = "w=640:h=480-w=640:h=480";
463
464 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
465 expected_result);
[email protected]744ff3e2014-06-19 19:28:01466}
[email protected]ff993f92014-05-22 17:24:00467
phoglunda1f6906c2015-08-27 13:57:27468IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund9a091622014-10-10 08:51:12469 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
timurrrr2ec7e9ae2015-01-19 13:24:06477// Test fails under MSan, http://crbug.com/445745
478#if defined(MEMORY_SANITIZER)
479#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
480 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
481#else
482#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
483 TwoGetUserMediaWithFirstHdSecondVga
484#endif
phoglunda1f6906c2015-08-27 13:57:27485IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
timurrrr2ec7e9ae2015-01-19 13:24:06486 MAYBE_TwoGetUserMediaWithFirstHdSecondVga) {
[email protected]ff993f92014-05-22 17:24:00487 std::string constraints1 =
mcasas0309b1d2014-12-03 21:06:12488 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\
489 minHeight: 720}}}";
[email protected]ff993f92014-05-22 17:24:00490 std::string constraints2 =
491 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
492 std::string expected_result = "w=1280:h=720-w=640:h=480";
493 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
494 expected_result);
495}
496
shrikantaaccc112014-12-17 23:17:08497#if defined(OS_WIN)
498// Timing out on Winodws 7 bot: http://crbug.com/443294
499#define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
500 DISABLED_TwoGetUserMediaWithFirst1080pSecondVga
501#else
502#define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\
503 TwoGetUserMediaWithFirst1080pSecondVga
504#endif
505
phoglunda1f6906c2015-08-27 13:57:27506IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
shrikantaaccc112014-12-17 23:17:08507 MAYBE_TwoGetUserMediaWithFirst1080pSecondVga) {
mcasas0309b1d2014-12-03 21:06:12508 std::string constraints1 =
509 "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080,\
510 minHeight: 1080}}}";
511 std::string constraints2 =
512 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
513 std::string expected_result = "w=1920:h=1080-w=640:h=480";
514 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
515 expected_result);
516}
517
timurrrr2ec7e9ae2015-01-19 13:24:06518// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03519#if defined(MEMORY_SANITIZER)
520#define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
521 DISABLED_TwoGetUserMediaAndVerifyFrameRate
522#else
523#define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
524 TwoGetUserMediaAndVerifyFrameRate
525#endif
phoglunda1f6906c2015-08-27 13:57:27526IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jyasskindc83b9a2015-01-13 03:15:03527 MAYBE_TwoGetUserMediaAndVerifyFrameRate) {
svaldezc3a9a172015-11-03 22:01:33528 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]697173d2014-06-26 11:52:13529
530 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
531 NavigateToURL(shell(), url);
532
533 std::string constraints1 =
534 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
535 "minFrameRate : 15, maxFrameRate : 15}}}";
536 std::string constraints2 =
537 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
538 "minFrameRate : 7, maxFrameRate : 7}}}";
539
540 std::string command = "twoGetUserMediaAndVerifyFrameRate(" +
541 constraints1 + ',' + constraints2 + ", 15, 7)";
542 ExecuteJavascriptAndWaitForOk(command);
543}
544
phoglunda1f6906c2015-08-27 13:57:27545IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
[email protected]0c7158b2014-03-17 16:46:38546 GetUserMediaWithTooHighVideoConstraintsValues) {
svaldezc3a9a172015-11-03 22:01:33547 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]0c7158b2014-03-17 16:46:38548
549 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
550
551 int large_value = 99999;
552 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
553 large_value,
554 large_value,
555 large_value,
556 large_value,
557 large_value,
558 large_value);
559 NavigateToURL(shell(), url);
560
[email protected]c3629aa2014-08-12 05:48:30561 EXPECT_EQ("ConstraintNotSatisfiedError",
562 ExecuteJavascriptAndReturnResult(call));
[email protected]0c7158b2014-03-17 16:46:38563}
564
jansson1c493cf2014-10-16 07:33:32565// This test makes two getUserMedia requests, one with impossible constraints
566// that should trigger an error, and one with valid constraints. The test
567// verifies getUserMedia can succeed after being given impossible constraints.
phoglunda1f6906c2015-08-27 13:57:27568IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
jansson1c493cf2014-10-16 07:33:32569 TwoGetUserMediaAndCheckCallbackAfterFailure) {
svaldezc3a9a172015-11-03 22:01:33570 ASSERT_TRUE(embedded_test_server()->Start());
jansson1c493cf2014-10-16 07:33:32571
572 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
573 NavigateToURL(shell(), url);
574
575 int large_value = 99999;
576 const std::string gum_with_impossible_constraints =
577 GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
578 large_value,
579 large_value,
580 large_value,
581 large_value,
582 large_value,
583 large_value);
584 const std::string gum_with_vga_constraints =
585 GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop,
586 640, 640, 480, 480, 10, 30);
587
588 ASSERT_EQ("ConstraintNotSatisfiedError",
589 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints));
590
591 ASSERT_EQ("w=640:h=480",
592 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints));
593}
594
[email protected]bdcc9702014-01-17 16:07:46595// This test will make a simple getUserMedia page, verify that video is playing
596// in a simple local <video>, and for a couple of seconds, collect some
[email protected]3fa8aa12014-01-20 19:06:54597// performance traces from VideoCaptureController colorspace conversion and
598// potential resizing.
[email protected]118c4582014-07-17 08:02:08599IN_PROC_BROWSER_TEST_F(
phoglunda1f6906c2015-08-27 13:57:27600 WebRtcGetUserMediaBrowserTest,
[email protected]3fa8aa12014-01-20 19:06:54601 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
602 RunGetUserMediaAndCollectMeasures(
603 10,
qiangchen939cdf302015-04-06 21:36:33604 "VideoCaptureDeviceClient::OnIncomingCapturedData",
605 "VideoCaptureDeviceClient");
[email protected]bdcc9702014-01-17 16:07:46606}
607
[email protected]bdcc9702014-01-17 16:07:46608// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27609IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund3619c422016-01-11 10:13:57610 TestGetUserMediaAspectRatio4To3) {
svaldezc3a9a172015-11-03 22:01:33611 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46612
613 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
614
615 std::string constraints_4_3 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07616 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46617
[email protected]bdcc9702014-01-17 16:07:46618 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05619 ASSERT_EQ("w=640:h=480",
[email protected]43ebe9e2014-03-08 21:00:58620 ExecuteJavascriptAndReturnResult(constraints_4_3));
[email protected]856f7cbd2014-03-07 09:54:32621}
622
[email protected]856f7cbd2014-03-07 09:54:32623// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27624IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund3619c422016-01-11 10:13:57625 TestGetUserMediaAspectRatio16To9) {
svaldezc3a9a172015-11-03 22:01:33626 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]856f7cbd2014-03-07 09:54:32627
628 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
629
630 std::string constraints_16_9 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07631 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
[email protected]bdcc9702014-01-17 16:07:46632
633 NavigateToURL(shell(), url);
[email protected]b5d213b2014-03-27 11:45:05634 ASSERT_EQ("w=640:h=360",
[email protected]43ebe9e2014-03-08 21:00:58635 ExecuteJavascriptAndReturnResult(constraints_16_9));
[email protected]bdcc9702014-01-17 16:07:46636}
637
[email protected]b5d213b2014-03-27 11:45:05638// This test calls getUserMedia and checks for aspect ratio behavior.
phoglunda1f6906c2015-08-27 13:57:27639IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
phoglund3619c422016-01-11 10:13:57640 TestGetUserMediaAspectRatio1To1) {
svaldezc3a9a172015-11-03 22:01:33641 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]b5d213b2014-03-27 11:45:05642
643 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
644
645 std::string constraints_1_1 = GenerateGetUserMediaCall(
[email protected]cbc7d672014-04-04 09:27:07646 kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
[email protected]b5d213b2014-03-27 11:45:05647
648 NavigateToURL(shell(), url);
649 ASSERT_EQ("w=320:h=320",
650 ExecuteJavascriptAndReturnResult(constraints_1_1));
651}
652
perkj64aae322015-04-10 14:51:41653// This test calls getUserMedia in an iframe and immediately close the iframe
654// in the scope of the success callback.
phoglunda1f6906c2015-08-27 13:57:27655IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41656 AudioInIFrameAndCloseInSuccessCb) {
svaldezc3a9a172015-11-03 22:01:33657 ASSERT_TRUE(embedded_test_server()->Start());
perkj64aae322015-04-10 14:51:41658
659 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
660 NavigateToURL(shell(), url);
661
662 std::string call =
663 "getUserMediaInIframeAndCloseInSuccessCb({audio: true});";
664 ExecuteJavascriptAndWaitForOk(call);
665}
666
phoglunda1f6906c2015-08-27 13:57:27667IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41668 VideoInIFrameAndCloseInSuccessCb) {
svaldezc3a9a172015-11-03 22:01:33669 ASSERT_TRUE(embedded_test_server()->Start());
perkj64aae322015-04-10 14:51:41670
671 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
672 NavigateToURL(shell(), url);
673
674 std::string call =
675 "getUserMediaInIframeAndCloseInSuccessCb({video: true});";
676 ExecuteJavascriptAndWaitForOk(call);
677}
678
679// This test calls getUserMedia in an iframe and immediately close the iframe
680// in the scope of the failure callback.
phoglunda1f6906c2015-08-27 13:57:27681IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41682 VideoWithBadConstraintsInIFrameAndCloseInFailureCb) {
svaldezc3a9a172015-11-03 22:01:33683 ASSERT_TRUE(embedded_test_server()->Start());
perkj64aae322015-04-10 14:51:41684
685 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
686
687 int large_value = 99999;
688 std::string call =
689 GenerateGetUserMediaCall("getUserMediaInIframeAndCloseInFailureCb",
690 large_value,
691 large_value,
692 large_value,
693 large_value,
694 large_value,
695 large_value);
696 NavigateToURL(shell(), url);
697
698 ExecuteJavascriptAndWaitForOk(call);
699}
700
phoglunda1f6906c2015-08-27 13:57:27701IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
perkj64aae322015-04-10 14:51:41702 InvalidSourceIdInIFrameAndCloseInFailureCb) {
svaldezc3a9a172015-11-03 22:01:33703 ASSERT_TRUE(embedded_test_server()->Start());
perkj64aae322015-04-10 14:51:41704
705 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
706
707 std::string call =
708 GenerateGetUserMediaWithMandatorySourceID(
709 "getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid");
710 NavigateToURL(shell(), url);
711
712 ExecuteJavascriptAndWaitForOk(call);
713}
714
[email protected]bdcc9702014-01-17 16:07:46715namespace {
716
717struct UserMediaSizes {
718 int min_width;
719 int max_width;
720 int min_height;
721 int max_height;
722 int min_frame_rate;
723 int max_frame_rate;
724};
725
726} // namespace
727
728class WebRtcConstraintsBrowserTest
[email protected]99063682014-03-13 15:15:30729 : public WebRtcContentBrowserTest,
[email protected]bdcc9702014-01-17 16:07:46730 public testing::WithParamInterface<UserMediaSizes> {
731 public:
guoweis8efb6d892015-10-12 18:26:17732 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {
733 // Automatically grant device permission.
734 AppendUseFakeUIForMediaStreamFlag();
735 }
[email protected]bdcc9702014-01-17 16:07:46736 const UserMediaSizes& user_media() const { return user_media_; }
737
738 private:
739 UserMediaSizes user_media_;
740};
741
timurrrr2ec7e9ae2015-01-19 13:24:06742// Test fails under MSan, http://crbug.com/445745
jyasskindc83b9a2015-01-13 03:15:03743#if defined(MEMORY_SANITIZER)
744#define MAYBE_GetUserMediaConstraints DISABLED_GetUserMediaConstraints
745#else
746#define MAYBE_GetUserMediaConstraints GetUserMediaConstraints
747#endif
[email protected]bdcc9702014-01-17 16:07:46748// This test calls getUserMedia in sequence with different constraints.
jyasskindc83b9a2015-01-13 03:15:03749IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest,
750 MAYBE_GetUserMediaConstraints) {
svaldezc3a9a172015-11-03 22:01:33751 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]bdcc9702014-01-17 16:07:46752
753 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
754
755 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop,
756 user_media().min_width,
757 user_media().max_width,
758 user_media().min_height,
759 user_media().max_height,
760 user_media().min_frame_rate,
761 user_media().max_frame_rate);
762 DVLOG(1) << "Calling getUserMedia: " << call;
763 NavigateToURL(shell(), url);
[email protected]43ebe9e2014-03-08 21:00:58764 ExecuteJavascriptAndWaitForOk(call);
[email protected]bdcc9702014-01-17 16:07:46765}
766
767static const UserMediaSizes kAllUserMediaSizes[] = {
[email protected]cbc7d672014-04-04 09:27:07768 {320, 320, 180, 180, 10, 30},
769 {320, 320, 240, 240, 10, 30},
770 {640, 640, 360, 360, 10, 30},
771 {640, 640, 480, 480, 10, 30},
772 {960, 960, 720, 720, 10, 30},
773 {1280, 1280, 720, 720, 10, 30}};
[email protected]bdcc9702014-01-17 16:07:46774
[email protected]33afb892014-07-11 08:17:30775INSTANTIATE_TEST_CASE_P(UserMedia,
[email protected]bdcc9702014-01-17 16:07:46776 WebRtcConstraintsBrowserTest,
777 testing::ValuesIn(kAllUserMediaSizes));
778
779} // namespace content