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")); | |
tommi
2015/09/16 21:51:01
Can you add ":", "", "stun:" too?
Taylor Brandstetter
2015/09/24 00:25:05
Done.
| |
1682 } | |
1683 | |
1684 TEST_F(IceServerParsingTest, VerifyDefaults) { | |
1685 // TURNS defaults | |
1686 EXPECT_TRUE(ParseUrl("turns:hostname")); | |
1687 EXPECT_EQ(1U, turn_configurations_.size()); | |
1688 EXPECT_EQ(5349, turn_configurations_[0].server.port()); | |
1689 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); | |
1690 turn_configurations_.clear(); | |
1691 | |
1692 // TURN defaults | |
1693 EXPECT_TRUE(ParseUrl("turn:hostname")); | |
1694 EXPECT_EQ(1U, turn_configurations_.size()); | |
1695 EXPECT_EQ(3478, turn_configurations_[0].server.port()); | |
1696 EXPECT_EQ("udp", turn_configurations_[0].transport_type); | |
1697 turn_configurations_.clear(); | |
1698 | |
1699 // STUN defaults | |
1700 EXPECT_TRUE(ParseUrl("stun:hostname")); | |
1701 EXPECT_EQ(1U, stun_configurations_.size()); | |
1702 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | |
1703 stun_configurations_.clear(); | |
1704 } | |
1705 | |
1706 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port | |
1707 // can be parsed correctly. | |
1708 TEST_F(IceServerParsingTest, ParseHostnameAndPort) { | |
1709 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); | |
1710 EXPECT_EQ(1U, stun_configurations_.size()); | |
1711 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); | |
1712 EXPECT_EQ(1234, stun_configurations_[0].server.port()); | |
1713 stun_configurations_.clear(); | |
1714 | |
1715 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); | |
1716 EXPECT_EQ(1U, stun_configurations_.size()); | |
1717 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); | |
1718 EXPECT_EQ(4321, stun_configurations_[0].server.port()); | |
1719 stun_configurations_.clear(); | |
1720 | |
1721 EXPECT_TRUE(ParseUrl("stun:hostname:9999")); | |
1722 EXPECT_EQ(1U, stun_configurations_.size()); | |
1723 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); | |
1724 EXPECT_EQ(9999, stun_configurations_[0].server.port()); | |
1725 stun_configurations_.clear(); | |
1726 | |
1727 EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); | |
1728 EXPECT_EQ(1U, stun_configurations_.size()); | |
1729 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); | |
1730 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | |
1731 stun_configurations_.clear(); | |
1732 | |
1733 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); | |
1734 EXPECT_EQ(1U, stun_configurations_.size()); | |
1735 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); | |
1736 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | |
1737 stun_configurations_.clear(); | |
1738 | |
1739 EXPECT_TRUE(ParseUrl("stun:hostname")); | |
1740 EXPECT_EQ(1U, stun_configurations_.size()); | |
1741 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); | |
1742 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | |
1743 stun_configurations_.clear(); | |
1744 | |
1745 // Try some invalid hostname:port strings. | |
1746 EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); | |
1747 EXPECT_FALSE(ParseUrl("stun:hostname:-1")); | |
1748 EXPECT_FALSE(ParseUrl("stun:hostname:")); | |
1749 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); | |
1750 EXPECT_FALSE(ParseUrl("stun::5555")); | |
1751 } | |
1752 | |
1753 // Test parsing the "?transport=xxx" part of the URL. | |
1754 TEST_F(IceServerParsingTest, ParseTransport) { | |
1755 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); | |
1756 EXPECT_EQ(1U, turn_configurations_.size()); | |
1757 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); | |
1758 turn_configurations_.clear(); | |
1759 | |
1760 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); | |
1761 EXPECT_EQ(1U, turn_configurations_.size()); | |
1762 EXPECT_EQ("udp", turn_configurations_[0].transport_type); | |
1763 turn_configurations_.clear(); | |
1764 | |
1765 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); | |
1766 } | |
1767 | |
1768 // Test parsing ICE username contained in URL. | |
1769 TEST_F(IceServerParsingTest, ParseUsername) { | |
1770 EXPECT_TRUE(ParseUrl("turn:user@hostname")); | |
1771 EXPECT_EQ(1U, turn_configurations_.size()); | |
1772 EXPECT_EQ("user", turn_configurations_[0].username); | |
1773 turn_configurations_.clear(); | |
1774 | |
1775 EXPECT_FALSE(ParseUrl("turn:@hostname")); | |
1776 EXPECT_FALSE(ParseUrl("turn:username@")); | |
1777 EXPECT_FALSE(ParseUrl("turn:@")); | |
1778 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); | |
1779 } | |
1780 | |
1781 // Test that username and password from IceServer is copied into the resulting | |
1782 // TurnConfiguration. | |
1783 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { | |
1784 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); | |
1785 EXPECT_EQ(1U, turn_configurations_.size()); | |
1786 EXPECT_EQ("username", turn_configurations_[0].username); | |
1787 EXPECT_EQ("password", turn_configurations_[0].password); | |
1788 } | |
1789 | |
1790 // Ensure that if a server has multiple URLs, each one is parsed. | |
1791 TEST_F(IceServerParsingTest, ParseMultipleUrls) { | |
1792 PeerConnectionInterface::IceServers servers; | |
1793 PeerConnectionInterface::IceServer server; | |
1794 server.urls.push_back("stun:hostname"); | |
1795 server.urls.push_back("turn:hostname"); | |
1796 servers.push_back(server); | |
1797 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, | |
1798 &turn_configurations_)); | |
1799 EXPECT_EQ(1U, stun_configurations_.size()); | |
1800 EXPECT_EQ(1U, turn_configurations_.size()); | |
1801 } | |
1802 | |
1629 #endif // if !defined(THREAD_SANITIZER) | 1803 #endif // if !defined(THREAD_SANITIZER) |
OLD | NEW |