Bug 916187. Part 2. Using the test stun server, write some tests to exercise the checking logic written in 908740. r=abr

This commit is contained in:
Byron Campen [:bwc] 2013-09-18 12:36:13 -07:00
parent baa0c1e9c7
commit 18a2f387e5
2 changed files with 47 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include <algorithm>
#include <mozilla/Scoped.h>
#include <m_cpp_utils.h>
#include <nsISupportsImpl.h>
namespace mozilla {

View File

@ -602,6 +602,28 @@ class IceGatherTest : public ::testing::Test {
ASSERT_TRUE_WAIT(peer_->gathering_complete(), 10000);
}
void UseFakeStunServerWithResponse(const std::string& fake_addr,
uint16_t fake_port) {
TestStunServer::GetInstance()->SetResponseAddr(fake_addr, fake_port);
// Sets an additional stun server
peer_->SetStunServer(TestStunServer::GetInstance()->addr(),
TestStunServer::GetInstance()->port());
}
// NB: Only does substring matching, watch out for stuff like "1.2.3.4"
// matching "21.2.3.47". " 1.2.3.4 " should not have false positives.
bool StreamHasMatchingCandidate(unsigned int stream,
const std::string& match) {
std::vector<std::string> candidates = peer_->GetCandidates(stream);
for (size_t c = 0; c < candidates.size(); ++c) {
if (std::string::npos != candidates[c].find(match)) {
return true;
}
}
return false;
}
protected:
mozilla::ScopedDeletePtr<IceTestPeer> peer_;
};
@ -876,6 +898,30 @@ TEST_F(IceGatherTest, TestBogusCandidate) {
peer_->ParseCandidate(0, kBogusIceCandidate);
}
TEST_F(IceGatherTest, VerifyTestStunServer) {
UseFakeStunServerWithResponse("192.0.2.133", 3333);
Gather();
ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.2.133 3333 "));
}
TEST_F(IceGatherTest, TestStunServerReturnsWildcardAddr) {
UseFakeStunServerWithResponse("0.0.0.0", 3333);
Gather();
ASSERT_FALSE(StreamHasMatchingCandidate(0, " 0.0.0.0 "));
}
TEST_F(IceGatherTest, TestStunServerReturnsPort0) {
UseFakeStunServerWithResponse("192.0.2.133", 0);
Gather();
ASSERT_FALSE(StreamHasMatchingCandidate(0, " 192.0.2.133 0 "));
}
TEST_F(IceGatherTest, TestStunServerReturnsLoopbackAddr) {
UseFakeStunServerWithResponse("127.0.0.133", 3333);
Gather();
ASSERT_FALSE(StreamHasMatchingCandidate(0, " 127.0.0.133 "));
}
TEST_F(IceConnectTest, TestGather) {
AddStream("first", 1);
ASSERT_TRUE(Gather(true));