Bug 919412 - Wait emulator cmd finished in tear down stage. r=hsinyi, a=test-only
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Wed, 02 Oct 2013 14:27:52 +0800
changeset 160916 cc371f7026a8d5a7ec1018c3ea1dcc6138616a09
parent 160915 d7a44a73156be4eee33355010d1278be25616e5f
child 160917 7c006c6b7dd7c63eca004e8268b9a3d3e2d48d68
child 161184 35161097095b1dbc80109e7d4196b5a2449b0f73
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi, test-only
bugs919412
milestone26.0a2
Bug 919412 - Wait emulator cmd finished in tear down stage. r=hsinyi, a=test-only
dom/telephony/test/marionette/head.js
dom/telephony/test/marionette/test_conference.js
dom/telephony/test/marionette/test_crash_emulator.js
dom/telephony/test/marionette/test_emergency.js
dom/telephony/test/marionette/test_emergency_badNumber.js
dom/telephony/test/marionette/test_emergency_label.js
dom/telephony/test/marionette/test_incoming_already_connected.js
dom/telephony/test/marionette/test_incoming_already_held.js
dom/telephony/test/marionette/test_incoming_answer_hangup.js
dom/telephony/test/marionette/test_incoming_answer_hangup_oncallschanged.js
dom/telephony/test/marionette/test_incoming_answer_remote_hangup.js
dom/telephony/test/marionette/test_incoming_connecting_hangup.js
dom/telephony/test/marionette/test_incoming_connecting_remote_hangup.js
dom/telephony/test/marionette/test_incoming_hangup_held.js
dom/telephony/test/marionette/test_incoming_hold_resume.js
dom/telephony/test/marionette/test_incoming_onstatechange.js
dom/telephony/test/marionette/test_incoming_reject.js
dom/telephony/test/marionette/test_incoming_remote_cancel.js
dom/telephony/test/marionette/test_incoming_remote_hangup_held.js
dom/telephony/test/marionette/test_multiple_hold.js
dom/telephony/test/marionette/test_outgoing_already_held.js
dom/telephony/test/marionette/test_outgoing_answer_hangup.js
dom/telephony/test/marionette/test_outgoing_answer_hangup_oncallschanged.js
dom/telephony/test/marionette/test_outgoing_answer_local_hangup.js
dom/telephony/test/marionette/test_outgoing_badNumber.js
dom/telephony/test/marionette/test_outgoing_busy.js
dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js
dom/telephony/test/marionette/test_outgoing_hangup_alerting.js
dom/telephony/test/marionette/test_outgoing_hangup_held.js
dom/telephony/test/marionette/test_outgoing_hold_resume.js
dom/telephony/test/marionette/test_outgoing_onstatechange.js
dom/telephony/test/marionette/test_outgoing_radio_off.js
dom/telephony/test/marionette/test_outgoing_reject.js
dom/telephony/test/marionette/test_outgoing_remote_hangup_held.js
dom/telephony/test/marionette/test_redundant_operations.js
dom/telephony/test/marionette/test_swap_held_and_active.js
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/head.js
@@ -0,0 +1,67 @@
+/* Any copyright is dedicated to the Public Domain.
+http://creativecommons.org/publicdomain/zero/1.0/ */
+
+let Promise = SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise;
+
+/**
+ * Emulator helper.
+ */
+let emulator = (function() {
+  let pendingCmdCount = 0;
+  let originalRunEmulatorCmd = runEmulatorCmd;
+
+  // Overwritten it so people could not call this function directly.
+  runEmulatorCmd = function() {
+    throw "Use emulator.run(cmd, callback) instead of runEmulatorCmd";
+  };
+
+  function run(cmd, callback) {
+    pendingCmdCount++;
+    originalRunEmulatorCmd(cmd, function(result) {
+      pendingCmdCount--;
+      if (callback && typeof callback === "function") {
+        callback(result);
+      }
+    });
+  }
+
+  /**
+   * @return Promise
+   */
+  function waitFinish() {
+    let deferred = Promise.defer();
+
+    waitFor(function() {
+      deferred.resolve();
+    }, function() {
+      return pendingCmdCount === 0;
+    });
+
+    return deferred.promise;
+  }
+
+  return {
+    run: run,
+    waitFinish: waitFinish
+  };
+}());
+
+function startTest(test) {
+  // Extend finish() with tear down.
+  finish = (function() {
+    let originalFinish = finish;
+
+    function tearDown() {
+      log('== Test TearDown ==');
+      emulator.waitFinish()
+        .then(function() {
+          originalFinish.apply(this, arguments);
+        });
+    }
+
+    return tearDown.bind(this);
+  }());
+
+  // Start the test.
+  test();
+}
--- a/dom/telephony/test/marionette/test_conference.js
+++ b/dom/telephony/test/marionette/test_conference.js
@@ -1,43 +1,33 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let conference = telephony.conferenceGroup;
 let outNumber = "5555551111";
 let inNumber = "5555552222";
 let inNumber2 = "5555553333";
 let outgoingCall;
 let incomingCall;
 let incomingCall2;
 let gotOriginalConnected = false;
 
-let pendingEmulatorCmdCount = 0;
-function sendCmdToEmulator(cmd, callback) {
-  ++pendingEmulatorCmdCount;
-  runEmulatorCmd(cmd, function(result) {
-    --pendingEmulatorCmdCount;
-    if (callback) {
-      callback(result);
-    }
-  });
-}
-
 // Make sure there's no pending event before we jump to the next case.
 function receivedPending(received, pending, nextTest) {
   let index = pending.indexOf(received);
   if (index != -1) {
     pending.splice(index, 1);
   }
-  if (pending.length == 0) {
+  if (pending.length === 0) {
     nextTest();
   }
 }
 
 function checkState(telephonyActive, telephonyCalls, conferenceState,
                     conferenceCalls) {
   is(telephony.active, telephonyActive);
 
@@ -53,26 +43,26 @@ function checkState(telephonyActive, tel
   }
 }
 
 function verifyInitialState() {
   log("Verifying initial state.");
   ok(telephony);
   ok(conference);
 
-  sendCmdToEmulator("gsm clear", function(result) {
+  emulator.run("gsm clear", function(result) {
     log("Clear up calls from a previous test if any.");
     is(result[0], "OK");
 
     // No more calls in the list; give time for emulator to catch up.
     waitFor(function next() {
       checkState(null, [], '', []);
       dial();
     }, function isDone() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
   });
 }
 
 function dial() {
   log("Making an outgoing call.");
   outgoingCall = telephony.dial(outNumber);
   ok(outgoingCall);
@@ -84,17 +74,17 @@ function dial() {
   outgoingCall.onalerting = function(event) {
     log("Received 'onalerting' call event.");
 
     outgoingCall.onalerting = null;
 
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : ringing");
       is(result[1], "OK");
 
       answer();
     });
   };
 }
@@ -107,32 +97,32 @@ function answer() {
     log("Received 'connected' call event for the original outgoing call.");
 
     outgoingCall.onconnected = null;
 
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
     is(outgoingCall, telephony.active);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "OK");
 
       if(!gotOriginalConnected){
         gotOriginalConnected = true;
         simulateIncoming();
       } else {
         // Received connected event for original call multiple times (fail).
         ok(false,
            "Received 'connected' event for original call multiple times");
       }
     });
   };
-  sendCmdToEmulator("gsm accept " + outNumber);
+  emulator.run("gsm accept " + outNumber);
 }
 
 // With one connected call already, simulate an incoming call.
 function simulateIncoming() {
   log("Simulating an incoming call (with one call already connected).");
 
   telephony.onincoming = function(event) {
     log("Received 'incoming' call event.");
@@ -142,26 +132,26 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     // Should be two calls now.
     checkState(outgoingCall, [outgoingCall, incomingCall], '', []);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "inbound from " + inNumber + " : incoming");
       is(result[2], "OK");
 
       answerIncoming();
     });
   };
-  sendCmdToEmulator("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 // Answer incoming call; original outgoing call should be held.
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
   incomingCall.onconnecting = function(event) {
@@ -181,17 +171,17 @@ function answerIncoming() {
 
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(outgoingCall.state, "held");
     checkState(incomingCall, [outgoingCall, incomingCall], '', []);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "inbound from " + inNumber + " : active");
       is(result[2], "OK");
 
       conferenceAddTwoCalls();
     });
   };
@@ -213,31 +203,31 @@ function conferenceAddTwoCalls() {
   conference.oncallschanged = function(event) {
     log("Received 'callschanged' event for the conference call.");
 
     let index = expected.indexOf(event.call);
     ok(index != -1);
     expected.splice(index, 1);
     is(conference.calls[conference.calls.length - 1].number, event.call.number);
 
-    if (expected.length == 0) {
+    if (expected.length === 0) {
       conference.oncallschanged = null;
       receivedPending("conference.oncallschanged", pending, nextTest);
     }
   };
 
   conference.onconnected = function(event) {
     log("Received 'connected' event for the conference call.");
     conference.onconnected = null;
 
     ok(!conference.oncallschanged);
 
     checkState(conference, [], 'connected', [outgoingCall, incomingCall]);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "inbound from " + inNumber + " : active");
       is(result[2], "OK");
 
       receivedPending("conference.onconnected", pending, nextTest);
     });
   };
@@ -304,17 +294,17 @@ function conferenceHold() {
 
   conference.onheld = function(event) {
     log("Received 'held' event for the conference call.");
     conference.onheld = null;
 
     ok(!conference.onholding);
     checkState(null, [], 'held', [outgoingCall, incomingCall]);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "inbound from " + inNumber + " : held");
       is(result[2], "OK");
 
       receivedPending("conference.onheld", pending, nextTest);
     });
   };
@@ -379,17 +369,17 @@ function conferenceResume() {
 
   conference.onconnected = function(event) {
     log("Received 'connected' event for the conference call.");
     conference.onconnected = null;
 
     ok(!conference.onresuming);
     checkState(conference, [], 'connected', [outgoingCall, incomingCall]);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "inbound from " + inNumber + " : active");
       is(result[2], "OK");
 
       receivedPending("conference.onconnected", pending, nextTest);
     });
   };
@@ -445,27 +435,27 @@ function simulate2ndIncoming() {
 
     incomingCall2 = event.call;
     ok(incomingCall2);
     is(incomingCall2.number, inNumber2);
     is(incomingCall2.state, "incoming");
 
     checkState(conference, [incomingCall2], 'connected', [outgoingCall, incomingCall]);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "inbound from " + inNumber + " : active");
       is(result[2], "inbound from " + inNumber2 + " : incoming");
       is(result[3], "OK");
 
       answer2ndIncoming();
     });
   };
-  sendCmdToEmulator("gsm call " + inNumber2);
+  emulator.run("gsm call " + inNumber2);
 }
 
 function answer2ndIncoming() {
   log("Answering the 2nd incoming call when there's a connected conference call.");
 
   let gotConnecting = false;
   incomingCall2.onconnecting = function(event) {
     log("Received 'connecting' event for the 2nd incoming call.");
@@ -480,17 +470,17 @@ function answer2ndIncoming() {
     incomingCall2.onconnected = null;
 
     is(incomingCall2, event.call);
     is(incomingCall2.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall2, telephony.active);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "inbound from " + inNumber + " : held");
       is(result[2], "inbound from " + inNumber2 + " : active");
       is(result[3], "OK");
 
       conferenceAddOneCall();
     });
@@ -523,17 +513,17 @@ function conferenceAddOneCall() {
     log("Received 'connected' event for the conference call.");
     conference.oncallschanged = null;
 
     ok(!conference.oncallschanged);
 
     checkState(conference, [], 'connected',
                [outgoingCall, incomingCall, incomingCall2]);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "inbound from " + inNumber + " : active");
       is(result[2], "inbound from " + inNumber2 + " : active");
       is(result[3], "OK");
 
       receivedPending("conference.onconnected", pending, nextTest);
     });
@@ -610,17 +600,17 @@ function conferenceRemove() {
     log("Received 'statechange' event for the conference.");
     conference.onstatechange = null;
 
     ok(!conference.oncallschanged);
 
     checkState(callToRemove, [callToRemove], 'held',
                [incomingCall, incomingCall2]);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "inbound from " + inNumber + " : held");
       is(result[2], "inbound from " + inNumber2 + " : held");
       is(result[3], "OK");
 
       receivedPending("conference.onstatechange", pending, nextTest);
     });
@@ -639,17 +629,17 @@ function emptyConference() {
     log("Received 'disconnected' event for the outgoing call.");
     outgoingCall.ondisconnected = null;
 
     checkState(null, [], 'held',
                [incomingCall, incomingCall2]);
 
     // We are going to release incomingCall. Once released, incomingCall2
     // is going to be moved out of the conference call automatically.
-    sendCmdToEmulator("gsm cancel " + inNumber);
+    emulator.run("gsm cancel " + inNumber);
   };
 
   let pending = ["conference.oncallschanged", "conference.onstatechange",
                  "incomingCall2.ongroupchange"];
   let nextTest = hangUpLastCall;
 
   incomingCall2.ongroupchange = function(event) {
     log("Received 'groupchange' event for the outgoing call.");
@@ -666,58 +656,56 @@ function emptyConference() {
   let expected = [incomingCall, incomingCall2];
   conference.oncallschanged = function(event) {
     log("Received 'callschanged' event for the conference call.");
 
     let index = expected.indexOf(event.call);
     ok(index != -1);
     expected.splice(index, 1);
 
-    if (expected.length == 0) {
+    if (expected.length === 0) {
       conference.oncallschanged = null;
       is(conference.calls.length, 0);
       receivedPending("conference.oncallschanged", pending, nextTest);
     }
   };
 
   conference.onstatechange = function(event) {
     log("Received 'statechange' event for the conference call.");
     conference.onstatechange = null;
 
     ok(!conference.oncallschanged);
     checkState(null, [incomingCall2], '', []);
 
     receivedPending("conference.onstatechange", pending, nextTest);
   };
 
-  sendCmdToEmulator("gsm cancel " + outNumber);
+  emulator.run("gsm cancel " + outNumber);
 }
 
 function hangUpLastCall() {
   log("Going to leave the test. Hanging up the last call.");
 
   incomingCall2.ondisconnected = function(event) {
     incomingCall2.ondisconnected = null;
 
     checkState(null, [], '', []);
 
-    sendCmdToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
 
       cleanUp();
     });
   };
 
-  sendCmdToEmulator("gsm cancel " + inNumber2);
+  emulator.run("gsm cancel " + inNumber2);
 }
 
 function cleanUp() {
-  if (pendingEmulatorCmdCount) {
-    window.setTimeout(cleanUp, 100);
-    return;
-  }
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-verifyInitialState();
+startTest(function() {
+  verifyInitialState();
+});
--- a/dom/telephony/test/marionette/test_crash_emulator.js
+++ b/dom/telephony/test/marionette/test_crash_emulator.js
@@ -1,49 +1,50 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let outNumber = "5555551111";
 let outgoingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       dial();
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(dial, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function dial() {
   log("Make an outgoing call.");
   outgoingCall = telephony.dial(outNumber);
 
   outgoingCall.onalerting = function onalerting(event) {
     log("Received 'alerting' call event.");
@@ -59,18 +60,20 @@ function answer() {
     // just some code to keep call active for awhile
     callStartTime = Date.now();
     waitFor(cleanUp,function() {
       callDuration = Date.now() - callStartTime;
       log("Waiting while call is active, call duration (ms): " + callDuration);
       return(callDuration >= 2000);
     });
   };
-  runEmulatorCmd("gsm accept " + outNumber);
+  emulator.run("gsm accept " + outNumber);
 }
 
 function cleanUp(){
   outgoingCall.hangUp();
   ok("passed");
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_emergency.js
+++ b/dom/telephony/test/marionette/test_emergency.js
@@ -1,29 +1,30 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "911";
 let outgoing;
 let calls;
 
 function verifyInitialState() {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   calls = telephony.calls;
 
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     is(result[0], "OK");
     if (result[0] == "OK") {
       dial();
     } else {
       log("Call exists from a previous test, failing out.");
       cleanUp();
     }
@@ -43,17 +44,17 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoing);
 
   outgoing.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + "        : ringing");
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -64,46 +65,48 @@ function answer() {
 
   outgoing.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "connected");
 
     is(outgoing, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + "        : active");
       is(result[1], "OK");
       hangUp();
     });
   };
-  runEmulatorCmd("gsm accept " + number);
-};
+  emulator.run("gsm accept " + number);
+}
 
 function hangUp() {
   log("Hanging up the emergency call.");
 
   // We get no "disconnecting" event when the remote party terminates the call.
 
   outgoing.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "disconnected");
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  runEmulatorCmd("gsm cancel " + number);
+  emulator.run("gsm cancel " + number);
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-verifyInitialState();
+startTest(function() {
+  verifyInitialState();
+});
--- a/dom/telephony/test/marionette/test_emergency_badNumber.js
+++ b/dom/telephony/test/marionette/test_emergency_badNumber.js
@@ -1,29 +1,30 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "not a valid emergency number";
 let outgoing;
 let calls;
 
 function verifyInitialState() {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   calls = telephony.calls;
 
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     is(result[0], "OK");
     if (result[0] == "OK") {
       dial();
     } else {
       log("Call exists from a previous test, failing out.");
       cleanUp();
     }
@@ -43,26 +44,28 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoing);
 
   outgoing.onerror = function onerror(event) {
     log("Received 'error' event.");
     is(event.call, outgoing);
     ok(event.call.error);
     is(event.call.error.name, "BadNumberError");
-    
+
     is(telephony.calls.length, 0);
     is(telephony.active, null);
-    
-    runEmulatorCmd("gsm list", function(result) {
+
+    emulator.run("gsm list", function(result) {
       log("Initial call list: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-verifyInitialState();
+startTest(function() {
+  verifyInitialState();
+});
--- a/dom/telephony/test/marionette/test_emergency_label.js
+++ b/dom/telephony/test/marionette/test_emergency_label.js
@@ -1,12 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number;
 let emergency;
 let outgoing;
 
@@ -14,63 +15,63 @@ let testCase = 0;
 let expectedResults = [
   ["112", true],
   ["911", true],
   ["0912345678", false],
   ["777", false],
 ];
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function createGoldenCallListResult0(number, state) {
   //  "outbound to  xxxxxxxxxx : ringing"
@@ -92,17 +93,17 @@ function dial() {
   is(telephony.calls[0], outgoing);
 
   outgoing.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "alerting");
     is(outgoing.emergency, emergency);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], createGoldenCallListResult0(number, "ringing"));
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -114,47 +115,47 @@ function answer() {
   outgoing.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "connected");
     is(outgoing.emergency, emergency);
 
     is(outgoing, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], createGoldenCallListResult0(number, "active"));
       is(result[1], "OK");
       hangUp();
     });
   };
-  runEmulatorCmd("gsm accept " + number);
-};
+  emulator.run("gsm accept " + number);
+}
 
 function hangUp() {
   log("Hanging up the call.");
 
   // We get no "disconnecting" event when the remote party terminates the call.
 
   outgoing.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "disconnected");
     is(outgoing.emergency, emergency);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       verifyNextEmergencyLabel();
     });
   };
-  runEmulatorCmd("gsm cancel " + number);
+  emulator.run("gsm cancel " + number);
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 function verifyNextEmergencyLabel() {
@@ -164,9 +165,11 @@ function verifyNextEmergencyLabel() {
     log("Running test case: " + testCase + "/" + expectedResults.length);
     number = expectedResults[testCase][0];
     emergency = expectedResults[testCase][1];
     getExistingCalls();
     testCase++;
   }
 }
 
-verifyNextEmergencyLabel();
+startTest(function() {
+  verifyNextEmergencyLabel();
+});
--- a/dom/telephony/test/marionette/test_incoming_already_connected.js
+++ b/dom/telephony/test/marionette/test_incoming_already_connected.js
@@ -1,71 +1,72 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let outNumber = "5555551111";
 let inNumber = "5555552222";
 let outgoingCall;
 let incomingCall;
 let gotOriginalConnected = false;
 
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -78,17 +79,17 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoingCall);
 
   outgoingCall.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : ringing");
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -98,32 +99,32 @@ function answer() {
   // We get no "connecting" event when the remote party answers the call.
   outgoingCall.onconnected = function onconnectedOut(event) {
     log("Received 'connected' call event for the original outgoing call.");
 
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
     is(outgoingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "OK");
 
       if(!gotOriginalConnected){
         gotOriginalConnected = true;
         simulateIncoming();
       } else {
         // Received connected event for original call multiple times (fail)
         ok(false,
            "Received 'connected' event for original call multiple times");
       }
     });
   };
-  runEmulatorCmd("gsm accept " + outNumber);
+  emulator.run("gsm accept " + outNumber);
 }
 
 // With one connected call already, simulate an incoming call
 function simulateIncoming() {
   log("Simulating an incoming call (with one call already connected).");
 
   telephony.onincoming = function onincoming(event) {
     log("Received 'incoming' call event.");
@@ -132,49 +133,49 @@ function simulateIncoming() {
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     // Should be two calls now
     is(telephony.calls.length, 2);
     is(telephony.calls[0], outgoingCall);
     is(telephony.calls[1], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "inbound from " + inNumber + " : incoming");
       is(result[2], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 // Answer incoming call; original outgoing call should be held
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for incoming/2nd call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for incoming/2nd call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
     is(outgoingCall.state, "held");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "inbound from " + inNumber + " : active");
       is(result[2], "OK");
       hangUpOutgoing();
     });
   };
   incomingCall.answer();
@@ -197,17 +198,17 @@ function hangUpOutgoing() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Back to one call now
     is(telephony.calls.length, 1);
     is(incomingCall.state, "connected");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       hangUpIncoming();
     });
   };
   outgoingCall.hangUp();
 }
@@ -229,25 +230,27 @@ function hangUpIncoming() {
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Zero calls left
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   incomingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_already_held.js
+++ b/dom/telephony/test/marionette/test_incoming_already_held.js
@@ -1,70 +1,71 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let outNumber = "5555551111";
 let inNumber = "5555552222";
 let outgoingCall;
 let incomingCall;
 let gotOriginalConnected = false;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 
 function dial() {
@@ -78,17 +79,17 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoingCall);
 
   outgoingCall.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : ringing");
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -98,32 +99,32 @@ function answer() {
   // We get no "connecting" event when the remote party answers the call.
   outgoingCall.onconnected = function onconnectedOut(event) {
     log("Received 'connected' call event for the original outgoing call.");
 
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
     is(outgoingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "OK");
 
       if(!gotOriginalConnected){
         gotOriginalConnected = true;
         holdCall();
       } else {
         // Received connected event for original call multiple times (fail)
         ok(false,
            "Received 'connected' event for original call multiple times");
       }
     });
   };
-  runEmulatorCmd("gsm accept " + outNumber);
+  emulator.run("gsm accept " + outNumber);
 }
 
 function holdCall() {
   log("Putting the original (outgoing) call on hold.");
 
   let gotHolding = false;
   outgoingCall.onholding = function onholding(event) {
     log("Received 'holding' call event");
@@ -137,17 +138,17 @@ function holdCall() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], outgoingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "OK");
       simulateIncoming();
     });
   };
   outgoingCall.hold();
 }
@@ -163,49 +164,49 @@ function simulateIncoming() {
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     // Should be two calls now
     is(telephony.calls.length, 2);
     is(telephony.calls[0], outgoingCall);
     is(telephony.calls[1], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "inbound from " + inNumber + " : incoming");
       is(result[2], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 // Answer incoming call; original outgoing call should be held
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for incoming/2nd call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for incoming/2nd call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
     is(outgoingCall.state, "held");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "inbound from " + inNumber + " : active");
       is(result[2], "OK");
       hangUpOutgoing();
     });
   };
   incomingCall.answer();
@@ -228,17 +229,17 @@ function hangUpOutgoing() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Back to one call now
     is(telephony.calls.length, 1);
     is(incomingCall.state, "connected");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       hangUpIncoming();
     });
   };
   outgoingCall.hangUp();
 }
@@ -260,25 +261,27 @@ function hangUpIncoming() {
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Zero calls left
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   incomingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_answer_hangup.js
+++ b/dom/telephony/test/marionette/test_incoming_answer_hangup.js
@@ -1,68 +1,69 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let incoming;
 let calls;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -73,54 +74,54 @@ function simulateIncoming() {
     ok(incoming);
     is(incoming.number, number);
     is(incoming.state, "incoming");
 
     //ok(telephony.calls === calls); // bug 717414
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incoming);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + number + " : incoming");
       is(result[1], "OK");
       answer();
     });
   };
-  runEmulatorCmd("gsm call " + number);
+  emulator.run("gsm call " + number);
 }
 
 function answer() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incoming.onconnecting = function onconnecting(event) { 
+  incoming.onconnecting = function onconnecting(event) {
     log("Received 'connecting' call event.");
     is(incoming, event.call);
     is(incoming.state, "connecting");
     gotConnecting = true;
   };
 
   incoming.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(incoming, event.call);
     is(incoming.state, "connected");
     ok(gotConnecting);
 
     is(incoming, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + number + " : active");
       is(result[1], "OK");
       hangUp();
     });
   };
   incoming.answer();
-};
+}
 
 function hangUp() {
   log("Hanging up the incoming call.");
 
   let gotDisconnecting = false;
   incoming.ondisconnecting = function ondisconnecting(event) {
     log("Received 'disconnecting' call event.");
     is(incoming, event.call);
@@ -132,23 +133,25 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(incoming, event.call);
     is(incoming.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   incoming.hangUp();
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_answer_hangup_oncallschanged.js
+++ b/dom/telephony/test/marionette/test_incoming_answer_hangup_oncallschanged.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let incoming;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -69,48 +70,35 @@ function simulateIncoming() {
   telephony.oncallschanged = function oncallschanged(event) {
     log("Received 'callschanged' event.");
 
     if (!event.call) {
       log("Notifying calls array is loaded. No call information accompanies.");
       return;
     }
 
-    let expected_states = ["incoming", "disconnected"];
-    ok(expected_states.indexOf(event.call.state) != -1,
-      "Unexpected call state: " + event.call.state);
+    telephony.oncallschanged = null;
 
-    if (event.call.state == "incoming") {
-      log("Received 'callschanged' event for an incoming call.");
-      incoming = event.call;
-      ok(incoming);
-      is(incoming.number, number);
-
-      is(telephony.calls.length, 1);
-      is(telephony.calls[0], incoming);
+    incoming = event.call;
+    ok(incoming);
+    is(incoming.number, number);
+    is(incoming.state, "incoming");
 
-      runEmulatorCmd("gsm list", function(result) {
-        log("Call list is now: " + result);
-        is(result[0], "inbound from " + number + " : incoming");
-        is(result[1], "OK");
-        answer();
-      });
-    }
+    is(telephony.calls.length, 1);
+    is(telephony.calls[0], incoming);
 
-    if (event.call.state == "disconnected") {
-      log("Received 'callschanged' event for a disconnected call.");
-      is(event.call, incoming);
-      is(incoming.state, "disconnected");
-      is(telephony.active, null);
-      is(telephony.calls.length, 0);
-      cleanUp();
-    }
+    emulator.run("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "inbound from " + number + " : incoming");
+      is(result[1], "OK");
+      answer();
+    });
   };
 
-  runEmulatorCmd("gsm call " + number);
+  emulator.run("gsm call " + number);
 }
 
 function answer() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
   incoming.onconnecting = function onconnecting(event) {
     log("Received 'connecting' call event.");
@@ -125,53 +113,77 @@ function answer() {
   incoming.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(incoming, event.call);
     is(incoming.state, "connected");
     ok(gotConnecting);
 
     is(incoming, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + number + " : active");
       is(result[1], "OK");
       hangUp();
     });
   };
   incoming.answer();
-};
+}
 
 function hangUp() {
   log("Hanging up the incoming call.");
 
+  // Should received 'diconnecting', 'callschanged', 'disconnected' events in
+  // order.
   let gotDisconnecting = false;
+  let gotCallschanged = false;
+
   incoming.ondisconnecting = function ondisconnecting(event) {
     log("Received 'disconnecting' call event.");
     is(incoming, event.call);
     is(incoming.state, "disconnecting");
     gotDisconnecting = true;
   };
 
+  telephony.oncallschanged = function oncallschanged(event) {
+    log("Received 'callschanged' event.");
+
+    if (!event.call) {
+      log("Notifying calls array is loaded. No call information accompanies.");
+      return;
+    }
+
+    is(incoming, event.call);
+    is(incoming.state, "disconnected");
+    is(telephony.active, null);
+    is(telephony.calls.length, 0);
+    gotCallschanged = true;
+  };
+
   incoming.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(incoming, event.call);
     is(incoming.state, "disconnected");
     ok(gotDisconnecting);
+    ok(gotCallschanged);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
+      cleanUp();
     });
   };
+
   incoming.hangUp();
 }
 
 function cleanUp() {
   telephony.oncallschanged = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_answer_remote_hangup.js
+++ b/dom/telephony/test/marionette/test_incoming_answer_remote_hangup.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let incomingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -71,46 +72,46 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for incoming call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for incoming call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       remoteHangUp();
     });
   };
   incomingCall.answer();
 }
@@ -123,25 +124,27 @@ function remoteHangUp() {
   incomingCall.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  runEmulatorCmd("gsm cancel " + inNumber);
+  emulator.run("gsm cancel " + inNumber);
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_connecting_hangup.js
+++ b/dom/telephony/test/marionette/test_incoming_connecting_hangup.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let incomingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -71,30 +72,30 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
-  incomingCall.onconnecting = function onconnecting(event) { 
+  incomingCall.onconnecting = function onconnecting(event) {
     log("Received 'connecting' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     // Now hang-up the call before it is fully connected
 
     // Bug 784429: Hang-up while connecting, call is not terminated
     // If hang-up between 'connecting' and 'connected' states, receive the
     // 'disconnecting' event but then a 'connected' event, and the call is
@@ -107,17 +108,17 @@ function answerIncoming() {
     log("==> Waiting one second, remove wait once bug 784429 is fixed <==");
     setTimeout(hangUp, 1000);
   };
 
   incomingCall.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
   };
   incomingCall.answer();
-};
+}
 
 function hangUp() {
   log("Hanging up the incoming call before fully connected.");
 
   let gotDisconnecting = false;
   incomingCall.ondisconnecting = function ondisconnecting(event) {
     log("Received 'disconnecting' call event.");
     is(incomingCall, event.call);
@@ -129,25 +130,27 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   incomingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_connecting_remote_hangup.js
+++ b/dom/telephony/test/marionette/test_incoming_connecting_remote_hangup.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let incomingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -71,65 +72,67 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
-  incomingCall.onconnecting = function onconnecting(event) { 
+  incomingCall.onconnecting = function onconnecting(event) {
     log("Received 'connecting' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     // Now have the remote party hang-up the call before it is fully connected
     remoteHangUp();
   };
 
   incomingCall.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
   };
   incomingCall.answer();
-};
+}
 
 function remoteHangUp() {
   log("Hanging up the incoming call (remotely) before fully connected.");
 
   // We get no 'disconnecting' event when remote party hangs-up the call
 
   incomingCall.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  runEmulatorCmd("gsm cancel " + inNumber);
+  emulator.run("gsm cancel " + inNumber);
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_hangup_held.js
+++ b/dom/telephony/test/marionette/test_incoming_hangup_held.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let incomingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -71,46 +72,46 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for incoming call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for incoming call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       hold();
     });
   };
   incomingCall.answer();
 }
@@ -131,17 +132,17 @@ function hold() {
     is(incomingCall, event.call);
     is(incomingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
       is(result[1], "OK");
       hangUp();
     });
   };
   incomingCall.hold();
 }
@@ -161,25 +162,27 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   incomingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_hold_resume.js
+++ b/dom/telephony/test/marionette/test_incoming_hold_resume.js
@@ -1,68 +1,69 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555551234";
 let connectedCalls;
 let incomingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -72,46 +73,46 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, number);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + number + " : incoming");
       is(result[1], "OK");
       answer();
     });
   };
-  runEmulatorCmd("gsm call " + number);
+  emulator.run("gsm call " + number);
 }
 
 function answer() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnecting(event) { 
+  incomingCall.onconnecting = function onconnecting(event) {
     log("Received 'connecting' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + number + " : active");
       is(result[1], "OK");
       hold();
     });
   };
   incomingCall.answer();
 }
@@ -132,20 +133,20 @@ function hold() {
     is(incomingCall, event.call);
     is(incomingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + number + " : held");
-      is(result[1], "OK");   
+      is(result[1], "OK");
       // Wait on hold for a couple of seconds
       log("Pausing 2 seconds while on hold");
       setTimeout(resume, 2000);
     });
   };
   incomingCall.hold();
 }
 
@@ -165,17 +166,17 @@ function resume() {
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotResuming);
 
     is(incomingCall, telephony.active);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + number + " : active");
       is(result[1], "OK");
       hangUp();
     });
   };
   incomingCall.resume();
 }
@@ -195,25 +196,27 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   incomingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
\ No newline at end of file
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_onstatechange.js
+++ b/dom/telephony/test/marionette/test_incoming_onstatechange.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
+MARIONETTE_HEAD_JS = 'head.js';
 MARIONETTE_TIMEOUT = 60000;
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let incomingCall;
 let inNumber = "5555551111";
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -71,24 +72,24 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
   gotConnecting = false;
   incomingCall.onstatechange = function statechangeconnect(event) {
     log("Received 'onstatechange' call event.");
@@ -97,26 +98,26 @@ function answerIncoming() {
       is(incomingCall.state, "connecting");
       gotConnecting = true;
     } else {
       is(incomingCall.state, "connected");
       is(telephony.active, incomingCall);
       is(telephony.calls.length, 1);
       is(telephony.calls[0], incomingCall);
 
-      runEmulatorCmd("gsm list", function(result) {
+      emulator.run("gsm list", function(result) {
         log("Call list is now: " + result);
         is(result[0], "inbound from " + inNumber + " : active");
         is(result[1], "OK");
         hold();
       });
-    };
+    }
   };
   incomingCall.answer();
-};
+}
 
 function hold() {
   log("Putting the call on hold.");
 
   let gotHolding = false;
   incomingCall.onstatechange = function onstatechangehold(event) {
     log("Received 'onstatechange' call event.");
     is(incomingCall, event.call);
@@ -124,23 +125,23 @@ function hold() {
       is(incomingCall.state, "holding");
       gotHolding = true;
     } else {
       is(incomingCall.state, "held");
       is(telephony.active, null);
       is(telephony.calls.length, 1);
       is(telephony.calls[0], incomingCall);
 
-      runEmulatorCmd("gsm list", function(result) {
+      emulator.run("gsm list", function(result) {
         log("Call list is now: " + result);
         is(result[0], "inbound from " + inNumber + " : held");
         is(result[1], "OK");
         resume();
       });
-    };
+    }
   };
   incomingCall.hold();
 }
 
 function resume() {
   log("Resuming the held call.");
 
   let gotResuming = false;
@@ -151,23 +152,23 @@ function resume() {
       is(incomingCall.state, "resuming");
       gotResuming = true;
     } else {
       is(incomingCall.state, "connected");
       is(telephony.active, incomingCall);
       is(telephony.calls.length, 1);
       is(telephony.calls[0], incomingCall);
 
-      runEmulatorCmd("gsm list", function(result) {
+      emulator.run("gsm list", function(result) {
         log("Call list is now: " + result);
         is(result[0], "inbound from " + inNumber + " : active");
         is(result[1], "OK");
         hangUp();
       });
-    };
+    }
   };
   incomingCall.resume();
 }
 
 function hangUp() {
   log("Hanging up the incoming call (local hang-up).");
 
   let gotDisconnecting = false;
@@ -177,26 +178,28 @@ function hangUp() {
     if(!gotDisconnecting){
       is(incomingCall.state, "disconnecting");
       gotDisconnecting = true;
     } else {
       is(incomingCall.state, "disconnected");
       is(telephony.active, null);
       is(telephony.calls.length, 0);
 
-      runEmulatorCmd("gsm list", function(result) {
+      emulator.run("gsm list", function(result) {
         log("Call list is now: " + result);
         is(result[0], "OK");
         cleanUp();
       });
-    };
+    }
   };
   incomingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_reject.js
+++ b/dom/telephony/test/marionette/test_incoming_reject.js
@@ -1,68 +1,69 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let incoming;
 let calls;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -73,24 +74,24 @@ function simulateIncoming() {
     ok(incoming);
     is(incoming.number, number);
     is(incoming.state, "incoming");
 
     //ok(telephony.calls === calls); // bug 717414
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incoming);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + number + " : incoming");
       is(result[1], "OK");
       reject();
     });
   };
-  runEmulatorCmd("gsm call " + number);
+  emulator.run("gsm call " + number);
 }
 
 function reject() {
   log("Reject the incoming call.");
 
   let gotDisconnecting = false;
   incoming.ondisconnecting = function ondisconnecting(event) {
     log("Received 'disconnecting' call event.");
@@ -103,24 +104,26 @@ function reject() {
     log("Received 'disconnected' call event.");
     is(incoming, event.call);
     is(incoming.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   incoming.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_remote_cancel.js
+++ b/dom/telephony/test/marionette/test_incoming_remote_cancel.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let incomingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -71,48 +72,50 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       cancelIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function cancelIncoming(){
   log("Remote party cancelling call before it is answered.");
 
   // We get no 'disconnecting' event when remote party cancels/hangs-up call
 
   incomingCall.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  runEmulatorCmd("gsm cancel " + inNumber);
+  emulator.run("gsm cancel " + inNumber);
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_incoming_remote_hangup_held.js
+++ b/dom/telephony/test/marionette/test_incoming_remote_hangup_held.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let incomingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -71,46 +72,46 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for incoming call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for incoming call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       hold();
     });
   };
   incomingCall.answer();
 }
@@ -131,17 +132,17 @@ function hold() {
     is(incomingCall, event.call);
     is(incomingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
       is(result[1], "OK");
       hangUp();
     });
   };
   incomingCall.hold();
 }
@@ -154,25 +155,27 @@ function hangUp() {
   incomingCall.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  runEmulatorCmd("gsm cancel " + inNumber);
+  emulator.run("gsm cancel " + inNumber);
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_multiple_hold.js
+++ b/dom/telephony/test/marionette/test_multiple_hold.js
@@ -1,69 +1,70 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let outNumber = "5555552222";
 let incomingCall;
 let outgoingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -73,45 +74,45 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for original (incoming) call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for original (incoming) call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
     is(incomingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       holdCall();
     });
   };
   incomingCall.answer();
 }
@@ -133,17 +134,17 @@ function holdCall() {
     is(incomingCall, event.call);
     is(incomingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
       is(result[1], "OK");
       dial();
     });
   };
   incomingCall.hold();
 }
@@ -161,17 +162,17 @@ function dial() {
   is(telephony.calls[0], incomingCall);
   is(telephony.calls[1], outgoingCall);
 
   outgoingCall.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
       is(result[1], "outbound to  " + outNumber + " : ringing");
       is(result[2], "OK");
       answerOutgoing();
     });
   };
 }
@@ -182,25 +183,25 @@ function answerOutgoing() {
 
   // We get no "connecting" event when the remote party answers the call.
   outgoingCall.onconnected = function onconnectedOut(event) {
     log("Received 'connected' call event for outgoing/2nd call.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
     is(outgoingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
       is(result[1], "outbound to  " + outNumber + " : active");
       is(result[2], "OK");
       holdSecondCall();
     });
   };
-  runEmulatorCmd("gsm accept " + outNumber);
+  emulator.run("gsm accept " + outNumber);
 }
 
 // With one held call and one active, hold the active one; expect the first
 // (held) call to automatically become active, and the 2nd call to go on hold
 function holdSecondCall() {
   let firstCallReconnected = false;
   let secondCallHeld = false;
 
@@ -241,17 +242,17 @@ function holdSecondCall() {
 }
 
 function verifyCalls() {
   is(telephony.active, incomingCall);
   is(telephony.calls.length, 2);
   is(telephony.calls[0], incomingCall);
   is(telephony.calls[1], outgoingCall);
 
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Call list is now: " + result);
     is(result[0], "inbound from " + inNumber + " : active");
     is(result[1], "outbound to  " + outNumber + " : held");
     is(result[2], "OK");
     hangUpIncoming();
   });
 }
 
@@ -273,17 +274,17 @@ function hangUpIncoming() {
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Now back to one call
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], outgoingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "OK");
       hangUpOutgoing();
     });
   };
   incomingCall.hangUp();
 }
@@ -305,25 +306,27 @@ function hangUpOutgoing() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Now no calls
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  outgoingCall.hangUp();  
+  outgoingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_already_held.js
+++ b/dom/telephony/test/marionette/test_outgoing_already_held.js
@@ -1,69 +1,70 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let outNumber = "5555552222";
 let incomingCall;
 let outgoingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -80,64 +81,64 @@ function simulateIncoming() {
 
     // Wait for emulator to catch up before continuing
     waitFor(verifyCallList,function() {
       return(rcvdEmulatorCallback);
     });
   };
 
   let rcvdEmulatorCallback = false;
-  runEmulatorCmd("gsm call " + inNumber, function(result) {
+  emulator.run("gsm call " + inNumber, function(result) {
     is(result[0], "OK", "emulator callback");
     rcvdEmulatorCallback = true;
   });
 }
 
 function verifyCallList(){
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Call list is now: " + result);
     is(result[0], "inbound from " + inNumber + " : incoming");
     is(result[1], "OK");
     answerIncoming();
   });
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for original (incoming) call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for original (incoming) call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       holdCall();
     });
   };
   incomingCall.answer();
 }
 
 // Put the original (incoming) call on hold
 function holdCall(){
   log("Putting the original (incoming) call on hold.");
-  
+
   let gotHolding = false;
   incomingCall.onholding = function onholding(event) {
     log("Received 'holding' call event");
     is(incomingCall, event.call);
     is(incomingCall.state, "holding");
     gotHolding = true;
   };
 
@@ -146,20 +147,20 @@ function holdCall(){
     is(incomingCall, event.call);
     is(incomingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
-      is(result[1], "OK");   
+      is(result[1], "OK");
       dial();
     });
   };
   incomingCall.hold();
 }
 
 // With one call on hold, make outgoing call
 function dial() {
@@ -175,17 +176,17 @@ function dial() {
   is(telephony.calls[0], incomingCall);
   is(telephony.calls[1], outgoingCall);
 
   outgoingCall.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
       is(result[1], "outbound to  " + outNumber + " : ringing");
       is(result[2], "OK");
       answerOutgoing();
     });
   };
 }
@@ -204,24 +205,24 @@ function answerOutgoing() {
 
     // Wait for emulator to catch up before continuing
     waitFor(checkCallList,function() {
       return(rcvdEmulatorCallback);
     });
   };
 
   let rcvdEmulatorCallback = false;
-  runEmulatorCmd("gsm accept " + outNumber, function(result) {
+  emulator.run("gsm accept " + outNumber, function(result) {
     is(result[0], "OK", "emulator callback");
     rcvdEmulatorCallback = true;
   });
 }
 
 function checkCallList(){
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Call list is now: " + result);
     is(result[0], "inbound from " + inNumber + " : held");
     is(result[1], "outbound to  " + outNumber + " : active");
     is(result[2], "OK");
     hangUpIncoming();
   });
 }
 
@@ -243,30 +244,30 @@ function hangUpIncoming() {
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Now back to one call
     is(telephony.active, outgoingCall);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], outgoingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "OK");
       hangUpOutgoing();
     });
   };
   incomingCall.hangUp();
 }
 
 // Hang-up the remaining (outgoing) call
 function hangUpOutgoing() {
   log("Hanging up the remaining (outgoing) call.");
- 
+
   let gotDisconnecting = false;
   outgoingCall.ondisconnecting = function ondisconnectingOut(event) {
     log("Received 'disconnecting' call event for remaining (outgoing) call.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnecting");
     gotDisconnecting = true;
   };
 
@@ -275,25 +276,27 @@ function hangUpOutgoing() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Now no calls
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  outgoingCall.hangUp();  
+  outgoingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_answer_hangup.js
+++ b/dom/telephony/test/marionette/test_outgoing_answer_hangup.js
@@ -1,68 +1,69 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let outgoing;
 let calls;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -77,17 +78,17 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoing);
 
   outgoing.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : ringing");
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -98,46 +99,48 @@ function answer() {
 
   outgoing.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "connected");
 
     is(outgoing, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : active");
       is(result[1], "OK");
       hangUp();
     });
   };
-  runEmulatorCmd("gsm accept " + number);
-};
+  emulator.run("gsm accept " + number);
+}
 
 function hangUp() {
   log("Hanging up the outgoing call.");
 
   // We get no "disconnecting" event when the remote party terminates the call.
 
   outgoing.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "disconnected");
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  runEmulatorCmd("gsm cancel " + number);
+  emulator.run("gsm cancel " + number);
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_answer_hangup_oncallschanged.js
+++ b/dom/telephony/test/marionette/test_outgoing_answer_hangup_oncallschanged.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let outgoing;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -97,18 +98,18 @@ function dial() {
       cleanUp();
     }
   };
 
   telephony.dial(number);
 }
 
 function checkCallList() {
-  runEmulatorCmd("gsm list", function(result) {
-    log("Call list is now: " + result)
+  emulator.run("gsm list", function(result) {
+    log("Call list is now: " + result);
     if ((result[0] == "outbound to  " + number + " : unknown") && (result[1] == "OK")) {
       answer();
     } else {
       window.setTimeout(checkCallList, 100);
     }
   });
 }
 
@@ -119,31 +120,33 @@ function answer() {
 
   outgoing.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "connected");
 
     is(outgoing, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list (after 'connected' event) is now: " + result);
       is(result[0], "outbound to  " + number + " : active");
       is(result[1], "OK");
       hangUp();
     });
   };
-  runEmulatorCmd("gsm accept " + number);
-};
+  emulator.run("gsm accept " + number);
+}
 
 function hangUp() {
   log("Hanging up the outgoing call.");
 
-  runEmulatorCmd("gsm cancel " + number);
+  emulator.run("gsm cancel " + number);
 }
 
 function cleanUp() {
   telephony.oncallschanged = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_answer_local_hangup.js
+++ b/dom/telephony/test/marionette/test_outgoing_answer_local_hangup.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let outgoingCall;
 let outNumber = "5555551111";
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -76,17 +77,17 @@ function dial() {
   is(telephony.calls[0], outgoingCall);
 
   outgoingCall.onalerting = function onalerting(event) {
     log("Received 'alerting' call event.");
 
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : ringing");
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -97,25 +98,25 @@ function answer() {
 
   outgoingCall.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
 
     is(outgoingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "OK");
       hangUp();
     });
   };
-  runEmulatorCmd("gsm accept " + outNumber);
-};
+  emulator.run("gsm accept " + outNumber);
+}
 
 function hangUp() {
   log("Hanging up the outgoing call (local hang-up).");
 
   let gotDisconnecting = false;
   outgoingCall.ondisconnecting = function ondisconnectingOut(event) {
     log("Received 'disconnecting' call event.");
     is(outgoingCall, event.call);
@@ -127,24 +128,26 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   outgoingCall.hangUp();
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_badNumber.js
+++ b/dom/telephony/test/marionette/test_outgoing_badNumber.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "****5555552368****";
 let outgoing;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call to an invalid number.");
@@ -76,22 +77,24 @@ function dial() {
   is(telephony.calls[0], outgoing);
 
   outgoing.onerror = function onerror(event) {
     log("Received 'error' event.");
     is(event.call, outgoing);
     ok(event.call.error);
     is(event.call.error.name, "BadNumberError");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Initial call list: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_busy.js
+++ b/dom/telephony/test/marionette/test_outgoing_busy.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let outgoing;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -75,41 +76,43 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoing);
 
   outgoing.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : ringing");
       is(result[1], "OK");
       busy();
     });
   };
 }
 
 function busy() {
   log("The receiver is busy.");
 
   outgoing.onerror = function onerror(event) {
     log("Received 'error' call event.");
     is(outgoing, event.call);
     is(event.call.error.name, "BusyError");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
 
-  runEmulatorCmd("gsm busy " + number);
-};
+  emulator.run("gsm busy " + number);
+}
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js
+++ b/dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js
@@ -1,62 +1,66 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 const KEY = "ril.radio.disabled";
 
 SpecialPowers.addPermission("telephony", true, document);
 SpecialPowers.addPermission("settings-write", true, document);
 
 // Permission changes can't change existing Navigator.prototype
 // objects, so grab our objects from a new Navigator
 let ifr = document.createElement("iframe");
 let settings;
 let telephony;
 let number = "112";
 let outgoing;
-ifr.onload = function() {
-  settings = ifr.contentWindow.navigator.mozSettings;
-  telephony = ifr.contentWindow.navigator.mozTelephony;
-  getExistingCalls();
-};
-document.body.appendChild(ifr);
+
+startTest(function() {
+  ifr.onload = function() {
+    settings = ifr.contentWindow.navigator.mozSettings;
+    telephony = ifr.contentWindow.navigator.mozTelephony;
+    getExistingCalls();
+  };
+  document.body.appendChild(ifr);
+});
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Turning on airplane mode");
 
   let setLock = settings.createLock();
   let obj = {};
   obj[KEY] = false;
@@ -69,17 +73,17 @@ function verifyInitialState(confirmNoCal
   });
 
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
       }
@@ -101,17 +105,17 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoing);
 
   outgoing.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + "        : ringing");
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -122,45 +126,45 @@ function answer() {
 
   outgoing.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "connected");
 
     is(outgoing, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + "        : active");
       is(result[1], "OK");
       hangUp();
     });
   };
-  runEmulatorCmd("gsm accept " + number);
-};
+  emulator.run("gsm accept " + number);
+}
 
 function hangUp() {
   log("Hanging up the outgoing call.");
 
   // We get no "disconnecting" event when the remote party terminates the call.
 
   outgoing.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "disconnected");
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  runEmulatorCmd("gsm cancel " + number);
+  emulator.run("gsm cancel " + number);
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   SpecialPowers.removePermission("settings-write", document);
   finish();
 }
--- a/dom/telephony/test/marionette/test_outgoing_hangup_alerting.js
+++ b/dom/telephony/test/marionette/test_outgoing_hangup_alerting.js
@@ -1,68 +1,69 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let outgoing;
 let calls;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -74,17 +75,17 @@ function dial() {
 
   is(outgoing, telephony.active);
   //ok(telephony.calls === calls); // bug 717414
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoing);
 
   outgoing.onalerting = function onalerting(event) {
     log("Received 'alerting' call event.");
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : ringing");
       is(result[1], "OK");
       hangUp();
     });
   };
 }
 
@@ -104,24 +105,26 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
 
   outgoing.hangUp();
-};
+}
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_hangup_held.js
+++ b/dom/telephony/test/marionette/test_outgoing_hangup_held.js
@@ -1,68 +1,69 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let outgoing;
 let calls;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -76,46 +77,46 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoing);
 
   outgoing.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : ringing");
       is(result[1], "OK");
       answer();
     });
-  };  
+  };
 }
 
 function answer() {
   log("Answering the outgoing call.");
 
   // We get no "connecting" event when the remote party answers the call.
 
   outgoing.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "connected");
 
     is(outgoing, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : active");
       is(result[1], "OK");
       hold();
     });
   };
-  runEmulatorCmd("gsm accept " + number);
-};
+  emulator.run("gsm accept " + number);
+}
 
 function hold() {
   log("Holding the outgoing call.");
 
   outgoing.onholding = function onholding(event) {
     log("Received 'holding' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "holding");
@@ -126,17 +127,17 @@ function hold() {
   outgoing.onheld = function onheld(event) {
     log("Received 'held' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "held");
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : held");
       is(result[1], "OK");
       hangUp();
     });
   };
   outgoing.hold();
 }
@@ -156,24 +157,26 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
 
   outgoing.hangUp();
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_hold_resume.js
+++ b/dom/telephony/test/marionette/test_outgoing_hold_resume.js
@@ -1,68 +1,69 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555557777";
 let connectedCalls;
 let outgoingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -76,17 +77,17 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoingCall);
 
   outgoingCall.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : ringing");
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -95,27 +96,27 @@ function answer() {
 
   // We get no "connecting" event when the remote party answers the call.
 
   outgoingCall.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
 
-    is(outgoingCall, telephony.active);    
+    is(outgoingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : active");
       is(result[1], "OK");
       hold();
     });
   };
-  runEmulatorCmd("gsm accept " + number);
-};
+  emulator.run("gsm accept " + number);
+}
 
 function hold() {
   log("Putting the call on hold.");
 
   let gotHolding = false;
   outgoingCall.onholding = function onholding(event) {
     log("Received 'holding' call event");
     is(outgoingCall, event.call);
@@ -128,17 +129,17 @@ function hold() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], outgoingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : held");
       is(result[1], "OK");
       // Bug 781604: emulator assertion if outgoing call kept on hold
       // Wait on hold for a couple of seconds
       //log("Pausing 2 seconds while on hold");
       //setTimeout(resume, 2000);
       resume();
@@ -163,17 +164,17 @@ function resume() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
     ok(gotResuming);
 
     is(outgoingCall, telephony.active);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], outgoingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : active");
       is(result[1], "OK");
       hangUp();
     });
   };
   outgoingCall.resume();
 }
@@ -193,24 +194,26 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   outgoingCall.hangUp();
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
\ No newline at end of file
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_onstatechange.js
+++ b/dom/telephony/test/marionette/test_outgoing_onstatechange.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let outgoingCall;
 let outNumber = "5555551111";
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -78,17 +79,17 @@ function dial() {
   outgoingCall.onstatechange = function statechangering(event) {
     log("Received 'onstatechange' call event.");
 
     is(outgoingCall, event.call);
     let expectedStates = ["dialing", "alerting"];
     ok(expectedStates.indexOf(event.call.state) != -1);
 
     if (event.call.state == "alerting") {
-      runEmulatorCmd("gsm list", function(result) {
+      emulator.run("gsm list", function(result) {
         log("Call list is now: " + result);
         is(result[0], "outbound to  " + outNumber + " : ringing");
         is(result[1], "OK");
         answer();
       });
     }
   };
 }
@@ -99,25 +100,25 @@ function answer() {
   // We get no "connecting" event when the remote party answers the call.
 
   outgoingCall.onstatechange = function onstatechangeanswer(event) {
     log("Received 'onstatechange' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
     is(outgoingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "OK");
       hold();
     });
   };
-  runEmulatorCmd("gsm accept " + outNumber);
-};
+  emulator.run("gsm accept " + outNumber);
+}
 
 function hold() {
   log("Putting the call on hold.");
 
   let gotHolding = false;
   outgoingCall.onstatechange = function onstatechangehold(event) {
     log("Received 'onstatechange' call event.");
     is(outgoingCall, event.call);
@@ -125,23 +126,23 @@ function hold() {
       is(outgoingCall.state, "holding");
       gotHolding = true;
     } else {
       is(outgoingCall.state, "held");
       is(telephony.active, null);
       is(telephony.calls.length, 1);
       is(telephony.calls[0], outgoingCall);
 
-      runEmulatorCmd("gsm list", function(result) {
+      emulator.run("gsm list", function(result) {
         log("Call list is now: " + result);
         is(result[0], "outbound to  " + outNumber + " : held");
         is(result[1], "OK");
         resume();
       });
-    };
+    }
   };
   outgoingCall.hold();
 }
 
 function resume() {
   log("Resuming the held call.");
 
   let gotResuming = false;
@@ -152,23 +153,23 @@ function resume() {
       is(outgoingCall.state, "resuming");
       gotResuming = true;
     } else {
       is(outgoingCall.state, "connected");
       is(telephony.active, outgoingCall);
       is(telephony.calls.length, 1);
       is(telephony.calls[0], outgoingCall);
 
-      runEmulatorCmd("gsm list", function(result) {
+      emulator.run("gsm list", function(result) {
         log("Call list is now: " + result);
         is(result[0], "outbound to  " + outNumber + " : active");
         is(result[1], "OK");
         hangUp();
       });
-    };
+    }
   };
   outgoingCall.resume();
 }
 
 function hangUp() {
   log("Hanging up the outgoing call (local hang-up).");
 
   let gotDisconnecting = false;
@@ -178,25 +179,27 @@ function hangUp() {
     if(!gotDisconnecting){
       is(outgoingCall.state, "disconnecting");
       gotDisconnecting = true;
     } else {
       is(outgoingCall.state, "disconnected");
       is(telephony.active, null);
       is(telephony.calls.length, 0);
 
-      runEmulatorCmd("gsm list", function(result) {
+      emulator.run("gsm list", function(result) {
         log("Call list is now: " + result);
         is(result[0], "OK");
         cleanUp();
       });
-    };
+    }
   };
   outgoingCall.hangUp();
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_radio_off.js
+++ b/dom/telephony/test/marionette/test_outgoing_radio_off.js
@@ -1,12 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 permissions = [
   "mobileconnection",
   "settings-write",
   "telephony"
 ];
 
 for (let per of permissions) {
@@ -25,27 +26,16 @@ let connection = navigator.mozMobileConn
 ok(connection instanceof MozMobileConnection,
    "connection is instanceof " + connection.constructor);
 
 let telephony = navigator.mozTelephony;
 ok(telephony instanceof Telephony,
    "telephony is instanceof " + telephony.constructor);
 
 let outgoing;
-let pendingEmulatorCmdCount = 0;
-
-function sendToEmulator(cmd, callback) {
-  pendingEmulatorCmdCount++;
-  runEmulatorCmd(cmd, function (result) {
-    pendingEmulatorCmdCount--;
-    if (callback && typeof callback === 'function') {
-      callback(result);
-    }
-  });
-}
 
 function changeSetting(key, value, callback) {
   let obj = {};
   obj[key] = value;
 
   let setReq = navigator.mozSettings.createLock().set(obj);
   setReq.addEventListener("success", function onSetSuccess() {
     ok(true, "set '" + key + "' to " + obj[key]);
@@ -91,41 +81,38 @@ function dial(number) {
   is(telephony.calls[0], outgoing);
 
   outgoing.onerror = function onerror(event) {
     log("Received 'error' event.");
     is(event.call, outgoing);
     ok(event.call.error);
     is(event.call.error.name, "RadioNotAvailable");
 
-    sendToEmulator("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Initial call list: " + result);
       is(result[0], "OK");
 
       setRadioEnabled(true, cleanUp);
     });
   };
 }
 
 function cleanUp() {
-  if (pendingEmulatorCmdCount) {
-    window.setTimeout(cleanUp, 100);
-    return;
-  }
-
   for (let per of permissions) {
     SpecialPowers.removePermission(per, document);
   }
   SpecialPowers.clearUserPref("dom.mozSettings.enabled");
   finish();
 }
 
-setRadioEnabled(false, function() {
-  sendToEmulator("gsm clear", function(result) {
-    is(result[0], "OK");
+startTest(function() {
+  setRadioEnabled(false, function() {
+    emulator.run("gsm clear", function(result) {
+      is(result[0], "OK");
 
-    waitFor(function() {
-      dial("0912345678");
-    }, function() {
-      return telephony.calls.length === 0;
+      waitFor(function() {
+        dial("0912345678");
+      }, function() {
+        return telephony.calls.length === 0;
+      });
     });
   });
 });
--- a/dom/telephony/test/marionette/test_outgoing_reject.js
+++ b/dom/telephony/test/marionette/test_outgoing_reject.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let number = "5555552368";
 let outgoing;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -75,17 +76,17 @@ function dial() {
   is(telephony.calls.length, 1);
   is(telephony.calls[0], outgoing);
 
   outgoing.onalerting = function onalerting(event) {
     log("Received 'onalerting' call event.");
     is(outgoing, event.call);
     is(outgoing.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + number + " : ringing");
       is(result[1], "OK");
       reject();
     });
   };
 }
 
@@ -103,28 +104,30 @@ function reject() {
 
     // Wait for emulator to catch up before continuing
     waitFor(verifyCallList,function() {
       return(rcvdEmulatorCallback);
     });
   };
 
   let rcvdEmulatorCallback = false;
-  runEmulatorCmd("gsm cancel " + number, function(result) {
+  emulator.run("gsm cancel " + number, function(result) {
     is(result[0], "OK", "emulator callback");
     rcvdEmulatorCallback = true;
   });
-};
+}
 
 function verifyCallList(){
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Call list is now: " + result);
     is(result[0], "OK");
     cleanUp();
   });
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_outgoing_remote_hangup_held.js
+++ b/dom/telephony/test/marionette/test_outgoing_remote_hangup_held.js
@@ -5,63 +5,63 @@ MARIONETTE_TIMEOUT = 60000;
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let outNumber = "5555551111";
 let outgoingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -76,17 +76,17 @@ function dial() {
   is(telephony.calls[0], outgoingCall);
 
   outgoingCall.onalerting = function onalerting(event) {
     log("Received 'alerting' call event.");
 
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : ringing");
       is(result[1], "OK");
       answer();
     });
   };
 }
 
@@ -97,25 +97,25 @@ function answer() {
 
   outgoingCall.onconnected = function onconnected(event) {
     log("Received 'connected' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
 
     is(outgoingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "OK");
       hold();
     });
   };
-  runEmulatorCmd("gsm accept " + outNumber);
-};
+  emulator.run("gsm accept " + outNumber);
+}
 
 function hold() {
   log("Holding the outgoing call.");
 
   outgoingCall.onholding = function onholding(event) {
     log("Received 'holding' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "holding");
@@ -127,47 +127,49 @@ function hold() {
     log("Received 'held' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "held");
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], outgoingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "OK");
       hangUp();
     });
   };
   outgoingCall.hold();
 }
 
 function hangUp() {
   log("Hanging up the outgoing call (remotely).");
 
   // We get no 'disconnecting' event when remote party hangs-up the call
-  
+
   outgoingCall.ondisconnected = function ondisconnected(event) {
     log("Received 'disconnected' call event.");
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnected");
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
-  runEmulatorCmd("gsm cancel " + outNumber);
+  emulator.run("gsm cancel " + outNumber);
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_redundant_operations.js
+++ b/dom/telephony/test/marionette/test_redundant_operations.js
@@ -1,67 +1,68 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let inNumber = "5555551111";
 let incomingCall;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         simulateIncoming();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     simulateIncoming();
   }
 }
 
 function simulateIncoming() {
   log("Simulating an incoming call.");
@@ -71,67 +72,67 @@ function simulateIncoming() {
     incomingCall = event.call;
     ok(incomingCall);
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : incoming");
       is(result[1], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for incoming call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for incoming call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       answerAlreadyConnected();
     });
   };
   incomingCall.answer();
 }
 
 function answerAlreadyConnected() {
   log("Attempting to answer already connected call, should be ignored.");
 
   incomingCall.onconnecting = function onconnectingErr(event) {
     log("Received 'connecting' call event, but should not have.");
     ok(false, "Received 'connecting' event when answered already active call");
-  }
+  };
 
   incomingCall.onconnected = function onconnectedErr(event) {
     log("Received 'connected' call event, but should not have.");
     ok(false, "Received 'connected' event when answered already active call");
-  }
+  };
 
   incomingCall.answer();
 
   is(incomingCall.state, "connected");
   is(telephony.calls.length, 1);
   is(telephony.calls[0], incomingCall);
   is(incomingCall, telephony.active);
   hold();
@@ -153,38 +154,38 @@ function hold() {
     is(incomingCall, event.call);
     is(incomingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
       is(result[1], "OK");
       holdAlreadyHeld();
     });
   };
   incomingCall.hold();
 }
 
 function holdAlreadyHeld() {
   log("Attempting to hold an already held call, should be ignored.");
 
   incomingCall.onholding = function onholding(event) {
     log("Received 'holding' call event, but should not have.");
     ok(false, "Received 'holding' event when held an already held call");
-  }
+  };
 
   incomingCall.onheld = function onheldErr(event) {
     log("Received 'held' call event, but should not have.");
     ok(false, "Received 'held' event when held an already held call");
-  }
+  };
 
   incomingCall.hold();
 
   is(incomingCall.state, "held");
   is(telephony.active, null);
   is(telephony.calls.length, 1);
   is(telephony.calls[0], incomingCall);
 
@@ -192,22 +193,22 @@ function holdAlreadyHeld() {
 }
 
 function answerHeld() {
   log("Attempting to answer a held call, should be ignored.");
 
   incomingCall.onconnecting = function onconnectingErr(event) {
     log("Received 'connecting' call event, but should not have.");
     ok(false, "Received 'connecting' event when answered a held call");
-  }
+  };
 
   incomingCall.onconnected = function onconnectedErr(event) {
     log("Received 'connected' call event, but should not have.");
     ok(false, "Received 'connected' event when answered a held call");
-  }
+  };
 
   incomingCall.answer();
 
   is(incomingCall.state, "held");
   is(telephony.active, null);
   is(telephony.calls.length, 1);
   is(telephony.calls[0], incomingCall);
 
@@ -230,38 +231,38 @@ function resume() {
     is(incomingCall, event.call);
     is(incomingCall.state, "connected");
     ok(gotResuming);
 
     is(incomingCall, telephony.active);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : active");
       is(result[1], "OK");
       resumeNonHeld();
     });
   };
   incomingCall.resume();
 }
 
 function resumeNonHeld() {
   log("Attempting to resume non-held call, should be ignored.");
 
   incomingCall.onresuming = function onresumingErr(event) {
     log("Received 'resuming' call event, but should not have.");
     ok(false, "Received 'resuming' event when resumed non-held call");
-  }
+  };
 
   incomingCall.onconnected = function onconnectedErr(event) {
     log("Received 'connected' call event, but should not have.");
     ok(false, "Received 'connected' event when resumed non-held call");
-  }
+  };
 
   incomingCall.resume();
 
   is(incomingCall.state, "connected");
   is(telephony.calls.length, 1);
   is(telephony.calls[0], incomingCall);
   is(incomingCall, telephony.active);
   hangUp();
@@ -282,105 +283,107 @@ function hangUp() {
     log("Received 'disconnected' call event.");
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       answerDisconnected();
     });
   };
   incomingCall.hangUp();
 }
 
 function answerDisconnected() {
   log("Attempting to answer disconnected call, should be ignored.");
 
   incomingCall.onconnecting = function onconnectingErr(event) {
     log("Received 'connecting' call event, but should not have.");
     ok(false, "Received 'connecting' event when answered disconnected call");
-  }
+  };
 
   incomingCall.onconnected = function onconnectedErr(event) {
     log("Received 'connected' call event, but should not have.");
     ok(false, "Received 'connected' event when answered disconnected call");
-  }
+  };
 
   incomingCall.answer();
 
   is(telephony.active, null);
   is(telephony.calls.length, 0);
   holdDisconnected();
 }
 
 function holdDisconnected() {
   log("Attempting to hold disconnected call, should be ignored.");
 
   incomingCall.onholding = function onholdingErr(event) {
     log("Received 'holding' call event, but should not have.");
     ok(false, "Received 'holding' event when held a disconnected call");
-  }
+  };
 
   incomingCall.onheld = function onheldErr(event) {
     log("Received 'held' call event, but should not have.");
     ok(false, "Received 'held' event when held a disconnected call");
-  }
+  };
 
   incomingCall.hold();
 
   is(telephony.active, null);
   is(telephony.calls.length, 0);
   resumeDisconnected();
 }
 
 function resumeDisconnected() {
   log("Attempting to resume disconnected call, should be ignored.");
 
   incomingCall.onresuming = function onresumingErr(event) {
     log("Received 'resuming' call event, but should not have.");
     ok(false, "Received 'resuming' event when resumed disconnected call");
-  }
+  };
 
   incomingCall.onconnected = function onconnectedErr(event) {
     log("Received 'connected' call event, but should not have.");
     ok(false, "Received 'connected' event when resumed disconnected call");
-  }
+  };
 
   incomingCall.resume();
 
   is(telephony.active, null);
   is(telephony.calls.length, 0);
   hangUpNonConnected();
 }
 
 function hangUpNonConnected() {
   log("Attempting to hang-up disconnected call, should be ignored.");
 
   incomingCall.ondisconnecting = function ondisconnectingErr(event) {
     log("Received 'disconnecting' call event, but should not have.");
     ok(false, "Received 'disconnecting' event when hung-up non-active call");
-  }
+  };
 
   incomingCall.ondisconnected = function ondisconnectedErr(event) {
     log("Received 'disconnected' call event, but should not have.");
     ok(false, "Received 'disconnected' event when hung-up non-active call");
-  }
+  };
 
   incomingCall.hangUp();
 
   is(telephony.active, null);
   is(telephony.calls.length, 0);
   cleanUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});
--- a/dom/telephony/test/marionette/test_swap_held_and_active.js
+++ b/dom/telephony/test/marionette/test_swap_held_and_active.js
@@ -1,72 +1,73 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
 
 SpecialPowers.addPermission("telephony", true, document);
 
 let telephony = window.navigator.mozTelephony;
 let outNumber = "5555551111";
 let inNumber = "5555552222";
 let outgoingCall;
 let incomingCall;
 let gotOriginalConnected = false;
 let gotHeld = false;
 let gotConnected = false;
 
 function getExistingCalls() {
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
     if (result[0] == "OK") {
       verifyInitialState(false);
     } else {
       cancelExistingCalls(result);
-    };
+    }
   });
 }
 
 function cancelExistingCalls(callList) {
   if (callList.length && callList[0] != "OK") {
     // Existing calls remain; get rid of the next one in the list
     nextCall = callList.shift().split(/\s+/)[2].trim();
     log("Cancelling existing call '" + nextCall +"'");
-    runEmulatorCmd("gsm cancel " + nextCall, function(result) {
+    emulator.run("gsm cancel " + nextCall, function(result) {
       if (result[0] == "OK") {
         cancelExistingCalls(callList);
       } else {
         log("Failed to cancel existing call");
         cleanUp();
-      };
+      }
     });
   } else {
     // No more calls in the list; give time for emulator to catch up
     waitFor(verifyInitialState, function() {
-      return (telephony.calls.length == 0);
+      return (telephony.calls.length === 0);
     });
-  };
+  }
 }
 
 function verifyInitialState(confirmNoCalls = true) {
   log("Verifying initial state.");
   ok(telephony);
   is(telephony.active, null);
   ok(telephony.calls);
   is(telephony.calls.length, 0);
   if (confirmNoCalls) {
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
     log("Initial call list: " + result);
       is(result[0], "OK");
       if (result[0] == "OK") {
         dial();
       } else {
         log("Call exists from a previous test, failing out.");
         cleanUp();
-      };
+      }
     });
   } else {
     dial();
   }
 }
 
 function dial() {
   log("Make an outgoing call.");
@@ -79,52 +80,52 @@ function dial() {
     log("Received 'alerting' call event.");
 
     is(outgoingCall, event.call);
     is(outgoingCall.state, "alerting");
     is(outgoingCall, telephony.active);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], outgoingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : ringing");
       is(result[1], "OK");
       answer();
     });
-  };  
+  };
 }
 
 function answer() {
   log("Answering the outgoing call.");
 
   // We get no "connecting" event when the remote party answers the call.
   outgoingCall.onconnected = function onconnectedOut(event) {
     log("Received 'connected' call event for the original outgoing call.");
 
     is(outgoingCall, event.call);
     is(outgoingCall.state, "connected");
     is(outgoingCall, telephony.active);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : active");
       is(result[1], "OK");
 
       if(!gotOriginalConnected){
         gotOriginalConnected = true;
         holdCall();
       } else {
         // Received connected event for original call multiple times (fail)
         ok(false,
            "Received 'connected' event for original call multiple times.");
       }
     });
   };
-  runEmulatorCmd("gsm accept " + outNumber);
+  emulator.run("gsm accept " + outNumber);
 }
 
 function holdCall() {
   log("Putting the original (outgoing) call on hold.");
 
   let gotHolding = false;
   outgoingCall.onholding = function onholding(event) {
     log("Received 'holding' call event");
@@ -138,17 +139,17 @@ function holdCall() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "held");
     ok(gotHolding);
 
     is(telephony.active, null);
     is(telephony.calls.length, 1);
     is(telephony.calls[0], outgoingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "OK");
       simulateIncoming();
     });
   };
   outgoingCall.hold();
 }
@@ -164,33 +165,33 @@ function simulateIncoming() {
     is(incomingCall.number, inNumber);
     is(incomingCall.state, "incoming");
 
     // Should be two calls now
     is(telephony.calls.length, 2);
     is(telephony.calls[0], outgoingCall);
     is(telephony.calls[1], incomingCall);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "inbound from " + inNumber + " : incoming");
       is(result[2], "OK");
       answerIncoming();
     });
   };
-  runEmulatorCmd("gsm call " + inNumber);
+  emulator.run("gsm call " + inNumber);
 }
 
 // Answer incoming call; original outgoing call should be held
 function answerIncoming() {
   log("Answering the incoming call.");
 
   let gotConnecting = false;
-  incomingCall.onconnecting = function onconnectingIn(event) { 
+  incomingCall.onconnecting = function onconnectingIn(event) {
     log("Received 'connecting' call event for incoming/2nd call.");
     is(incomingCall, event.call);
     is(incomingCall.state, "connecting");
     gotConnecting = true;
   };
 
   incomingCall.onconnected = function onconnectedIn(event) {
     log("Received 'connected' call event for incoming/2nd call.");
@@ -198,17 +199,17 @@ function answerIncoming() {
     ok(gotConnecting);
 
     is(incomingCall, telephony.active);
 
     // Original outbound call now held, incoming call active
     is(outgoingCall.state, "held");
     is(incomingCall.state, "connected");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "outbound to  " + outNumber + " : held");
       is(result[1], "inbound from " + inNumber + " : active");
       is(result[2], "OK");
       swapCalls();
     });
   };
   incomingCall.answer();
@@ -244,25 +245,25 @@ function swapCalls() {
     is(outgoingCall, telephony.active);
     is(telephony.calls.length, 2);
     is(telephony.calls[0], outgoingCall);
     is(telephony.calls[1], incomingCall);
     gotConnected = true;
 
     if (gotHeld && gotConnected) { verifySwap(); }
   };
-  outgoingCall.resume();     
+  outgoingCall.resume();
 }
 
 function verifySwap() {
   // Call status reflects swap
   is(outgoingCall.state, "connected");
   is(incomingCall.state, "held");
 
-  runEmulatorCmd("gsm list", function(result) {
+  emulator.run("gsm list", function(result) {
     log("Call list is now: " + result);
     is(result[0], "outbound to  " + outNumber + " : active");
     is(result[1], "inbound from " + inNumber + " : held");
 
     // Begin hang-up
     hangUpOutgoing();
   });
 }
@@ -284,17 +285,17 @@ function hangUpOutgoing() {
     is(outgoingCall, event.call);
     is(outgoingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Back to one call now
     is(telephony.calls.length, 1);
     is(incomingCall.state, "held");
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "inbound from " + inNumber + " : held");
       is(result[1], "OK");
       hangUpIncoming();
     });
   };
   outgoingCall.hangUp();
 }
@@ -316,25 +317,27 @@ function hangUpIncoming() {
     is(incomingCall, event.call);
     is(incomingCall.state, "disconnected");
     ok(gotDisconnecting);
 
     // Zero calls left
     is(telephony.active, null);
     is(telephony.calls.length, 0);
 
-    runEmulatorCmd("gsm list", function(result) {
+    emulator.run("gsm list", function(result) {
       log("Call list is now: " + result);
       is(result[0], "OK");
       cleanUp();
     });
   };
   incomingCall.hangUp();
 }
 
 function cleanUp() {
   telephony.onincoming = null;
   SpecialPowers.removePermission("telephony", document);
   finish();
 }
 
 // Start the test
-getExistingCalls();
+startTest(function() {
+  getExistingCalls();
+});