Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: webrtc/api/peerconnection_unittest.cc

Issue 2587133004: Reland of: Adding error output param to SetConfiguration, using new RTCError type. (Closed)
Patch Set: Fixing compile error in less confusing way. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/peerconnection.cc ('k') | webrtc/api/peerconnectioninterface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 2603 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 delete set_receiving_client(nullptr); 2614 delete set_receiving_client(nullptr);
2615 } 2615 }
2616 2616
2617 class IceServerParsingTest : public testing::Test { 2617 class IceServerParsingTest : public testing::Test {
2618 public: 2618 public:
2619 // Convenience for parsing a single URL. 2619 // Convenience for parsing a single URL.
2620 bool ParseUrl(const std::string& url) { 2620 bool ParseUrl(const std::string& url) {
2621 return ParseUrl(url, std::string(), std::string()); 2621 return ParseUrl(url, std::string(), std::string());
2622 } 2622 }
2623 2623
2624 bool ParseTurnUrl(const std::string& url) {
2625 return ParseUrl(url, "username", "password");
2626 }
2627
2624 bool ParseUrl(const std::string& url, 2628 bool ParseUrl(const std::string& url,
2625 const std::string& username, 2629 const std::string& username,
2626 const std::string& password) { 2630 const std::string& password) {
2627 return ParseUrl( 2631 return ParseUrl(
2628 url, username, password, 2632 url, username, password,
2629 PeerConnectionInterface::TlsCertPolicy::kTlsCertPolicySecure); 2633 PeerConnectionInterface::TlsCertPolicy::kTlsCertPolicySecure);
2630 } 2634 }
2631 2635
2632 bool ParseUrl(const std::string& url, 2636 bool ParseUrl(const std::string& url,
2633 const std::string& username, 2637 const std::string& username,
2634 const std::string& password, 2638 const std::string& password,
2635 PeerConnectionInterface::TlsCertPolicy tls_certificate_policy) { 2639 PeerConnectionInterface::TlsCertPolicy tls_certificate_policy) {
2636 PeerConnectionInterface::IceServers servers; 2640 PeerConnectionInterface::IceServers servers;
2637 PeerConnectionInterface::IceServer server; 2641 PeerConnectionInterface::IceServer server;
2638 server.urls.push_back(url); 2642 server.urls.push_back(url);
2639 server.username = username; 2643 server.username = username;
2640 server.password = password; 2644 server.password = password;
2641 server.tls_cert_policy = tls_certificate_policy; 2645 server.tls_cert_policy = tls_certificate_policy;
2642 servers.push_back(server); 2646 servers.push_back(server);
2643 return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_); 2647 return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_) ==
2648 webrtc::RTCErrorType::NONE;
2644 } 2649 }
2645 2650
2646 protected: 2651 protected:
2647 cricket::ServerAddresses stun_servers_; 2652 cricket::ServerAddresses stun_servers_;
2648 std::vector<cricket::RelayServerConfig> turn_servers_; 2653 std::vector<cricket::RelayServerConfig> turn_servers_;
2649 }; 2654 };
2650 2655
2651 // Make sure all STUN/TURN prefixes are parsed correctly. 2656 // Make sure all STUN/TURN prefixes are parsed correctly.
2652 TEST_F(IceServerParsingTest, ParseStunPrefixes) { 2657 TEST_F(IceServerParsingTest, ParseStunPrefixes) {
2653 EXPECT_TRUE(ParseUrl("stun:hostname")); 2658 EXPECT_TRUE(ParseUrl("stun:hostname"));
2654 EXPECT_EQ(1U, stun_servers_.size()); 2659 EXPECT_EQ(1U, stun_servers_.size());
2655 EXPECT_EQ(0U, turn_servers_.size()); 2660 EXPECT_EQ(0U, turn_servers_.size());
2656 stun_servers_.clear(); 2661 stun_servers_.clear();
2657 2662
2658 EXPECT_TRUE(ParseUrl("stuns:hostname")); 2663 EXPECT_TRUE(ParseUrl("stuns:hostname"));
2659 EXPECT_EQ(1U, stun_servers_.size()); 2664 EXPECT_EQ(1U, stun_servers_.size());
2660 EXPECT_EQ(0U, turn_servers_.size()); 2665 EXPECT_EQ(0U, turn_servers_.size());
2661 stun_servers_.clear(); 2666 stun_servers_.clear();
2662 2667
2663 EXPECT_TRUE(ParseUrl("turn:hostname")); 2668 EXPECT_TRUE(ParseTurnUrl("turn:hostname"));
2664 EXPECT_EQ(0U, stun_servers_.size()); 2669 EXPECT_EQ(0U, stun_servers_.size());
2665 EXPECT_EQ(1U, turn_servers_.size()); 2670 EXPECT_EQ(1U, turn_servers_.size());
2666 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); 2671 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
2667 turn_servers_.clear(); 2672 turn_servers_.clear();
2668 2673
2669 EXPECT_TRUE(ParseUrl("turns:hostname")); 2674 EXPECT_TRUE(ParseTurnUrl("turns:hostname"));
2670 EXPECT_EQ(0U, stun_servers_.size()); 2675 EXPECT_EQ(0U, stun_servers_.size());
2671 EXPECT_EQ(1U, turn_servers_.size()); 2676 EXPECT_EQ(1U, turn_servers_.size());
2672 EXPECT_EQ(cricket::PROTO_TLS, turn_servers_[0].ports[0].proto); 2677 EXPECT_EQ(cricket::PROTO_TLS, turn_servers_[0].ports[0].proto);
2673 EXPECT_TRUE(turn_servers_[0].tls_cert_policy == 2678 EXPECT_TRUE(turn_servers_[0].tls_cert_policy ==
2674 cricket::TlsCertPolicy::TLS_CERT_POLICY_SECURE); 2679 cricket::TlsCertPolicy::TLS_CERT_POLICY_SECURE);
2675 turn_servers_.clear(); 2680 turn_servers_.clear();
2676 2681
2677 EXPECT_TRUE(ParseUrl( 2682 EXPECT_TRUE(ParseUrl(
2678 "turns:hostname", "", "", 2683 "turns:hostname", "username", "password",
2679 PeerConnectionInterface::TlsCertPolicy::kTlsCertPolicyInsecureNoCheck)); 2684 PeerConnectionInterface::TlsCertPolicy::kTlsCertPolicyInsecureNoCheck));
2680 EXPECT_EQ(0U, stun_servers_.size()); 2685 EXPECT_EQ(0U, stun_servers_.size());
2681 EXPECT_EQ(1U, turn_servers_.size()); 2686 EXPECT_EQ(1U, turn_servers_.size());
2682 EXPECT_TRUE(turn_servers_[0].tls_cert_policy == 2687 EXPECT_TRUE(turn_servers_[0].tls_cert_policy ==
2683 cricket::TlsCertPolicy::TLS_CERT_POLICY_INSECURE_NO_CHECK); 2688 cricket::TlsCertPolicy::TLS_CERT_POLICY_INSECURE_NO_CHECK);
2684 EXPECT_EQ(cricket::PROTO_TLS, turn_servers_[0].ports[0].proto); 2689 EXPECT_EQ(cricket::PROTO_TLS, turn_servers_[0].ports[0].proto);
2685 turn_servers_.clear(); 2690 turn_servers_.clear();
2686 2691
2687 // invalid prefixes 2692 // invalid prefixes
2688 EXPECT_FALSE(ParseUrl("stunn:hostname")); 2693 EXPECT_FALSE(ParseUrl("stunn:hostname"));
2689 EXPECT_FALSE(ParseUrl(":hostname")); 2694 EXPECT_FALSE(ParseUrl(":hostname"));
2690 EXPECT_FALSE(ParseUrl(":")); 2695 EXPECT_FALSE(ParseUrl(":"));
2691 EXPECT_FALSE(ParseUrl("")); 2696 EXPECT_FALSE(ParseUrl(""));
2692 } 2697 }
2693 2698
2694 TEST_F(IceServerParsingTest, VerifyDefaults) { 2699 TEST_F(IceServerParsingTest, VerifyDefaults) {
2695 // TURNS defaults 2700 // TURNS defaults
2696 EXPECT_TRUE(ParseUrl("turns:hostname")); 2701 EXPECT_TRUE(ParseTurnUrl("turns:hostname"));
2697 EXPECT_EQ(1U, turn_servers_.size()); 2702 EXPECT_EQ(1U, turn_servers_.size());
2698 EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port()); 2703 EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port());
2699 EXPECT_EQ(cricket::PROTO_TLS, turn_servers_[0].ports[0].proto); 2704 EXPECT_EQ(cricket::PROTO_TLS, turn_servers_[0].ports[0].proto);
2700 turn_servers_.clear(); 2705 turn_servers_.clear();
2701 2706
2702 // TURN defaults 2707 // TURN defaults
2703 EXPECT_TRUE(ParseUrl("turn:hostname")); 2708 EXPECT_TRUE(ParseTurnUrl("turn:hostname"));
2704 EXPECT_EQ(1U, turn_servers_.size()); 2709 EXPECT_EQ(1U, turn_servers_.size());
2705 EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port()); 2710 EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port());
2706 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); 2711 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
2707 turn_servers_.clear(); 2712 turn_servers_.clear();
2708 2713
2709 // STUN defaults 2714 // STUN defaults
2710 EXPECT_TRUE(ParseUrl("stun:hostname")); 2715 EXPECT_TRUE(ParseUrl("stun:hostname"));
2711 EXPECT_EQ(1U, stun_servers_.size()); 2716 EXPECT_EQ(1U, stun_servers_.size());
2712 EXPECT_EQ(3478, stun_servers_.begin()->port()); 2717 EXPECT_EQ(3478, stun_servers_.begin()->port());
2713 stun_servers_.clear(); 2718 stun_servers_.clear();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2758 EXPECT_FALSE(ParseUrl("stun:hostname:port:more")); 2763 EXPECT_FALSE(ParseUrl("stun:hostname:port:more"));
2759 EXPECT_FALSE(ParseUrl("stun:hostname:port more")); 2764 EXPECT_FALSE(ParseUrl("stun:hostname:port more"));
2760 EXPECT_FALSE(ParseUrl("stun:hostname:")); 2765 EXPECT_FALSE(ParseUrl("stun:hostname:"));
2761 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); 2766 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000"));
2762 EXPECT_FALSE(ParseUrl("stun::5555")); 2767 EXPECT_FALSE(ParseUrl("stun::5555"));
2763 EXPECT_FALSE(ParseUrl("stun:")); 2768 EXPECT_FALSE(ParseUrl("stun:"));
2764 } 2769 }
2765 2770
2766 // Test parsing the "?transport=xxx" part of the URL. 2771 // Test parsing the "?transport=xxx" part of the URL.
2767 TEST_F(IceServerParsingTest, ParseTransport) { 2772 TEST_F(IceServerParsingTest, ParseTransport) {
2768 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); 2773 EXPECT_TRUE(ParseTurnUrl("turn:hostname:1234?transport=tcp"));
2769 EXPECT_EQ(1U, turn_servers_.size()); 2774 EXPECT_EQ(1U, turn_servers_.size());
2770 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); 2775 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
2771 turn_servers_.clear(); 2776 turn_servers_.clear();
2772 2777
2773 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); 2778 EXPECT_TRUE(ParseTurnUrl("turn:hostname?transport=udp"));
2774 EXPECT_EQ(1U, turn_servers_.size()); 2779 EXPECT_EQ(1U, turn_servers_.size());
2775 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); 2780 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
2776 turn_servers_.clear(); 2781 turn_servers_.clear();
2777 2782
2778 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); 2783 EXPECT_FALSE(ParseTurnUrl("turn:hostname?transport=invalid"));
2779 EXPECT_FALSE(ParseUrl("turn:hostname?transport=")); 2784 EXPECT_FALSE(ParseTurnUrl("turn:hostname?transport="));
2780 EXPECT_FALSE(ParseUrl("turn:hostname?=")); 2785 EXPECT_FALSE(ParseTurnUrl("turn:hostname?="));
2781 EXPECT_FALSE(ParseUrl("?")); 2786 EXPECT_FALSE(ParseTurnUrl("?"));
2782 } 2787 }
2783 2788
2784 // Test parsing ICE username contained in URL. 2789 // Test parsing ICE username contained in URL.
2785 TEST_F(IceServerParsingTest, ParseUsername) { 2790 TEST_F(IceServerParsingTest, ParseUsername) {
2786 EXPECT_TRUE(ParseUrl("turn:user@hostname")); 2791 EXPECT_TRUE(ParseTurnUrl("turn:user@hostname"));
2787 EXPECT_EQ(1U, turn_servers_.size()); 2792 EXPECT_EQ(1U, turn_servers_.size());
2788 EXPECT_EQ("user", turn_servers_[0].credentials.username); 2793 EXPECT_EQ("user", turn_servers_[0].credentials.username);
2789 turn_servers_.clear(); 2794 turn_servers_.clear();
2790 2795
2791 EXPECT_FALSE(ParseUrl("turn:@hostname")); 2796 EXPECT_FALSE(ParseTurnUrl("turn:@hostname"));
2792 EXPECT_FALSE(ParseUrl("turn:username@")); 2797 EXPECT_FALSE(ParseTurnUrl("turn:username@"));
2793 EXPECT_FALSE(ParseUrl("turn:@")); 2798 EXPECT_FALSE(ParseTurnUrl("turn:@"));
2794 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); 2799 EXPECT_FALSE(ParseTurnUrl("turn:user@name@hostname"));
2795 } 2800 }
2796 2801
2797 // Test that username and password from IceServer is copied into the resulting 2802 // Test that username and password from IceServer is copied into the resulting
2798 // RelayServerConfig. 2803 // RelayServerConfig.
2799 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { 2804 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) {
2800 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); 2805 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password"));
2801 EXPECT_EQ(1U, turn_servers_.size()); 2806 EXPECT_EQ(1U, turn_servers_.size());
2802 EXPECT_EQ("username", turn_servers_[0].credentials.username); 2807 EXPECT_EQ("username", turn_servers_[0].credentials.username);
2803 EXPECT_EQ("password", turn_servers_[0].credentials.password); 2808 EXPECT_EQ("password", turn_servers_[0].credentials.password);
2804 } 2809 }
2805 2810
2806 // Ensure that if a server has multiple URLs, each one is parsed. 2811 // Ensure that if a server has multiple URLs, each one is parsed.
2807 TEST_F(IceServerParsingTest, ParseMultipleUrls) { 2812 TEST_F(IceServerParsingTest, ParseMultipleUrls) {
2808 PeerConnectionInterface::IceServers servers; 2813 PeerConnectionInterface::IceServers servers;
2809 PeerConnectionInterface::IceServer server; 2814 PeerConnectionInterface::IceServer server;
2810 server.urls.push_back("stun:hostname"); 2815 server.urls.push_back("stun:hostname");
2811 server.urls.push_back("turn:hostname"); 2816 server.urls.push_back("turn:hostname");
2817 server.username = "foo";
2818 server.password = "bar";
2812 servers.push_back(server); 2819 servers.push_back(server);
2813 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2820 EXPECT_EQ(webrtc::RTCErrorType::NONE,
2821 webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2814 EXPECT_EQ(1U, stun_servers_.size()); 2822 EXPECT_EQ(1U, stun_servers_.size());
2815 EXPECT_EQ(1U, turn_servers_.size()); 2823 EXPECT_EQ(1U, turn_servers_.size());
2816 } 2824 }
2817 2825
2818 // Ensure that TURN servers are given unique priorities, 2826 // Ensure that TURN servers are given unique priorities,
2819 // so that their resulting candidates have unique priorities. 2827 // so that their resulting candidates have unique priorities.
2820 TEST_F(IceServerParsingTest, TurnServerPrioritiesUnique) { 2828 TEST_F(IceServerParsingTest, TurnServerPrioritiesUnique) {
2821 PeerConnectionInterface::IceServers servers; 2829 PeerConnectionInterface::IceServers servers;
2822 PeerConnectionInterface::IceServer server; 2830 PeerConnectionInterface::IceServer server;
2823 server.urls.push_back("turn:hostname"); 2831 server.urls.push_back("turn:hostname");
2824 server.urls.push_back("turn:hostname2"); 2832 server.urls.push_back("turn:hostname2");
2833 server.username = "foo";
2834 server.password = "bar";
2825 servers.push_back(server); 2835 servers.push_back(server);
2826 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2836 EXPECT_EQ(webrtc::RTCErrorType::NONE,
2837 webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2827 EXPECT_EQ(2U, turn_servers_.size()); 2838 EXPECT_EQ(2U, turn_servers_.size());
2828 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2839 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2829 } 2840 }
2830 2841
2831 #endif // if !defined(THREAD_SANITIZER) 2842 #endif // if !defined(THREAD_SANITIZER)
2832 2843
2833 } // namespace 2844 } // namespace
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.cc ('k') | webrtc/api/peerconnectioninterface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698