OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "base/command_line.h" |
5 #include "base/debug/trace_event_impl.h" | 6 #include "base/debug/trace_event_impl.h" |
6 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
7 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
8 #include "base/test/trace_event_analyzer.h" | 9 #include "base/test/trace_event_analyzer.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "content/browser/media/webrtc_internals.h" | 11 #include "content/browser/media/webrtc_internals.h" |
11 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 13 #include "content/public/common/content_switches.h" |
12 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
13 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
14 #include "content/shell/browser/shell.h" | 16 #include "content/shell/browser/shell.h" |
15 #include "content/test/content_browser_test_utils.h" | 17 #include "content/test/content_browser_test_utils.h" |
16 #include "content/test/webrtc_content_browsertest_base.h" | 18 #include "content/test/webrtc_content_browsertest_base.h" |
17 #include "net/test/embedded_test_server/embedded_test_server.h" | 19 #include "net/test/embedded_test_server/embedded_test_server.h" |
18 #include "testing/perf/perf_test.h" | 20 #include "testing/perf/perf_test.h" |
19 | 21 |
20 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
21 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 60 |
59 const std::string video_constraint = | 61 const std::string video_constraint = |
60 "video: {optional: [{ sourceId:\"" + video_source_id + "\"}]}"; | 62 "video: {optional: [{ sourceId:\"" + video_source_id + "\"}]}"; |
61 return function_name + "({" + audio_constraint + video_constraint + "});"; | 63 return function_name + "({" + audio_constraint + video_constraint + "});"; |
62 } | 64 } |
63 | 65 |
64 } // namespace | 66 } // namespace |
65 | 67 |
66 namespace content { | 68 namespace content { |
67 | 69 |
68 class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest { | 70 class WebRtcGetUserMediaBrowserTest: public WebRtcContentBrowserTest, |
| 71 public testing::WithParamInterface<bool> { |
69 public: | 72 public: |
70 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {} | 73 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {} |
71 virtual ~WebRtcGetUserMediaBrowserTest() {} | 74 virtual ~WebRtcGetUserMediaBrowserTest() {} |
72 | 75 |
| 76 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 77 WebRtcContentBrowserTest::SetUpCommandLine(command_line); |
| 78 |
| 79 bool enable_audio_track_processing = GetParam(); |
| 80 if (enable_audio_track_processing) |
| 81 command_line->AppendSwitch(switches::kEnableAudioTrackProcessing); |
| 82 } |
| 83 |
73 void StartTracing() { | 84 void StartTracing() { |
74 CHECK(trace_log_ == NULL) << "Can only can start tracing once"; | 85 CHECK(trace_log_ == NULL) << "Can only can start tracing once"; |
75 trace_log_ = base::debug::TraceLog::GetInstance(); | 86 trace_log_ = base::debug::TraceLog::GetInstance(); |
76 trace_log_->SetEnabled(base::debug::CategoryFilter("video"), | 87 trace_log_->SetEnabled(base::debug::CategoryFilter("video"), |
77 base::debug::TraceLog::RECORDING_MODE, | 88 base::debug::TraceLog::RECORDING_MODE, |
78 base::debug::TraceLog::ENABLE_SAMPLING); | 89 base::debug::TraceLog::ENABLE_SAMPLING); |
79 // Check that we are indeed recording. | 90 // Check that we are indeed recording. |
80 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1); | 91 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1); |
81 } | 92 } |
82 | 93 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 ASSERT_FALSE(audio_ids->empty()); | 212 ASSERT_FALSE(audio_ids->empty()); |
202 ASSERT_FALSE(video_ids->empty()); | 213 ASSERT_FALSE(video_ids->empty()); |
203 } | 214 } |
204 | 215 |
205 private: | 216 private: |
206 base::debug::TraceLog* trace_log_; | 217 base::debug::TraceLog* trace_log_; |
207 scoped_refptr<base::RefCountedString> recorded_trace_data_; | 218 scoped_refptr<base::RefCountedString> recorded_trace_data_; |
208 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 219 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
209 }; | 220 }; |
210 | 221 |
| 222 static const bool kRunTestsWithFlag[] = { false, true }; |
| 223 INSTANTIATE_TEST_CASE_P(WebRtcGetUserMediaBrowserTests, |
| 224 WebRtcGetUserMediaBrowserTest, |
| 225 testing::ValuesIn(kRunTestsWithFlag)); |
| 226 |
211 // These tests will all make a getUserMedia call with different constraints and | 227 // These tests will all make a getUserMedia call with different constraints and |
212 // see that the success callback is called. If the error callback is called or | 228 // see that the success callback is called. If the error callback is called or |
213 // none of the callbacks are called the tests will simply time out and fail. | 229 // none of the callbacks are called the tests will simply time out and fail. |
214 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, GetVideoStreamAndStop) { | 230 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, GetVideoStreamAndStop) { |
215 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 231 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
216 | 232 |
217 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 233 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
218 NavigateToURL(shell(), url); | 234 NavigateToURL(shell(), url); |
219 | 235 |
220 ExecuteJavascriptAndWaitForOk( | 236 ExecuteJavascriptAndWaitForOk( |
221 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop)); | 237 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop)); |
222 } | 238 } |
223 | 239 |
224 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | 240 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
225 GetAudioAndVideoStreamAndStop) { | 241 GetAudioAndVideoStreamAndStop) { |
226 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 242 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
227 | 243 |
228 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 244 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
229 NavigateToURL(shell(), url); | 245 NavigateToURL(shell(), url); |
230 | 246 |
231 ExecuteJavascriptAndWaitForOk(base::StringPrintf( | 247 ExecuteJavascriptAndWaitForOk(base::StringPrintf( |
232 "%s({video: true, audio: true});", kGetUserMediaAndStop)); | 248 "%s({video: true, audio: true});", kGetUserMediaAndStop)); |
233 } | 249 } |
234 | 250 |
235 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | 251 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
236 GetAudioAndVideoStreamAndClone) { | 252 GetAudioAndVideoStreamAndClone) { |
237 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 253 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
238 | 254 |
239 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 255 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
240 NavigateToURL(shell(), url); | 256 NavigateToURL(shell(), url); |
241 | 257 |
242 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();"); | 258 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();"); |
243 } | 259 } |
244 | 260 |
245 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | 261 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
246 GetUserMediaWithMandatorySourceID) { | 262 GetUserMediaWithMandatorySourceID) { |
247 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 263 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
248 | 264 |
249 std::vector<std::string> audio_ids; | 265 std::vector<std::string> audio_ids; |
250 std::vector<std::string> video_ids; | 266 std::vector<std::string> video_ids; |
251 GetSources(&audio_ids, &video_ids); | 267 GetSources(&audio_ids, &video_ids); |
252 | 268 |
253 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 269 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
254 | 270 |
255 // Test all combinations of mandatory sourceID; | 271 // Test all combinations of mandatory sourceID; |
256 for (std::vector<std::string>::const_iterator video_it = video_ids.begin(); | 272 for (std::vector<std::string>::const_iterator video_it = video_ids.begin(); |
257 video_it != video_ids.end(); ++video_it) { | 273 video_it != video_ids.end(); ++video_it) { |
258 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin(); | 274 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin(); |
259 audio_it != audio_ids.end(); ++audio_it) { | 275 audio_it != audio_ids.end(); ++audio_it) { |
260 NavigateToURL(shell(), url); | 276 NavigateToURL(shell(), url); |
261 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( | 277 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
262 GenerateGetUserMediaWithMandatorySourceID( | 278 GenerateGetUserMediaWithMandatorySourceID( |
263 kGetUserMediaAndStop, | 279 kGetUserMediaAndStop, |
264 *audio_it, | 280 *audio_it, |
265 *video_it))); | 281 *video_it))); |
266 } | 282 } |
267 } | 283 } |
268 } | 284 } |
269 | 285 |
270 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | 286 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
271 GetUserMediaWithInvalidMandatorySourceID) { | 287 GetUserMediaWithInvalidMandatorySourceID) { |
272 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 288 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
273 | 289 |
274 std::vector<std::string> audio_ids; | 290 std::vector<std::string> audio_ids; |
275 std::vector<std::string> video_ids; | 291 std::vector<std::string> video_ids; |
276 GetSources(&audio_ids, &video_ids); | 292 GetSources(&audio_ids, &video_ids); |
277 | 293 |
278 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 294 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
279 | 295 |
280 // Test with invalid mandatory audio sourceID. | 296 // Test with invalid mandatory audio sourceID. |
(...skipping 12 matching lines...) Expand all Loading... |
293 "something invalid")); | 309 "something invalid")); |
294 | 310 |
295 // Test with empty mandatory audio sourceID. | 311 // Test with empty mandatory audio sourceID. |
296 ExecuteJavascriptAndWaitForOk( | 312 ExecuteJavascriptAndWaitForOk( |
297 GenerateGetUserMediaWithMandatorySourceID( | 313 GenerateGetUserMediaWithMandatorySourceID( |
298 kGetUserMediaAndExpectFailure, | 314 kGetUserMediaAndExpectFailure, |
299 "", | 315 "", |
300 video_ids[0])); | 316 video_ids[0])); |
301 } | 317 } |
302 | 318 |
303 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | 319 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
304 GetUserMediaWithInvalidOptionalSourceID) { | 320 GetUserMediaWithInvalidOptionalSourceID) { |
305 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 321 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
306 | 322 |
307 std::vector<std::string> audio_ids; | 323 std::vector<std::string> audio_ids; |
308 std::vector<std::string> video_ids; | 324 std::vector<std::string> video_ids; |
309 GetSources(&audio_ids, &video_ids); | 325 GetSources(&audio_ids, &video_ids); |
310 | 326 |
311 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 327 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
312 | 328 |
313 // Test with invalid optional audio sourceID. | 329 // Test with invalid optional audio sourceID. |
(...skipping 12 matching lines...) Expand all Loading... |
326 "something invalid"))); | 342 "something invalid"))); |
327 | 343 |
328 // Test with empty optional audio sourceID. | 344 // Test with empty optional audio sourceID. |
329 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( | 345 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult( |
330 GenerateGetUserMediaWithOptionalSourceID( | 346 GenerateGetUserMediaWithOptionalSourceID( |
331 kGetUserMediaAndStop, | 347 kGetUserMediaAndStop, |
332 "", | 348 "", |
333 video_ids[0]))); | 349 video_ids[0]))); |
334 } | 350 } |
335 | 351 |
336 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, TwoGetUserMediaAndStop) { | 352 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, TwoGetUserMediaAndStop) { |
337 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 353 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
338 | 354 |
339 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 355 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
340 NavigateToURL(shell(), url); | 356 NavigateToURL(shell(), url); |
341 | 357 |
342 ExecuteJavascriptAndWaitForOk( | 358 ExecuteJavascriptAndWaitForOk( |
343 "twoGetUserMediaAndStop({video: true, audio: true});"); | 359 "twoGetUserMediaAndStop({video: true, audio: true});"); |
344 } | 360 } |
345 | 361 |
346 // This test will make a simple getUserMedia page, verify that video is playing | 362 // This test will make a simple getUserMedia page, verify that video is playing |
347 // in a simple local <video>, and for a couple of seconds, collect some | 363 // in a simple local <video>, and for a couple of seconds, collect some |
348 // performance traces from VideoCaptureController colorspace conversion and | 364 // performance traces from VideoCaptureController colorspace conversion and |
349 // potential resizing. | 365 // potential resizing. |
350 IN_PROC_BROWSER_TEST_F( | 366 IN_PROC_BROWSER_TEST_P( |
351 WebRtcGetUserMediaBrowserTest, | 367 WebRtcGetUserMediaBrowserTest, |
352 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) { | 368 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) { |
353 RunGetUserMediaAndCollectMeasures( | 369 RunGetUserMediaAndCollectMeasures( |
354 10, | 370 10, |
355 "VideoCaptureController::OnIncomingCapturedData", | 371 "VideoCaptureController::OnIncomingCapturedData", |
356 "VideoCaptureController"); | 372 "VideoCaptureController"); |
357 } | 373 } |
358 | 374 |
359 // This test calls getUserMedia and checks for aspect ratio behavior. | 375 // This test calls getUserMedia and checks for aspect ratio behavior. |
360 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | 376 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
361 TestGetUserMediaAspectRatio4To3) { | 377 TestGetUserMediaAspectRatio4To3) { |
362 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 378 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
363 | 379 |
364 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 380 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
365 | 381 |
366 std::string constraints_4_3 = GenerateGetUserMediaCall( | 382 std::string constraints_4_3 = GenerateGetUserMediaCall( |
367 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 30, 30); | 383 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 30, 30); |
368 | 384 |
369 // TODO(mcasas): add more aspect ratios, in particular 16:10 crbug.com/275594. | 385 // TODO(mcasas): add more aspect ratios, in particular 16:10 crbug.com/275594. |
370 | 386 |
371 NavigateToURL(shell(), url); | 387 NavigateToURL(shell(), url); |
372 ASSERT_EQ("4:3 letterbox", | 388 ASSERT_EQ("4:3 letterbox", |
373 ExecuteJavascriptAndReturnResult(constraints_4_3)); | 389 ExecuteJavascriptAndReturnResult(constraints_4_3)); |
374 } | 390 } |
375 | 391 |
376 // This test calls getUserMedia and checks for aspect ratio behavior. | 392 // This test calls getUserMedia and checks for aspect ratio behavior. |
377 // TODO(perkj): Enable this test as soon as crbug/349450 is fixed. | 393 // TODO(perkj): Enable this test as soon as crbug/349450 is fixed. |
378 // Currently the render pipeline doesn't support cropping where the new cropped | 394 // Currently the render pipeline doesn't support cropping where the new cropped |
379 // frame doesn't have the same top left coordinates as the original frame. | 395 // frame doesn't have the same top left coordinates as the original frame. |
380 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | 396 IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest, |
381 DISABLED_TestGetUserMediaAspectRatio16To9) { | 397 DISABLED_TestGetUserMediaAspectRatio16To9) { |
382 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 398 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
383 | 399 |
384 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 400 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
385 | 401 |
386 std::string constraints_16_9 = GenerateGetUserMediaCall( | 402 std::string constraints_16_9 = GenerateGetUserMediaCall( |
387 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 30, 30); | 403 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 30, 30); |
388 | 404 |
389 NavigateToURL(shell(), url); | 405 NavigateToURL(shell(), url); |
390 ASSERT_EQ("16:9 letterbox", | 406 ASSERT_EQ("16:9 letterbox", |
391 ExecuteJavascriptAndReturnResult(constraints_16_9)); | 407 ExecuteJavascriptAndReturnResult(constraints_16_9)); |
392 } | 408 } |
393 | 409 |
394 namespace { | 410 namespace { |
395 | 411 |
396 struct UserMediaSizes { | 412 struct UserMediaSizes { |
397 int min_width; | 413 int min_width; |
398 int max_width; | 414 int max_width; |
399 int min_height; | 415 int min_height; |
400 int max_height; | 416 int max_height; |
401 int min_frame_rate; | 417 int min_frame_rate; |
402 int max_frame_rate; | 418 int max_frame_rate; |
403 }; | 419 }; |
404 | 420 |
405 } // namespace | 421 } // namespace |
406 | 422 |
407 class WebRtcConstraintsBrowserTest | 423 class WebRtcConstraintsBrowserTest |
408 : public WebRtcGetUserMediaBrowserTest, | 424 : public WebRtcContentBrowserTest, |
409 public testing::WithParamInterface<UserMediaSizes> { | 425 public testing::WithParamInterface<UserMediaSizes> { |
410 public: | 426 public: |
411 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {} | 427 WebRtcConstraintsBrowserTest() : user_media_(GetParam()) {} |
412 const UserMediaSizes& user_media() const { return user_media_; } | 428 const UserMediaSizes& user_media() const { return user_media_; } |
413 | 429 |
414 private: | 430 private: |
415 UserMediaSizes user_media_; | 431 UserMediaSizes user_media_; |
416 }; | 432 }; |
417 | 433 |
418 // This test calls getUserMedia in sequence with different constraints. | 434 // This test calls getUserMedia in sequence with different constraints. |
(...skipping 21 matching lines...) Expand all Loading... |
440 {640, 640, 480, 480, 30, 30}, | 456 {640, 640, 480, 480, 30, 30}, |
441 {960, 960, 720, 720, 30, 30}, | 457 {960, 960, 720, 720, 30, 30}, |
442 {1280, 1280, 720, 720, 30, 30}, | 458 {1280, 1280, 720, 720, 30, 30}, |
443 {1920, 1920, 1080, 1080, 30, 30}}; | 459 {1920, 1920, 1080, 1080, 30, 30}}; |
444 | 460 |
445 INSTANTIATE_TEST_CASE_P(UserMedia, | 461 INSTANTIATE_TEST_CASE_P(UserMedia, |
446 WebRtcConstraintsBrowserTest, | 462 WebRtcConstraintsBrowserTest, |
447 testing::ValuesIn(kAllUserMediaSizes)); | 463 testing::ValuesIn(kAllUserMediaSizes)); |
448 | 464 |
449 } // namespace content | 465 } // namespace content |
OLD | NEW |