webrtc_m130/webrtc/api/jsepsessiondescription_unittest.cc
tommi 6f59a4fc4f Revert of Remove candidates when doing continual gathering (patchset #15 id:560001 of https://codereview.webrtc.org/1648813004/ )
Reason for revert:
Breaks the build.  Suggest we reland with a default implementation of the new method, update Chrome, land a change that changes |{}| -> |= 0;|

Here's the error:

FAILED: /b/build/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/content/renderer/media/webrtc/test_support_content.mock_peer_connection_dependency_factory.o.d -DV8_DEPRECATION_WARNINGS -DCLD_VERSION=2 -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0 -DCHROMIUM_BUILD -DCR_CLANG_REVISION=262839-1 -DUSE_LIBJPEG_TURBO=1 -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 -DUSE_PROPRIETARY_CODECS -DENABLE_PEPPER_CDMS -DENABLE_CONFIGURATION_POLICY -DENABLE_NOTIFICATIONS -DENABLE_TOPCHROME_MD=1 -DDCHECK_ALWAYS_ON=1 -DFIELDTRIAL_TESTING_ENABLED -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 -DENABLE_PDF=1 -DENABLE_PLUGIN_INSTALLATION=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 -DENABLE_AUTOFILL_DIALOG=1 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 -DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 -DUSE_BROWSER_SPELLCHECKER=1 -DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SETTINGS_APP=1 -DENABLE_SUPERVISED_USERS=1 -DENABLE_SERVICE_DISCOVERY=1 -DV8_USE_EXTERNAL_STARTUP_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DMOJO_USE_SYSTEM_IMPL -DGTEST_HAS_POSIX_RE=0 -DGTEST_LANG_CXX11=0 -DSK_SUPPORT_GPU=1 -DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS -DUNIT_TEST -DGTEST_HAS_RTTI=0 -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DU_STATIC_IMPLEMENTATION -DPROTOBUF_USE_DLLS -DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -DCHROME_PNG_WRITE_SUPPORT -DPNG_USER_CONFIG -DFEATURE_ENABLE_SSL -DFEATURE_ENABLE_VOICEMAIL -DEXPAT_RELATIVE_PATH -DGTEST_RELATIVE_PATH -DNO_MAIN_THREAD_WRAPPING -DNO_SOUND_SYSTEM -DOSX -DWEBRTC_MAC -DWEBRTC_POSIX -DXML_STATIC -DWEBRTC_CHROMIUM_BUILD -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -D_FORTIFY_SOURCE=2 -Igen -I../.. -I../../third_party/khronos -I../../gpu -I../../skia/config -Igen/angle -I../../third_party/WebKit/Source -I../../third_party/skia/include/core -I../../third_party/skia/include/effects -I../../third_party/skia/include/pdf -I../../third_party/skia/include/gpu -I../../third_party/skia/include/lazy -I../../third_party/skia/include/pathops -I../../third_party/skia/include/pipe -I../../third_party/skia/include/ports -I../../third_party/skia/include/utils -I../../third_party/skia/include/utils/mac -I../../skia/ext -I../../testing/gmock/include -I../../testing/gtest/include -I../../third_party/icu/source/i18n -I../../third_party/icu/source/common -Igen/ui/resources -Igen/protoc_out -I../../third_party/protobuf -I../../third_party/protobuf/src -I../../third_party/WebKit -I../../ipc -I../../third_party/opus/src/include -I../../third_party/WebKit -I../../third_party/npapi -I../../third_party/npapi/bindings -I../../third_party/libpng -I../../third_party/zlib -I../../third_party/libwebp -I../../third_party/ots/include -I../../third_party/qcms/src -I../../third_party/iccjpeg -I../../third_party/libjpeg_turbo -I../../v8/include -I../../third_party/webrtc_overrides -I../../third_party/libjingle/overrides -I../../third_party/libjingle/source -I../../third_party -I../../third_party/expat/files/lib -I../../third_party/libvpx/source/libvpx -isysroot /Applications/Xcode5.1.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -O2 -gdwarf-2 -fvisibility=hidden -Werror -mmacosx-version-min=10.6 -arch x86_64 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-selector-type-mismatch -Wpartial-availability -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-deprecated-register -Wno-inconsistent-missing-override -Wno-shift-negative-value -std=c++11 -stdlib=libc++ -fno-rtti -fno-exceptions -fvisibility-inlines-hidden -fno-threadsafe-statics -Xclang -load -Xclang /b/build/slave/Mac_Builder/build/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.dylib -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -Xclang -plugin-arg-find-bad-constructs -Xclang follow-macro-expansion -fcolor-diagnostics -fno-strict-aliasing  -c ../../content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc -o obj/content/renderer/media/webrtc/test_support_content.mock_peer_connection_dependency_factory.o
../../content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc:404:14: error: allocating an object of abstract class type 'content::MockSessionDescription'
  return new MockSessionDescription(type, sdp);
             ^
../../third_party/webrtc/api/jsep.h💯18: note: unimplemented pure virtual method 'RemoveCandidates' in 'MockSessionDescription'
  virtual size_t RemoveCandidates(
                 ^
1 error generated.
ninja: build stopped: subcommand failed.

Original issue's description:
> When doing candidate re-gathering in the same generation, Remove the existing local candidate on the same network
> and signaling the remote side to remove its remote candidate by setting the candidate priority to 0.
>
> BUG=
>
> Committed: https://crrev.com/84430da6817ce69c53bfad088be5c9df8b420f01
> Cr-Commit-Position: refs/heads/master@{#11958}

TBR=pthatcher@webrtc.org,deadbeef@webrtc.org,glaznev@webrtc.org,honghaiz@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review URL: https://codereview.webrtc.org/1785613011

Cr-Commit-Position: refs/heads/master@{#11960}
2016-03-11 22:05:15 +00:00

222 lines
9.0 KiB
C++

/*
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <string>
#include "webrtc/api/jsepicecandidate.h"
#include "webrtc/api/jsepsessiondescription.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/helpers.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/base/ssladapter.h"
#include "webrtc/base/stringencode.h"
#include "webrtc/p2p/base/candidate.h"
#include "webrtc/p2p/base/p2pconstants.h"
#include "webrtc/p2p/base/sessiondescription.h"
#include "webrtc/pc/mediasession.h"
using webrtc::IceCandidateCollection;
using webrtc::IceCandidateInterface;
using webrtc::JsepIceCandidate;
using webrtc::JsepSessionDescription;
using webrtc::SessionDescriptionInterface;
using rtc::scoped_ptr;
static const char kCandidateUfrag[] = "ufrag";
static const char kCandidatePwd[] = "pwd";
static const char kCandidateUfragVoice[] = "ufrag_voice";
static const char kCandidatePwdVoice[] = "pwd_voice";
static const char kCandidateUfragVideo[] = "ufrag_video";
static const char kCandidatePwdVideo[] = "pwd_video";
// This creates a session description with both audio and video media contents.
// In SDP this is described by two m lines, one audio and one video.
static cricket::SessionDescription* CreateCricketSessionDescription() {
cricket::SessionDescription* desc(new cricket::SessionDescription());
// AudioContentDescription
scoped_ptr<cricket::AudioContentDescription> audio(
new cricket::AudioContentDescription());
// VideoContentDescription
scoped_ptr<cricket::VideoContentDescription> video(
new cricket::VideoContentDescription());
audio->AddCodec(cricket::AudioCodec(103, "ISAC", 16000, 0, 0, 0));
desc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
audio.release());
video->AddCodec(cricket::VideoCodec(120, "VP8", 640, 480, 30, 0));
desc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
video.release());
EXPECT_TRUE(desc->AddTransportInfo(cricket::TransportInfo(
cricket::CN_AUDIO,
cricket::TransportDescription(
std::vector<std::string>(), kCandidateUfragVoice, kCandidatePwdVoice,
cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, NULL))));
EXPECT_TRUE(desc->AddTransportInfo(cricket::TransportInfo(
cricket::CN_VIDEO,
cricket::TransportDescription(
std::vector<std::string>(), kCandidateUfragVideo, kCandidatePwdVideo,
cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, NULL))));
return desc;
}
class JsepSessionDescriptionTest : public testing::Test {
protected:
virtual void SetUp() {
int port = 1234;
rtc::SocketAddress address("127.0.0.1", port++);
cricket::Candidate candidate(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
address, 1, "", "", "local", 0, "1");
candidate_ = candidate;
const std::string session_id =
rtc::ToString(rtc::CreateRandomId64());
const std::string session_version =
rtc::ToString(rtc::CreateRandomId());
jsep_desc_.reset(new JsepSessionDescription("dummy"));
ASSERT_TRUE(jsep_desc_->Initialize(CreateCricketSessionDescription(),
session_id, session_version));
}
std::string Serialize(const SessionDescriptionInterface* desc) {
std::string sdp;
EXPECT_TRUE(desc->ToString(&sdp));
EXPECT_FALSE(sdp.empty());
return sdp;
}
SessionDescriptionInterface* DeSerialize(const std::string& sdp) {
JsepSessionDescription* desc(new JsepSessionDescription("dummy"));
EXPECT_TRUE(desc->Initialize(sdp, NULL));
return desc;
}
cricket::Candidate candidate_;
rtc::scoped_ptr<JsepSessionDescription> jsep_desc_;
};
// Test that number_of_mediasections() returns the number of media contents in
// a session description.
TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) {
EXPECT_EQ(2u, jsep_desc_->number_of_mediasections());
}
// Test that we can add a candidate to a session description.
TEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) {
JsepIceCandidate jsep_candidate("", 0, candidate_);
EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0);
ASSERT_TRUE(ice_candidates != NULL);
EXPECT_EQ(1u, ice_candidates->count());
const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
ASSERT_TRUE(ice_candidate != NULL);
candidate_.set_username(kCandidateUfragVoice);
candidate_.set_password(kCandidatePwdVoice);
EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
EXPECT_EQ(0, ice_candidate->sdp_mline_index());
EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
}
TEST_F(JsepSessionDescriptionTest, AddCandidateWithMid) {
// mid and m-line index don't match, in this case mid is preferred.
JsepIceCandidate jsep_candidate("video", 0, candidate_);
EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
EXPECT_EQ(0u, jsep_desc_->candidates(0)->count());
const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(1);
ASSERT_TRUE(ice_candidates != NULL);
EXPECT_EQ(1u, ice_candidates->count());
const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
ASSERT_TRUE(ice_candidate != NULL);
candidate_.set_username(kCandidateUfragVideo);
candidate_.set_password(kCandidatePwdVideo);
EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
// The mline index should have been updated according to mid.
EXPECT_EQ(1, ice_candidate->sdp_mline_index());
}
TEST_F(JsepSessionDescriptionTest, AddCandidateAlreadyHasUfrag) {
candidate_.set_username(kCandidateUfrag);
candidate_.set_password(kCandidatePwd);
JsepIceCandidate jsep_candidate("audio", 0, candidate_);
EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0);
ASSERT_TRUE(ice_candidates != NULL);
EXPECT_EQ(1u, ice_candidates->count());
const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
ASSERT_TRUE(ice_candidate != NULL);
candidate_.set_username(kCandidateUfrag);
candidate_.set_password(kCandidatePwd);
EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
}
// Test that we can not add a candidate if there is no corresponding media
// content in the session description.
TEST_F(JsepSessionDescriptionTest, AddBadCandidate) {
JsepIceCandidate bad_candidate1("", 55, candidate_);
EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate1));
JsepIceCandidate bad_candidate2("some weird mid", 0, candidate_);
EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate2));
}
// Tests that repeatedly adding the same candidate, with or without credentials,
// does not increase the number of candidates in the description.
TEST_F(JsepSessionDescriptionTest, AddCandidateDuplicates) {
JsepIceCandidate jsep_candidate("", 0, candidate_);
EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
// Add the same candidate again. It should be ignored.
EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
// Create a new candidate, identical except that the ufrag and pwd are now
// populated.
candidate_.set_username(kCandidateUfragVoice);
candidate_.set_password(kCandidatePwdVoice);
JsepIceCandidate jsep_candidate_with_credentials("", 0, candidate_);
// This should also be identified as redundant and ignored.
EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate_with_credentials));
EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
}
// Test that we can serialize a JsepSessionDescription and deserialize it again.
TEST_F(JsepSessionDescriptionTest, SerializeDeserialize) {
std::string sdp = Serialize(jsep_desc_.get());
scoped_ptr<SessionDescriptionInterface> parsed_jsep_desc(DeSerialize(sdp));
EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections());
std::string parsed_sdp = Serialize(parsed_jsep_desc.get());
EXPECT_EQ(sdp, parsed_sdp);
}
// Tests that we can serialize and deserialize a JsepSesssionDescription
// with candidates.
TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) {
std::string sdp = Serialize(jsep_desc_.get());
// Add a candidate and check that the serialized result is different.
JsepIceCandidate jsep_candidate("audio", 0, candidate_);
EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
std::string sdp_with_candidate = Serialize(jsep_desc_.get());
EXPECT_NE(sdp, sdp_with_candidate);
scoped_ptr<SessionDescriptionInterface> parsed_jsep_desc(
DeSerialize(sdp_with_candidate));
std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get());
EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate);
}