Bug 1231975: Basic audio mochitests for NAT scenarios. r?drno draft
authorByron Campen [:bwc] <docfaraday@gmail.com>
Mon, 14 Mar 2016 13:31:01 -0500
changeset 340016 150bf6ab9fb7e22187a27d42840730163d8a932f
parent 340015 efee9a79c762607d36a0a990a6cac8dfee117ce1
child 516119 9c4be2378948fddc1e9903ea9bf0278f734e584a
push id12877
push userbcampen@mozilla.com
push dateMon, 14 Mar 2016 19:27:05 +0000
reviewersdrno
bugs1231975
milestone48.0a1
Bug 1231975: Basic audio mochitests for NAT scenarios. r?drno MozReview-Commit-ID: 1chfSrXeCL1
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/pc.js
dom/media/tests/mochitest/templates.js
dom/media/tests/mochitest/test_peerConnection_basicAudioNATRelay.html
dom/media/tests/mochitest/test_peerConnection_basicAudioNATRelayTCP.html
dom/media/tests/mochitest/test_peerConnection_basicAudioNATSrflx.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -68,16 +68,22 @@ skip-if = (toolkit == 'gonk' || buildapp
 [test_getUserMedia_stopVideoAudioStreamWithFollowupVideoAudio.html]
 [test_getUserMedia_stopVideoStream.html]
 [test_getUserMedia_stopVideoStreamWithFollowupVideo.html]
 [test_getUserMedia_peerIdentity.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g(Bug 1021776, too --ing slow on b2g)
 [test_peerConnection_addIceCandidate.html]
 [test_peerConnection_basicAudio.html]
 skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
+[test_peerConnection_basicAudioNATSrflx.html]
+skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
+[test_peerConnection_basicAudioNATRelay.html]
+skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
+[test_peerConnection_basicAudioNATRelayTCP.html]
+skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
 [test_peerConnection_basicAudioRequireEOC.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_basicAudioPcmaPcmuOnly.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_basicAudioDynamicPtMissingRtpmap.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_basicAudioVideo.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -1621,53 +1621,57 @@ PeerConnectionWrapper.prototype = {
 
   /**
    * Compares the Ice server configured for this PeerConnectionWrapper
    * with the ICE candidates received in the RTCP stats.
    *
    * @param {object} stats
    *        The stats to be verified for relayed vs. direct connection.
    */
-  checkStatsIceConnectionType : function(stats) {
+  checkStatsIceConnectionType : function(stats, expectedLocalCandidateType) {
     var lId;
     var rId;
     Object.keys(stats).forEach(name => {
       if ((stats[name].type === "candidatepair") &&
           (stats[name].selected)) {
         lId = stats[name].localCandidateId;
         rId = stats[name].remoteCandidateId;
       }
     });
     ok(typeof lId !== 'undefined', "Got local candidate ID " +
        JSON.stringify(lId) + " for selected pair");
     ok(typeof rId !== 'undefined', "Got remote candidate ID " +
        JSON.stringify(rId) + " for selected pair");
-    if ((typeof stats[lId] === 'undefined') ||
-        (typeof stats[rId] === 'undefined')) {
+    var lCand = stats[lId];
+    var rCand = stats[rId];
+    if ((typeof lCand === 'undefined') ||
+        (typeof rCand === 'undefined')) {
       ok(false, "failed to find candidatepair IDs or stats for local: " +
          JSON.stringify(lId) + " remote: " + JSON.stringify(rId));
       return;
     }
+
     info("checkStatsIceConnectionType verifying: local=" +
-         JSON.stringify(stats[lId]) + " remote=" + JSON.stringify(stats[rId]));
-    var lType = stats[lId].candidateType;
-    var rType = stats[rId].candidateType;
-    var lIp = stats[lId].ipAddress;
-    var rIp = stats[rId].ipAddress;
-    if ((this.configuration) && (typeof this.configuration.iceServers !== 'undefined')) {
-//      info("Ice Server configured");
-//      // Note: the IP comparising is a workaround for bug 1097333
-//      //       And this will fail if a TURN server address is a DNS name!
-//      var serverIp = this.configuration.iceServers[0].url.split(':')[1];
-//      ok((lType === "relayed" || rType === "relayed") ||
-//         (lIp === serverIp || rIp === serverIp), "One peer uses a relay");
-    } else {
-      info("P2P configured");
-      ok(((lType !== "relayed") && (rType !== "relayed")), "Pure peer to peer call without a relay");
+         JSON.stringify(lCand) + " remote=" + JSON.stringify(rCand));
+    expectedLocalCandidateType = expectedLocalCandidateType || "host";
+    var candidateType = lCand.candidateType;
+    if ((lCand.mozLocalTransport === "tcp") && (candidateType === "relayed")) {
+      candidateType = "relayed-tcp";
     }
+
+    if ((expectedLocalCandidateType === "serverreflexive") &&
+        (candidateType === "peerreflexive")) {
+      // Be forgiving of prflx when expecting srflx, since that can happen due
+      // to timing.
+      candidateType = "serverreflexive";
+    }
+
+    is(candidateType,
+       expectedLocalCandidateType,
+       "Local candidate type is what we expected for selected pair");
   },
 
   /**
    * Compares amount of established ICE connection according to ICE candidate
    * pairs in the stats reporting with the expected amount of connection based
    * on the constraints.
    *
    * @param {object} stats
--- a/dom/media/tests/mochitest/templates.js
+++ b/dom/media/tests/mochitest/templates.js
@@ -436,23 +436,25 @@ var commandsPeerConnectionOfferAnswer = 
   function PC_REMOTE_CHECK_STATS(test) {
     return test.pcRemote.getStats().then(stats => {
       test.pcRemote.checkStats(stats, test.testOptions.steeplechase);
     });
   },
 
   function PC_LOCAL_CHECK_ICE_CONNECTION_TYPE(test) {
     return test.pcLocal.getStats().then(stats => {
-      test.pcLocal.checkStatsIceConnectionType(stats);
+      test.pcLocal.checkStatsIceConnectionType(stats,
+          test.testOptions.expectedLocalCandidateType);
     });
   },
 
   function PC_REMOTE_CHECK_ICE_CONNECTION_TYPE(test) {
     return test.pcRemote.getStats().then(stats => {
-      test.pcRemote.checkStatsIceConnectionType(stats);
+      test.pcRemote.checkStatsIceConnectionType(stats,
+          test.testOptions.expectedRemoteCandidateType);
     });
   },
 
   function PC_LOCAL_CHECK_ICE_CONNECTIONS(test) {
     return test.pcLocal.getStats().then(stats => {
       test.pcLocal.checkStatsIceConnections(stats,
                                             test._offer_constraints,
                                             test._offer_options,
copy from dom/media/tests/mochitest/test_peerConnection_basicAudio.html
copy to dom/media/tests/mochitest/test_peerConnection_basicAudioNATRelay.html
--- a/dom/media/tests/mochitest/test_peerConnection_basicAudio.html
+++ b/dom/media/tests/mochitest/test_peerConnection_basicAudioNATRelay.html
@@ -2,22 +2,33 @@
 <html>
 <head>
   <script type="application/javascript" src="pc.js"></script>
 </head>
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
-    bug: "796892",
-    title: "Basic audio-only peer connection"
+    bug: "1231975",
+    title: "Basic audio-only peer connection with port dependent NAT"
   });
 
   var test;
-  runNetworkTest(function (options) {
-    test = new PeerConnectionTest(options);
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.run();
-  });
+  runNetworkTest( () => {
+    SpecialPowers.pushPrefEnv(
+      {
+        'set': [
+          ['media.peerconnection.nat_simulator.filtering_type', 'PORT_DEPENDENT'],
+          ['media.peerconnection.nat_simulator.mapping_type', 'PORT_DEPENDENT']
+        ]
+      }, function (options) {
+        options = options || {};
+        options.expectedLocalCandidateType = "relayed";
+        options.expectedRemoteCandidateType = "relayed";
+        test = new PeerConnectionTest(options);
+        test.setMediaConstraints([{audio: true}], [{audio: true}]);
+        test.run();
+      })
+  }, { useIceServer: true });
 </script>
 </pre>
 </body>
 </html>
copy from dom/media/tests/mochitest/test_peerConnection_basicAudio.html
copy to dom/media/tests/mochitest/test_peerConnection_basicAudioNATRelayTCP.html
--- a/dom/media/tests/mochitest/test_peerConnection_basicAudio.html
+++ b/dom/media/tests/mochitest/test_peerConnection_basicAudioNATRelayTCP.html
@@ -2,22 +2,34 @@
 <html>
 <head>
   <script type="application/javascript" src="pc.js"></script>
 </head>
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
-    bug: "796892",
-    title: "Basic audio-only peer connection"
+    bug: "1231975",
+    title: "Basic audio-only peer connection with port dependent NAT that blocks TCP"
   });
 
   var test;
-  runNetworkTest(function (options) {
-    test = new PeerConnectionTest(options);
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.run();
-  });
+  runNetworkTest( () => {
+    SpecialPowers.pushPrefEnv(
+      {
+        'set': [
+          ['media.peerconnection.nat_simulator.filtering_type', 'PORT_DEPENDENT'],
+          ['media.peerconnection.nat_simulator.mapping_type', 'PORT_DEPENDENT'],
+          ['media.peerconnection.nat_simulator.block_udp', true]
+        ]
+      }, function (options) {
+        options = options || {};
+        options.expectedLocalCandidateType = "relayed-tcp";
+        options.expectedRemoteCandidateType = "relayed-tcp";
+        test = new PeerConnectionTest(options);
+        test.setMediaConstraints([{audio: true}], [{audio: true}]);
+        test.run();
+      })
+  }, { useIceServer: true });
 </script>
 </pre>
 </body>
 </html>
copy from dom/media/tests/mochitest/test_peerConnection_basicAudio.html
copy to dom/media/tests/mochitest/test_peerConnection_basicAudioNATSrflx.html
--- a/dom/media/tests/mochitest/test_peerConnection_basicAudio.html
+++ b/dom/media/tests/mochitest/test_peerConnection_basicAudioNATSrflx.html
@@ -2,22 +2,33 @@
 <html>
 <head>
   <script type="application/javascript" src="pc.js"></script>
 </head>
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
-    bug: "796892",
-    title: "Basic audio-only peer connection"
+    bug: "1231975",
+    title: "Basic audio-only peer connection with endpoint independent NAT"
   });
 
   var test;
-  runNetworkTest(function (options) {
-    test = new PeerConnectionTest(options);
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.run();
-  });
+  runNetworkTest( () => {
+    SpecialPowers.pushPrefEnv(
+      {
+        'set': [
+          ['media.peerconnection.nat_simulator.filtering_type', 'ENDPOINT_INDEPENDENT'],
+          ['media.peerconnection.nat_simulator.mapping_type', 'ENDPOINT_INDEPENDENT']
+        ]
+      }, function (options) {
+        options = options || {};
+        options.expectedLocalCandidateType = "serverreflexive";
+        options.expectedRemoteCandidateType = "serverreflexive";
+        test = new PeerConnectionTest(options);
+        test.setMediaConstraints([{audio: true}], [{audio: true}]);
+        test.run();
+      })
+  }, { useIceServer: true });
 </script>
 </pre>
 </body>
 </html>