Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / app / webrtc / jsepsessiondescription_unittest.cc
index e2b59fb..55eb3d5 100644 (file)
@@ -32,6 +32,7 @@
 #include "talk/base/gunit.h"
 #include "talk/base/helpers.h"
 #include "talk/base/scoped_ptr.h"
+#include "talk/base/ssladapter.h"
 #include "talk/base/stringencode.h"
 #include "talk/p2p/base/candidate.h"
 #include "talk/p2p/base/constants.h"
@@ -96,6 +97,14 @@ static cricket::SessionDescription* CreateCricketSessionDescription() {
 
 class JsepSessionDescriptionTest : public testing::Test {
  protected:
+  static void SetUpTestCase() {
+    talk_base::InitializeSSL();
+  }
+
+  static void TearDownTestCase() {
+    talk_base::CleanupSSL();
+  }
+
   virtual void SetUp() {
     int port = 1234;
     talk_base::SocketAddress address("127.0.0.1", port++);
@@ -195,6 +204,28 @@ TEST_F(JsepSessionDescriptionTest, AddBadCandidate) {
   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());