Bug 1144432 - Part 4: Unbust signaling_unittests r=mt
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 18 Mar 2015 14:56:19 -0700
changeset 263632 47772f47152b103a4df0c1c4868c8e346a568d34
parent 263631 9efa1d056f16dbd258bab7464e41449fe7485469
child 263633 dd253f2a520b26c969ade2e6eefea21db40d4000
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmt
bugs1144432
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1144432 - Part 4: Unbust signaling_unittests r=mt
media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
media/webrtc/signaling/test/signaling_unittests.cpp
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
@@ -205,74 +205,96 @@ PeerConnectionMedia::PeerConnectionMedia
       mParentName(parent->GetName()),
       mAllowIceLoopback(false),
       mIceCtx(nullptr),
       mDNSResolver(new NrIceResolver()),
       mUuidGen(MakeUnique<PCUuidGenerator>()),
       mMainThread(mParent->GetMainThread()),
       mSTSThread(mParent->GetSTSThread()),
       mProxyResolveCompleted(false) {
+}
+
+nsresult PeerConnectionMedia::Init(const std::vector<NrIceStunServer>& stun_servers,
+                                   const std::vector<NrIceTurnServer>& turn_servers)
+{
   nsresult rv;
 
   nsCOMPtr<nsIProtocolProxyService> pps =
     do_GetService(NS_PROTOCOLPROXYSERVICE_CONTRACTID, &rv);
   if (NS_FAILED(rv)) {
     CSFLogError(logTag, "%s: Failed to get proxy service: %d", __FUNCTION__, (int)rv);
-    return;
+    return NS_ERROR_FAILURE;
   }
 
   // We use the following URL to find the "default" proxy address for all HTTPS
   // connections.  We will only attempt one HTTP(S) CONNECT per peer connection.
   // "example.com" is guaranteed to be unallocated and should return the best default.
   nsCOMPtr<nsIURI> fakeHttpsLocation;
   rv = NS_NewURI(getter_AddRefs(fakeHttpsLocation), "https://example.com");
   if (NS_FAILED(rv)) {
     CSFLogError(logTag, "%s: Failed to set URI: %d", __FUNCTION__, (int)rv);
-    return;
+    return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIChannel> channel;
-  nsCOMPtr<nsIDocument> doc = mParent->GetWindow()->GetExtantDoc();
+
+#ifdef MOZILLA_INTERNAL_API
+  nsCOMPtr<nsIDocument> principal = mParent->GetWindow()->GetExtantDoc();
+#else
+  // For unit-tests
+  nsCOMPtr<nsIScriptSecurityManager> secMan(
+      do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
+  if (NS_FAILED(rv)) {
+    CSFLogError(logTag, "%s: Failed to get IOService: %d",
+        __FUNCTION__, (int)rv);
+    CSFLogError(logTag, "%s: Failed to get securityManager: %d", __FUNCTION__, (int)rv);
+    return NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsIPrincipal> principal;
+  rv = secMan->GetSystemPrincipal(getter_AddRefs(principal));
+  if (NS_FAILED(rv)) {
+    CSFLogError(logTag, "%s: Failed to get systemPrincipal: %d", __FUNCTION__, (int)rv);
+    return NS_ERROR_FAILURE;
+  }
+#endif
+
   rv = NS_NewChannel(getter_AddRefs(channel),
                      fakeHttpsLocation,
-                     doc,
+                     principal,
                      nsILoadInfo::SEC_NORMAL,
                      nsIContentPolicy::TYPE_OTHER);
 
   if (NS_FAILED(rv)) {
     CSFLogError(logTag, "%s: Failed to get channel from URI: %d",
                 __FUNCTION__, (int)rv);
-    return;
+    return NS_ERROR_FAILURE;
   }
 
   nsRefPtr<ProtocolProxyQueryHandler> handler = new ProtocolProxyQueryHandler(this);
   rv = pps->AsyncResolve(channel,
                          nsIProtocolProxyService::RESOLVE_PREFER_HTTPS_PROXY |
                          nsIProtocolProxyService::RESOLVE_ALWAYS_TUNNEL,
                          handler, getter_AddRefs(mProxyRequest));
   if (NS_FAILED(rv)) {
     CSFLogError(logTag, "%s: Failed to resolve protocol proxy: %d", __FUNCTION__, (int)rv);
-    return;
+    return NS_ERROR_FAILURE;
   }
-}
 
-nsresult PeerConnectionMedia::Init(const std::vector<NrIceStunServer>& stun_servers,
-                                   const std::vector<NrIceTurnServer>& turn_servers)
-{
   // TODO(ekr@rtfm.com): need some way to set not offerer later
   // Looks like a bug in the NrIceCtx API.
   mIceCtx = NrIceCtx::Create("PC:" + mParentName,
                              true, // Offerer
                              true, // Trickle
                              mAllowIceLoopback);
   if(!mIceCtx) {
     CSFLogError(logTag, "%s: Failed to create Ice Context", __FUNCTION__);
     return NS_ERROR_FAILURE;
   }
-  nsresult rv;
+
   if (NS_FAILED(rv = mIceCtx->SetStunServers(stun_servers))) {
     CSFLogError(logTag, "%s: Failed to set stun servers", __FUNCTION__);
     return rv;
   }
   // Give us a way to globally turn off TURN support
 #ifdef MOZILLA_INTERNAL_API
   bool disabled = Preferences::GetBool("media.peerconnection.turn.disable", false);
 #else
--- a/media/webrtc/signaling/test/signaling_unittests.cpp
+++ b/media/webrtc/signaling/test/signaling_unittests.cpp
@@ -2308,24 +2308,16 @@ TEST_P(SignalingTest, OfferAnswerVideoIn
 {
   OfferOptions options;
   options.setInt32Option("OfferToReceiveAudio", 1);
   options.setInt32Option("OfferToReceiveVideo", 1);
   OfferAnswer(options, OFFER_AUDIO | ANSWER_AUDIO);
   CloseStreams();
 }
 
-TEST_P(SignalingTest, OfferAnswerBothInactive)
-{
-  OfferOptions options;
-  options.setInt32Option("OfferToReceiveAudio", 1);
-  options.setInt32Option("OfferToReceiveVideo", 1);
-  OfferAnswer(options, OFFER_NONE);
-}
-
 TEST_P(SignalingTest, CreateOfferAddCandidate)
 {
   OfferOptions options;
   CreateOfferAddCandidate(options, strSampleCandidate,
                           strSampleMid, nSamplelevel);
 }
 
 TEST_P(SignalingTest, AddIceCandidateEarly)