Bug 950317 - enable WebRTC mochitest on b2g emulator. r=jesup,vicamo,jsmith. a=fabrice
authorShih-Chiang Chien <schien@mozilla.com>
Fri, 10 Jan 2014 19:39:18 +0800
changeset 176022 cddd640cd774ddff09f82624cd69f88a39dfe4e9
parent 176021 4b8d14a78596e0b9a2c5eb7f28a1e756408c8536
child 176023 fc759d21bd14058c5fa61e1d2fe1b38c8a9b2087
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, vicamo, jsmith, fabrice
bugs950317
milestone28.0a2
Bug 950317 - enable WebRTC mochitest on b2g emulator. r=jesup,vicamo,jsmith. a=fabrice
dom/media/tests/mochitest/NetworkPreparationChromeScript.js
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/pc.js
dom/media/tests/mochitest/test_zmedia_cleanup.html
testing/mochitest/b2g-debug.json
testing/mochitest/b2g.json
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/NetworkPreparationChromeScript.js
@@ -0,0 +1,65 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
+const { Services } = Cu.import('resource://gre/modules/Services.jsm');
+
+var browser = Services.wm.getMostRecentWindow('navigator:browser');
+var connection = browser.navigator.mozMobileConnections[0];
+
+// provide a fake APN and enable data connection.
+function enableDataConnection() {
+  let setLock = browser.navigator.mozSettings.createLock();
+  setLock.set({
+    'ril.data.enabled': true,
+    'ril.data.apnSettings': [
+      [
+        {'carrier':'T-Mobile US',
+         'apn':'epc.tmobile.com',
+         'mmsc':'http://mms.msg.eng.t-mobile.com/mms/wapenc',
+         'types':['default','supl','mms']}
+      ]
+    ]
+  });
+}
+
+// enable 3G radio
+function enableRadio() {
+  if (connection.radioState !== 'enabled') {
+    connection.setRadioEnabled(true);
+  }
+}
+
+// disable 3G radio
+function disableRadio() {
+  if (connection.radioState === 'enabled') {
+    connection.setRadioEnabled(false);
+  }
+}
+
+addMessageListener('prepare-network', function(message) {
+  //RIL DOM events will be pending until RIL receiveing system-message-listener-ready event.
+  Services.obs.notifyObservers(null, 'system-message-listener-ready', null);
+
+  connection.addEventListener('datachange', function onDataChange() {
+    if (connection.data.connected) {
+      connection.removeEventListener('datachange', onDataChange);
+      Services.prefs.setIntPref('network.proxy.type', 2);
+      sendAsyncMessage('network-ready', true);
+    }
+  });
+
+  enableRadio();
+  enableDataConnection();
+});
+
+addMessageListener('network-cleanup', function(message) {
+  connection.addEventListener('datachange', function onDataChange() {
+    if (!connection.data.connected) {
+      connection.removeEventListener('datachange', onDataChange);
+      Services.prefs.setIntPref('network.proxy.type', 2);
+      sendAsyncMessage('network-disabled', true);
+    }
+  });
+  disableRadio();
+});
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 support-files =
   head.js
   mediaStreamPlayback.js
   pc.js
   templates.js
+  NetworkPreparationChromeScript.js
 
 [test_dataChannel_basicAudio.html]
 [test_dataChannel_basicAudioVideo.html]
 # Disabled on OS X for bug 930481 timeouts
 skip-if = os == 'mac'
 [test_dataChannel_basicAudioVideoCombined.html]
 # Disabled on OS X for bug 930481 timeouts
 skip-if = os == 'mac'
@@ -47,8 +48,10 @@ skip-if = os == 'mac'
 [test_peerConnection_setLocalAnswerInHaveLocalOffer.html]
 [test_peerConnection_setLocalAnswerInStable.html]
 [test_peerConnection_setLocalOfferInHaveRemoteOffer.html]
 [test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html]
 [test_peerConnection_setRemoteAnswerInStable.html]
 [test_peerConnection_setRemoteOfferInHaveLocalOffer.html]
 [test_peerConnection_throwInCallbacks.html]
 [test_peerConnection_toJSON.html]
+# Bug950317: Hack for making a cleanup hook after finishing all WebRTC cases
+[test_zmedia_cleanup.html]
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -318,16 +318,85 @@ MediaElementChecker.prototype = {
    * state of the media element is HAVE_METADATA.
    */
   checkForNoMediaFlow : function MEC_CheckForNoMediaFlow() {
     ok(this.element.readyState === HTMLMediaElement.HAVE_METADATA,
        'Media element has a ready state of HAVE_METADATA');
   }
 };
 
+/**
+ * Query function for determining if any IP address is available for
+ * generating SDP.
+ *
+ * @return false if required additional network setup.
+ */
+function isNetworkReady() {
+  // for gonk platform
+  if ("nsINetworkInterfaceListService" in SpecialPowers.Ci) {
+    var listService = SpecialPowers.Cc["@mozilla.org/network/interface-list-service;1"]
+                        .getService(SpecialPowers.Ci.nsINetworkInterfaceListService);
+    var itfList = listService.getDataInterfaceList(
+          SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_MMS_INTERFACES |
+          SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_SUPL_INTERFACES);
+    var num = itfList.getNumberOfInterface();
+    for (var i = 0; i < num; i++) {
+      if (itfList.getInterface(i).ip) {
+        info("Network interface is ready with address: " + itfList.getInterface(i).ip);
+        return true;
+      }
+    }
+    // ip address is not available
+    info("Network interface is not ready, required additional network setup");
+    return false;
+  }
+  info("Network setup is not required");
+  return true;
+}
+
+/**
+ * Network setup utils for Gonk
+ *
+ * @return {object} providing functions for setup/teardown data connection
+ */
+function getNetworkUtils() {
+  var url = SimpleTest.getTestFileURL("NetworkPreparationChromeScript.js");
+  var script = SpecialPowers.loadChromeScript(url);
+
+  var utils = {
+    /**
+     * Utility for setting up data connection.
+     *
+     * @param aCallback callback after data connection is ready.
+     */
+    prepareNetwork: function(aCallback) {
+      script.addMessageListener('network-ready', function (message) {
+        info("Network interface is ready");
+        aCallback();
+      });
+      info("Setup network interface");
+      script.sendAsyncMessage("prepare-network", true);
+    },
+    /**
+     * Utility for tearing down data connection.
+     *
+     * @param aCallback callback after data connection is closed.
+     */
+    tearDownNetwork: function(aCallback) {
+      script.addMessageListener('network-disabled', function (message) {
+        ok(true, 'network-disabled');
+        script.destroy();
+        aCallback();
+      });
+      script.sendAsyncMessage("network-cleanup", true);
+    }
+  };
+
+  return utils;
+}
 
 /**
  * This class handles tests for peer connections.
  *
  * @constructor
  * @param {object} [options={}]
  *        Optional options for the peer connection test
  * @param {object} [options.commands=commandsPeerConnection]
@@ -344,16 +413,37 @@ MediaElementChecker.prototype = {
  */
 function PeerConnectionTest(options) {
   // If no options are specified make it an empty object
   options = options || { };
   options.commands = options.commands || commandsPeerConnection;
   options.is_local = "is_local" in options ? options.is_local : true;
   options.is_remote = "is_remote" in options ? options.is_remote : true;
 
+  var netTeardownCommand = null;
+  if (!isNetworkReady()) {
+    var utils = getNetworkUtils();
+    // Trigger network setup to obtain IP address before creating any PeerConnection.
+    utils.prepareNetwork(function() {
+      ok(isNetworkReady(),'setup network connection successfully');
+    });
+
+    netTeardownCommand = [
+      [
+        'TEARDOWN_NETWORK',
+        function(test) {
+          utils.tearDownNetwork(function() {
+            info('teardown network connection');
+            test.next();
+          });
+        }
+      ]
+    ];
+  }
+
   if (options.is_local)
     this.pcLocal = new PeerConnectionWrapper('pcLocal', options.config_pc1);
   else
     this.pcLocal = null;
 
   if (options.is_remote)
     this.pcRemote = new PeerConnectionWrapper('pcRemote', options.config_pc2 || options.config_pc1);
   else
@@ -365,16 +455,21 @@ function PeerConnectionTest(options) {
   this.chain = new CommandChain(this, options.commands);
   if (!options.is_local) {
     this.chain.filterOut(/^PC_LOCAL/);
   }
   if (!options.is_remote) {
     this.chain.filterOut(/^PC_REMOTE/);
   }
 
+  // Insert network teardown after testcase execution.
+  if (netTeardownCommand) {
+    this.chain.append(netTeardownCommand);
+  }
+
   var self = this;
   this.chain.onFinished = function () {
     self.teardown();
   };
 }
 
 /**
  * Closes the peer connection if it is active
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_zmedia_cleanup.html
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+    <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  </head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+
+if ("nsINetworkInterfaceListService" in SpecialPowers.Ci) {
+  var url = SimpleTest.getTestFileURL("NetworkPreparationChromeScript.js");
+  var script = SpecialPowers.loadChromeScript(url);
+  script.addMessageListener('network-disabled', function (message) {
+    ok(true, 'network-disabled');
+    script.destroy();
+    SimpleTest.finish();
+  });
+  script.sendAsyncMessage("network-cleanup", true);
+} else {
+  ok(true, 'no need to cleanup network interface');
+  SimpleTest.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>
--- a/testing/mochitest/b2g-debug.json
+++ b/testing/mochitest/b2g-debug.json
@@ -290,43 +290,30 @@
     "dom/file/test/test_readonly_lockedfiles.html":"",
     "dom/file/test/test_success_events_after_abort.html":"",
     "dom/file/test/test_truncate.html":"",
     "dom/file/test/test_workers.html":"",
     "dom/file/test/test_write_read_data.html":"",
 
     "dom/imptests/editing/conformancetest/test_runtest.html":"takes too long",
 
-    "dom/media/tests/mochitest/test_dataChannel_basicAudio.html":"bug 908473",
-    "dom/media/tests/mochitest/test_dataChannel_basicAudioVideo.html":"",
-    "dom/media/tests/mochitest/test_dataChannel_basicAudioVideoCombined.html":"",
-    "dom/media/tests/mochitest/test_dataChannel_basicDataOnly.html":"",
-    "dom/media/tests/mochitest/test_dataChannel_basicVideo.html":"",
-    "dom/media/tests/mochitest/test_dataChannel_noOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_addCandidateInHaveLocalOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_basicAudio.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_basicVideo.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug822674.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug825703.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug827843.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug834153.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug835370.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_errorCallbacks.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideoAudio.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInHaveLocalOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInStable.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setLocalOfferInHaveRemoteOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"",
+    "dom/media/tests/mochitest/test_dataChannel_basicAudio.html":"Bug 962984, test fail on b2g debug build",
+    "dom/media/tests/mochitest/test_dataChannel_basicAudioVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_dataChannel_basicAudioVideoCombined.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_dataChannel_basicVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_basicAudio.html":"Bug 962984, test fail on b2g debug build",
+    "dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_basicVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_bug827843.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideoAudio.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/ipc/test_ipc.html":"nested ipc not working",
 
     "dom/network/tests/test_networkstats_basics.html":"Will be fixed in bug 858005",
     "dom/permission/tests/test_permission_basics.html":"https not working, bug 907770",
 
     "dom/tests/mochitest/bugs/test_bug335976.xhtml":"",
     "dom/tests/mochitest/bugs/test_bug369306.html":"test timed out, can't focus back from popup window to opener?",
     "dom/tests/mochitest/bugs/test_bug396843.html":"",
     "dom/tests/mochitest/bugs/test_bug406375.html":"",
--- a/testing/mochitest/b2g.json
+++ b/testing/mochitest/b2g.json
@@ -297,43 +297,27 @@
     "dom/file/test/test_readonly_lockedfiles.html":"",
     "dom/file/test/test_success_events_after_abort.html":"",
     "dom/file/test/test_truncate.html":"",
     "dom/file/test/test_workers.html":"",
     "dom/file/test/test_write_read_data.html":"",
 
     "dom/imptests/editing/conformancetest/test_runtest.html":"takes too long",
 
-    "dom/media/tests/mochitest/test_dataChannel_basicAudio.html":"bug 908473",
-    "dom/media/tests/mochitest/test_dataChannel_basicAudioVideo.html":"",
-    "dom/media/tests/mochitest/test_dataChannel_basicAudioVideoCombined.html":"",
-    "dom/media/tests/mochitest/test_dataChannel_basicDataOnly.html":"",
-    "dom/media/tests/mochitest/test_dataChannel_basicVideo.html":"",
-    "dom/media/tests/mochitest/test_dataChannel_noOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_addCandidateInHaveLocalOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_basicAudio.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_basicVideo.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug822674.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug825703.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug827843.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug834153.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_bug835370.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_errorCallbacks.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideoAudio.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInHaveLocalOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInStable.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setLocalOfferInHaveRemoteOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html":"",
-    "dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"",
+    "dom/media/tests/mochitest/test_dataChannel_basicAudioVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_dataChannel_basicAudioVideoCombined.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_dataChannel_basicVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_basicVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_bug827843.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideoAudio.html":"Bug 960442, video support for WebRTC is disabled on b2g",
+    "dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"Bug 960442, video support for WebRTC is disabled on b2g",
     "dom/media/tests/ipc/test_ipc.html":"nested ipc not working",
 
     "dom/network/tests/test_networkstats_basics.html":"Will be fixed in bug 858005",
     "dom/permission/tests/test_permission_basics.html":"https not working, bug 907770",
 
     "dom/tests/mochitest/bugs/test_bug335976.xhtml":"",
     "dom/tests/mochitest/bugs/test_bug369306.html":"test timed out, can't focus back from popup window to opener?",
     "dom/tests/mochitest/bugs/test_bug396843.html":"",