[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/debug/trace_event_impl.h" |
| 7 | #include "base/json/json_reader.h" |
| 8 | #include "base/strings/stringprintf.h" |
| 9 | #include "base/test/trace_event_analyzer.h" |
| 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 | |
| 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 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 78 | class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest, |
| 79 | public testing::WithParamInterface<bool> { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 80 | public: |
| 81 | WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {} |
| 82 | virtual ~WebRtcGetUserMediaBrowserTest() {} |
| 83 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 84 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 85 | WebRtcContentBrowserTest::SetUpCommandLine(command_line); |
| 86 | |
| 87 | bool enable_audio_track_processing = GetParam(); |
[email protected] | 8aa6807 | 2014-06-09 21:59:12 | [diff] [blame] | 88 | if (!enable_audio_track_processing) |
| 89 | command_line->AppendSwitch(switches::kDisableAudioTrackProcessing); |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 90 | } |
| 91 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 92 | void StartTracing() { |
| 93 | CHECK(trace_log_ == NULL) << "Can only can start tracing once"; |
| 94 | trace_log_ = base::debug::TraceLog::GetInstance(); |
| 95 | trace_log_->SetEnabled(base::debug::CategoryFilter("video"), |
| 96 | base::debug::TraceLog::RECORDING_MODE, |
| 97 | base::debug::TraceLog::ENABLE_SAMPLING); |
| 98 | // Check that we are indeed recording. |
| 99 | EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1); |
| 100 | } |
| 101 | |
| 102 | void StopTracing() { |
| 103 | CHECK(message_loop_runner_ == NULL) << "Calling StopTracing more than once"; |
| 104 | trace_log_->SetDisabled(); |
| 105 | message_loop_runner_ = new MessageLoopRunner; |
| 106 | trace_log_->Flush(base::Bind( |
| 107 | &WebRtcGetUserMediaBrowserTest::OnTraceDataCollected, |
| 108 | base::Unretained(this))); |
| 109 | message_loop_runner_->Run(); |
| 110 | } |
| 111 | |
| 112 | void OnTraceDataCollected( |
| 113 | const scoped_refptr<base::RefCountedString>& events_str_ptr, |
| 114 | bool has_more_events) { |
| 115 | CHECK(!has_more_events); |
| 116 | recorded_trace_data_ = events_str_ptr; |
| 117 | message_loop_runner_->Quit(); |
| 118 | } |
| 119 | |
| 120 | TraceAnalyzer* CreateTraceAnalyzer() { |
| 121 | return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]"); |
| 122 | } |
| 123 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 124 | void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs, |
| 125 | const std::string& measure_filter, |
| 126 | const std::string& graph_name) { |
| 127 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 128 | |
| 129 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 130 | NavigateToURL(shell(), url); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 131 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 132 | // Put getUserMedia to work and let it run for a couple of seconds. |
| 133 | DCHECK(time_to_sample_secs); |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 134 | ExecuteJavascriptAndWaitForOk( |
| 135 | base::StringPrintf("%s({video: true});", |
| 136 | kGetUserMediaAndGetStreamUp)); |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 137 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 138 | // Now the stream is up and running, start collecting traces. |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 139 | StartTracing(); |
| 140 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 141 | // Let the stream run for a while in javascript. |
| 142 | ExecuteJavascriptAndWaitForOk( |
| 143 | base::StringPrintf("waitAndStopVideoTrack(%d);", time_to_sample_secs)); |
| 144 | |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 145 | // Wait until the page title changes to "OK". Do not sleep() here since that |
| 146 | // would stop both this code and the browser underneath. |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 147 | StopTracing(); |
| 148 | |
| 149 | scoped_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer()); |
| 150 | analyzer->AssociateBeginEndEvents(); |
| 151 | trace_analyzer::TraceEventVector events; |
| 152 | DCHECK(measure_filter.size()); |
| 153 | analyzer->FindEvents( |
| 154 | Query::EventNameIs(measure_filter), |
| 155 | &events); |
| 156 | ASSERT_GT(events.size(), 0u) |
| 157 | << "Could not collect any samples during test, this is bad"; |
| 158 | |
| 159 | std::string duration_us; |
| 160 | std::string interarrival_us; |
| 161 | for (size_t i = 0; i != events.size(); ++i) { |
| 162 | duration_us.append( |
| 163 | base::StringPrintf("%d,", static_cast<int>(events[i]->duration))); |
| 164 | } |
| 165 | |
| 166 | for (size_t i = 1; i < events.size(); ++i) { |
| 167 | // The event |timestamp| comes in ns, divide to get us like |duration|. |
| 168 | interarrival_us.append(base::StringPrintf("%d,", |
| 169 | static_cast<int>((events[i]->timestamp - events[i - 1]->timestamp) / |
| 170 | base::Time::kNanosecondsPerMicrosecond))); |
| 171 | } |
| 172 | |
| 173 | perf_test::PrintResultList( |
| 174 | graph_name, "", "sample_duration", duration_us, "us", true); |
| 175 | |
| 176 | perf_test::PrintResultList( |
| 177 | graph_name, "", "interarrival_time", interarrival_us, "us", true); |
| 178 | } |
| 179 | |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 180 | void RunTwoGetTwoGetUserMediaWithDifferentContraints( |
| 181 | const std::string& constraints1, |
| 182 | const std::string& constraints2, |
| 183 | const std::string& expected_result) { |
| 184 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 185 | |
| 186 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 187 | NavigateToURL(shell(), url); |
| 188 | |
| 189 | std::string command = "twoGetUserMedia(" + constraints1 + ',' + |
| 190 | constraints2 + ')'; |
| 191 | |
| 192 | EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command)); |
| 193 | } |
| 194 | |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 195 | void GetInputDevices(std::vector<std::string>* audio_ids, |
| 196 | std::vector<std::string>* video_ids) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 197 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 198 | NavigateToURL(shell(), url); |
| 199 | |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 200 | std::string devices_as_json = ExecuteJavascriptAndReturnResult( |
| 201 | "getMediaDevices()"); |
| 202 | EXPECT_FALSE(devices_as_json.empty()); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 203 | |
| 204 | int error_code; |
| 205 | std::string error_message; |
| 206 | scoped_ptr<base::Value> value( |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 207 | base::JSONReader::ReadAndReturnError(devices_as_json, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 208 | base::JSON_ALLOW_TRAILING_COMMAS, |
| 209 | &error_code, |
| 210 | &error_message)); |
| 211 | |
| 212 | ASSERT_TRUE(value.get() != NULL) << error_message; |
| 213 | EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST); |
| 214 | |
| 215 | base::ListValue* values; |
| 216 | ASSERT_TRUE(value->GetAsList(&values)); |
| 217 | |
| 218 | for (base::ListValue::iterator it = values->begin(); |
| 219 | it != values->end(); ++it) { |
| 220 | const base::DictionaryValue* dict; |
| 221 | std::string kind; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 222 | std::string device_id; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 223 | ASSERT_TRUE((*it)->GetAsDictionary(&dict)); |
| 224 | ASSERT_TRUE(dict->GetString("kind", &kind)); |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 225 | ASSERT_TRUE(dict->GetString("deviceId", &device_id)); |
| 226 | ASSERT_FALSE(device_id.empty()); |
| 227 | EXPECT_TRUE(kind == "audioinput" || kind == "videoinput" || |
| 228 | kind == "audiooutput"); |
| 229 | if (kind == "audioinput") { |
| 230 | audio_ids->push_back(device_id); |
| 231 | } else if (kind == "videoinput") { |
| 232 | video_ids->push_back(device_id); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 233 | } |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 234 | // We ignore audio output. |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 235 | } |
| 236 | ASSERT_FALSE(audio_ids->empty()); |
| 237 | ASSERT_FALSE(video_ids->empty()); |
| 238 | } |
| 239 | |
| 240 | private: |
| 241 | base::debug::TraceLog* trace_log_; |
| 242 | scoped_refptr<base::RefCountedString> recorded_trace_data_; |
| 243 | scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 244 | }; |
| 245 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 246 | static const bool kRunTestsWithFlag[] = { false, true }; |
| 247 | INSTANTIATE_TEST_CASE_P(WebRtcGetUserMediaBrowserTests, |
| 248 | WebRtcGetUserMediaBrowserTest, |
| 249 | testing::ValuesIn(kRunTestsWithFlag)); |
| 250 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 251 | // These tests will all make a getUserMedia call with different constraints and |
| 252 | // see that the success callback is called. If the error callback is called or |
| 253 | // none of the callbacks are called the tests will simply time out and fail. |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 254 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, GetVideoStreamAndStop) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 255 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 256 | |
| 257 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 258 | NavigateToURL(shell(), url); |
| 259 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 260 | ExecuteJavascriptAndWaitForOk( |
| 261 | base::StringPrintf("%s({video: true});", kGetUserMediaAndStop)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 264 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | 1670d03 | 2014-03-20 15:01:45 | [diff] [blame] | 265 | RenderSameTrackMediastreamAndStop) { |
| 266 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 267 | |
| 268 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 269 | NavigateToURL(shell(), url); |
| 270 | |
| 271 | ExecuteJavascriptAndWaitForOk( |
| 272 | base::StringPrintf("%s({video: true});", |
| 273 | kRenderSameTrackMediastreamAndStop)); |
| 274 | } |
| 275 | |
| 276 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
| 277 | RenderClonedMediastreamAndStop) { |
| 278 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 279 | |
| 280 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 281 | NavigateToURL(shell(), url); |
| 282 | |
| 283 | |
| 284 | ExecuteJavascriptAndWaitForOk( |
| 285 | base::StringPrintf("%s({video: true});", |
| 286 | kRenderClonedMediastreamAndStop)); |
| 287 | } |
| 288 | |
| 289 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
| 290 | kRenderClonedTrackMediastreamAndStop) { |
| 291 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 292 | |
| 293 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 294 | NavigateToURL(shell(), url); |
| 295 | |
| 296 | ExecuteJavascriptAndWaitForOk( |
| 297 | base::StringPrintf("%s({video: true});", |
| 298 | kRenderClonedTrackMediastreamAndStop)); |
| 299 | } |
| 300 | |
| 301 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
| 302 | kRenderDuplicatedMediastreamAndStop) { |
| 303 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 304 | |
| 305 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 306 | NavigateToURL(shell(), url); |
| 307 | |
| 308 | ExecuteJavascriptAndWaitForOk( |
| 309 | base::StringPrintf("%s({video: true});", |
| 310 | kRenderDuplicatedMediastreamAndStop)); |
| 311 | } |
| 312 | |
| 313 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 314 | GetAudioAndVideoStreamAndStop) { |
| 315 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 316 | |
| 317 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 318 | NavigateToURL(shell(), url); |
| 319 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 320 | ExecuteJavascriptAndWaitForOk(base::StringPrintf( |
| 321 | "%s({video: true, audio: true});", kGetUserMediaAndStop)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 322 | } |
| 323 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 324 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 325 | GetAudioAndVideoStreamAndClone) { |
| 326 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 327 | |
| 328 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 329 | NavigateToURL(shell(), url); |
| 330 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 331 | ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 332 | } |
| 333 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 334 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | c606287 | 2014-03-21 14:35:37 | [diff] [blame] | 335 | RenderVideoTrackInMultipleTagsAndPause) { |
| 336 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 337 | |
| 338 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 339 | NavigateToURL(shell(), url); |
| 340 | |
| 341 | ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();"); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | |
| 346 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 347 | GetUserMediaWithMandatorySourceID) { |
| 348 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 349 | |
| 350 | std::vector<std::string> audio_ids; |
| 351 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 352 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 353 | |
| 354 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 355 | |
| 356 | // Test all combinations of mandatory sourceID; |
| 357 | for (std::vector<std::string>::const_iterator video_it = video_ids.begin(); |
| 358 | video_it != video_ids.end(); ++video_it) { |
| 359 | for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin(); |
| 360 | audio_it != audio_ids.end(); ++audio_it) { |
| 361 | NavigateToURL(shell(), url); |
| 362 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 363 | GenerateGetUserMediaWithMandatorySourceID( |
| 364 | kGetUserMediaAndStop, |
| 365 | *audio_it, |
| 366 | *video_it))); |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 371 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 372 | GetUserMediaWithInvalidMandatorySourceID) { |
| 373 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 374 | |
| 375 | std::vector<std::string> audio_ids; |
| 376 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 377 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 378 | |
| 379 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 380 | |
| 381 | // Test with invalid mandatory audio sourceID. |
| 382 | NavigateToURL(shell(), url); |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 383 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 384 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 385 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 386 | "something invalid", |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 387 | video_ids[0]))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 388 | |
| 389 | // Test with invalid mandatory video sourceID. |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 390 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 391 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 392 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 393 | audio_ids[0], |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 394 | "something invalid"))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 395 | |
| 396 | // Test with empty mandatory audio sourceID. |
[email protected] | 32d37741 | 2014-03-19 21:15:43 | [diff] [blame] | 397 | EXPECT_EQ("DevicesNotFoundError", ExecuteJavascriptAndReturnResult( |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 398 | GenerateGetUserMediaWithMandatorySourceID( |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 399 | kGetUserMediaAndExpectFailure, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 400 | "", |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 401 | video_ids[0]))); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 402 | } |
| 403 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 404 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 405 | GetUserMediaWithInvalidOptionalSourceID) { |
| 406 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 407 | |
| 408 | std::vector<std::string> audio_ids; |
| 409 | std::vector<std::string> video_ids; |
[email protected] | 8926d569 | 2014-06-11 05:02:22 | [diff] [blame^] | 410 | GetInputDevices(&audio_ids, &video_ids); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 411 | |
| 412 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 413 | |
| 414 | // Test with invalid optional audio sourceID. |
| 415 | NavigateToURL(shell(), url); |
| 416 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 417 | GenerateGetUserMediaWithOptionalSourceID( |
| 418 | kGetUserMediaAndStop, |
| 419 | "something invalid", |
| 420 | video_ids[0]))); |
| 421 | |
| 422 | // Test with invalid optional video sourceID. |
| 423 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 424 | GenerateGetUserMediaWithOptionalSourceID( |
| 425 | kGetUserMediaAndStop, |
| 426 | audio_ids[0], |
| 427 | "something invalid"))); |
| 428 | |
| 429 | // Test with empty optional audio sourceID. |
| 430 | EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
| 431 | GenerateGetUserMediaWithOptionalSourceID( |
| 432 | kGetUserMediaAndStop, |
| 433 | "", |
| 434 | video_ids[0]))); |
| 435 | } |
| 436 | |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 437 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, TwoGetUserMediaAndStop) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 438 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 439 | |
| 440 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 441 | NavigateToURL(shell(), url); |
| 442 | |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 443 | ExecuteJavascriptAndWaitForOk( |
| 444 | "twoGetUserMediaAndStop({video: true, audio: true});"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 445 | } |
| 446 | |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 447 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 448 | TwoGetUserMediaWithEqualConstraints) { |
| 449 | std::string constraints1 = "{video: true, audio: true}"; |
| 450 | const std::string& constraints2 = constraints1; |
| 451 | std::string expected_result = "w=640:h=480-w=640:h=480"; |
| 452 | |
| 453 | RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, |
| 454 | expected_result); |
| 455 | } |
| 456 | |
| 457 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
| 458 | TwoGetUserMediaWithSecondVideoCropped) { |
| 459 | std::string constraints1 = "{video: true}"; |
| 460 | std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}"; |
| 461 | std::string expected_result = "w=640:h=480-w=640:h=360"; |
| 462 | RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, |
| 463 | expected_result); |
| 464 | } |
| 465 | |
| 466 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | 8d5a328 | 2014-06-06 22:01:28 | [diff] [blame] | 467 | DISABLED_TwoGetUserMediaWithFirstHdSecondVga) { |
[email protected] | ff993f9 | 2014-05-22 17:24:00 | [diff] [blame] | 468 | std::string constraints1 = |
| 469 | "{video: {mandatory: {minWidth:1280 , minHeight: 720}}}"; |
| 470 | std::string constraints2 = |
| 471 | "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}"; |
| 472 | std::string expected_result = "w=1280:h=720-w=640:h=480"; |
| 473 | RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, |
| 474 | expected_result); |
| 475 | } |
| 476 | |
| 477 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | 0c7158b | 2014-03-17 16:46:38 | [diff] [blame] | 478 | GetUserMediaWithTooHighVideoConstraintsValues) { |
| 479 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 480 | |
| 481 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 482 | |
| 483 | int large_value = 99999; |
| 484 | std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure, |
| 485 | large_value, |
| 486 | large_value, |
| 487 | large_value, |
| 488 | large_value, |
| 489 | large_value, |
| 490 | large_value); |
| 491 | NavigateToURL(shell(), url); |
| 492 | |
| 493 | // TODO(perkj): A proper error code should be returned by gUM. |
| 494 | EXPECT_EQ("TrackStartError", ExecuteJavascriptAndReturnResult(call)); |
| 495 | } |
| 496 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 497 | // This test will make a simple getUserMedia page, verify that video is playing |
| 498 | // in a simple local <video>, and for a couple of seconds, collect some |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 499 | // performance traces from VideoCaptureController colorspace conversion and |
| 500 | // potential resizing. |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 501 | IN_PROC_BROWSER_TEST_P( |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 502 | WebRtcGetUserMediaBrowserTest, |
| 503 | TraceVideoCaptureControllerPerformanceDuringGetUserMedia) { |
| 504 | RunGetUserMediaAndCollectMeasures( |
| 505 | 10, |
[email protected] | 5a64203 | 2014-02-28 15:43:28 | [diff] [blame] | 506 | "VideoCaptureController::OnIncomingCapturedData", |
[email protected] | 3fa8aa1 | 2014-01-20 19:06:54 | [diff] [blame] | 507 | "VideoCaptureController"); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 508 | } |
| 509 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 510 | // This test calls getUserMedia and checks for aspect ratio behavior. |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 511 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 512 | TestGetUserMediaAspectRatio4To3) { |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 513 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 514 | |
| 515 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 516 | |
| 517 | std::string constraints_4_3 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 518 | kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 519 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 520 | NavigateToURL(shell(), url); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 521 | ASSERT_EQ("w=640:h=480", |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 522 | ExecuteJavascriptAndReturnResult(constraints_4_3)); |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | // This test calls getUserMedia and checks for aspect ratio behavior. |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 526 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
[email protected] | 599b15a2 | 2014-03-27 16:33:10 | [diff] [blame] | 527 | TestGetUserMediaAspectRatio16To9) { |
[email protected] | 856f7cbd | 2014-03-07 09:54:32 | [diff] [blame] | 528 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 529 | |
| 530 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 531 | |
| 532 | std::string constraints_16_9 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 533 | kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 534 | |
| 535 | NavigateToURL(shell(), url); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 536 | ASSERT_EQ("w=640:h=360", |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 537 | ExecuteJavascriptAndReturnResult(constraints_16_9)); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 538 | } |
| 539 | |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 540 | // This test calls getUserMedia and checks for aspect ratio behavior. |
[email protected] | 599b15a2 | 2014-03-27 16:33:10 | [diff] [blame] | 541 | IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
| 542 | TestGetUserMediaAspectRatio1To1) { |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 543 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 544 | |
| 545 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 546 | |
| 547 | std::string constraints_1_1 = GenerateGetUserMediaCall( |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 548 | kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30); |
[email protected] | b5d213b | 2014-03-27 11:45:05 | [diff] [blame] | 549 | |
| 550 | NavigateToURL(shell(), url); |
| 551 | ASSERT_EQ("w=320:h=320", |
| 552 | ExecuteJavascriptAndReturnResult(constraints_1_1)); |
| 553 | } |
| 554 | |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 555 | namespace { |
| 556 | |
| 557 | struct UserMediaSizes { |
| 558 | int min_width; |
| 559 | int max_width; |
| 560 | int min_height; |
| 561 | int max_height; |
| 562 | int min_frame_rate; |
| 563 | int max_frame_rate; |
| 564 | }; |
| 565 | |
| 566 | } // namespace |
| 567 | |
| 568 | class WebRtcConstraintsBrowserTest |
[email protected] | 9906368 | 2014-03-13 15:15:30 | [diff] [blame] | 569 | : public WebRtcContentBrowserTest, |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 570 | public testing::WithParamInterface<UserMediaSizes> { |
| 571 | public: |
| 572 | WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {} |
| 573 | const UserMediaSizes& user_media() const { return user_media_; } |
| 574 | |
| 575 | private: |
| 576 | UserMediaSizes user_media_; |
| 577 | }; |
| 578 | |
| 579 | // This test calls getUserMedia in sequence with different constraints. |
| 580 | IN_PROC_BROWSER_TEST_P(WebRtcConstraintsBrowserTest, GetUserMediaConstraints) { |
| 581 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 582 | |
| 583 | GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 584 | |
| 585 | std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop, |
| 586 | user_media().min_width, |
| 587 | user_media().max_width, |
| 588 | user_media().min_height, |
| 589 | user_media().max_height, |
| 590 | user_media().min_frame_rate, |
| 591 | user_media().max_frame_rate); |
| 592 | DVLOG(1) << "Calling getUserMedia: " << call; |
| 593 | NavigateToURL(shell(), url); |
[email protected] | 43ebe9e | 2014-03-08 21:00:58 | [diff] [blame] | 594 | ExecuteJavascriptAndWaitForOk(call); |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | static const UserMediaSizes kAllUserMediaSizes[] = { |
[email protected] | cbc7d67 | 2014-04-04 09:27:07 | [diff] [blame] | 598 | {320, 320, 180, 180, 10, 30}, |
| 599 | {320, 320, 240, 240, 10, 30}, |
| 600 | {640, 640, 360, 360, 10, 30}, |
| 601 | {640, 640, 480, 480, 10, 30}, |
| 602 | {960, 960, 720, 720, 10, 30}, |
| 603 | {1280, 1280, 720, 720, 10, 30}}; |
[email protected] | bdcc970 | 2014-01-17 16:07:46 | [diff] [blame] | 604 | |
| 605 | INSTANTIATE_TEST_CASE_P(UserMedia, |
| 606 | WebRtcConstraintsBrowserTest, |
| 607 | testing::ValuesIn(kAllUserMediaSizes)); |
| 608 | |
| 609 | } // namespace content |