[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" |
lukasza | 7947ccd | 2016-07-28 21:56:25 | [diff] [blame] | 12 | #include "base/threading/thread_restrictions.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 13 | #include "base/trace_event/trace_event_impl.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 14 | #include "base/values.h" |
avi | 7f27756 | 2015-12-25 02:41:26 | [diff] [blame] | 15 | #include "build/build_config.h" |
qiangchen | f6ca1ed | 2016-10-13 22:25:00 | [diff] [blame] | 16 | #include "content/browser/browser_main_loop.h" |
| 17 | #include "content/browser/renderer_host/media/media_stream_manager.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 18 | #include "content/browser/web_contents/web_contents_impl.h" |
mcasas | 6b8c0c8 | 2016-07-29 23:04:35 | [diff] [blame] | 19 | #include "content/browser/webrtc/webrtc_content_browsertest_base.h" |
| 20 | #include "content/browser/webrtc/webrtc_internals.h" |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 21 | #include "content/public/common/content_switches.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 22 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 6e9def1 | 2014-03-27 20:23:28 | [diff] [blame] | 23 | #include "content/public/test/content_browser_test_utils.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 24 | #include "content/public/test/test_utils.h" |
| 25 | #include "content/shell/browser/shell.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 26 | #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 | |
| 33 | using trace_analyzer::TraceAnalyzer; |
| 34 | using trace_analyzer::Query; |
| 35 | using trace_analyzer::TraceEventVector; |
| 36 | |
| 37 | namespace { |
| 38 | |
| 39 | static const char kGetUserMediaAndStop[] = "getUserMediaAndStop"; |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 40 | static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 41 | static const char kGetUserMediaAndAnalyseAndStop[] = |
| 42 | "getUserMediaAndAnalyseAndStop"; |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 43 | static const char kGetUserMediaAndExpectFailure[] = |
| 44 | "getUserMediaAndExpectFailure"; |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 45 | static const char kRenderSameTrackMediastreamAndStop[] = |
| 46 | "renderSameTrackMediastreamAndStop"; |
| 47 | static const char kRenderClonedMediastreamAndStop[] = |
| 48 | "renderClonedMediastreamAndStop"; |
| 49 | static const char kRenderClonedTrackMediastreamAndStop[] = |
| 50 | "renderClonedTrackMediastreamAndStop"; |
| 51 | static const char kRenderDuplicatedMediastreamAndStop[] = |
| 52 | "renderDuplicatedMediastreamAndStop"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 53 | |
| 54 | // Results returned by JS. |
| 55 | static const char kOK[] = "OK"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 56 | |
| 57 | std::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 | |
| 69 | std::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 | |
qiangchen | f6ca1ed | 2016-10-13 22:25:00 | [diff] [blame] | 81 | std::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 | |
| 93 | bool VerifyDisableLocalEcho(bool expect_value, |
| 94 | const content::StreamControls& controls) { |
| 95 | return expect_value == controls.disable_local_echo; |
| 96 | } |
| 97 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 98 | } // namespace |
| 99 | |
| 100 | namespace content { |
| 101 | |
mcasas | 41f5b70 | 2016-08-03 20:19:41 | [diff] [blame] | 102 | class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 103 | public: |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 104 | WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) { |
| 105 | // Automatically grant device permission. |
| 106 | AppendUseFakeUIForMediaStreamFlag(); |
| 107 | } |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 108 | ~WebRtcGetUserMediaBrowserTest() override {} |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 109 | |
| 110 | void StartTracing() { |
| 111 | CHECK(trace_log_ == NULL) << "Can only can start tracing once"; |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 112 | trace_log_ = base::trace_event::TraceLog::GetInstance(); |
zhenw | d601ddc5 | 2015-06-02 21:46:34 | [diff] [blame] | 113 | base::trace_event::TraceConfig trace_config( |
| 114 | "video", base::trace_event::RECORD_UNTIL_FULL); |
zhenw | d601ddc5 | 2015-06-02 21:46:34 | [diff] [blame] | 115 | trace_log_->SetEnabled(trace_config, |
| 116 | base::trace_event::TraceLog::RECORDING_MODE); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 117 | // Check that we are indeed recording. |
| 118 | EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1); |
| 119 | } |
| 120 | |
| 121 | void StopTracing() { |
dcheng | 7707e97 | 2014-08-26 19:37:01 | [diff] [blame] | 122 | CHECK(message_loop_runner_.get() == NULL) |
| 123 | << "Calling StopTracing more than once"; |
lukasza | 7947ccd | 2016-07-28 21:56:25 | [diff] [blame] | 124 | |
| 125 | { |
| 126 | base::ThreadRestrictions::ScopedAllowIO allow_thread_join_caused_by_test; |
| 127 | trace_log_->SetDisabled(); |
| 128 | } |
| 129 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 130 | message_loop_runner_ = new MessageLoopRunner; |
| 131 | trace_log_->Flush(base::Bind( |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 132 | &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 133 | 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] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 149 | void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs, |
| 150 | const std::string& measure_filter, |
| 151 | const std::string& graph_name) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 152 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 153 | |
| 154 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 155 | NavigateToURL(shell(), url); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 156 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 157 | // Put getUserMedia to work and let it run for a couple of seconds. |
| 158 | DCHECK(time_to_sample_secs); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 159 | ExecuteJavascriptAndWaitForOk( |
phoglund | 4eb7545 | 2014-10-07 15:34:07 | [diff] [blame] | 160 | base::StringPrintf("%s({video: true}, 'myStreamName');", |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 161 | kGetUserMediaAndGetStreamUp)); |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 162 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 163 | // Now the stream is up and running, start collecting traces. |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 164 | StartTracing(); |
| 165 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 166 | ExecuteJavascriptAndWaitForOk( |
phoglund | 4eb7545 | 2014-10-07 15:34:07 | [diff] [blame] | 167 | base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);", |
| 168 | time_to_sample_secs)); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 169 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 170 | // 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] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 172 | StopTracing(); |
| 173 | |
dcheng | 3b4fe47 | 2016-04-08 23:45:13 | [diff] [blame] | 174 | std::unique_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer()); |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 175 | 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] | 697173d | 2014-06-26 11:52:13 | [diff] [blame] | 205 | // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|. |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 206 | void RunTwoGetTwoGetUserMediaWithDifferentContraints( |
| 207 | const std::string& constraints1, |
| 208 | const std::string& constraints2, |
| 209 | const std::string& expected_result) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 210 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 211 | |
| 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] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 221 | void GetInputDevices(std::vector<std::string>* audio_ids, |
| 222 | std::vector<std::string>* video_ids) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 223 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 224 | NavigateToURL(shell(), url); |
| 225 | |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 226 | std::string devices_as_json = ExecuteJavascriptAndReturnResult( |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 227 | "getSources()"); |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 228 | EXPECT_FALSE(devices_as_json.empty()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 229 | |
| 230 | int error_code; |
| 231 | std::string error_message; |
dcheng | 3b4fe47 | 2016-04-08 23:45:13 | [diff] [blame] | 232 | std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
olli.raula | 4b5fb793 | 2015-08-24 11:51:58 | [diff] [blame] | 233 | devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, |
| 234 | &error_message); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 235 | |
| 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] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 246 | std::string device_id; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 247 | ASSERT_TRUE((*it)->GetAsDictionary(&dict)); |
| 248 | ASSERT_TRUE(dict->GetString("kind", &kind)); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 249 | ASSERT_TRUE(dict->GetString("id", &device_id)); |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 250 | ASSERT_FALSE(device_id.empty()); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 251 | EXPECT_TRUE(kind == "audio" || kind == "video"); |
| 252 | if (kind == "audio") { |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 253 | audio_ids->push_back(device_id); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 254 | } else if (kind == "video") { |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 255 | video_ids->push_back(device_id); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | ASSERT_FALSE(audio_ids->empty()); |
| 259 | ASSERT_FALSE(video_ids->empty()); |
| 260 | } |
| 261 | |
| 262 | private: |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 263 | base::trace_event::TraceLog* trace_log_; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 264 | 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. |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 271 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 272 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 273 | #if defined(MEMORY_SANITIZER) |
| 274 | #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop |
| 275 | #else |
| 276 | #define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop |
| 277 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 278 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 279 | MAYBE_GetVideoStreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 280 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 281 | |
| 282 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 283 | NavigateToURL(shell(), url); |
| 284 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 285 | ExecuteJavascriptAndWaitForOk( |
| 286 | base::StringPrintf("%s({video: true});", kGetUserMediaAndStop)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 287 | } |
| 288 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 289 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 290 | #if defined(MEMORY_SANITIZER) |
| 291 | #define MAYBE_RenderSameTrackMediastreamAndStop \ |
| 292 | DISABLED_RenderSameTrackMediastreamAndStop |
| 293 | #else |
| 294 | #define MAYBE_RenderSameTrackMediastreamAndStop \ |
| 295 | RenderSameTrackMediastreamAndStop |
| 296 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 297 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 298 | MAYBE_RenderSameTrackMediastreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 299 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 300 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 309 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 310 | RenderClonedMediastreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 311 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 312 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 322 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 323 | kRenderClonedTrackMediastreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 324 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 325 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 334 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 335 | kRenderDuplicatedMediastreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 336 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 337 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 346 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 347 | GetAudioAndVideoStreamAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 348 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 349 | |
| 350 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 351 | NavigateToURL(shell(), url); |
| 352 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 353 | ExecuteJavascriptAndWaitForOk(base::StringPrintf( |
| 354 | "%s({video: true, audio: true});", kGetUserMediaAndStop)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 355 | } |
| 356 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 357 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 358 | GetAudioAndVideoStreamAndClone) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 359 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 360 | |
| 361 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 362 | NavigateToURL(shell(), url); |
| 363 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 364 | ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 365 | } |
| 366 | |
battre | 89812d1 | 2015-08-25 12:40:09 | [diff] [blame] | 367 | // Test fails under Android, http://crbug.com/524388 |
phoglund | c0556e2 | 2015-08-28 07:47:25 | [diff] [blame] | 368 | // Test fails under MSan |
| 369 | // Flaky everywhere else: http://crbug.com/523152 |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 370 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
qiangchen | 4819b085 | 2015-11-02 22:53:02 | [diff] [blame] | 371 | RenderVideoTrackInMultipleTagsAndPause) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 372 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | c606287 | 2014-03-21 14:35:37 | [diff] [blame] | 373 | |
| 374 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 375 | NavigateToURL(shell(), url); |
| 376 | |
| 377 | ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();"); |
| 378 | } |
| 379 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 380 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 381 | GetUserMediaWithMandatorySourceID) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 382 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 383 | |
| 384 | std::vector<std::string> audio_ids; |
| 385 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 386 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 387 | |
| 388 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
perkj | 5225533 | 2016-07-06 14:22:40 | [diff] [blame] | 389 | NavigateToURL(shell(), url); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 390 | |
| 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] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 396 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 397 | GenerateGetUserMediaWithMandatorySourceID( |
| 398 | kGetUserMediaAndStop, |
| 399 | *audio_it, |
| 400 | *video_it))); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 405 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 406 | GetUserMediaWithInvalidMandatorySourceID) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 407 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 408 | |
| 409 | std::vector<std::string> audio_ids; |
| 410 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 411 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 412 | |
| 413 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 414 | |
| 415 | // Test with invalid mandatory audio sourceID. |
| 416 | NavigateToURL(shell(), url); |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 417 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 418 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 419 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 420 | "something invalid", |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 421 | video_ids[0]))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 422 | |
| 423 | // Test with invalid mandatory video sourceID. |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 424 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 425 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 426 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 427 | audio_ids[0], |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 428 | "something invalid"))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 429 | |
| 430 | // Test with empty mandatory audio sourceID. |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 431 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 432 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 433 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 434 | "", |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 435 | video_ids[0]))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 436 | } |
| 437 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 438 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 439 | GetUserMediaWithInvalidOptionalSourceID) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 440 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 441 | |
| 442 | std::vector<std::string> audio_ids; |
| 443 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 444 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 445 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 471 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | f3296cd | 2015-08-10 16:05:32 | [diff] [blame] | 472 | TwoGetUserMediaAndStop) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 473 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 474 | |
| 475 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 476 | NavigateToURL(shell(), url); |
| 477 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 478 | ExecuteJavascriptAndWaitForOk( |
| 479 | "twoGetUserMediaAndStop({video: true, audio: true});"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 480 | } |
| 481 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 482 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 483 | TwoGetUserMediaWithEqualConstraints) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 484 | 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] | 744ff3e | 2014-06-19 19:28:01 | [diff] [blame] | 490 | } |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 491 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 492 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 493 | TwoGetUserMediaWithSecondVideoCropped) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 494 | 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 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 501 | // 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 |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 509 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 510 | MAYBE_TwoGetUserMediaWithFirstHdSecondVga) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 511 | std::string constraints1 = |
mcasas | 0309b1d | 2014-12-03 21:06:12 | [diff] [blame] | 512 | "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\ |
| 513 | minHeight: 720}}}"; |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 514 | 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 | |
phoglund | 311334d06 | 2016-10-31 10:50:19 | [diff] [blame] | 521 | // Timing out on Windows 7 bot: http://crbug.com/443294 |
| 522 | // Flaky: http://crbug.com/660656; possible the test is too perf sensitive. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 523 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 311334d06 | 2016-10-31 10:50:19 | [diff] [blame] | 524 | DISABLED_TwoGetUserMediaWithFirst1080pSecondVga) { |
mcasas | 0309b1d | 2014-12-03 21:06:12 | [diff] [blame] | 525 | 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 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 535 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 536 | #if defined(MEMORY_SANITIZER) |
| 537 | #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \ |
| 538 | DISABLED_TwoGetUserMediaAndVerifyFrameRate |
| 539 | #else |
| 540 | #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \ |
| 541 | TwoGetUserMediaAndVerifyFrameRate |
| 542 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 543 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 544 | MAYBE_TwoGetUserMediaAndVerifyFrameRate) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 545 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 697173d | 2014-06-26 11:52:13 | [diff] [blame] | 546 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 562 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 563 | GetUserMediaWithTooHighVideoConstraintsValues) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 564 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 565 | |
| 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] | c3629aa | 2014-08-12 05:48:30 | [diff] [blame] | 578 | EXPECT_EQ("ConstraintNotSatisfiedError", |
| 579 | ExecuteJavascriptAndReturnResult(call)); |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 580 | } |
| 581 | |
jansson | 1c493cf | 2014-10-16 07:33:32 | [diff] [blame] | 582 | // 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. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 585 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jansson | 1c493cf | 2014-10-16 07:33:32 | [diff] [blame] | 586 | TwoGetUserMediaAndCheckCallbackAfterFailure) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 587 | ASSERT_TRUE(embedded_test_server()->Start()); |
jansson | 1c493cf | 2014-10-16 07:33:32 | [diff] [blame] | 588 | |
| 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 | |
aboxhall | 68ab189 | 2016-08-04 22:43:36 | [diff] [blame] | 612 | #if defined(OS_ANDROID) && defined(NDEBUG) |
| 613 | #define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia DISABLED_TraceVideoCaptureControllerPerformanceDuringGetUserMedia |
| 614 | #else |
| 615 | #define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia TraceVideoCaptureControllerPerformanceDuringGetUserMedia |
| 616 | #endif |
| 617 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 618 | // 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] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 620 | // performance traces from VideoCaptureController colorspace conversion and |
| 621 | // potential resizing. |
[email protected] | 118c458 | 2014-07-17 08:02:08 | [diff] [blame] | 622 | IN_PROC_BROWSER_TEST_F( |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 623 | WebRtcGetUserMediaBrowserTest, |
aboxhall | 68ab189 | 2016-08-04 22:43:36 | [diff] [blame] | 624 | MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia) { |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 625 | RunGetUserMediaAndCollectMeasures( |
| 626 | 10, |
qiangchen | 939cdf30 | 2015-04-06 21:36:33 | [diff] [blame] | 627 | "VideoCaptureDeviceClient::OnIncomingCapturedData", |
| 628 | "VideoCaptureDeviceClient"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 629 | } |
| 630 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 631 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 632 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 3619c42 | 2016-01-11 10:13:57 | [diff] [blame] | 633 | TestGetUserMediaAspectRatio4To3) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 634 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 635 | |
| 636 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 637 | |
| 638 | std::string constraints_4_3 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 639 | kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 640 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 641 | NavigateToURL(shell(), url); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 642 | ASSERT_EQ("w=640:h=480", |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 643 | ExecuteJavascriptAndReturnResult(constraints_4_3)); |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 644 | } |
| 645 | |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 646 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 647 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 3619c42 | 2016-01-11 10:13:57 | [diff] [blame] | 648 | TestGetUserMediaAspectRatio16To9) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 649 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 650 | |
| 651 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 652 | |
| 653 | std::string constraints_16_9 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 654 | kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 655 | |
| 656 | NavigateToURL(shell(), url); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 657 | ASSERT_EQ("w=640:h=360", |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 658 | ExecuteJavascriptAndReturnResult(constraints_16_9)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 659 | } |
| 660 | |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 661 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 662 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 3619c42 | 2016-01-11 10:13:57 | [diff] [blame] | 663 | TestGetUserMediaAspectRatio1To1) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 664 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 665 | |
| 666 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 667 | |
| 668 | std::string constraints_1_1 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 669 | kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 670 | |
| 671 | NavigateToURL(shell(), url); |
| 672 | ASSERT_EQ("w=320:h=320", |
| 673 | ExecuteJavascriptAndReturnResult(constraints_1_1)); |
| 674 | } |
| 675 | |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 676 | // This test calls getUserMedia in an iframe and immediately close the iframe |
| 677 | // in the scope of the success callback. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 678 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 679 | AudioInIFrameAndCloseInSuccessCb) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 680 | ASSERT_TRUE(embedded_test_server()->Start()); |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 681 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 690 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 691 | VideoInIFrameAndCloseInSuccessCb) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 692 | ASSERT_TRUE(embedded_test_server()->Start()); |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 693 | |
| 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. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 704 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 705 | VideoWithBadConstraintsInIFrameAndCloseInFailureCb) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 706 | ASSERT_TRUE(embedded_test_server()->Start()); |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 707 | |
| 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 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 724 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 725 | InvalidSourceIdInIFrameAndCloseInFailureCb) { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 726 | ASSERT_TRUE(embedded_test_server()->Start()); |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 727 | |
| 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 | |
qiangchen | f6ca1ed | 2016-10-13 22:25:00 | [diff] [blame] | 738 | IN_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] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 766 | } // namespace content |