OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include <algorithm> | 30 #include <algorithm> |
31 #include <list> | 31 #include <list> |
32 #include <map> | 32 #include <map> |
33 #include <vector> | 33 #include <vector> |
34 | 34 |
35 #include "talk/app/webrtc/dtmfsender.h" | 35 #include "talk/app/webrtc/dtmfsender.h" |
36 #include "talk/app/webrtc/fakemetricsobserver.h" | 36 #include "talk/app/webrtc/fakemetricsobserver.h" |
37 #include "talk/app/webrtc/fakeportallocatorfactory.h" | 37 #include "talk/app/webrtc/fakeportallocatorfactory.h" |
38 #include "talk/app/webrtc/localaudiosource.h" | 38 #include "talk/app/webrtc/localaudiosource.h" |
39 #include "talk/app/webrtc/mediastreaminterface.h" | 39 #include "talk/app/webrtc/mediastreaminterface.h" |
| 40 #include "talk/app/webrtc/peerconnection.h" |
40 #include "talk/app/webrtc/peerconnectionfactory.h" | 41 #include "talk/app/webrtc/peerconnectionfactory.h" |
41 #include "talk/app/webrtc/peerconnectioninterface.h" | 42 #include "talk/app/webrtc/peerconnectioninterface.h" |
42 #include "talk/app/webrtc/test/fakeaudiocapturemodule.h" | 43 #include "talk/app/webrtc/test/fakeaudiocapturemodule.h" |
43 #include "talk/app/webrtc/test/fakeconstraints.h" | 44 #include "talk/app/webrtc/test/fakeconstraints.h" |
44 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" | 45 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
45 #include "talk/app/webrtc/test/fakeperiodicvideocapturer.h" | 46 #include "talk/app/webrtc/test/fakeperiodicvideocapturer.h" |
46 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" | 47 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" |
47 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" | 48 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" |
48 #include "talk/app/webrtc/videosourceinterface.h" | 49 #include "talk/app/webrtc/videosourceinterface.h" |
49 #include "talk/media/webrtc/fakewebrtcvideoengine.h" | 50 #include "talk/media/webrtc/fakewebrtcvideoengine.h" |
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1619 // VideoDecoderFactory. | 1620 // VideoDecoderFactory. |
1620 // TODO(holmer): Disabled due to sometimes crashing on buildbots. | 1621 // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
1621 // See issue webrtc/2378. | 1622 // See issue webrtc/2378. |
1622 TEST_F(JsepPeerConnectionP2PTestClient, | 1623 TEST_F(JsepPeerConnectionP2PTestClient, |
1623 DISABLED_LocalP2PTestWithVideoDecoderFactory) { | 1624 DISABLED_LocalP2PTestWithVideoDecoderFactory) { |
1624 ASSERT_TRUE(CreateTestClients()); | 1625 ASSERT_TRUE(CreateTestClients()); |
1625 EnableVideoDecoderFactory(); | 1626 EnableVideoDecoderFactory(); |
1626 LocalP2PTest(); | 1627 LocalP2PTest(); |
1627 } | 1628 } |
1628 | 1629 |
| 1630 class IceServerParsingTest : public testing::Test { |
| 1631 public: |
| 1632 // Convenience for parsing a single URL. |
| 1633 bool ParseUrl(const std::string& url) { |
| 1634 return ParseUrl(url, std::string(), std::string()); |
| 1635 } |
| 1636 |
| 1637 bool ParseUrl(const std::string& url, |
| 1638 const std::string& username, |
| 1639 const std::string& password) { |
| 1640 PeerConnectionInterface::IceServers servers; |
| 1641 PeerConnectionInterface::IceServer server; |
| 1642 server.urls.push_back(url); |
| 1643 server.username = username; |
| 1644 server.password = password; |
| 1645 servers.push_back(server); |
| 1646 return webrtc::ParseIceServers(servers, &stun_configurations_, |
| 1647 &turn_configurations_); |
| 1648 } |
| 1649 |
| 1650 protected: |
| 1651 webrtc::StunConfigurations stun_configurations_; |
| 1652 webrtc::TurnConfigurations turn_configurations_; |
| 1653 }; |
| 1654 |
| 1655 // Make sure all STUN/TURN prefixes are parsed correctly. |
| 1656 TEST_F(IceServerParsingTest, ParseStunPrefixes) { |
| 1657 EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1658 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1659 EXPECT_EQ(0U, turn_configurations_.size()); |
| 1660 stun_configurations_.clear(); |
| 1661 |
| 1662 EXPECT_TRUE(ParseUrl("stuns:hostname")); |
| 1663 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1664 EXPECT_EQ(0U, turn_configurations_.size()); |
| 1665 stun_configurations_.clear(); |
| 1666 |
| 1667 EXPECT_TRUE(ParseUrl("turn:hostname")); |
| 1668 EXPECT_EQ(0U, stun_configurations_.size()); |
| 1669 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1670 EXPECT_FALSE(turn_configurations_[0].secure); |
| 1671 turn_configurations_.clear(); |
| 1672 |
| 1673 EXPECT_TRUE(ParseUrl("turns:hostname")); |
| 1674 EXPECT_EQ(0U, stun_configurations_.size()); |
| 1675 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1676 EXPECT_TRUE(turn_configurations_[0].secure); |
| 1677 turn_configurations_.clear(); |
| 1678 |
| 1679 // invalid prefixes |
| 1680 EXPECT_FALSE(ParseUrl("stunn:hostname")); |
| 1681 EXPECT_FALSE(ParseUrl(":hostname")); |
| 1682 EXPECT_FALSE(ParseUrl(":")); |
| 1683 EXPECT_FALSE(ParseUrl("")); |
| 1684 } |
| 1685 |
| 1686 TEST_F(IceServerParsingTest, VerifyDefaults) { |
| 1687 // TURNS defaults |
| 1688 EXPECT_TRUE(ParseUrl("turns:hostname")); |
| 1689 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1690 EXPECT_EQ(5349, turn_configurations_[0].server.port()); |
| 1691 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); |
| 1692 turn_configurations_.clear(); |
| 1693 |
| 1694 // TURN defaults |
| 1695 EXPECT_TRUE(ParseUrl("turn:hostname")); |
| 1696 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1697 EXPECT_EQ(3478, turn_configurations_[0].server.port()); |
| 1698 EXPECT_EQ("udp", turn_configurations_[0].transport_type); |
| 1699 turn_configurations_.clear(); |
| 1700 |
| 1701 // STUN defaults |
| 1702 EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1703 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1704 EXPECT_EQ(3478, stun_configurations_[0].server.port()); |
| 1705 stun_configurations_.clear(); |
| 1706 } |
| 1707 |
| 1708 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port |
| 1709 // can be parsed correctly. |
| 1710 TEST_F(IceServerParsingTest, ParseHostnameAndPort) { |
| 1711 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); |
| 1712 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1713 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); |
| 1714 EXPECT_EQ(1234, stun_configurations_[0].server.port()); |
| 1715 stun_configurations_.clear(); |
| 1716 |
| 1717 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); |
| 1718 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1719 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); |
| 1720 EXPECT_EQ(4321, stun_configurations_[0].server.port()); |
| 1721 stun_configurations_.clear(); |
| 1722 |
| 1723 EXPECT_TRUE(ParseUrl("stun:hostname:9999")); |
| 1724 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1725 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); |
| 1726 EXPECT_EQ(9999, stun_configurations_[0].server.port()); |
| 1727 stun_configurations_.clear(); |
| 1728 |
| 1729 EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); |
| 1730 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1731 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); |
| 1732 EXPECT_EQ(3478, stun_configurations_[0].server.port()); |
| 1733 stun_configurations_.clear(); |
| 1734 |
| 1735 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); |
| 1736 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1737 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); |
| 1738 EXPECT_EQ(3478, stun_configurations_[0].server.port()); |
| 1739 stun_configurations_.clear(); |
| 1740 |
| 1741 EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1742 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1743 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); |
| 1744 EXPECT_EQ(3478, stun_configurations_[0].server.port()); |
| 1745 stun_configurations_.clear(); |
| 1746 |
| 1747 // Try some invalid hostname:port strings. |
| 1748 EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); |
| 1749 EXPECT_FALSE(ParseUrl("stun:hostname:-1")); |
| 1750 EXPECT_FALSE(ParseUrl("stun:hostname:")); |
| 1751 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); |
| 1752 EXPECT_FALSE(ParseUrl("stun::5555")); |
| 1753 EXPECT_FALSE(ParseUrl("stun:")); |
| 1754 } |
| 1755 |
| 1756 // Test parsing the "?transport=xxx" part of the URL. |
| 1757 TEST_F(IceServerParsingTest, ParseTransport) { |
| 1758 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); |
| 1759 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1760 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); |
| 1761 turn_configurations_.clear(); |
| 1762 |
| 1763 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); |
| 1764 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1765 EXPECT_EQ("udp", turn_configurations_[0].transport_type); |
| 1766 turn_configurations_.clear(); |
| 1767 |
| 1768 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); |
| 1769 } |
| 1770 |
| 1771 // Test parsing ICE username contained in URL. |
| 1772 TEST_F(IceServerParsingTest, ParseUsername) { |
| 1773 EXPECT_TRUE(ParseUrl("turn:user@hostname")); |
| 1774 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1775 EXPECT_EQ("user", turn_configurations_[0].username); |
| 1776 turn_configurations_.clear(); |
| 1777 |
| 1778 EXPECT_FALSE(ParseUrl("turn:@hostname")); |
| 1779 EXPECT_FALSE(ParseUrl("turn:username@")); |
| 1780 EXPECT_FALSE(ParseUrl("turn:@")); |
| 1781 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); |
| 1782 } |
| 1783 |
| 1784 // Test that username and password from IceServer is copied into the resulting |
| 1785 // TurnConfiguration. |
| 1786 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { |
| 1787 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); |
| 1788 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1789 EXPECT_EQ("username", turn_configurations_[0].username); |
| 1790 EXPECT_EQ("password", turn_configurations_[0].password); |
| 1791 } |
| 1792 |
| 1793 // Ensure that if a server has multiple URLs, each one is parsed. |
| 1794 TEST_F(IceServerParsingTest, ParseMultipleUrls) { |
| 1795 PeerConnectionInterface::IceServers servers; |
| 1796 PeerConnectionInterface::IceServer server; |
| 1797 server.urls.push_back("stun:hostname"); |
| 1798 server.urls.push_back("turn:hostname"); |
| 1799 servers.push_back(server); |
| 1800 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, |
| 1801 &turn_configurations_)); |
| 1802 EXPECT_EQ(1U, stun_configurations_.size()); |
| 1803 EXPECT_EQ(1U, turn_configurations_.size()); |
| 1804 } |
| 1805 |
1629 #endif // if !defined(THREAD_SANITIZER) | 1806 #endif // if !defined(THREAD_SANITIZER) |
OLD | NEW |