OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/media/webrtc/webrtc_browsertest_base.h" | 5 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
20 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" | 21 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" |
21 #include "chrome/browser/permissions/permission_request_manager.h" | 22 #include "chrome/browser/permissions/permission_request_manager.h" |
22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 "failed-with-error-PermissionDismissedError"; | 58 "failed-with-error-PermissionDismissedError"; |
58 const char WebRtcTestBase::kAudioVideoCallConstraints360p[] = | 59 const char WebRtcTestBase::kAudioVideoCallConstraints360p[] = |
59 "{audio: true, video: {mandatory: {minWidth: 640, maxWidth: 640, " | 60 "{audio: true, video: {mandatory: {minWidth: 640, maxWidth: 640, " |
60 " minHeight: 360, maxHeight: 360}}}"; | 61 " minHeight: 360, maxHeight: 360}}}"; |
61 const char WebRtcTestBase::kAudioVideoCallConstraints720p[] = | 62 const char WebRtcTestBase::kAudioVideoCallConstraints720p[] = |
62 "{audio: true, video: {mandatory: {minWidth: 1280, maxWidth: 1280, " | 63 "{audio: true, video: {mandatory: {minWidth: 1280, maxWidth: 1280, " |
63 " minHeight: 720, maxHeight: 720}}}"; | 64 " minHeight: 720, maxHeight: 720}}}"; |
64 const char WebRtcTestBase::kUseDefaultCertKeygen[] = "null"; | 65 const char WebRtcTestBase::kUseDefaultCertKeygen[] = "null"; |
65 const char WebRtcTestBase::kUseDefaultAudioCodec[] = ""; | 66 const char WebRtcTestBase::kUseDefaultAudioCodec[] = ""; |
66 const char WebRtcTestBase::kUseDefaultVideoCodec[] = ""; | 67 const char WebRtcTestBase::kUseDefaultVideoCodec[] = ""; |
| 68 const char WebRtcTestBase::kUndefined[] = "undefined"; |
67 | 69 |
68 namespace { | 70 namespace { |
69 | 71 |
70 base::LazyInstance<bool>::DestructorAtExit hit_javascript_errors_ = | 72 base::LazyInstance<bool>::DestructorAtExit hit_javascript_errors_ = |
71 LAZY_INSTANCE_INITIALIZER; | 73 LAZY_INSTANCE_INITIALIZER; |
72 | 74 |
73 // Intercepts all log messages. We always attach this handler but only look at | 75 // Intercepts all log messages. We always attach this handler but only look at |
74 // the results if the test requests so. Note that this will only work if the | 76 // the results if the test requests so. Note that this will only work if the |
75 // WebrtcTestBase-inheriting test cases do not run in parallel (if they did they | 77 // WebrtcTestBase-inheriting test cases do not run in parallel (if they did they |
76 // would race to look at the log, which is global to all tests). | 78 // would race to look at the log, which is global to all tests). |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 590 |
589 void WebRtcTestBase::VerifyRtpReceivers( | 591 void WebRtcTestBase::VerifyRtpReceivers( |
590 content::WebContents* tab, | 592 content::WebContents* tab, |
591 base::Optional<size_t> expected_num_tracks) const { | 593 base::Optional<size_t> expected_num_tracks) const { |
592 std::string javascript = | 594 std::string javascript = |
593 expected_num_tracks ? "verifyRtpReceivers(" + | 595 expected_num_tracks ? "verifyRtpReceivers(" + |
594 base::SizeTToString(*expected_num_tracks) + ")" | 596 base::SizeTToString(*expected_num_tracks) + ")" |
595 : "verifyRtpReceivers()"; | 597 : "verifyRtpReceivers()"; |
596 EXPECT_EQ("ok-receivers-verified", ExecuteJavascript(javascript, tab)); | 598 EXPECT_EQ("ok-receivers-verified", ExecuteJavascript(javascript, tab)); |
597 } | 599 } |
| 600 |
| 601 std::vector<std::string> WebRtcTestBase::CreateAndAddAudioAndVideoTrack( |
| 602 content::WebContents* tab, |
| 603 StreamArgumentType stream_argument_type) const { |
| 604 const char* string_argument_type_str = nullptr; |
| 605 switch (stream_argument_type) { |
| 606 case StreamArgumentType::NO_STREAM: |
| 607 string_argument_type_str = "'no-stream'"; |
| 608 break; |
| 609 case StreamArgumentType::SHARED_STREAM: |
| 610 string_argument_type_str = "'shared-stream'"; |
| 611 break; |
| 612 case StreamArgumentType::INDIVIDUAL_STREAMS: |
| 613 string_argument_type_str = "'individual-streams'"; |
| 614 break; |
| 615 } |
| 616 std::string result = |
| 617 ExecuteJavascript(base::StringPrintf("createAndAddAudioAndVideoTrack(%s)", |
| 618 string_argument_type_str), |
| 619 tab); |
| 620 EXPECT_TRUE(base::StartsWith(result, "ok-", base::CompareCase::SENSITIVE)); |
| 621 std::vector<std::string> ids = base::SplitString( |
| 622 result.substr(3), " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 623 EXPECT_EQ(4u, ids.size()); |
| 624 return ids; |
| 625 } |
| 626 |
| 627 void WebRtcTestBase::RemoveTrack(content::WebContents* tab, |
| 628 const std::string& track_id) const { |
| 629 EXPECT_EQ( |
| 630 "ok-sender-removed", |
| 631 ExecuteJavascript( |
| 632 base::StringPrintf("removeTrack('%s')", track_id.c_str()), tab)); |
| 633 } |
| 634 |
| 635 bool WebRtcTestBase::HasLocalStreamWithTrack( |
| 636 content::WebContents* tab, |
| 637 const std::string& stream_id, |
| 638 const std::string& track_id) const { |
| 639 return HasStreamWithTrack(tab, "hasLocalStreamWithTrack", stream_id, |
| 640 track_id); |
| 641 } |
| 642 |
| 643 bool WebRtcTestBase::HasRemoteStreamWithTrack( |
| 644 content::WebContents* tab, |
| 645 const std::string& stream_id, |
| 646 const std::string& track_id) const { |
| 647 return HasStreamWithTrack(tab, "hasRemoteStreamWithTrack", stream_id, |
| 648 track_id); |
| 649 } |
| 650 |
| 651 bool WebRtcTestBase::HasStreamWithTrack(content::WebContents* tab, |
| 652 const char* function_name, |
| 653 std::string stream_id, |
| 654 std::string track_id) const { |
| 655 if (stream_id != kUndefined) |
| 656 stream_id = "'" + stream_id + "'"; |
| 657 std::string javascript = base::StringPrintf( |
| 658 "%s(%s, '%s')", function_name, stream_id.c_str(), track_id.c_str()); |
| 659 std::string result = ExecuteJavascript(javascript, tab); |
| 660 EXPECT_TRUE(result == "ok-stream-with-track-found" || |
| 661 result == "ok-stream-with-track-not-found"); |
| 662 return result == "ok-stream-with-track-found"; |
| 663 } |
| 664 |
| 665 bool WebRtcTestBase::HasSenderWithTrack(content::WebContents* tab, |
| 666 std::string track_id) const { |
| 667 std::string javascript = |
| 668 base::StringPrintf("hasSenderWithTrack('%s')", track_id.c_str()); |
| 669 std::string result = ExecuteJavascript(javascript, tab); |
| 670 EXPECT_TRUE(result == "ok-sender-with-track-found" || |
| 671 result == "ok-sender-with-track-not-found"); |
| 672 return result == "ok-sender-with-track-found"; |
| 673 } |
| 674 |
| 675 bool WebRtcTestBase::HasReceiverWithTrack(content::WebContents* tab, |
| 676 std::string track_id) const { |
| 677 std::string javascript = |
| 678 base::StringPrintf("hasReceiverWithTrack('%s')", track_id.c_str()); |
| 679 std::string result = ExecuteJavascript(javascript, tab); |
| 680 EXPECT_TRUE(result == "ok-receiver-with-track-found" || |
| 681 result == "ok-receiver-with-track-not-found"); |
| 682 return result == "ok-receiver-with-track-found"; |
| 683 } |
| 684 |
| 685 size_t WebRtcTestBase::GetNegotiationNeededCount( |
| 686 content::WebContents* tab) const { |
| 687 std::string result = ExecuteJavascript("getNegotiationNeededCount()", tab); |
| 688 EXPECT_TRUE(base::StartsWith(result, "ok-negotiation-count-is-", |
| 689 base::CompareCase::SENSITIVE)); |
| 690 size_t count = 0; |
| 691 EXPECT_TRUE(base::StringToSizeT(result.substr(24), &count)); |
| 692 return count; |
| 693 } |
OLD | NEW |