1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/strings/stringprintf.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/browser/webrtc/webrtc_content_browsertest_base.h"
#include "content/browser/webrtc/webrtc_internals.h"
#include "content/public/browser/audio_service.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "media/audio/audio_manager.h"
#include "media/audio/fake_audio_input_stream.h"
#include "media/base/media_switches.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/audio/public/mojom/testing_api.mojom.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#endif
namespace {
static const char kGetUserMediaAndStop[] = "getUserMediaAndStop";
static const char kGetUserMediaAndAnalyseAndStop[] =
"getUserMediaAndAnalyseAndStop";
static const char kGetUserMediaAndExpectFailure[] =
"getUserMediaAndExpectFailure";
static const char kRenderSameTrackMediastreamAndStop[] =
"renderSameTrackMediastreamAndStop";
static const char kRenderClonedMediastreamAndStop[] =
"renderClonedMediastreamAndStop";
static const char kRenderClonedTrackMediastreamAndStop[] =
"renderClonedTrackMediastreamAndStop";
static const char kRenderDuplicatedMediastreamAndStop[] =
"renderDuplicatedMediastreamAndStop";
std::string GenerateGetUserMediaWithMandatorySourceID(
const std::string& function_name,
const std::string& audio_source_id,
const std::string& video_source_id) {
const std::string audio_constraint =
"audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, ";
const std::string video_constraint =
"video: {mandatory: { sourceId:\"" + video_source_id + "\"}}";
return function_name + "({" + audio_constraint + video_constraint + "});";
}
std::string GenerateGetUserMediaWithOptionalSourceID(
const std::string& function_name,
const std::string& audio_source_id,
const std::string& video_source_id) {
const std::string audio_constraint =
"audio: {optional: [{sourceId:\"" + audio_source_id + "\"}]}, ";
const std::string video_constraint =
"video: {optional: [{ sourceId:\"" + video_source_id + "\"}]}";
return function_name + "({" + audio_constraint + video_constraint + "});";
}
// TODO(crbug.com/40841334): Bring back when
// WebRtcGetUserMediaBrowserTest.DisableLocalEchoParameter is fixed.
#if 0
std::string GenerateGetUserMediaWithDisableLocalEcho(
const std::string& function_name,
const std::string& disable_local_echo) {
const std::string audio_constraint =
"audio:{mandatory: { chromeMediaSource : 'system', disableLocalEcho : " +
disable_local_echo + " }},";
const std::string video_constraint =
"video: { mandatory: { chromeMediaSource:'screen' }}";
return function_name + "({" + audio_constraint + video_constraint + "});";
}
bool VerifyDisableLocalEcho(bool expect_value,
const blink::StreamControls& controls) {
return expect_value == controls.disable_local_echo;
}
#endif
} // namespace
namespace content {
class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase {
public:
WebRtcGetUserMediaBrowserTest() {
// Automatically grant device permission.
AppendUseFakeUIForMediaStreamFlag();
scoped_feature_list_.InitAndEnableFeature(
features::kUserMediaCaptureOnFocus);
}
~WebRtcGetUserMediaBrowserTest() override {}
// Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
void RunTwoGetTwoGetUserMediaWithDifferentContraints(
const std::string& constraints1,
const std::string& constraints2,
const std::string& expected_result) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
std::string command = "twoGetUserMedia(" + constraints1 + ',' +
constraints2 + ')';
EXPECT_EQ(expected_result, EvalJs(shell(), command));
}
void GetInputDevices(std::vector<std::string>* audio_ids,
std::vector<std::string>* video_ids) {
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
std::string devices_as_json =
EvalJs(shell(), "getSources()").ExtractString();
EXPECT_FALSE(devices_as_json.empty());
ASSERT_OK_AND_ASSIGN(
auto parsed_json,
base::JSONReader::ReadAndReturnValueWithError(
devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS));
ASSERT_TRUE(parsed_json.is_list());
for (const auto& entry : parsed_json.GetList()) {
const base::Value::Dict* dict = entry.GetIfDict();
ASSERT_TRUE(dict);
const std::string* kind = dict->FindString("kind");
const std::string* device_id = dict->FindString("id");
ASSERT_TRUE(kind);
ASSERT_TRUE(device_id);
ASSERT_FALSE(device_id->empty());
EXPECT_TRUE(*kind == "audio" || *kind == "video");
if (*kind == "audio") {
audio_ids->push_back(*device_id);
} else if (*kind == "video") {
video_ids->push_back(*device_id);
}
}
ASSERT_FALSE(audio_ids->empty());
ASSERT_FALSE(video_ids->empty());
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// These tests will all make a getUserMedia call with different constraints and
// see that the success callback is called. If the error callback is called or
// none of the callbacks are called the tests will simply time out and fail.
// Test fails under MSan, http://crbug.com/445745
#if defined(MEMORY_SANITIZER)
#define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
#else
#define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_GetVideoStreamAndStop) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(
shell(), base::StringPrintf("%s({video: true});", kGetUserMediaAndStop)));
}
// Test fails under MSan, http://crbug.com/445745
#if defined(MEMORY_SANITIZER)
#define MAYBE_RenderSameTrackMediastreamAndStop \
DISABLED_RenderSameTrackMediastreamAndStop
#else
#define MAYBE_RenderSameTrackMediastreamAndStop \
RenderSameTrackMediastreamAndStop
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_RenderSameTrackMediastreamAndStop) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(
ExecJs(shell(), base::StringPrintf("%s({video: true});",
kRenderSameTrackMediastreamAndStop)));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
RenderClonedMediastreamAndStop) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(
ExecJs(shell(), base::StringPrintf("%s({video: true});",
kRenderClonedMediastreamAndStop)));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
kRenderClonedTrackMediastreamAndStop) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(),
base::StringPrintf("%s({video: true});",
kRenderClonedTrackMediastreamAndStop)));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
kRenderDuplicatedMediastreamAndStop) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(
ExecJs(shell(), base::StringPrintf("%s({video: true});",
kRenderDuplicatedMediastreamAndStop)));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetAudioAndVideoStreamAndStop) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(
ExecJs(shell(), base::StringPrintf("%s({video: true, audio: true});",
kGetUserMediaAndStop)));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetAudioAndVideoStreamAndClone) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "getUserMediaAndClone();"));
}
// TODO(crbug.com/41365739) : Flaky on all platforms.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_RenderVideoTrackInMultipleTagsAndPause) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "getUserMediaAndRenderInSeveralVideoTags();"));
}
// TODO(crbug.com/571389, crbug.com/1241538): Flaky on TSAN bots and macOS.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC)
#define MAYBE_GetUserMediaWithMandatorySourceID \
DISABLED_GetUserMediaWithMandatorySourceID
#else
#define MAYBE_GetUserMediaWithMandatorySourceID \
GetUserMediaWithMandatorySourceID
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_GetUserMediaWithMandatorySourceID) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
std::vector<std::string> audio_ids;
std::vector<std::string> video_ids;
GetInputDevices(&audio_ids, &video_ids);
// Test all combinations of mandatory sourceID;
for (std::vector<std::string>::const_iterator video_it = video_ids.begin();
video_it != video_ids.end(); ++video_it) {
for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin();
audio_it != audio_ids.end(); ++audio_it) {
EXPECT_TRUE(
ExecJs(shell(), GenerateGetUserMediaWithMandatorySourceID(
kGetUserMediaAndStop, *audio_it, *video_it)));
}
}
}
#undef MAYBE_GetUserMediaWithMandatorySourceID
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetUserMediaWithInvalidMandatorySourceID) {
ASSERT_TRUE(embedded_test_server()->Start());
std::vector<std::string> audio_ids;
std::vector<std::string> video_ids;
GetInputDevices(&audio_ids, &video_ids);
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
// Test with invalid mandatory audio sourceID.
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ("OverconstrainedError",
EvalJs(shell(), GenerateGetUserMediaWithMandatorySourceID(
kGetUserMediaAndExpectFailure,
"something invalid", video_ids[0])));
// Test with invalid mandatory video sourceID.
EXPECT_EQ("OverconstrainedError",
EvalJs(shell(), GenerateGetUserMediaWithMandatorySourceID(
kGetUserMediaAndExpectFailure, audio_ids[0],
"something invalid")));
// Test with empty mandatory audio sourceID.
EXPECT_EQ(
"OverconstrainedError",
EvalJs(shell(), GenerateGetUserMediaWithMandatorySourceID(
kGetUserMediaAndExpectFailure, "", video_ids[0])));
}
// TODO(crbug.com/40784748): Flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_GetUserMediaWithInvalidOptionalSourceID \
DISABLED_GetUserMediaWithInvalidOptionalSourceID
#else
#define MAYBE_GetUserMediaWithInvalidOptionalSourceID \
GetUserMediaWithInvalidOptionalSourceID
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_GetUserMediaWithInvalidOptionalSourceID) {
ASSERT_TRUE(embedded_test_server()->Start());
std::vector<std::string> audio_ids;
std::vector<std::string> video_ids;
GetInputDevices(&audio_ids, &video_ids);
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
// Test with invalid optional audio sourceID.
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(
shell(), GenerateGetUserMediaWithOptionalSourceID(
kGetUserMediaAndStop, "something invalid", video_ids[0])));
// Test with invalid optional video sourceID.
EXPECT_TRUE(ExecJs(
shell(), GenerateGetUserMediaWithOptionalSourceID(
kGetUserMediaAndStop, audio_ids[0], "something invalid")));
// Test with empty optional audio sourceID.
EXPECT_TRUE(ExecJs(shell(), GenerateGetUserMediaWithOptionalSourceID(
kGetUserMediaAndStop, "", video_ids[0])));
}
// Sheriff 2021-08-10, test is flaky.
// See https://crbug.com/1238334.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaAndStop) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(
ExecJs(shell(), "twoGetUserMediaAndStop({video: true, audio: true});"));
}
// Flaky. See https://crbug.com/846741.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithEqualConstraints) {
std::string constraints1 = "{video: true, audio: true}";
const std::string& constraints2 = constraints1;
std::string expected_result = "w=640:h=480-w=640:h=480";
RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
expected_result);
}
// Flaky. See https://crbug.com/843844.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithSecondVideoCropped) {
std::string constraints1 = "{video: true}";
std::string constraints2 =
"{video: {width: {exact: 640}, height: {exact: 360}}}";
std::string expected_result = "w=640:h=480-w=640:h=360";
RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
expected_result);
}
// Test fails under MSan, http://crbug.com/445745.
// Flaky. See https://crbug.com/846960.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithFirstHdSecondVga) {
std::string constraints1 =
"{video: {width : {exact: 1280}, height: {exact: 720}}}";
std::string constraints2 =
"{video: {width : {exact: 640}, height: {exact: 480}}}";
std::string expected_result = "w=1280:h=720-w=640:h=480";
RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
expected_result);
}
// Timing out on Windows 7 bot: http://crbug.com/443294
// Flaky: http://crbug.com/660656; possible the test is too perf sensitive.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithFirst1080pSecondVga) {
std::string constraints1 =
"{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080, "
"minHeight: 1080}}}";
std::string constraints2 =
"{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
std::string expected_result = "w=1920:h=1080-w=640:h=480";
RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
expected_result);
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetUserMediaWithTooHighVideoConstraintsValues) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
int large_value = 99999;
std::string call = GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
large_value,
large_value,
large_value,
large_value,
large_value,
large_value);
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_EQ("OverconstrainedError", EvalJs(shell(), call));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetUserMediaFailToAccessAudioDevice) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
// Make sure we'll fail creating the audio stream.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kFailAudioStreamCreation);
const std::string call = base::StringPrintf(
"%s({video: false, audio: true});", kGetUserMediaAndExpectFailure);
EXPECT_EQ("NotReadableError", EvalJs(shell(), call));
}
// This test makes two getUserMedia requests, one with impossible constraints
// that should trigger an error, and one with valid constraints. The test
// verifies getUserMedia can succeed after being given impossible constraints.
// Flaky. See https://crbug.com/846984.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaAndCheckCallbackAfterFailure) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
int large_value = 99999;
const std::string gum_with_impossible_constraints =
GenerateGetUserMediaCall(kGetUserMediaAndExpectFailure,
large_value,
large_value,
large_value,
large_value,
large_value,
large_value);
const std::string gum_with_vga_constraints =
GenerateGetUserMediaCall(kGetUserMediaAndAnalyseAndStop,
640, 640, 480, 480, 10, 30);
ASSERT_EQ("OverconstrainedError",
EvalJs(shell(), gum_with_impossible_constraints));
ASSERT_EQ("w=640:h=480", EvalJs(shell(), gum_with_vga_constraints));
}
// This test calls getUserMedia and checks for aspect ratio behavior.
// TODO(crbug.com/40229233): Flaky for tsan, mac.
#if defined(THREAD_SANITIZER) || BUILDFLAG(IS_MAC)
#define MAYBE_TestGetUserMediaAspectRatio4To3 \
DISABLED_TestGetUserMediaAspectRatio4To3
#else
#define MAYBE_TestGetUserMediaAspectRatio4To3 TestGetUserMediaAspectRatio4To3
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_TestGetUserMediaAspectRatio4To3) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
std::string constraints_4_3 = GenerateGetUserMediaCall(
kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
EXPECT_TRUE(NavigateToURL(shell(), url));
ASSERT_EQ("w=640:h=480", EvalJs(shell(), constraints_4_3));
}
// This test calls getUserMedia and checks for aspect ratio behavior.
// Flaky: crbug.com/846582.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TestGetUserMediaAspectRatio16To9) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
std::string constraints_16_9 = GenerateGetUserMediaCall(
kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
EXPECT_TRUE(NavigateToURL(shell(), url));
ASSERT_EQ("w=640:h=360", EvalJs(shell(), constraints_16_9));
}
// This test calls getUserMedia and checks for aspect ratio behavior.
// TODO(crbug.com/40229233): Flaky for tsan, mac.
#if defined(THREAD_SANITIZER) || BUILDFLAG(IS_MAC)
#define MAYBE_TestGetUserMediaAspectRatio1To1 \
DISABLED_TestGetUserMediaAspectRatio1To1
#else
#define MAYBE_TestGetUserMediaAspectRatio1To1 TestGetUserMediaAspectRatio1To1
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_TestGetUserMediaAspectRatio1To1) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
std::string constraints_1_1 = GenerateGetUserMediaCall(
kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
EXPECT_TRUE(NavigateToURL(shell(), url));
ASSERT_EQ("w=320:h=320", EvalJs(shell(), constraints_1_1));
}
// This test calls getUserMedia in an iframe and immediately close the iframe
// in the scope of the success callback.
// Flaky: crbug.com/727601.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_AudioInIFrameAndCloseInSuccessCb) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
std::string call =
"getUserMediaInIframeAndCloseInSuccessCb({audio: true});";
EXPECT_TRUE(ExecJs(shell(), call));
}
// Flaky: crbug.com/807638
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_VideoInIFrameAndCloseInSuccessCb) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
std::string call =
"getUserMediaInIframeAndCloseInSuccessCb({video: true});";
EXPECT_TRUE(ExecJs(shell(), call));
}
// This test calls getUserMedia in an iframe and immediately close the iframe
// in the scope of the failure callback.
// Flaky on mac bots. http://crbug.com/1196389
#if BUILDFLAG(IS_MAC)
#define MAYBE_VideoWithBadConstraintsInIFrameAndCloseInFailureCb \
DISABLED_VideoWithBadConstraintsInIFrameAndCloseInFailureCb
#else
#define MAYBE_VideoWithBadConstraintsInIFrameAndCloseInFailureCb \
VideoWithBadConstraintsInIFrameAndCloseInFailureCb
#endif
IN_PROC_BROWSER_TEST_F(
WebRtcGetUserMediaBrowserTest,
MAYBE_VideoWithBadConstraintsInIFrameAndCloseInFailureCb) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
int large_value = 99999;
std::string call =
GenerateGetUserMediaCall("getUserMediaInIframeAndCloseInFailureCb",
large_value,
large_value,
large_value,
large_value,
large_value,
large_value);
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), call));
}
// TODO(http://crbug.com/1205560): This test is flaky on mac bots. Re-enable the
// test after fixing the issue.
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#define MAYBE_InvalidSourceIdInIFrameAndCloseInFailureCb \
DISABLED_InvalidSourceIdInIFrameAndCloseInFailureCb
#else
#define MAYBE_InvalidSourceIdInIFrameAndCloseInFailureCb \
InvalidSourceIdInIFrameAndCloseInFailureCb
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_InvalidSourceIdInIFrameAndCloseInFailureCb) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
std::string call =
GenerateGetUserMediaWithMandatorySourceID(
"getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid");
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), call));
}
// TODO(crbug.com/40841334): Fix this test. It seems to be broken (no audio /
// video tracks are requested; "uncaught (in promise) undefined)") and was false
// positive before disabling.
#if 0
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DisableLocalEchoParameter) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
MediaStreamManager* manager =
BrowserMainLoop::GetInstance()->media_stream_manager();
manager->SetGenerateStreamsCallbackForTesting(
base::BindOnce(&VerifyDisableLocalEcho, false));
std::string call = GenerateGetUserMediaWithDisableLocalEcho(
"getUserMediaAndExpectSuccess", "false");
EXPECT_TRUE(ExecJs(shell(), call));
manager->SetGenerateStreamsCallbackForTesting(
base::BindOnce(&VerifyDisableLocalEcho, true));
call = GenerateGetUserMediaWithDisableLocalEcho(
"getUserMediaAndExpectSuccess", "true");
EXPECT_TRUE(ExecJs(shell(), call));
manager->SetGenerateStreamsCallbackForTesting(
MediaStreamManager::GenerateStreamTestCallback());
}
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, GetAudioSettingsDefault) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "getAudioSettingsDefault()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetAudioSettingsNoEchoCancellation) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "getAudioSettingsNoEchoCancellation()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetAudioSettingsDeviceId) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "getAudioSettingsDeviceId()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, SrcObjectAddVideoTrack) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "srcObjectAddVideoTrack()"));
}
// TODO(crbug.com/41392081) Flaky on all platforms
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_SrcObjectReplaceInactiveTracks) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "srcObjectReplaceInactiveTracks()"));
}
// Flaky on all platforms. https://crbug.com/835332
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_SrcObjectRemoveVideoTrack) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "srcObjectRemoveVideoTrack()"));
}
// Flaky. https://crbug.com/843844
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_SrcObjectRemoveFirstOfTwoVideoTracks) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "srcObjectRemoveFirstOfTwoVideoTracks()"));
}
// TODO(guidou): Add SrcObjectAddAudioTrack and SrcObjectRemoveAudioTrack tests
// when a straightforward mechanism to detect the presence/absence of audio in a
// media element with an assigned MediaStream becomes available.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
SrcObjectReassignSameObject) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "srcObjectReassignSameObject()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, ApplyConstraintsVideo) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "applyConstraintsVideo()"));
}
// Flaky due to https://crbug.com/1113820
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_ApplyConstraintsVideoTwoStreams) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "applyConstraintsVideoTwoStreams()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
ApplyConstraintsVideoOverconstrained) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "applyConstraintsVideoOverconstrained()"));
}
// Flaky on Win, see https://crbug.com/915135
// Flaky on Linux, see https://crbug.com/952381
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_ApplyConstraintsNonDevice DISABLED_ApplyConstraintsNonDevice
#else
#define MAYBE_ApplyConstraintsNonDevice ApplyConstraintsNonDevice
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_ApplyConstraintsNonDevice) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "applyConstraintsNonDevice()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
ConcurrentGetUserMediaStop) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "concurrentGetUserMediaStop()"));
}
// TODO(crbug.com/40694651) : Flaky on all platforms.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_GetUserMediaAfterStopElementCapture) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "getUserMediaAfterStopCanvasCapture()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetUserMediaEchoCancellationOnAndOff) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "getUserMediaEchoCancellationOnAndOff()"));
}
// TODO(crbug.com/40694651) : Flaky on all platforms.
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_GetUserMediaEchoCancellationOnAndOffAndVideo) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(
ExecJs(shell(), "getUserMediaEchoCancellationOnAndOffAndVideo()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
EnumerationAfterSameDocumentNavigation) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "enumerationAfterSameDocumentNaviagtion()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
RecoverFromCrashInAudioService) {
// This test only makes sense with the audio service running out of process,
// with or without sandbox.
if (!base::FeatureList::IsEnabled(features::kAudioServiceOutOfProcess))
return;
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_TRUE(ExecJs(shell(), "setUpForAudioServiceCrash()"));
// Crash the audio service process.
mojo::Remote<audio::mojom::TestingApi> service_testing_api;
GetAudioService().BindTestingApi(
service_testing_api.BindNewPipeAndPassReceiver());
service_testing_api->Crash();
EXPECT_TRUE(ExecJs(shell(), "verifyAfterAudioServiceCrash()"));
}
} // namespace content
|