[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 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 5 | #include "base/command_line.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 6 | #include "base/json/json_reader.h" |
| 7 | #include "base/strings/stringprintf.h" |
| 8 | #include "base/test/trace_event_analyzer.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 9 | #include "base/trace_event/trace_event_impl.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 10 | #include "base/values.h" |
| 11 | #include "content/browser/media/webrtc_internals.h" |
| 12 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 13 | #include "content/public/common/content_switches.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 14 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 6e9def1 | 2014-03-27 20:23:28 | [diff] [blame] | 15 | #include "content/public/test/content_browser_test_utils.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 16 | #include "content/public/test/test_utils.h" |
| 17 | #include "content/shell/browser/shell.h" |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 18 | #include "content/test/webrtc_content_browsertest_base.h" |
| 19 | #include "net/test/embedded_test_server/embedded_test_server.h" |
| 20 | #include "testing/perf/perf_test.h" |
| 21 | |
| 22 | #if defined(OS_WIN) |
| 23 | #include "base/win/windows_version.h" |
| 24 | #endif |
| 25 | |
| 26 | using trace_analyzer::TraceAnalyzer; |
| 27 | using trace_analyzer::Query; |
| 28 | using trace_analyzer::TraceEventVector; |
| 29 | |
| 30 | namespace { |
| 31 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 32 | static const char kGetUserMediaAndStop[] = "getUserMediaAndStop"; |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 33 | static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 34 | static const char kGetUserMediaAndAnalyseAndStop[] = |
| 35 | "getUserMediaAndAnalyseAndStop"; |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 36 | static const char kGetUserMediaAndExpectFailure[] = |
| 37 | "getUserMediaAndExpectFailure"; |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 38 | static const char kRenderSameTrackMediastreamAndStop[] = |
| 39 | "renderSameTrackMediastreamAndStop"; |
| 40 | static const char kRenderClonedMediastreamAndStop[] = |
| 41 | "renderClonedMediastreamAndStop"; |
| 42 | static const char kRenderClonedTrackMediastreamAndStop[] = |
| 43 | "renderClonedTrackMediastreamAndStop"; |
| 44 | static const char kRenderDuplicatedMediastreamAndStop[] = |
| 45 | "renderDuplicatedMediastreamAndStop"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 46 | |
| 47 | // Results returned by JS. |
| 48 | static const char kOK[] = "OK"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 49 | |
| 50 | std::string GenerateGetUserMediaWithMandatorySourceID( |
| 51 | const std::string& function_name, |
| 52 | const std::string& audio_source_id, |
| 53 | const std::string& video_source_id) { |
| 54 | const std::string audio_constraint = |
| 55 | "audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, "; |
| 56 | |
| 57 | const std::string video_constraint = |
| 58 | "video: {mandatory: { sourceId:\"" + video_source_id + "\"}}"; |
| 59 | return function_name + "({" + audio_constraint + video_constraint + "});"; |
| 60 | } |
| 61 | |
| 62 | std::string GenerateGetUserMediaWithOptionalSourceID( |
| 63 | const std::string& function_name, |
| 64 | const std::string& audio_source_id, |
| 65 | const std::string& video_source_id) { |
| 66 | const std::string audio_constraint = |
| 67 | "audio: {optional: [{sourceId:\"" + audio_source_id + "\"}]}, "; |
| 68 | |
| 69 | const std::string video_constraint = |
| 70 | "video: {optional: [{ sourceId:\"" + video_source_id + "\"}]}"; |
| 71 | return function_name + "({" + audio_constraint + video_constraint + "});"; |
| 72 | } |
| 73 | |
| 74 | } // namespace |
| 75 | |
| 76 | namespace content { |
| 77 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 78 | class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 79 | public: |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 80 | WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) { |
| 81 | // Automatically grant device permission. |
| 82 | AppendUseFakeUIForMediaStreamFlag(); |
| 83 | } |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 84 | ~WebRtcGetUserMediaBrowserTest() override {} |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 85 | |
| 86 | void StartTracing() { |
| 87 | CHECK(trace_log_ == NULL) << "Can only can start tracing once"; |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 88 | trace_log_ = base::trace_event::TraceLog::GetInstance(); |
zhenw | d601ddc5 | 2015-06-02 21:46:34 | [diff] [blame] | 89 | base::trace_event::TraceConfig trace_config( |
| 90 | "video", base::trace_event::RECORD_UNTIL_FULL); |
| 91 | trace_config.EnableSampling(); |
| 92 | trace_log_->SetEnabled(trace_config, |
| 93 | base::trace_event::TraceLog::RECORDING_MODE); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 94 | // Check that we are indeed recording. |
| 95 | EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1); |
| 96 | } |
| 97 | |
| 98 | void StopTracing() { |
dcheng | 7707e97 | 2014-08-26 19:37:01 | [diff] [blame] | 99 | CHECK(message_loop_runner_.get() == NULL) |
| 100 | << "Calling StopTracing more than once"; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 101 | trace_log_->SetDisabled(); |
| 102 | message_loop_runner_ = new MessageLoopRunner; |
| 103 | trace_log_->Flush(base::Bind( |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 104 | &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 105 | base::Unretained(this))); |
| 106 | message_loop_runner_->Run(); |
| 107 | } |
| 108 | |
| 109 | void OnTraceDataCollected( |
| 110 | const scoped_refptr<base::RefCountedString>& events_str_ptr, |
| 111 | bool has_more_events) { |
| 112 | CHECK(!has_more_events); |
| 113 | recorded_trace_data_ = events_str_ptr; |
| 114 | message_loop_runner_->Quit(); |
| 115 | } |
| 116 | |
| 117 | TraceAnalyzer* CreateTraceAnalyzer() { |
| 118 | return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]"); |
| 119 | } |
| 120 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 121 | void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs, |
| 122 | const std::string& measure_filter, |
| 123 | const std::string& graph_name) { |
| 124 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 125 | |
| 126 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 127 | NavigateToURL(shell(), url); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 128 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 129 | // Put getUserMedia to work and let it run for a couple of seconds. |
| 130 | DCHECK(time_to_sample_secs); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 131 | ExecuteJavascriptAndWaitForOk( |
phoglund | 4eb7545 | 2014-10-07 15:34:07 | [diff] [blame] | 132 | base::StringPrintf("%s({video: true}, 'myStreamName');", |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 133 | kGetUserMediaAndGetStreamUp)); |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 134 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 135 | // Now the stream is up and running, start collecting traces. |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 136 | StartTracing(); |
| 137 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 138 | ExecuteJavascriptAndWaitForOk( |
phoglund | 4eb7545 | 2014-10-07 15:34:07 | [diff] [blame] | 139 | base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);", |
| 140 | time_to_sample_secs)); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 141 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 142 | // Wait until the page title changes to "OK". Do not sleep() here since that |
| 143 | // would stop both this code and the browser underneath. |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 144 | StopTracing(); |
| 145 | |
| 146 | scoped_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer()); |
| 147 | analyzer->AssociateBeginEndEvents(); |
| 148 | trace_analyzer::TraceEventVector events; |
| 149 | DCHECK(measure_filter.size()); |
| 150 | analyzer->FindEvents( |
| 151 | Query::EventNameIs(measure_filter), |
| 152 | &events); |
| 153 | ASSERT_GT(events.size(), 0u) |
| 154 | << "Could not collect any samples during test, this is bad"; |
| 155 | |
| 156 | std::string duration_us; |
| 157 | std::string interarrival_us; |
| 158 | for (size_t i = 0; i != events.size(); ++i) { |
| 159 | duration_us.append( |
| 160 | base::StringPrintf("%d,", static_cast<int>(events[i]->duration))); |
| 161 | } |
| 162 | |
| 163 | for (size_t i = 1; i < events.size(); ++i) { |
| 164 | // The event |timestamp| comes in ns, divide to get us like |duration|. |
| 165 | interarrival_us.append(base::StringPrintf("%d,", |
| 166 | static_cast<int>((events[i]->timestamp - events[i - 1]->timestamp) / |
| 167 | base::Time::kNanosecondsPerMicrosecond))); |
| 168 | } |
| 169 | |
| 170 | perf_test::PrintResultList( |
| 171 | graph_name, "", "sample_duration", duration_us, "us", true); |
| 172 | |
| 173 | perf_test::PrintResultList( |
| 174 | graph_name, "", "interarrival_time", interarrival_us, "us", true); |
| 175 | } |
| 176 | |
[email protected] | 697173d | 2014-06-26 11:52:13 | [diff] [blame] | 177 | // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|. |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 178 | void RunTwoGetTwoGetUserMediaWithDifferentContraints( |
| 179 | const std::string& constraints1, |
| 180 | const std::string& constraints2, |
| 181 | const std::string& expected_result) { |
| 182 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 183 | |
| 184 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 185 | NavigateToURL(shell(), url); |
| 186 | |
| 187 | std::string command = "twoGetUserMedia(" + constraints1 + ',' + |
| 188 | constraints2 + ')'; |
| 189 | |
| 190 | EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command)); |
| 191 | } |
| 192 | |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 193 | void GetInputDevices(std::vector<std::string>* audio_ids, |
| 194 | std::vector<std::string>* video_ids) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 195 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 196 | NavigateToURL(shell(), url); |
| 197 | |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 198 | std::string devices_as_json = ExecuteJavascriptAndReturnResult( |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 199 | "getSources()"); |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 200 | EXPECT_FALSE(devices_as_json.empty()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 201 | |
| 202 | int error_code; |
| 203 | std::string error_message; |
olli.raula | 4b5fb793 | 2015-08-24 11:51:58 | [diff] [blame] | 204 | scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
| 205 | devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, |
| 206 | &error_message); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 207 | |
| 208 | ASSERT_TRUE(value.get() != NULL) << error_message; |
| 209 | EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST); |
| 210 | |
| 211 | base::ListValue* values; |
| 212 | ASSERT_TRUE(value->GetAsList(&values)); |
| 213 | |
| 214 | for (base::ListValue::iterator it = values->begin(); |
| 215 | it != values->end(); ++it) { |
| 216 | const base::DictionaryValue* dict; |
| 217 | std::string kind; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 218 | std::string device_id; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 219 | ASSERT_TRUE((*it)->GetAsDictionary(&dict)); |
| 220 | ASSERT_TRUE(dict->GetString("kind", &kind)); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 221 | ASSERT_TRUE(dict->GetString("id", &device_id)); |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 222 | ASSERT_FALSE(device_id.empty()); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 223 | EXPECT_TRUE(kind == "audio" || kind == "video"); |
| 224 | if (kind == "audio") { |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 225 | audio_ids->push_back(device_id); |
[email protected] | b9ced84 | 2014-07-03 13:10:03 | [diff] [blame] | 226 | } else if (kind == "video") { |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 227 | video_ids->push_back(device_id); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | ASSERT_FALSE(audio_ids->empty()); |
| 231 | ASSERT_FALSE(video_ids->empty()); |
| 232 | } |
| 233 | |
| 234 | private: |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 235 | base::trace_event::TraceLog* trace_log_; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 236 | scoped_refptr<base::RefCountedString> recorded_trace_data_; |
| 237 | scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 238 | }; |
| 239 | |
| 240 | // These tests will all make a getUserMedia call with different constraints and |
| 241 | // see that the success callback is called. If the error callback is called or |
| 242 | // none of the callbacks are called the tests will simply time out and fail. |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 243 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 244 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 245 | #if defined(MEMORY_SANITIZER) |
| 246 | #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop |
| 247 | #else |
| 248 | #define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop |
| 249 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 250 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 251 | MAYBE_GetVideoStreamAndStop) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 252 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 253 | |
| 254 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 255 | NavigateToURL(shell(), url); |
| 256 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 257 | ExecuteJavascriptAndWaitForOk( |
| 258 | base::StringPrintf("%s({video: true});", kGetUserMediaAndStop)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 259 | } |
| 260 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 261 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 262 | #if defined(MEMORY_SANITIZER) |
| 263 | #define MAYBE_RenderSameTrackMediastreamAndStop \ |
| 264 | DISABLED_RenderSameTrackMediastreamAndStop |
| 265 | #else |
| 266 | #define MAYBE_RenderSameTrackMediastreamAndStop \ |
| 267 | RenderSameTrackMediastreamAndStop |
| 268 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 269 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 270 | MAYBE_RenderSameTrackMediastreamAndStop) { |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 271 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 272 | |
| 273 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 274 | NavigateToURL(shell(), url); |
| 275 | |
| 276 | ExecuteJavascriptAndWaitForOk( |
| 277 | base::StringPrintf("%s({video: true});", |
| 278 | kRenderSameTrackMediastreamAndStop)); |
| 279 | } |
| 280 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 281 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 282 | RenderClonedMediastreamAndStop) { |
| 283 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 284 | |
| 285 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 286 | NavigateToURL(shell(), url); |
| 287 | |
| 288 | |
| 289 | ExecuteJavascriptAndWaitForOk( |
| 290 | base::StringPrintf("%s({video: true});", |
| 291 | kRenderClonedMediastreamAndStop)); |
| 292 | } |
| 293 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 294 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 295 | kRenderClonedTrackMediastreamAndStop) { |
| 296 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 297 | |
| 298 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 299 | NavigateToURL(shell(), url); |
| 300 | |
| 301 | ExecuteJavascriptAndWaitForOk( |
| 302 | base::StringPrintf("%s({video: true});", |
| 303 | kRenderClonedTrackMediastreamAndStop)); |
| 304 | } |
| 305 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 306 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 307 | kRenderDuplicatedMediastreamAndStop) { |
| 308 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 309 | |
| 310 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 311 | NavigateToURL(shell(), url); |
| 312 | |
| 313 | ExecuteJavascriptAndWaitForOk( |
| 314 | base::StringPrintf("%s({video: true});", |
| 315 | kRenderDuplicatedMediastreamAndStop)); |
| 316 | } |
| 317 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 318 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 319 | GetAudioAndVideoStreamAndStop) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 320 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 321 | |
| 322 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 323 | NavigateToURL(shell(), url); |
| 324 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 325 | ExecuteJavascriptAndWaitForOk(base::StringPrintf( |
| 326 | "%s({video: true, audio: true});", kGetUserMediaAndStop)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 327 | } |
| 328 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 329 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 330 | GetAudioAndVideoStreamAndClone) { |
| 331 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 332 | |
| 333 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 334 | NavigateToURL(shell(), url); |
| 335 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 336 | ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 337 | } |
| 338 | |
battre | 89812d1 | 2015-08-25 12:40:09 | [diff] [blame] | 339 | // Test fails under Android, http://crbug.com/524388 |
phoglund | c0556e2 | 2015-08-28 07:47:25 | [diff] [blame] | 340 | // Test fails under MSan |
| 341 | // Flaky everywhere else: http://crbug.com/523152 |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 342 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
qiangchen | 4819b085 | 2015-11-02 22:53:02 | [diff] [blame^] | 343 | RenderVideoTrackInMultipleTagsAndPause) { |
[email protected] | c606287 | 2014-03-21 14:35:37 | [diff] [blame] | 344 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 345 | |
| 346 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 347 | NavigateToURL(shell(), url); |
| 348 | |
| 349 | ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();"); |
| 350 | } |
| 351 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 352 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 353 | GetUserMediaWithMandatorySourceID) { |
| 354 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 355 | |
| 356 | std::vector<std::string> audio_ids; |
| 357 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 358 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 359 | |
| 360 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 361 | |
| 362 | // Test all combinations of mandatory sourceID; |
| 363 | for (std::vector<std::string>::const_iterator video_it = video_ids.begin(); |
| 364 | video_it != video_ids.end(); ++video_it) { |
| 365 | for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin(); |
| 366 | audio_it != audio_ids.end(); ++audio_it) { |
| 367 | NavigateToURL(shell(), url); |
| 368 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 369 | GenerateGetUserMediaWithMandatorySourceID( |
| 370 | kGetUserMediaAndStop, |
| 371 | *audio_it, |
| 372 | *video_it))); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 377 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 378 | GetUserMediaWithInvalidMandatorySourceID) { |
| 379 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 380 | |
| 381 | std::vector<std::string> audio_ids; |
| 382 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 383 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 384 | |
| 385 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 386 | |
| 387 | // Test with invalid mandatory audio sourceID. |
| 388 | NavigateToURL(shell(), url); |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 389 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 390 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 391 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 392 | "something invalid", |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 393 | video_ids[0]))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 394 | |
| 395 | // Test with invalid mandatory video sourceID. |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 396 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 397 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 398 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 399 | audio_ids[0], |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 400 | "something invalid"))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 401 | |
| 402 | // Test with empty mandatory audio sourceID. |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 403 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 404 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 405 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 406 | "", |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 407 | video_ids[0]))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 408 | } |
| 409 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 410 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 411 | GetUserMediaWithInvalidOptionalSourceID) { |
| 412 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 413 | |
| 414 | std::vector<std::string> audio_ids; |
| 415 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame] | 416 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 417 | |
| 418 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 419 | |
| 420 | // Test with invalid optional audio sourceID. |
| 421 | NavigateToURL(shell(), url); |
| 422 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 423 | GenerateGetUserMediaWithOptionalSourceID( |
| 424 | kGetUserMediaAndStop, |
| 425 | "something invalid", |
| 426 | video_ids[0]))); |
| 427 | |
| 428 | // Test with invalid optional video sourceID. |
| 429 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 430 | GenerateGetUserMediaWithOptionalSourceID( |
| 431 | kGetUserMediaAndStop, |
| 432 | audio_ids[0], |
| 433 | "something invalid"))); |
| 434 | |
| 435 | // Test with empty optional audio sourceID. |
| 436 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 437 | GenerateGetUserMediaWithOptionalSourceID( |
| 438 | kGetUserMediaAndStop, |
| 439 | "", |
| 440 | video_ids[0]))); |
| 441 | } |
| 442 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 443 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | f3296cd | 2015-08-10 16:05:32 | [diff] [blame] | 444 | TwoGetUserMediaAndStop) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 445 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 446 | |
| 447 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 448 | NavigateToURL(shell(), url); |
| 449 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 450 | ExecuteJavascriptAndWaitForOk( |
| 451 | "twoGetUserMediaAndStop({video: true, audio: true});"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 452 | } |
| 453 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 454 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 455 | TwoGetUserMediaWithEqualConstraints) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 456 | std::string constraints1 = "{video: true, audio: true}"; |
| 457 | const std::string& constraints2 = constraints1; |
| 458 | std::string expected_result = "w=640:h=480-w=640:h=480"; |
| 459 | |
| 460 | RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, |
| 461 | expected_result); |
[email protected] | 744ff3e | 2014-06-19 19:28:01 | [diff] [blame] | 462 | } |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 463 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 464 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
phoglund | 9a09162 | 2014-10-10 08:51:12 | [diff] [blame] | 465 | TwoGetUserMediaWithSecondVideoCropped) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 466 | std::string constraints1 = "{video: true}"; |
| 467 | std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}"; |
| 468 | std::string expected_result = "w=640:h=480-w=640:h=360"; |
| 469 | RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, |
| 470 | expected_result); |
| 471 | } |
| 472 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 473 | // Test fails under MSan, http://crbug.com/445745 |
| 474 | #if defined(MEMORY_SANITIZER) |
| 475 | #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \ |
| 476 | DISABLED_TwoGetUserMediaWithFirstHdSecondVga |
| 477 | #else |
| 478 | #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \ |
| 479 | TwoGetUserMediaWithFirstHdSecondVga |
| 480 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 481 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 482 | MAYBE_TwoGetUserMediaWithFirstHdSecondVga) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 483 | std::string constraints1 = |
mcasas | 0309b1d | 2014-12-03 21:06:12 | [diff] [blame] | 484 | "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720,\ |
| 485 | minHeight: 720}}}"; |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 486 | std::string constraints2 = |
| 487 | "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}"; |
| 488 | std::string expected_result = "w=1280:h=720-w=640:h=480"; |
| 489 | RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, |
| 490 | expected_result); |
| 491 | } |
| 492 | |
shrikant | aaccc11 | 2014-12-17 23:17:08 | [diff] [blame] | 493 | #if defined(OS_WIN) |
| 494 | // Timing out on Winodws 7 bot: http://crbug.com/443294 |
| 495 | #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\ |
| 496 | DISABLED_TwoGetUserMediaWithFirst1080pSecondVga |
| 497 | #else |
| 498 | #define MAYBE_TwoGetUserMediaWithFirst1080pSecondVga\ |
| 499 | TwoGetUserMediaWithFirst1080pSecondVga |
| 500 | #endif |
| 501 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 502 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
shrikant | aaccc11 | 2014-12-17 23:17:08 | [diff] [blame] | 503 | MAYBE_TwoGetUserMediaWithFirst1080pSecondVga) { |
mcasas | 0309b1d | 2014-12-03 21:06:12 | [diff] [blame] | 504 | std::string constraints1 = |
| 505 | "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080,\ |
| 506 | minHeight: 1080}}}"; |
| 507 | std::string constraints2 = |
| 508 | "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}"; |
| 509 | std::string expected_result = "w=1920:h=1080-w=640:h=480"; |
| 510 | RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, |
| 511 | expected_result); |
| 512 | } |
| 513 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 514 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 515 | #if defined(MEMORY_SANITIZER) |
| 516 | #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \ |
| 517 | DISABLED_TwoGetUserMediaAndVerifyFrameRate |
| 518 | #else |
| 519 | #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \ |
| 520 | TwoGetUserMediaAndVerifyFrameRate |
| 521 | #endif |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 522 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 523 | MAYBE_TwoGetUserMediaAndVerifyFrameRate) { |
[email protected] | 697173d | 2014-06-26 11:52:13 | [diff] [blame] | 524 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 525 | |
| 526 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 527 | NavigateToURL(shell(), url); |
| 528 | |
| 529 | std::string constraints1 = |
| 530 | "{video: {mandatory: {minWidth:640 , minHeight: 480, " |
| 531 | "minFrameRate : 15, maxFrameRate : 15}}}"; |
| 532 | std::string constraints2 = |
| 533 | "{video: {mandatory: {maxWidth:320 , maxHeight: 240," |
| 534 | "minFrameRate : 7, maxFrameRate : 7}}}"; |
| 535 | |
| 536 | std::string command = "twoGetUserMediaAndVerifyFrameRate(" + |
| 537 | constraints1 + ',' + constraints2 + ", 15, 7)"; |
| 538 | ExecuteJavascriptAndWaitForOk(command); |
| 539 | } |
| 540 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 541 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 542 | GetUserMediaWithTooHighVideoConstraintsValues) { |
| 543 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 544 | |
| 545 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 546 | |
| 547 | int large_value = 99999; |
| 548 | std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure, |
| 549 | large_value, |
| 550 | large_value, |
| 551 | large_value, |
| 552 | large_value, |
| 553 | large_value, |
| 554 | large_value); |
| 555 | NavigateToURL(shell(), url); |
| 556 | |
[email protected] | c3629aa | 2014-08-12 05:48:30 | [diff] [blame] | 557 | EXPECT_EQ("ConstraintNotSatisfiedError", |
| 558 | ExecuteJavascriptAndReturnResult(call)); |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 559 | } |
| 560 | |
jansson | 1c493cf | 2014-10-16 07:33:32 | [diff] [blame] | 561 | // This test makes two getUserMedia requests, one with impossible constraints |
| 562 | // that should trigger an error, and one with valid constraints. The test |
| 563 | // verifies getUserMedia can succeed after being given impossible constraints. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 564 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jansson | 1c493cf | 2014-10-16 07:33:32 | [diff] [blame] | 565 | TwoGetUserMediaAndCheckCallbackAfterFailure) { |
| 566 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 567 | |
| 568 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 569 | NavigateToURL(shell(), url); |
| 570 | |
| 571 | int large_value = 99999; |
| 572 | const std::string gum_with_impossible_constraints = |
| 573 | GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure, |
| 574 | large_value, |
| 575 | large_value, |
| 576 | large_value, |
| 577 | large_value, |
| 578 | large_value, |
| 579 | large_value); |
| 580 | const std::string gum_with_vga_constraints = |
| 581 | GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop, |
| 582 | 640, 640, 480, 480, 10, 30); |
| 583 | |
| 584 | ASSERT_EQ("ConstraintNotSatisfiedError", |
| 585 | ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints)); |
| 586 | |
| 587 | ASSERT_EQ("w=640:h=480", |
| 588 | ExecuteJavascriptAndReturnResult(gum_with_vga_constraints)); |
| 589 | } |
| 590 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 591 | // This test will make a simple getUserMedia page, verify that video is playing |
| 592 | // in a simple local <video>, and for a couple of seconds, collect some |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 593 | // performance traces from VideoCaptureController colorspace conversion and |
| 594 | // potential resizing. |
[email protected] | 118c458 | 2014-07-17 08:02:08 | [diff] [blame] | 595 | IN_PROC_BROWSER_TEST_F( |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 596 | WebRtcGetUserMediaBrowserTest, |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 597 | TraceVideoCaptureControllerPerformanceDuringGetUserMedia) { |
| 598 | RunGetUserMediaAndCollectMeasures( |
| 599 | 10, |
qiangchen | 939cdf30 | 2015-04-06 21:36:33 | [diff] [blame] | 600 | "VideoCaptureDeviceClient::OnIncomingCapturedData", |
| 601 | "VideoCaptureDeviceClient"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 602 | } |
| 603 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 604 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 605 | #if defined(MEMORY_SANITIZER) |
| 606 | #define MAYBE_TestGetUserMediaAspectRatio4To3 \ |
| 607 | DISABLED_TestGetUserMediaAspectRatio4To3 |
| 608 | #else |
| 609 | #define MAYBE_TestGetUserMediaAspectRatio4To3 TestGetUserMediaAspectRatio4To3 |
| 610 | #endif |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 611 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 612 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 613 | MAYBE_TestGetUserMediaAspectRatio4To3) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 614 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 615 | |
| 616 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 617 | |
| 618 | std::string constraints_4_3 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 619 | kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 620 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 621 | NavigateToURL(shell(), url); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 622 | ASSERT_EQ("w=640:h=480", |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 623 | ExecuteJavascriptAndReturnResult(constraints_4_3)); |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 624 | } |
| 625 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 626 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 627 | #if defined(MEMORY_SANITIZER) |
| 628 | #define MAYBE_TestGetUserMediaAspectRatio16To9 \ |
| 629 | DISABLED_TestGetUserMediaAspectRatio16To9 |
| 630 | #else |
| 631 | #define MAYBE_TestGetUserMediaAspectRatio16To9 TestGetUserMediaAspectRatio16To9 |
| 632 | #endif |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 633 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 634 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 635 | MAYBE_TestGetUserMediaAspectRatio16To9) { |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 636 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 637 | |
| 638 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 639 | |
| 640 | std::string constraints_16_9 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 641 | kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 642 | |
| 643 | NavigateToURL(shell(), url); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 644 | ASSERT_EQ("w=640:h=360", |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 645 | ExecuteJavascriptAndReturnResult(constraints_16_9)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 646 | } |
| 647 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 648 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 649 | #if defined(MEMORY_SANITIZER) |
| 650 | #define MAYBE_TestGetUserMediaAspectRatio1To1 \ |
| 651 | DISABLED_TestGetUserMediaAspectRatio1To1 |
| 652 | #else |
| 653 | #define MAYBE_TestGetUserMediaAspectRatio1To1 TestGetUserMediaAspectRatio1To1 |
| 654 | #endif |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 655 | // This test calls getUserMedia and checks for aspect ratio behavior. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 656 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 657 | MAYBE_TestGetUserMediaAspectRatio1To1) { |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 658 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 659 | |
| 660 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 661 | |
| 662 | std::string constraints_1_1 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 663 | kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 664 | |
| 665 | NavigateToURL(shell(), url); |
| 666 | ASSERT_EQ("w=320:h=320", |
| 667 | ExecuteJavascriptAndReturnResult(constraints_1_1)); |
| 668 | } |
| 669 | |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 670 | // This test calls getUserMedia in an iframe and immediately close the iframe |
| 671 | // in the scope of the success callback. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 672 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 673 | AudioInIFrameAndCloseInSuccessCb) { |
| 674 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 675 | |
| 676 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 677 | NavigateToURL(shell(), url); |
| 678 | |
| 679 | std::string call = |
| 680 | "getUserMediaInIframeAndCloseInSuccessCb({audio: true});"; |
| 681 | ExecuteJavascriptAndWaitForOk(call); |
| 682 | } |
| 683 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 684 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 685 | VideoInIFrameAndCloseInSuccessCb) { |
| 686 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 687 | |
| 688 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 689 | NavigateToURL(shell(), url); |
| 690 | |
| 691 | std::string call = |
| 692 | "getUserMediaInIframeAndCloseInSuccessCb({video: true});"; |
| 693 | ExecuteJavascriptAndWaitForOk(call); |
| 694 | } |
| 695 | |
| 696 | // This test calls getUserMedia in an iframe and immediately close the iframe |
| 697 | // in the scope of the failure callback. |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 698 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 699 | VideoWithBadConstraintsInIFrameAndCloseInFailureCb) { |
| 700 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 701 | |
| 702 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 703 | |
| 704 | int large_value = 99999; |
| 705 | std::string call = |
| 706 | GenerateGetUserMediaCall("getUserMediaInIframeAndCloseInFailureCb", |
| 707 | large_value, |
| 708 | large_value, |
| 709 | large_value, |
| 710 | large_value, |
| 711 | large_value, |
| 712 | large_value); |
| 713 | NavigateToURL(shell(), url); |
| 714 | |
| 715 | ExecuteJavascriptAndWaitForOk(call); |
| 716 | } |
| 717 | |
phoglund | a1f6906c | 2015-08-27 13:57:27 | [diff] [blame] | 718 | IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
perkj | 64aae32 | 2015-04-10 14:51:41 | [diff] [blame] | 719 | InvalidSourceIdInIFrameAndCloseInFailureCb) { |
| 720 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 721 | |
| 722 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 723 | |
| 724 | std::string call = |
| 725 | GenerateGetUserMediaWithMandatorySourceID( |
| 726 | "getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid"); |
| 727 | NavigateToURL(shell(), url); |
| 728 | |
| 729 | ExecuteJavascriptAndWaitForOk(call); |
| 730 | } |
| 731 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 732 | namespace { |
| 733 | |
| 734 | struct UserMediaSizes { |
| 735 | int min_width; |
| 736 | int max_width; |
| 737 | int min_height; |
| 738 | int max_height; |
| 739 | int min_frame_rate; |
| 740 | int max_frame_rate; |
| 741 | }; |
| 742 | |
| 743 | } // namespace |
| 744 | |
| 745 | class WebRtcConstraintsBrowserTest |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 746 | : public WebRtcContentBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 747 | public testing::WithParamInterface<UserMediaSizes> { |
| 748 | public: |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 749 | WebRtcConstraintsBrowserTest() : user_media_(GetParam()) { |
| 750 | // Automatically grant device permission. |
| 751 | AppendUseFakeUIForMediaStreamFlag(); |
| 752 | } |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 753 | const UserMediaSizes& user_media() const { return user_media_; } |
| 754 | |
| 755 | private: |
| 756 | UserMediaSizes user_media_; |
| 757 | }; |
| 758 | |
timurrrr | 2ec7e9ae | 2015-01-19 13:24:06 | [diff] [blame] | 759 | // Test fails under MSan, http://crbug.com/445745 |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 760 | #if defined(MEMORY_SANITIZER) |
| 761 | #define MAYBE_GetUserMediaConstraints DISABLED_GetUserMediaConstraints |
| 762 | #else |
| 763 | #define MAYBE_GetUserMediaConstraints GetUserMediaConstraints |
| 764 | #endif |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 765 | // This test calls getUserMedia in sequence with different constraints. |
jyasskin | dc83b9a | 2015-01-13 03:15:03 | [diff] [blame] | 766 | IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest, |
| 767 | MAYBE_GetUserMediaConstraints) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 768 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 769 | |
| 770 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 771 | |
| 772 | std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop, |
| 773 | user_media().min_width, |
| 774 | user_media().max_width, |
| 775 | user_media().min_height, |
| 776 | user_media().max_height, |
| 777 | user_media().min_frame_rate, |
| 778 | user_media().max_frame_rate); |
| 779 | DVLOG(1) << "Calling getUserMedia: " << call; |
| 780 | NavigateToURL(shell(), url); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 781 | ExecuteJavascriptAndWaitForOk(call); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static const UserMediaSizes kAllUserMediaSizes[] = { |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 785 | {320, 320, 180, 180, 10, 30}, |
| 786 | {320, 320, 240, 240, 10, 30}, |
| 787 | {640, 640, 360, 360, 10, 30}, |
| 788 | {640, 640, 480, 480, 10, 30}, |
| 789 | {960, 960, 720, 720, 10, 30}, |
| 790 | {1280, 1280, 720, 720, 10, 30}}; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 791 | |
[email protected] | 33afb89 | 2014-07-11 08:17:30 | [diff] [blame] | 792 | INSTANTIATE_TEST_CASE_P(UserMedia, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 793 | WebRtcConstraintsBrowserTest, |
| 794 | testing::ValuesIn(kAllUserMediaSizes)); |
| 795 | |
| 796 | } // namespace content |