2012-10-03 00:04:58 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
// Original author: ekr@rtfm.com
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "sigslot.h"
|
|
|
|
|
|
|
|
#include "nspr.h"
|
|
|
|
#include "nss.h"
|
|
|
|
#include "ssl.h"
|
|
|
|
|
2013-01-05 23:40:34 +04:00
|
|
|
#include "mozilla/Scoped.h"
|
2012-10-03 00:04:58 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsXPCOM.h"
|
|
|
|
|
|
|
|
#include "logging.h"
|
|
|
|
#include "nricectx.h"
|
|
|
|
#include "nricemediastream.h"
|
2013-02-21 20:52:30 +04:00
|
|
|
#include "nriceresolverfake.h"
|
2012-10-03 00:04:58 +04:00
|
|
|
#include "mtransport_test_utils.h"
|
|
|
|
#include "runnable_utils.h"
|
|
|
|
|
|
|
|
#define GTEST_HAS_RTTI 0
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "gtest_utils.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-10-31 19:31:47 +04:00
|
|
|
MtransportTestUtils *test_utils;
|
2012-10-03 00:04:58 +04:00
|
|
|
|
|
|
|
bool stream_added = false;
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
const std::string kDefaultStunServerAddress((char *)"23.21.150.121");
|
2013-03-08 20:41:27 +04:00
|
|
|
const std::string kDefaultStunServerHostname((char *)"stun-server.invalid");
|
2013-02-21 20:52:30 +04:00
|
|
|
const std::string kBogusStunServerHostname((char *)"stun-server-nonexistent.invalid");
|
|
|
|
const uint16_t kDefaultStunServerPort=3478;
|
|
|
|
|
2012-10-03 00:04:58 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum TrickleMode { TRICKLE_NONE, TRICKLE_DEFERRED };
|
|
|
|
|
|
|
|
class IceTestPeer : public sigslot::has_slots<> {
|
|
|
|
public:
|
|
|
|
|
|
|
|
IceTestPeer(const std::string& name, bool offerer, bool set_priorities) :
|
|
|
|
name_(name),
|
|
|
|
ice_ctx_(NrIceCtx::Create(name, offerer, set_priorities)),
|
|
|
|
streams_(),
|
|
|
|
candidates_(),
|
|
|
|
gathering_complete_(false),
|
|
|
|
ready_ct_(0),
|
|
|
|
ice_complete_(false),
|
|
|
|
received_(0),
|
2012-12-20 20:12:45 +04:00
|
|
|
sent_(0),
|
2013-02-21 20:52:30 +04:00
|
|
|
fake_resolver_(),
|
2012-12-20 20:12:45 +04:00
|
|
|
remote_(nullptr) {
|
2012-10-03 00:04:58 +04:00
|
|
|
ice_ctx_->SignalGatheringCompleted.connect(this,
|
2013-03-08 20:41:27 +04:00
|
|
|
&IceTestPeer::GatheringComplete);
|
2012-10-03 00:04:58 +04:00
|
|
|
ice_ctx_->SignalCompleted.connect(this, &IceTestPeer::IceCompleted);
|
|
|
|
}
|
|
|
|
|
2013-02-16 06:33:31 +04:00
|
|
|
~IceTestPeer() {
|
|
|
|
test_utils->sts_target()->Dispatch(WrapRunnable(this,
|
|
|
|
&IceTestPeer::Shutdown),
|
|
|
|
NS_DISPATCH_SYNC);
|
2013-02-21 20:52:30 +04:00
|
|
|
|
|
|
|
// Give the ICE destruction callback time to fire before
|
|
|
|
// we destroy the resolver.
|
|
|
|
PR_Sleep(1000);
|
2013-02-16 06:33:31 +04:00
|
|
|
}
|
|
|
|
|
2012-10-03 00:04:58 +04:00
|
|
|
void AddStream(int components) {
|
|
|
|
char name[100];
|
|
|
|
snprintf(name, sizeof(name), "%s:stream%d", name_.c_str(), (int)streams_.size());
|
|
|
|
|
|
|
|
mozilla::RefPtr<NrIceMediaStream> stream =
|
|
|
|
ice_ctx_->CreateStream(static_cast<char *>(name), components);
|
|
|
|
|
|
|
|
ASSERT_TRUE(stream);
|
|
|
|
streams_.push_back(stream);
|
|
|
|
stream->SignalCandidate.connect(this, &IceTestPeer::GotCandidate);
|
|
|
|
stream->SignalReady.connect(this, &IceTestPeer::StreamReady);
|
|
|
|
stream->SignalPacketReceived.connect(this, &IceTestPeer::PacketReceived);
|
|
|
|
}
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
void SetStunServer(const std::string addr, uint16_t port) {
|
2013-01-05 23:40:34 +04:00
|
|
|
std::vector<NrIceStunServer> stun_servers;
|
2013-02-21 20:52:30 +04:00
|
|
|
ScopedDeletePtr<NrIceStunServer> server(NrIceStunServer::Create(addr,
|
|
|
|
port));
|
2013-01-05 23:40:34 +04:00
|
|
|
stun_servers.push_back(*server);
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(ice_ctx_->SetStunServers(stun_servers)));
|
2013-02-21 20:52:30 +04:00
|
|
|
}
|
|
|
|
|
2013-03-08 20:41:27 +04:00
|
|
|
void AddAddressToResolver(const std::string hostname,
|
|
|
|
const std::string address) {
|
2013-02-21 20:52:30 +04:00
|
|
|
PRNetAddr addr;
|
2013-03-08 20:41:27 +04:00
|
|
|
PRStatus status = PR_StringToNetAddr(address.c_str(), &addr);
|
2013-02-21 20:52:30 +04:00
|
|
|
ASSERT_EQ(PR_SUCCESS, status);
|
2013-03-08 20:41:27 +04:00
|
|
|
|
|
|
|
fake_resolver_.SetAddr(hostname, addr);
|
2013-02-21 20:52:30 +04:00
|
|
|
}
|
|
|
|
|
2013-03-08 20:41:27 +04:00
|
|
|
void SetResolver() {
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(ice_ctx_->SetResolver(
|
|
|
|
fake_resolver_.AllocateResolver())));
|
2013-02-21 20:52:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gather() {
|
|
|
|
nsresult res;
|
2013-01-05 23:40:34 +04:00
|
|
|
|
2012-10-31 19:31:47 +04:00
|
|
|
test_utils->sts_target()->Dispatch(
|
2012-10-03 00:04:58 +04:00
|
|
|
WrapRunnableRet(ice_ctx_, &NrIceCtx::StartGathering, &res),
|
|
|
|
NS_DISPATCH_SYNC);
|
|
|
|
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get various pieces of state
|
|
|
|
std::vector<std::string> GetGlobalAttributes() {
|
|
|
|
return ice_ctx_->GetGlobalAttributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string>& GetCandidates(const std::string &name) {
|
|
|
|
return candidates_[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gathering_complete() { return gathering_complete_; }
|
|
|
|
int ready_ct() { return ready_ct_; }
|
2012-12-20 20:12:45 +04:00
|
|
|
bool is_ready(size_t stream) {
|
|
|
|
return streams_[stream]->state() == NrIceMediaStream::ICE_OPEN;
|
|
|
|
}
|
2012-10-03 00:04:58 +04:00
|
|
|
bool ice_complete() { return ice_complete_; }
|
|
|
|
size_t received() { return received_; }
|
|
|
|
size_t sent() { return sent_; }
|
|
|
|
|
|
|
|
// Start connecting to another peer
|
2012-11-20 18:12:52 +04:00
|
|
|
void Connect(IceTestPeer *remote, TrickleMode trickle_mode, bool start = true) {
|
2012-10-03 00:04:58 +04:00
|
|
|
nsresult res;
|
|
|
|
|
2012-12-20 20:12:45 +04:00
|
|
|
remote_ = remote;
|
|
|
|
|
2012-10-31 19:31:47 +04:00
|
|
|
test_utils->sts_target()->Dispatch(
|
2012-10-03 00:04:58 +04:00
|
|
|
WrapRunnableRet(ice_ctx_,
|
|
|
|
&NrIceCtx::ParseGlobalAttributes, remote->GetGlobalAttributes(), &res),
|
|
|
|
NS_DISPATCH_SYNC);
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(res));
|
|
|
|
|
|
|
|
if (trickle_mode == TRICKLE_NONE) {
|
|
|
|
for (size_t i=0; i<streams_.size(); ++i) {
|
2012-10-31 19:31:47 +04:00
|
|
|
test_utils->sts_target()->Dispatch(
|
2012-10-03 00:04:58 +04:00
|
|
|
WrapRunnableRet(streams_[i], &NrIceMediaStream::ParseAttributes,
|
|
|
|
remote->GetCandidates(remote->streams_[i]->name()),
|
|
|
|
&res), NS_DISPATCH_SYNC);
|
|
|
|
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(res));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Parse empty attributes and then trickle them out later
|
|
|
|
for (size_t i=0; i<streams_.size(); ++i) {
|
|
|
|
std::vector<std::string> empty_attrs;
|
2012-10-31 19:31:47 +04:00
|
|
|
test_utils->sts_target()->Dispatch(
|
2012-10-03 00:04:58 +04:00
|
|
|
WrapRunnableRet(streams_[i], &NrIceMediaStream::ParseAttributes,
|
|
|
|
empty_attrs,
|
|
|
|
&res), NS_DISPATCH_SYNC);
|
|
|
|
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(res));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:12:52 +04:00
|
|
|
if (start) {
|
|
|
|
// Now start checks
|
|
|
|
test_utils->sts_target()->Dispatch(
|
2012-10-03 00:04:58 +04:00
|
|
|
WrapRunnableRet(ice_ctx_, &NrIceCtx::StartChecks, &res),
|
|
|
|
NS_DISPATCH_SYNC);
|
2012-11-20 18:12:52 +04:00
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(res));
|
|
|
|
}
|
2012-12-20 20:12:45 +04:00
|
|
|
}
|
2012-10-03 00:04:58 +04:00
|
|
|
|
2012-12-20 20:12:45 +04:00
|
|
|
void DoTrickle(size_t stream) {
|
|
|
|
std::cerr << "Doing trickle for stream " << stream << std::endl;
|
|
|
|
// If we are in trickle deferred mode, now trickle in the candidates
|
|
|
|
// for |stream}
|
|
|
|
nsresult res;
|
2012-10-03 00:04:58 +04:00
|
|
|
|
2012-12-20 20:12:45 +04:00
|
|
|
ASSERT_GT(remote_->streams_.size(), stream);
|
2012-10-03 00:04:58 +04:00
|
|
|
|
2012-12-20 20:12:45 +04:00
|
|
|
std::vector<std::string> candidates =
|
|
|
|
remote_->GetCandidates(remote_->streams_[stream]->name());
|
|
|
|
|
|
|
|
for (size_t j=0; j<candidates.size(); j++) {
|
|
|
|
test_utils->sts_target()->Dispatch(
|
|
|
|
WrapRunnableRet(streams_[stream],
|
|
|
|
&NrIceMediaStream::ParseTrickleCandidate,
|
|
|
|
candidates[j],
|
|
|
|
&res), NS_DISPATCH_SYNC);
|
|
|
|
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(res));
|
2012-10-03 00:04:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:12:52 +04:00
|
|
|
void Close() {
|
2013-02-16 06:33:31 +04:00
|
|
|
test_utils->sts_target()->Dispatch(
|
|
|
|
WrapRunnable(ice_ctx_, &NrIceCtx::destroy_peer_ctx),
|
|
|
|
NS_DISPATCH_SYNC);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown() {
|
|
|
|
ice_ctx_ = nullptr;
|
2012-11-20 18:12:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void StartChecks() {
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
// Now start checks
|
|
|
|
test_utils->sts_target()->Dispatch(
|
|
|
|
WrapRunnableRet(ice_ctx_, &NrIceCtx::StartChecks, &res),
|
|
|
|
NS_DISPATCH_SYNC);
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(res));
|
|
|
|
}
|
|
|
|
|
2012-10-03 00:04:58 +04:00
|
|
|
// Handle events
|
|
|
|
void GatheringComplete(NrIceCtx *ctx) {
|
|
|
|
gathering_complete_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GotCandidate(NrIceMediaStream *stream, const std::string &candidate) {
|
|
|
|
std::cout << "Got candidate " << candidate << std::endl;
|
|
|
|
candidates_[stream->name()].push_back(candidate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StreamReady(NrIceMediaStream *stream) {
|
|
|
|
std::cout << "Stream ready " << stream->name() << std::endl;
|
|
|
|
++ready_ct_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IceCompleted(NrIceCtx *ctx) {
|
|
|
|
std::cout << "ICE completed " << name_ << std::endl;
|
|
|
|
ice_complete_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PacketReceived(NrIceMediaStream *stream, int component, const unsigned char *data,
|
|
|
|
int len) {
|
|
|
|
std::cerr << "Received " << len << " bytes" << std::endl;
|
|
|
|
++received_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendPacket(int stream, int component, const unsigned char *data,
|
|
|
|
int len) {
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(streams_[stream]->SendPacket(component, data, len)));
|
|
|
|
|
|
|
|
++sent_;
|
|
|
|
std::cerr << "Sent " << len << " bytes" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string name_;
|
|
|
|
nsRefPtr<NrIceCtx> ice_ctx_;
|
|
|
|
std::vector<mozilla::RefPtr<NrIceMediaStream> > streams_;
|
|
|
|
std::map<std::string, std::vector<std::string> > candidates_;
|
|
|
|
bool gathering_complete_;
|
|
|
|
int ready_ct_;
|
|
|
|
bool ice_complete_;
|
|
|
|
size_t received_;
|
|
|
|
size_t sent_;
|
2013-02-21 20:52:30 +04:00
|
|
|
NrIceResolverFake fake_resolver_;
|
2012-12-20 20:12:45 +04:00
|
|
|
IceTestPeer *remote_;
|
2012-10-03 00:04:58 +04:00
|
|
|
};
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
class IceGatherTest : public ::testing::Test {
|
2012-10-03 00:04:58 +04:00
|
|
|
public:
|
2013-02-21 20:52:30 +04:00
|
|
|
void SetUp() {
|
|
|
|
peer_ = new IceTestPeer("P1", true, false);
|
|
|
|
peer_->AddStream(1);
|
2013-03-08 20:41:27 +04:00
|
|
|
peer_->AddAddressToResolver(kDefaultStunServerHostname,
|
|
|
|
kDefaultStunServerAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetResolver() {
|
|
|
|
peer_->SetResolver();
|
2013-02-21 20:52:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gather() {
|
|
|
|
peer_->Gather();
|
|
|
|
|
|
|
|
ASSERT_TRUE_WAIT(peer_->gathering_complete(), 10000);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
mozilla::ScopedDeletePtr<IceTestPeer> peer_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IceConnectTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
IceConnectTest() : initted_(false) {}
|
2012-10-03 00:04:58 +04:00
|
|
|
|
|
|
|
void SetUp() {
|
|
|
|
nsresult rv;
|
|
|
|
target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddStream(const std::string& name, int components) {
|
|
|
|
Init(false);
|
|
|
|
p1_->AddStream(components);
|
|
|
|
p2_->AddStream(components);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(bool set_priorities) {
|
|
|
|
if (!initted_) {
|
|
|
|
p1_ = new IceTestPeer("P1", true, set_priorities);
|
|
|
|
p2_ = new IceTestPeer("P2", false, set_priorities);
|
|
|
|
}
|
|
|
|
initted_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gather(bool wait) {
|
|
|
|
Init(false);
|
2013-02-21 20:52:30 +04:00
|
|
|
p1_->SetStunServer(kDefaultStunServerAddress, kDefaultStunServerPort);
|
|
|
|
p2_->SetStunServer(kDefaultStunServerAddress, kDefaultStunServerPort);
|
2012-10-03 00:04:58 +04:00
|
|
|
p1_->Gather();
|
|
|
|
p2_->Gather();
|
|
|
|
|
|
|
|
EXPECT_TRUE_WAIT(p1_->gathering_complete(), 10000);
|
|
|
|
if (!p1_->gathering_complete())
|
|
|
|
return false;
|
|
|
|
EXPECT_TRUE_WAIT(p2_->gathering_complete(), 10000);
|
|
|
|
if (!p2_->gathering_complete())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-20 20:12:45 +04:00
|
|
|
void Connect() {
|
|
|
|
p1_->Connect(p2_, TRICKLE_NONE);
|
|
|
|
p2_->Connect(p1_, TRICKLE_NONE);
|
2012-10-03 00:04:58 +04:00
|
|
|
|
|
|
|
ASSERT_TRUE_WAIT(p1_->ready_ct() == 1 && p2_->ready_ct() == 1, 5000);
|
|
|
|
ASSERT_TRUE_WAIT(p1_->ice_complete() && p2_->ice_complete(), 5000);
|
|
|
|
}
|
|
|
|
|
2012-12-20 20:12:45 +04:00
|
|
|
void ConnectTrickle() {
|
|
|
|
p1_->Connect(p2_, TRICKLE_DEFERRED);
|
|
|
|
p2_->Connect(p1_, TRICKLE_DEFERRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoTrickle(size_t stream) {
|
|
|
|
p1_->DoTrickle(stream);
|
|
|
|
p2_->DoTrickle(stream);
|
|
|
|
ASSERT_TRUE_WAIT(p1_->is_ready(stream), 5000);
|
|
|
|
ASSERT_TRUE_WAIT(p2_->is_ready(stream), 5000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyConnected() {
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:12:52 +04:00
|
|
|
void CloseP1() {
|
|
|
|
p1_->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectThenDelete() {
|
|
|
|
p1_->Connect(p2_, TRICKLE_NONE, true);
|
|
|
|
p2_->Connect(p1_, TRICKLE_NONE, false);
|
2012-12-20 20:12:45 +04:00
|
|
|
test_utils->sts_target()->Dispatch(WrapRunnable(this,
|
2013-02-21 20:52:30 +04:00
|
|
|
&IceConnectTest::CloseP1),
|
2012-11-20 18:12:52 +04:00
|
|
|
NS_DISPATCH_SYNC);
|
|
|
|
p2_->StartChecks();
|
|
|
|
|
|
|
|
// Wait to see if we crash
|
|
|
|
PR_Sleep(PR_MillisecondsToInterval(5000));
|
|
|
|
}
|
|
|
|
|
2012-10-03 00:04:58 +04:00
|
|
|
void SendReceive() {
|
|
|
|
// p1_->Send(2);
|
2013-02-16 06:33:31 +04:00
|
|
|
test_utils->sts_target()->Dispatch(
|
|
|
|
WrapRunnable(p1_.get(),
|
|
|
|
&IceTestPeer::SendPacket, 0, 1,
|
|
|
|
reinterpret_cast<const unsigned char *>("TEST"), 4),
|
|
|
|
NS_DISPATCH_SYNC);
|
2013-01-30 19:31:55 +04:00
|
|
|
ASSERT_EQ(1u, p1_->sent());
|
2012-10-03 00:04:58 +04:00
|
|
|
ASSERT_TRUE_WAIT(p2_->received() == 1, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool initted_;
|
|
|
|
nsCOMPtr<nsIEventTarget> target_;
|
|
|
|
mozilla::ScopedDeletePtr<IceTestPeer> p1_;
|
|
|
|
mozilla::ScopedDeletePtr<IceTestPeer> p2_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
|
2013-03-08 20:41:27 +04:00
|
|
|
TEST_F(IceGatherTest, TestGatherStunServerIpAddress) {
|
2013-02-21 20:52:30 +04:00
|
|
|
peer_->SetStunServer(kDefaultStunServerAddress, kDefaultStunServerPort);
|
2013-03-08 20:41:27 +04:00
|
|
|
peer_->SetResolver();
|
2013-02-21 20:52:30 +04:00
|
|
|
Gather();
|
|
|
|
}
|
|
|
|
|
2013-03-08 20:41:27 +04:00
|
|
|
TEST_F(IceGatherTest, TestGatherStunServerHostname) {
|
2013-02-21 20:52:30 +04:00
|
|
|
peer_->SetStunServer(kDefaultStunServerHostname, kDefaultStunServerPort);
|
2013-03-08 20:41:27 +04:00
|
|
|
peer_->SetResolver();
|
2013-02-21 20:52:30 +04:00
|
|
|
Gather();
|
|
|
|
}
|
|
|
|
|
2013-03-08 20:41:27 +04:00
|
|
|
TEST_F(IceGatherTest, TestGatherStunBogusHostname) {
|
2013-02-21 20:52:30 +04:00
|
|
|
peer_->SetStunServer(kBogusStunServerHostname, kDefaultStunServerPort);
|
2013-03-08 20:41:27 +04:00
|
|
|
peer_->SetResolver();
|
2013-02-21 20:52:30 +04:00
|
|
|
Gather();
|
|
|
|
}
|
|
|
|
|
2013-03-08 20:41:27 +04:00
|
|
|
TEST_F(IceGatherTest, TestGatherStunServerHostnameNoResolver) {
|
2013-02-21 20:52:30 +04:00
|
|
|
peer_->SetStunServer(kDefaultStunServerHostname, kDefaultStunServerPort);
|
|
|
|
Gather();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(IceConnectTest, TestGather) {
|
2012-10-03 00:04:58 +04:00
|
|
|
AddStream("first", 1);
|
|
|
|
ASSERT_TRUE(Gather(true));
|
|
|
|
}
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
TEST_F(IceConnectTest, TestGatherAutoPrioritize) {
|
2012-10-03 00:04:58 +04:00
|
|
|
Init(false);
|
|
|
|
AddStream("first", 1);
|
|
|
|
ASSERT_TRUE(Gather(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
TEST_F(IceConnectTest, TestConnect) {
|
2012-10-03 00:04:58 +04:00
|
|
|
AddStream("first", 1);
|
|
|
|
ASSERT_TRUE(Gather(true));
|
|
|
|
Connect();
|
|
|
|
}
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
TEST_F(IceConnectTest, TestConnectAutoPrioritize) {
|
2012-10-03 00:04:58 +04:00
|
|
|
Init(false);
|
|
|
|
AddStream("first", 1);
|
|
|
|
ASSERT_TRUE(Gather(true));
|
|
|
|
Connect();
|
|
|
|
}
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
TEST_F(IceConnectTest, TestConnectTrickleOneStreamOneComponent) {
|
2012-10-03 00:04:58 +04:00
|
|
|
AddStream("first", 1);
|
|
|
|
ASSERT_TRUE(Gather(true));
|
2012-12-20 20:12:45 +04:00
|
|
|
ConnectTrickle();
|
|
|
|
DoTrickle(0);
|
|
|
|
ASSERT_TRUE_WAIT(p1_->ice_complete(), 1000);
|
|
|
|
ASSERT_TRUE_WAIT(p2_->ice_complete(), 1000);
|
2012-10-03 00:04:58 +04:00
|
|
|
}
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
TEST_F(IceConnectTest, TestConnectTrickleTwoStreamsOneComponent) {
|
2012-12-20 20:12:45 +04:00
|
|
|
AddStream("first", 1);
|
|
|
|
AddStream("second", 1);
|
|
|
|
ASSERT_TRUE(Gather(true));
|
|
|
|
ConnectTrickle();
|
|
|
|
DoTrickle(0);
|
|
|
|
DoTrickle(1);
|
|
|
|
ASSERT_TRUE_WAIT(p1_->ice_complete(), 1000);
|
|
|
|
ASSERT_TRUE_WAIT(p2_->ice_complete(), 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
TEST_F(IceConnectTest, TestSendReceive) {
|
2012-10-03 00:04:58 +04:00
|
|
|
AddStream("first", 1);
|
|
|
|
ASSERT_TRUE(Gather(true));
|
|
|
|
Connect();
|
|
|
|
SendReceive();
|
|
|
|
}
|
|
|
|
|
2013-02-21 20:52:30 +04:00
|
|
|
TEST_F(IceConnectTest, TestConnectShutdownOneSide) {
|
2012-11-20 18:12:52 +04:00
|
|
|
AddStream("first", 1);
|
|
|
|
ASSERT_TRUE(Gather(true));
|
|
|
|
ConnectThenDelete();
|
|
|
|
}
|
|
|
|
|
2012-10-03 00:04:58 +04:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-11-26 21:47:18 +04:00
|
|
|
#ifdef LINUX
|
|
|
|
// This test can cause intermittent oranges on the builders on Linux
|
|
|
|
CHECK_ENVIRONMENT_FLAG("MOZ_WEBRTC_TESTS")
|
|
|
|
#endif
|
|
|
|
|
2012-10-31 19:31:47 +04:00
|
|
|
test_utils = new MtransportTestUtils();
|
2012-10-03 00:04:58 +04:00
|
|
|
NSS_NoDB_Init(nullptr);
|
|
|
|
NSS_SetDomesticPolicy();
|
|
|
|
|
|
|
|
// Start the tests
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
2012-10-31 19:31:47 +04:00
|
|
|
int rv = RUN_ALL_TESTS();
|
|
|
|
delete test_utils;
|
|
|
|
return rv;
|
2012-10-03 00:04:58 +04:00
|
|
|
}
|