[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 1 | // 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 | |
avi | 7f27756 | 2015-12-25 02:41:26 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 8 | #include "base/json/json_reader.h" |
primiano | 30c5afa | 2016-02-22 14:37:08 | [diff] [blame] | 9 | #include "base/memory/ref_counted_memory.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 10 | #include "base/strings/stringprintf.h" |
| 11 | #include "base/test/trace_event_analyzer.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 12 | #include "base/trace_event/trace_event_impl.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 13 | #include "base/values.h" |
avi | 7f27756 | 2015-12-25 02:41:26 | [diff] [blame] | 14 | #include "build/build_config.h" |
mcasas | 6c910df | 2016-02-23 23:27:58 | [diff] [blame] | 15 | #include "content/browser/media/webrtc/webrtc_internals.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 16 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 17 | #include "content/public/common/content_switches.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 18 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 6e9def1 | 2014-03-27 20:23:28 | [diff] [blame] | 19 | #include "content/public/test/content_browser_test_utils.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 20 | #include "content/public/test/test_utils.h" |
| 21 | #include "content/shell/browser/shell.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 22 | #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 | |
| 30 | using trace_analyzer::TraceAnalyzer; |
| 31 | using trace_analyzer::Query; |
| 32 | using trace_analyzer::TraceEventVector; |
| 33 | |
| 34 | namespace { |
| 35 | |
| 36 | static const char kGetUserMediaAndStop[] = "getUserMediaAndStop"; |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 37 | static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 38 | static const char kGetUserMediaAndAnalyseAndStop[] = |
| 39 | "getUserMediaAndAnalyseAndStop"; |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 40 | static const char kGetUserMediaAndExpectFailure[] = |
| 41 | "getUserMediaAndExpectFailure"; |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 42 | static const char kRenderSameTrackMediastreamAndStop[] = |
| 43 | "renderSameTrackMediastreamAndStop"; |
| 44 | static const char kRenderClonedMediastreamAndStop[] = |
| 45 | "renderClonedMediastreamAndStop"; |
| 46 | static const char kRenderClonedTrackMediastreamAndStop[] = |
| 47 | "renderClonedTrackMediastreamAndStop"; |
| 48 | static const char kRenderDuplicatedMediastreamAndStop[] = |
| 49 | "renderDuplicatedMediastreamAndStop"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 50 | |
| 51 | // Results returned by JS. |
| 52 | static const char kOK[] = "OK"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 53 | |
| 54 | std::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 | |
| 66 | std::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 | |
| 80 | namespace content { |
| 81 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 82 | class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 83 | public: |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 84 | WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) { |
| 85 | // Automatically grant device permission. |
| 86 | AppendUseFakeUIForMediaStreamFlag(); |
| 87 | } |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 88 | ~WebRtcGetUserMediaBrowserTest() override {} |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 89 | |
| 90 | void StartTracing() { |
| 91 | CHECK(trace_log_ == NULL) << "Can only can start tracing once"; |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 92 | trace_log_ = base::trace_event::TraceLog::GetInstance(); |
zhenw | d601ddc5 | 2015-06-02 21:46:34 | [diff] [blame] | 93 | 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] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 98 | // Check that we are indeed recording. |
| 99 | EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1); |
| 100 | } |
| 101 | |
| 102 | void StopTracing() { |
dcheng | 7707e97 | 2014-08-26 19:37:01 | [diff] [blame] | 103 | CHECK(message_loop_runner_.get() == NULL) |
| 104 | << "Calling StopTracing more than once"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 105 | trace_log_->SetDisabled(); |
| 106 | message_loop_runner_ = new MessageLoopRunner; |
| 107 | trace_log_->Flush(base::Bind( |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 108 | &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 109 | 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] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 125 | void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs, |
| 126 | const std::string& measure_filter, |
| 127 | const std::string& graph_name) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 128 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 129 | |
| 130 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 131 | NavigateToURL(shell(), url); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 132 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 133 | // Put getUserMedia to work and let it run for a couple of seconds. |
| 134 | DCHECK(time_to_sample_secs); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 135 | ExecuteJavascriptAndWaitForOk( |
phoglund | 4eb7545 | 2014-10-07 15:34:07 | [diff] [blame] | 136 | base::StringPrintf("%s({video: true}, 'myStreamName');", |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 137 | kGetUserMediaAndGetStreamUp)); |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 138 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 139 | // Now the stream is up and running, start collecting traces. |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 140 | StartTracing(); |
| 141 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 142 | ExecuteJavascriptAndWaitForOk( |
phoglund | 4eb7545 | 2014-10-07 15:34:07 | [diff] [blame] | 143 | base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);", |
| 144 | time_to_sample_secs)); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 145 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 146 | // 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] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 148 | StopTracing(); |
| 149 | |
dcheng | 3b4fe47 | 2016-04-08 23:45:13 | [diff] [blame] | 150 | std::unique_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer()); |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 151 | 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] | 697173d | 2014-06-26 11:52:13 | [diff] [blame] | 181 | // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|. |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 182 | void RunTwoGetTwoGetUserMediaWithDifferentContraints( |
| 183 | const std::string& constraints1, |
| 184 | const std::string& constraints2, |
| 185 | const std::string& expected_result) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 186 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 187 | |
| 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] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 197 | void GetInputDevices(std::vector<std::string>* audio_ids, |
| 198 | std::vector<std::string>* video_ids) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 199 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 200 | NavigateToURL(shell(), url); |
| 201 | |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 202 | std::string devices_as_json = ExecuteJavascriptAndReturnResult( |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 203 | "getSources()"); |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 204 | EXPECT_FALSE(devices_as_json.empty()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 205 | |
| 206 | int error_code; |
| 207 | std::string error_message; |
dcheng | 3b4fe47 | 2016-04-08 23:45:13 | [diff] [blame] | 208 | std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
olli.raula | 4b5fb793 | 2015-08-24 11:51:58 | [diff] [blame] | 209 | devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, |
| 210 | &error_message); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 211 | |
| 212 | ASSERT_TRUE(value.get() != NULL) << error_message; |
| 213 | EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST); |
| 214 | |
| 215 | base::ListValue* values; |
| 216 | ASSERT_TRUE(value->GetAsList(&values)); |
| 217 | |
| 218 | for (base::ListValue::iterator it = values->begin(); |
| 219 | it != values->end(); ++it) { |
| 220 | const base::DictionaryValue* dict; |
| 221 | std::string kind; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 222 | std::string device_id; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 223 | ASSERT_TRUE((*it)->GetAsDictionary(&dict)); |
| 224 | ASSERT_TRUE(dict->GetString("kind", &kind)); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 225 | ASSERT_TRUE(dict->GetString("id", &device_id)); |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 226 | ASSERT_FALSE(device_id.empty()); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 227 | EXPECT_TRUE(kind == "audio" || kind == "video"); |
| 228 | if (kind == "audio") { |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 229 | audio_ids->push_back(device_id); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 230 | } else if (kind == "video") { |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 231 | video_ids->push_back(device_id); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | ASSERT_FALSE(audio_ids->empty()); |
| 235 | ASSERT_FALSE(video_ids->empty()); |
| 236 | } |
| 237 | |
| 238 | private: |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 239 | base::trace_event::TraceLog* trace_log_; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 240 | 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. |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 247 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 248 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 249 | #if defined(MEMORY_SANITIZER) |
| 250 | #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop |
| 251 | #else |
| 252 | #define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop |
| 253 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 254 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 255 | MAYBE_GetVideoStreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 256 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 257 | |
| 258 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 259 | NavigateToURL(shell(), url); |
| 260 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 261 | ExecuteJavascriptAndWaitForOk( |
| 262 | base::StringPrintf("%s({video: true});", kGetUserMediaAndStop)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 263 | } |
| 264 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 265 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 266 | #if defined(MEMORY_SANITIZER) |
| 267 | #define MAYBE_RenderSameTrackMediastreamAndStop \ |
| 268 | DISABLED_RenderSameTrackMediastreamAndStop |
| 269 | #else |
| 270 | #define MAYBE_RenderSameTrackMediastreamAndStop \ |
| 271 | RenderSameTrackMediastreamAndStop |
| 272 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 273 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 274 | MAYBE_RenderSameTrackMediastreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 275 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 276 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 285 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 286 | RenderClonedMediastreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 287 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 288 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 298 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 299 | kRenderClonedTrackMediastreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 300 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 301 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 310 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 311 | kRenderDuplicatedMediastreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 312 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 313 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 322 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 323 | GetAudioAndVideoStreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 324 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 325 | |
| 326 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 327 | NavigateToURL(shell(), url); |
| 328 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 329 | ExecuteJavascriptAndWaitForOk(base::StringPrintf( |
| 330 | "%s({video: true, audio: true});", kGetUserMediaAndStop)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 331 | } |
| 332 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 333 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 334 | GetAudioAndVideoStreamAndClone) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 335 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 336 | |
| 337 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 338 | NavigateToURL(shell(), url); |
| 339 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 340 | ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 341 | } |
| 342 | |
battre | 89812d1 | 2015-08-25 12:40:09 | [diff] [blame] | 343 | // Test fails under Android, http://crbug.com/524388 |
phoglund | c0556e2 | 2015-08-28 07:47:25 | [diff] [blame] | 344 | // Test fails under MSan |
| 345 | // Flaky everywhere else: http://crbug.com/523152 |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 346 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
qiangchen | 4819b085 | 2015-11-02 22:53:02 | [diff] [blame] | 347 | RenderVideoTrackInMultipleTagsAndPause) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 348 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | c606287 | 2014-03-21 14:35:37 | [diff] [blame] | 349 | |
| 350 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 351 | NavigateToURL(shell(), url); |
| 352 | |
| 353 | ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();"); |
| 354 | } |
| 355 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 356 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 357 | GetUserMediaWithMandatorySourceID) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 358 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 359 | |
| 360 | std::vector<std::string> audio_ids; |
| 361 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 362 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 363 | |
| 364 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
perkj | 5225533 | 2016-07-06 14:22:40 | [diff] [blame^] | 365 | NavigateToURL(shell(), url); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 366 | |
| 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] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 372 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 373 | GenerateGetUserMediaWithMandatorySourceID( |
| 374 | kGetUserMediaAndStop, |
| 375 | *audio_it, |
| 376 | *video_it))); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 381 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 382 | GetUserMediaWithInvalidMandatorySourceID) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 383 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 384 | |
| 385 | std::vector<std::string> audio_ids; |
| 386 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 387 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 388 | |
| 389 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 390 | |
| 391 | // Test with invalid mandatory audio sourceID. |
| 392 | NavigateToURL(shell(), url); |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 393 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 394 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 395 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 396 | "something invalid", |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 397 | video_ids[0]))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 398 | |
| 399 | // Test with invalid mandatory video sourceID. |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 400 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 401 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 402 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 403 | audio_ids[0], |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 404 | "something invalid"))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 405 | |
| 406 | // Test with empty mandatory audio sourceID. |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 407 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 408 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 409 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 410 | "", |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 411 | video_ids[0]))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 412 | } |
| 413 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 414 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 415 | GetUserMediaWithInvalidOptionalSourceID) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 416 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 417 | |
| 418 | std::vector<std::string> audio_ids; |
| 419 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 420 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 421 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 447 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | f3296cd | 2015-08-10 16:05:32 | [diff] [blame] | 448 | TwoGetUserMediaAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 449 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 450 | |
| 451 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 452 | NavigateToURL(shell(), url); |
| 453 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 454 | ExecuteJavascriptAndWaitForOk( |
| 455 | "twoGetUserMediaAndStop({video: true, audio: true});"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 456 | } |
| 457 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 458 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 459 | TwoGetUserMediaWithEqualConstraints) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 460 | 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] | 744ff3e | 2014-06-19 19:28:01 | [diff] [blame] | 466 | } |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 467 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 468 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 469 | TwoGetUserMediaWithSecondVideoCropped) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 470 | 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 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 477 | // 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 |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 485 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 486 | MAYBE_TwoGetUserMediaWithFirstHdSecondVga) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 487 | std::string constraints1 = |
mcasas | 0309b1d | 2014-12-03 21:06:12 | [diff] [blame] | 488 | "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\ |
| 489 | minHeight: 720}}}"; |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 490 | 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 | |
shrikant | aaccc11 | 2014-12-17 23:17:08 | [diff] [blame] | 497 | #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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 506 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
shrikant | aaccc11 | 2014-12-17 23:17:08 | [diff] [blame] | 507 | MAYBE_TwoGetUserMediaWithFirst1080pSecondVga) { |
mcasas | 0309b1d | 2014-12-03 21:06:12 | [diff] [blame] | 508 | 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 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 518 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 519 | #if defined(MEMORY_SANITIZER) |
| 520 | #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \ |
| 521 | DISABLED_TwoGetUserMediaAndVerifyFrameRate |
| 522 | #else |
| 523 | #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \ |
| 524 | TwoGetUserMediaAndVerifyFrameRate |
| 525 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 526 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 527 | MAYBE_TwoGetUserMediaAndVerifyFrameRate) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 528 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 697173d | 2014-06-26 11:52:13 | [diff] [blame] | 529 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 545 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 546 | GetUserMediaWithTooHighVideoConstraintsValues) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 547 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 548 | |
| 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] | c3629aa | 2014-08-12 05:48:30 | [diff] [blame] | 561 | EXPECT_EQ("ConstraintNotSatisfiedError", |
| 562 | ExecuteJavascriptAndReturnResult(call)); |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 563 | } |
| 564 | |
jansson | 1c493cf | 2014-10-16 07:33:32 | [diff] [blame] | 565 | // 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. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 568 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jansson | 1c493cf | 2014-10-16 07:33:32 | [diff] [blame] | 569 | TwoGetUserMediaAndCheckCallbackAfterFailure) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 570 | ASSERT_TRUE(embedded_test_server()->Start()); |
jansson | 1c493cf | 2014-10-16 07:33:32 | [diff] [blame] | 571 | |
| 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] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 595 | // 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] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 597 | // performance traces from VideoCaptureController colorspace conversion and |
| 598 | // potential resizing. |
[email protected] | 118c458 | 2014-07-17 08:02:08 | [diff] [blame] | 599 | IN_PROC_BROWSER_TEST_F( |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 600 | WebRtcGetUserMediaBrowserTest, |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 601 | TraceVideoCaptureControllerPerformanceDuringGetUserMedia) { |
| 602 | RunGetUserMediaAndCollectMeasures( |
| 603 | 10, |
qiangchen | 939cdf30 | 2015-04-06 21:36:33 | [diff] [blame] | 604 | "VideoCaptureDeviceClient::OnIncomingCapturedData", |
| 605 | "VideoCaptureDeviceClient"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 606 | } |
| 607 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 608 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 609 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 3619c42 | 2016-01-11 10:13:57 | [diff] [blame] | 610 | TestGetUserMediaAspectRatio4To3) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 611 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 612 | |
| 613 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 614 | |
| 615 | std::string constraints_4_3 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 616 | kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 617 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 618 | NavigateToURL(shell(), url); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 619 | ASSERT_EQ("w=640:h=480", |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 620 | ExecuteJavascriptAndReturnResult(constraints_4_3)); |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 623 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 624 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 3619c42 | 2016-01-11 10:13:57 | [diff] [blame] | 625 | TestGetUserMediaAspectRatio16To9) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 626 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 627 | |
| 628 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 629 | |
| 630 | std::string constraints_16_9 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 631 | kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 632 | |
| 633 | NavigateToURL(shell(), url); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 634 | ASSERT_EQ("w=640:h=360", |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 635 | ExecuteJavascriptAndReturnResult(constraints_16_9)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 636 | } |
| 637 | |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 638 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 639 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 3619c42 | 2016-01-11 10:13:57 | [diff] [blame] | 640 | TestGetUserMediaAspectRatio1To1) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 641 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 642 | |
| 643 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 644 | |
| 645 | std::string constraints_1_1 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 646 | kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 647 | |
| 648 | NavigateToURL(shell(), url); |
| 649 | ASSERT_EQ("w=320:h=320", |
| 650 | ExecuteJavascriptAndReturnResult(constraints_1_1)); |
| 651 | } |
| 652 | |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 653 | // This test calls getUserMedia in an iframe and immediately close the iframe |
| 654 | // in the scope of the success callback. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 655 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 656 | AudioInIFrameAndCloseInSuccessCb) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 657 | ASSERT_TRUE(embedded_test_server()->Start()); |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 658 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 667 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 668 | VideoInIFrameAndCloseInSuccessCb) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 669 | ASSERT_TRUE(embedded_test_server()->Start()); |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 670 | |
| 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. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 681 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 682 | VideoWithBadConstraintsInIFrameAndCloseInFailureCb) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 683 | ASSERT_TRUE(embedded_test_server()->Start()); |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 684 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 701 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 702 | InvalidSourceIdInIFrameAndCloseInFailureCb) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 703 | ASSERT_TRUE(embedded_test_server()->Start()); |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 704 | |
| 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] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 715 | namespace { |
| 716 | |
| 717 | struct 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 | |
| 728 | class WebRtcConstraintsBrowserTest |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 729 | : public WebRtcContentBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 730 | public testing::WithParamInterface<UserMediaSizes> { |
| 731 | public: |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 732 | WebRtcConstraintsBrowserTest() : user_media_(GetParam()) { |
| 733 | // Automatically grant device permission. |
| 734 | AppendUseFakeUIForMediaStreamFlag(); |
| 735 | } |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 736 | const UserMediaSizes& user_media() const { return user_media_; } |
| 737 | |
| 738 | private: |
| 739 | UserMediaSizes user_media_; |
| 740 | }; |
| 741 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 742 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 743 | #if defined(MEMORY_SANITIZER) |
| 744 | #define MAYBE_GetUserMediaConstraints DISABLED_GetUserMediaConstraints |
| 745 | #else |
| 746 | #define MAYBE_GetUserMediaConstraints GetUserMediaConstraints |
| 747 | #endif |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 748 | // This test calls getUserMedia in sequence with different constraints. |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 749 | IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest, |
| 750 | MAYBE_GetUserMediaConstraints) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 751 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 752 | |
| 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] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 764 | ExecuteJavascriptAndWaitForOk(call); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static const UserMediaSizes kAllUserMediaSizes[] = { |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 768 | {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] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 774 | |
[email protected] | 33afb89 | 2014-07-11 08:17:30 | [diff] [blame] | 775 | INSTANTIATE_TEST_CASE_P(UserMedia, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 776 | WebRtcConstraintsBrowserTest, |
| 777 | testing::ValuesIn(kAllUserMediaSizes)); |
| 778 | |
| 779 | } // namespace content |