Bug 1190574 - make test.chain.replace and cohorts throw on unknown test name + fix broken tests draft
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 03 Aug 2015 17:07:06 -0400
changeset 306550 8c850071a79df67a30e0aa1a8d038f5f69fe6c36
parent 306504 6077f51254c69a1e14e1b61acba4af451bf1783e
child 306551 926a19c8c719542ba80f4e389bba37f23377d74b
child 306629 bbfea50981cf9abe3537e15e4039dd92fffb6375
child 306630 e94878460681a84037f34d51f9c06fc410e47b0b
child 307022 4fabf45cf80aab300a09807c40674d5004ebc370
push id7157
push userjbruaroey@mozilla.com
push dateWed, 04 Nov 2015 21:23:55 +0000
bugs1190574
milestone45.0a1
Bug 1190574 - make test.chain.replace and cohorts throw on unknown test name + fix broken tests
dom/media/tests/mochitest/head.js
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_peerConnection_forwarding_basicAudioVideoCombined.html
dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
dom/media/tests/mochitest/test_peerConnection_syncSetDescription.html
dom/media/tests/mochitest/test_selftest.html
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -548,16 +548,24 @@ CommandChain.prototype = {
       if (index !== -1) {
         index += start;
       }
       return index;
     }
     return this.commands.indexOf(functionOrName, start);
   },
 
+  mustHaveIndexOf: function(functionOrName, start) {
+    var index = this.indexOf(functionOrName, start);
+    if (index == -1) {
+      throw new Error("Unknown test: " + functionOrName);
+    }
+    return index;
+  },
+
   /**
    * Inserts the new commands after the specified command.
    */
   insertAfter: function(functionOrName, commands, all, start) {
     this._insertHelper(functionOrName, commands, 1, all, start);
   },
 
   /**
@@ -570,17 +578,17 @@ CommandChain.prototype = {
   /**
    * Inserts the new commands before the specified command.
    */
   insertBefore: function(functionOrName, commands, all, start) {
     this._insertHelper(functionOrName, commands, 0, all, start);
   },
 
   _insertHelper: function(functionOrName, commands, delta, all, start) {
-    var index = this.indexOf(functionOrName);
+    var index = this.mustHaveIndexOf(functionOrName);
     start = start || 0;
     for (; index !== -1; index = this.indexOf(functionOrName, index)) {
       if (!start) {
         this.commands = [].concat(
           this.commands.slice(0, index + delta),
           commands,
           this.commands.slice(index + delta));
         if (!all) {
@@ -592,43 +600,31 @@ CommandChain.prototype = {
       index += (commands.length + 1);
     }
   },
 
   /**
    * Removes the specified command, returns what was removed.
    */
   remove: function(functionOrName) {
-    var index = this.indexOf(functionOrName);
-    if (index >= 0) {
-      return this.commands.splice(index, 1);
-    }
-    return [];
+    return this.commands.splice(this.mustHaveIndexOf(functionOrName), 1);
   },
 
   /**
    * Removes all commands after the specified one, returns what was removed.
    */
   removeAfter: function(functionOrName, start) {
-    var index = this.indexOf(functionOrName, start);
-    if (index >= 0) {
-      return this.commands.splice(index + 1);
-    }
-    return [];
+    return this.commands.splice(this.mustHaveIndexOf(functionOrName, start) + 1);
   },
 
   /**
    * Removes all commands before the specified one, returns what was removed.
    */
   removeBefore: function(functionOrName) {
-    var index = this.indexOf(functionOrName);
-    if (index >= 0) {
-      return this.commands.splice(0, index);
-    }
-    return [];
+    return this.commands.splice(0, this.mustHaveIndexOf(functionOrName));
   },
 
   /**
    * Replaces a single command, returns what was removed.
    */
   replace: function(functionOrName, commands) {
     this.insertBefore(functionOrName, commands);
     return this.remove(functionOrName);
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -207,11 +207,12 @@ skip-if = toolkit == 'gonk' || buildapp 
 [test_peerConnection_localRollback.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_localReofferRollback.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_remoteRollback.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g (Bug 1059867), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_remoteReofferRollback.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
+[test_selftest.html]
 
 # Bug 950317: Hack for making a cleanup hook after finishing all WebRTC cases
 [test_zmedia_cleanup.html]
--- a/dom/media/tests/mochitest/test_peerConnection_forwarding_basicAudioVideoCombined.html
+++ b/dom/media/tests/mochitest/test_peerConnection_forwarding_basicAudioVideoCombined.html
@@ -24,17 +24,17 @@ runNetworkTest(function() {
     function PC_FORWARDING_CAPTUREVIDEO(test) {
       var streams = gumTest.pcRemote._pc.getRemoteStreams();
       is(streams.length, 1, "One stream to forward");
       is(streams[0].getTracks().length, 2, "Forwarded stream has 2 tracks");
       forwardingTest.pcLocal.attachMedia(streams[0], 'audiovideo', 'local');
       return Promise.resolve();
     }
   ]);
-  gumTest.chain.removeAfter("PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT");
+  gumTest.chain.removeAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW");
   gumTest.chain.execute()
     .then(() => forwardingTest.chain.execute())
     .then(() => gumTest.close())
     .then(() => forwardingTest.close())
     .then(() => networkTestFinished());
 });
 </script>
 </pre>
--- a/dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
+++ b/dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
@@ -54,17 +54,17 @@
                         "replacing with different kind should fail"));
       });
   }
 
   runNetworkTest(function () {
     test = new PeerConnectionTest();
     test.audioCtx = new AudioContext();
     test.setMediaConstraints([{video: true, audio: true}], [{video: true}]);
-    test.chain.removeAfter("PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT");
+    test.chain.removeAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW");
 
     // Test replaceTrack on pcRemote separately since it's video only.
     test.chain.append([
       function PC_REMOTE_VIDEOONLY_REPLACE_VIDEOTRACK(test) {
         return replacetest(test.pcRemote);
       },
       function PC_LOCAL_NEW_VIDEOTRACK_WAIT_FOR_MEDIA_FLOW(test) {
         return test.pcLocal.waitForMediaFlow();
--- a/dom/media/tests/mochitest/test_peerConnection_syncSetDescription.html
+++ b/dom/media/tests/mochitest/test_peerConnection_syncSetDescription.html
@@ -28,25 +28,20 @@ function PC_REMOTE_SET_LOCAL_DESCRIPTION
   test.pcRemote._pc.setLocalDescription(test.originalAnswer);
 }
 function PC_LOCAL_SET_REMOTE_DESCRIPTION_SYNC(test) {
   test.pcLocal.onsignalingstatechange = function() {};
   test.pcLocal._pc.setRemoteDescription(test._remote_answer);
 }
 
 runNetworkTest(() => {
-  var replace = (test, name, command) => {
-    test.chain.insertAfter(name, command);
-    test.chain.remove(name);
-  }
-
   var test = new PeerConnectionTest();
   test.setMediaConstraints([{video: true}], [{video: true}]);
-  test.chain.replace(test, "PC_LOCAL_SET_LOCAL_DESCRIPTION", PC_LOCAL_SET_LOCAL_DESCRIPTION_SYNC);
-  test.chain.replace(test, "PC_REMOTE_SET_REMOTE_DESCRIPTION", PC_REMOTE_SET_REMOTE_DESCRIPTION_SYNC);
-  test.chain.replace(test, "PC_REMOTE_SET_LOCAL_DESCRIPTION", PC_REMOTE_SET_LOCAL_DESCRIPTION_SYNC);
-  test.chain.replace(test, "PC_LOCAL_SET_REMOTE_DESCRIPTION", PC_LOCAL_SET_REMOTE_DESCRIPTION_SYNC);
+  test.chain.replace("PC_LOCAL_SET_LOCAL_DESCRIPTION", PC_LOCAL_SET_LOCAL_DESCRIPTION_SYNC);
+  test.chain.replace("PC_REMOTE_SET_REMOTE_DESCRIPTION", PC_REMOTE_SET_REMOTE_DESCRIPTION_SYNC);
+  test.chain.replace("PC_REMOTE_SET_LOCAL_DESCRIPTION", PC_REMOTE_SET_LOCAL_DESCRIPTION_SYNC);
+  test.chain.replace("PC_LOCAL_SET_REMOTE_DESCRIPTION", PC_LOCAL_SET_REMOTE_DESCRIPTION_SYNC);
   test.run();
 });
 </script>
 </pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_selftest.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript;version=1.8">
+  createHTML({
+    title: "Self-test of harness functions",
+    visible: true
+  });
+
+function TEST(test) {}
+
+var catcher = func => {
+  try {
+    func();
+    return null;
+  } catch (e) {
+    return e.message;
+  }
+};
+
+runNetworkTest(() => {
+  var test = new PeerConnectionTest();
+  test.setMediaConstraints([{video: true}], [{video: true}]);
+  is(catcher(() => test.chain.replace("PC_LOCAL_SET_LOCAL_DESCRIPTION", TEST)),
+     null, "test.chain.replace works");
+  is(catcher(() => test.chain.replace("FOO", TEST)),
+     "Unknown test: FOO", "test.chain.replace catches typos");
+});
+
+</script>
+</pre>
+</body>
+</html>