Bug 1475004 - Enable ESLint for dom/presentation - manual fixes. r=mccr8
authorMark Banner <standard8@mozilla.com>
Tue, 03 Jul 2018 16:25:27 +0100
changeset 429897 ee957e55c91e5a68849eef53e9a4bfacdf9d1a12
parent 429896 0639e328afdecd64c1ac3c7f640bbf6dd3b19f8f
child 429898 ebd853eb196e0fe92e03875be88c8c5a14c2ed08
push id106015
push usernbeleuzu@mozilla.com
push dateThu, 02 Aug 2018 22:36:07 +0000
treeherdermozilla-inbound@055397065a0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1475004
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1475004 - Enable ESLint for dom/presentation - manual fixes. r=mccr8 MozReview-Commit-ID: 8UGertZYKk
.eslintignore
dom/presentation/provider/AndroidCastDeviceProvider.js
dom/presentation/provider/PresentationControlService.js
dom/presentation/tests/mochitest/.eslintrc.js
dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js
dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
dom/presentation/tests/mochitest/PresentationSessionChromeScript1UA.js
dom/presentation/tests/mochitest/PresentationSessionFrameScript.js
dom/presentation/tests/mochitest/file_presentation_non_receiver_inner_iframe.html
dom/presentation/tests/mochitest/file_presentation_receiver.html
dom/presentation/tests/mochitest/file_presentation_reconnect.html
dom/presentation/tests/mochitest/test_presentation_1ua_connection_wentaway.js
dom/presentation/tests/mochitest/test_presentation_1ua_sender_and_receiver.js
dom/presentation/tests/mochitest/test_presentation_availability_iframe.html
dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
dom/presentation/tests/mochitest/test_presentation_dc_receiver.html
dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html
dom/presentation/tests/mochitest/test_presentation_fingerprinting_resistance.html
dom/presentation/tests/mochitest/test_presentation_receiver_auxiliary_navigation.js
dom/presentation/tests/mochitest/test_presentation_tcp_receiver.html
dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_error.html
dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_timeout.html
dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_unknown_content_type.js
dom/presentation/tests/mochitest/test_presentation_tcp_receiver_oop.html
dom/presentation/tests/mochitest/test_presentation_terminate.js
dom/presentation/tests/mochitest/test_presentation_terminate_establish_connection_error.js
dom/presentation/tests/xpcshell/test_multicast_dns_device_provider.js
dom/presentation/tests/xpcshell/test_presentation_device_manager.js
dom/presentation/tests/xpcshell/test_presentation_state_machine.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -224,20 +224,16 @@ dom/notification/test/unit/**
 dom/notification/test/mochitest/**
 dom/offline/**
 dom/payments/**
 dom/performance/**
 dom/permission/**
 dom/plugins/test/mochitest/**
 dom/plugins/test/unit/**
 dom/power/**
-dom/presentation/Presentation*.js
-dom/presentation/provider/**
-dom/presentation/tests/mochitest/**
-dom/presentation/tests/xpcshell/**
 dom/promise/**
 dom/push/**
 dom/quota/**
 dom/res/**
 dom/secureelement/**
 dom/security/test/contentverifier/**
 dom/security/test/cors/**
 dom/security/test/csp/**
--- a/dom/presentation/provider/AndroidCastDeviceProvider.js
+++ b/dom/presentation/provider/AndroidCastDeviceProvider.js
@@ -1,22 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-/* jshint esnext:true, globalstrict:true, moz:true, undef:true, unused:true */
-/* globals Components, dump */
 "use strict";
 
-// globals XPCOMUtils
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-// globals Services
 ChromeUtils.import("resource://gre/modules/Services.jsm");
-// globals EventDispatcher
 ChromeUtils.import("resource://gre/modules/Messaging.jsm");
 
 function log(str) {
   // dump("-*- AndroidCastDeviceProvider -*-: " + str + "\n");
 }
 
 // Helper function: transfer nsIPresentationChannelDescription to json
 function descriptionToString(aDescription) {
@@ -323,19 +318,17 @@ ChromecastRemoteDisplayDevice.prototype 
     // Disconnect from Chromecast.
     EventDispatcher.instance.sendRequestForResult({
       type: TOPIC_ANDROID_CAST_DEVICE_STOP,
       id:   this.id
     });
   },
 
   isRequestedUrlSupported: function CRDD_isRequestedUrlSupported(aUrl) {
-    let url = Cc["@mozilla.org/network/io-service;1"]
-                .getService(Ci.nsIIOService)
-                .newURI(aUrl);
+    let url = Services.io.newURI(aUrl);
     return url.scheme == "http" || url.scheme == "https";
   },
 
   // nsIPresentationLocalDevice
   get windowId() { return this._id; },
 
   // nsIObserver
   observe: function CRDD_observe(aSubject, aTopic, aData) {
--- a/dom/presentation/provider/PresentationControlService.js
+++ b/dom/presentation/provider/PresentationControlService.js
@@ -1,29 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-/* jshint esnext:true, globalstrict:true, moz:true, undef:true, unused:true */
-/* globals Components, dump */
 "use strict";
 
-/* globals XPCOMUtils */
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-/* globals Services */
 ChromeUtils.import("resource://gre/modules/Services.jsm");
-/* globals NetUtil */
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
-/* globals setTimeout, clearTimeout */
 ChromeUtils.import("resource://gre/modules/Timer.jsm");
 
-/* globals ControllerStateMachine */
-ChromeUtils.defineModuleGetter(this, "ControllerStateMachine", // jshint ignore:line
+ChromeUtils.defineModuleGetter(this, "ControllerStateMachine",
                                "resource://gre/modules/presentation/ControllerStateMachine.jsm");
-/* global ReceiverStateMachine */
-ChromeUtils.defineModuleGetter(this, "ReceiverStateMachine", // jshint ignore:line
+ChromeUtils.defineModuleGetter(this, "ReceiverStateMachine",
                                "resource://gre/modules/presentation/ReceiverStateMachine.jsm");
 
 const kProtocolVersion = 1; // need to review isCompatibleServer while fiddling the version number.
 const kLocalCertName = "presentation";
 
 const DEBUG = Services.prefs.getBoolPref("dom.presentation.tcp_server.debug");
 function log(aMsg) {
   dump("-*- PresentationControlService.js: " + aMsg + "\n");
@@ -854,17 +846,17 @@ TCPControlChannel.prototype = {
       }, kDisconnectTimeout);
     }
   },
 
   reconnect(aPresentationId, aUrl) {
     DEBUG && log("TCPControlChannel - reconnect with role: " +
                  this._direction); // jshint ignore:line
     if (this._direction != "sender") {
-      return Cr.NS_ERROR_FAILURE;
+      throw Cr.NS_ERROR_FAILURE;
     }
 
     this._stateMachine.reconnect(aPresentationId, aUrl);
   },
 
   // callback from state machine
   sendCommand(command) {
     this._outgoingMsgs.push(command);
new file mode 100644
--- /dev/null
+++ b/dom/presentation/tests/mochitest/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "plugin:mozilla/mochitest-test"
+  ]
+};
--- a/dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js
+++ b/dom/presentation/tests/mochitest/PresentationDeviceInfoChromeScript.js
@@ -1,14 +1,16 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
-const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+/* eslint-env mozilla/frame-script */
+
+const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {});
 
 const manager = Cc["@mozilla.org/presentation-device/manager;1"]
                   .getService(Ci.nsIPresentationDeviceManager);
 
 var testProvider = {
   QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceProvider]),
   forceDiscovery() {
     sendAsyncMessage("force-discovery");
--- a/dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
+++ b/dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
@@ -1,13 +1,15 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
+/* eslint-env mozilla/frame-script */
+
 const Cm = Components.manager;
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/Timer.jsm");
 
 const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
                       .getService(Ci.nsIUUIDGenerator);
@@ -119,21 +121,21 @@ const mockedControlChannel = {
     if (answer.type == Ci.nsIPresentationChannelDescription.TYPE_TCP) {
       this._listener.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportReady();
     }
   },
   _isValidSDP(aSDP) {
     var isValid = false;
     if (aSDP.type == Ci.nsIPresentationChannelDescription.TYPE_TCP) {
       try {
-        var addresses = aSDP.tcpAddress;
-        if (addresses.length > 0) {
-          for (var i = 0; i < addresses.length; i++) {
+        var sdpAddresses = aSDP.tcpAddress;
+        if (sdpAddresses.length > 0) {
+          for (var i = 0; i < sdpAddresses.length; i++) {
             // Ensure CString addresses are used. Otherwise, an error will be thrown.
-            addresses.queryElementAt(i, Ci.nsISupportsCString);
+            sdpAddresses.queryElementAt(i, Ci.nsISupportsCString);
           }
 
           isValid = true;
         }
       } catch (e) {
         isValid = false;
       }
     } else if (aSDP.type == Ci.nsIPresentationChannelDescription.TYPE_DATACHANNEL) {
@@ -250,21 +252,21 @@ const mockedSessionTransport = {
     setTimeout(() => {
       this.simulateTransportReady();
     }, 0);
   },
   buildTCPReceiverTransport(description, listener) {
     this._listener = listener;
     this._role = Ci.nsIPresentationService.ROLE_RECEIVER;
 
-    var addresses = description.QueryInterface(Ci.nsIPresentationChannelDescription).tcpAddress;
+    var tcpAddresses = description.QueryInterface(Ci.nsIPresentationChannelDescription).tcpAddress;
     this._selfAddress = {
       QueryInterface: ChromeUtils.generateQI([Ci.nsINetAddr]),
-      address: (addresses.length > 0) ?
-                addresses.queryElementAt(0, Ci.nsISupportsCString).data : "",
+      address: (tcpAddresses.length > 0) ?
+                tcpAddresses.queryElementAt(0, Ci.nsISupportsCString).data : "",
       port: description.QueryInterface(Ci.nsIPresentationChannelDescription).tcpPort,
     };
 
     setTimeout(() => {
       this._listener.onSessionTransport(this);
       this._listener = null;
     }, 0);
   },
@@ -459,15 +461,13 @@ addMessageListener("save-control-channel
   controlChannelListener = mockedControlChannel.listener;
 });
 
 addMessageListener("restore-control-channel-listener", function(message) {
   mockedControlChannel.listener = controlChannelListener;
   controlChannelListener = null;
 });
 
-var obs = Cc["@mozilla.org/observer-service;1"]
-          .getService(Ci.nsIObserverService);
-obs.addObserver(function observer(aSubject, aTopic, aData) {
-  obs.removeObserver(observer, aTopic);
+Services.obs.addObserver(function observer(aSubject, aTopic, aData) {
+  Services.obs.removeObserver(observer, aTopic);
 
   requestPromise = aSubject;
 }, "setup-request-promise");
--- a/dom/presentation/tests/mochitest/PresentationSessionChromeScript1UA.js
+++ b/dom/presentation/tests/mochitest/PresentationSessionChromeScript1UA.js
@@ -1,15 +1,17 @@
 /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+/* eslint-env mozilla/frame-script */
+
 const Cm = Components.manager;
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
                       .getService(Ci.nsIUUIDGenerator);
 
@@ -246,18 +248,16 @@ function initMockAndListener() {
 
     return { contractId,
              mockClassId,
              mockFactory,
              originalClassId,
              originalFactory };
   }
   // Register mock factories.
-  const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
-                        .getService(Ci.nsIUUIDGenerator);
   originalFactoryData.push(registerMockFactory("@mozilla.org/presentation-device/prompt;1",
                                                uuidGenerator.generateUUID(),
                                                mockDevicePrompt));
   originalFactoryData.push(registerMockFactory("@mozilla.org/presentation/requestuiglue;1",
                                                uuidGenerator.generateUUID(),
                                                mockRequestUIGlue));
 
   addMessageListener("trigger-device-add", function() {
@@ -321,20 +321,19 @@ function initMockAndListener() {
   // Used to call sendAsyncMessage in chrome script from receiver.
   addMessageListener("forward-command", function(command_data) {
     let command = JSON.parse(command_data);
     sendAsyncMessage(command.name, command.data);
   });
 
   addMessageListener("teardown", teardown);
 
-  var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-  obs.addObserver(function setupRequestPromiseHandler(aSubject, aTopic, aData) {
+  Services.obs.addObserver(function setupRequestPromiseHandler(aSubject, aTopic, aData) {
     debug("Got observer: setup-request-promise");
-    obs.removeObserver(setupRequestPromiseHandler, aTopic);
+    Services.obs.removeObserver(setupRequestPromiseHandler, aTopic);
     mockRequestUIGlue.promise = aSubject;
     sendAsyncMessage("promise-setup-ready");
   }, "setup-request-promise");
 }
 
 function teardown() {
 
   function registerOriginalFactory(contractId, mockedClassId, mockedFactory, originalClassId, originalFactory) {
--- a/dom/presentation/tests/mochitest/PresentationSessionFrameScript.js
+++ b/dom/presentation/tests/mochitest/PresentationSessionFrameScript.js
@@ -1,12 +1,14 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+/* eslint-env mozilla/frame-script */
+
 function loadPrivilegedScriptTest() {
   /**
    * The script is loaded as
    * (a) a privileged script in content process for dc_sender.html
    * (b) a frame script in the remote iframe process for dc_receiver_oop.html
    * |type port == "undefined"| indicates the script is load by
    * |loadPrivilegedScript| which is the first case.
    */
@@ -29,46 +31,50 @@ function loadPrivilegedScriptTest() {
       var type = e.data.type;
       if (!handlers.hasOwnProperty(type)) {
         return;
       }
       var args = [e];
       handlers[type].forEach(handler => handler.apply(null, args));
     };
     var handlers = {};
+    /* eslint-disable-next-line no-native-reassign */
     addMessageListener = function(message, handler) {
       if (handlers.hasOwnProperty(message)) {
         handlers[message].push(handler);
       } else {
         handlers[message] = [handler];
       }
     };
+    /* eslint-disable-next-line no-native-reassign */
     removeMessageListener = function(message, handler) {
       if (!handler || !handlers.hasOwnProperty(message)) {
         return;
       }
       var index = handlers[message].indexOf(handler);
       if (index != -1) {
         handlers[message].splice(index, 1);
       }
     };
   }
 
   const Cm = Components.manager;
 
   const mockedChannelDescription = {
+    /* eslint-disable-next-line mozilla/use-chromeutils-generateqi */
     QueryInterface(iid) {
       const interfaces = [Ci.nsIPresentationChannelDescription];
 
       if (!interfaces.some(v => iid.equals(v))) {
           throw Cr.NS_ERROR_NO_INTERFACE;
       }
       return this;
     },
     get type() {
+      /* global Services */
       if (Services.prefs.getBoolPref("dom.presentation.session_transport.data_channel.enable")) {
         return Ci.nsIPresentationChannelDescription.TYPE_DATACHANNEL;
       }
       return Ci.nsIPresentationChannelDescription.TYPE_TCP;
     },
     get dataChannelSDP() {
       return "test-sdp";
     }
@@ -78,16 +84,17 @@ function loadPrivilegedScriptTest() {
     let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     timer.initWithCallback({ notify: callback },
                            delay,
                            Ci.nsITimer.TYPE_ONE_SHOT);
     return timer;
   }
 
   const mockedSessionTransport = {
+    /* eslint-disable-next-line mozilla/use-chromeutils-generateqi */
     QueryInterface(iid) {
         const interfaces = [Ci.nsIPresentationSessionTransport,
                             Ci.nsIPresentationDataChannelSessionTransportBuilder,
                             Ci.nsIFactory];
 
         if (!interfaces.some(v => iid.equals(v))) {
             throw Cr.NS_ERROR_NO_INTERFACE;
         }
--- a/dom/presentation/tests/mochitest/file_presentation_non_receiver_inner_iframe.html
+++ b/dom/presentation/tests/mochitest/file_presentation_non_receiver_inner_iframe.html
@@ -5,18 +5,18 @@
   <title>Test for B2G PresentationReceiver on a non-receiver inner iframe of the receiver page at receiver side</title>
 </head>
 <body onload="testConnectionAvailable()">
 <div id="content"></div>
 <script type="application/javascript">
 
 "use strict";
 
-function ok(a, msg) {
-  alert((a ? "OK " : "KO ") + msg);
+function is(a, b, msg) {
+  alert((a === b ? "OK " : "KO ") + msg);
 }
 
 function testConnectionAvailable() {
   return new Promise(function(aResolve, aReject) {
     is(navigator.presentation.receiver, null, "navigator.presentation.receiver shouldn't be available in inner iframes with different origins from receiving pages.");
     aResolve();
   });
 }
--- a/dom/presentation/tests/mochitest/file_presentation_receiver.html
+++ b/dom/presentation/tests/mochitest/file_presentation_receiver.html
@@ -80,17 +80,17 @@ function testConnectionUnavailableDiffOr
 
     aResolve();
   });
 }
 
 function testConnectionListSameObject() {
   return new Promise(function(aResolve, aReject) {
     is(navigator.presentation.receiver.connectionList, navigator.presentation.receiver.connectionList, "The promise should be the same object.");
-    var promise = navigator.presentation.receiver.connectionList.then(
+    navigator.presentation.receiver.connectionList.then(
       function(aList) {
         is(connection, aList.connections[0], "The connection from list and the one from |connectionavailable| event should be the same.");
         aResolve();
       },
       function(aError) {
         ok(false, "Error occurred when getting the connection list: " + aError);
         finish();
         aReject();
--- a/dom/presentation/tests/mochitest/file_presentation_reconnect.html
+++ b/dom/presentation/tests/mochitest/file_presentation_reconnect.html
@@ -50,17 +50,16 @@ function testStartRequest() {
         connection.onconnect = function() {
           connection.onconnect = null;
           is(connection.state, "connected", "Connection should be connected.");
           aResolve();
         };
       },
       function(aError) {
         ok(false, "Error occurred when establishing a connection: " + aError);
-        teardown();
         aReject();
       }
     );
   });
 }
 
 function testCloseConnection() {
   return new Promise(function(aResolve, aReject) {
--- a/dom/presentation/tests/mochitest/test_presentation_1ua_connection_wentaway.js
+++ b/dom/presentation/tests/mochitest/test_presentation_1ua_connection_wentaway.js
@@ -60,18 +60,17 @@ function setup() {
       }
     });
 
     var promise = new Promise(function(aResolve, aReject) {
       document.body.appendChild(receiverIframe);
       aResolve(receiverIframe);
     });
 
-    var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-                           .getService(SpecialPowers.Ci.nsIObserverService);
+    var obs = SpecialPowers.Services.obs;
     obs.notifyObservers(promise, "setup-request-promise");
   });
 
   gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
     debug("Got message: promise-setup-ready");
     gScript.removeMessageListener("promise-setup-ready",
                                   promiseSetupReadyHandler);
     gScript.sendAsyncMessage("trigger-on-session-request", receiverUrl);
--- a/dom/presentation/tests/mochitest/test_presentation_1ua_sender_and_receiver.js
+++ b/dom/presentation/tests/mochitest/test_presentation_1ua_sender_and_receiver.js
@@ -69,18 +69,17 @@ function setup() {
       }
     });
 
     var promise = new Promise(function(aResolve, aReject) {
       document.body.appendChild(receiverIframe);
       aResolve(receiverIframe);
     });
 
-    var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-                           .getService(SpecialPowers.Ci.nsIObserverService);
+    var obs = SpecialPowers.Services.obs;
     obs.notifyObservers(promise, "setup-request-promise");
   });
 
   gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
     debug("Got message: promise-setup-ready");
     gScript.removeMessageListener("promise-setup-ready", promiseSetupReadyHandler);
     gScript.sendAsyncMessage("trigger-on-session-request", receiverUrl);
   });
--- a/dom/presentation/tests/mochitest/test_presentation_availability_iframe.html
+++ b/dom/presentation/tests/mochitest/test_presentation_availability_iframe.html
@@ -82,36 +82,36 @@ function testOnChangeEvent() {
       is(availability.value, false, "Should have no available device after device removed");
       aResolve();
     };
     gScript.sendAsyncMessage("trigger-device-remove");
   });
 }
 
 function testConsecutiveGetAvailability() {
-  let request = new PresentationRequest("https://example.org");
+  let presRequest = new PresentationRequest("https://example.org");
   let firstAvailabilityResolved = false;
   return Promise.all([
-    request.getAvailability().then(function() {
+    presRequest.getAvailability().then(function() {
       firstAvailabilityResolved = true;
     }),
-    request.getAvailability().then(function() {
+    presRequest.getAvailability().then(function() {
       ok(firstAvailabilityResolved, "getAvailability() should be resolved in sequence");
     })
   ]).catch(function(aError) {
     ok(false, "Error occurred when getting availability: " + aError);
     teardown();
   });
 }
 
 function testUnsupportedDeviceAvailability() {
   return Promise.race([
     new Promise(function(aResolve, aReject) {
-      let request = new PresentationRequest("https://test.com");
-      request.getAvailability().then(function(aAvailability) {
+      let presRequest = new PresentationRequest("https://test.com");
+      presRequest.getAvailability().then(function(aAvailability) {
         availability = aAvailability;
         aAvailability.onchange = function() {
           availability.onchange = null;
           ok(false, "Should not get onchange event.");
           teardown();
         };
       });
       gScript.sendAsyncMessage("trigger-add-unsupport-url-device");
--- a/dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
+++ b/dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
@@ -25,18 +25,18 @@ const loadingTimeoutPref = "presentation
 var clientBuilder;
 var serverBuilder;
 var clientTransport;
 var serverTransport;
 
 const clientMessage = "Client Message";
 const serverMessage = "Server Message";
 
-const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
+const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {});
+const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm", {});
 
 var isClientReady = false;
 var isServerReady = false;
 var isClientClosed = false;
 var isServerClosed = false;
 
 var gResolve;
 var gReject;
--- a/dom/presentation/tests/mochitest/test_presentation_dc_receiver.html
+++ b/dom/presentation/tests/mochitest/test_presentation_dc_receiver.html
@@ -15,18 +15,17 @@
 <pre id="test"></pre>
 <script type="application/javascript">
 
 "use strict";
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
 var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver.html");
 
-var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-          .getService(SpecialPowers.Ci.nsIObserverService);
+var obs = SpecialPowers.Services.obs;
 
 function setup() {
   return new Promise(function(aResolve, aReject) {
     gScript.sendAsyncMessage("trigger-device-add");
 
     var iframe = document.createElement("iframe");
     iframe.setAttribute("src", receiverUrl);
     iframe.setAttribute("mozbrowser", "true");
@@ -46,20 +45,20 @@ function setup() {
         gScript.sendAsyncMessage(command.name, command.data);
       } else if (/^DONE$/.exec(message)) {
         iframe.removeEventListener("mozbrowsershowmodalprompt",
                                    receiverListener);
         teardown();
       }
     });
 
-    var promise = new Promise(function(aResolve, aReject) {
+    var promise = new Promise(function(aInnerResolve, aInnerReject) {
       document.body.appendChild(iframe);
 
-      aResolve(iframe);
+      aInnerResolve(iframe);
     });
     obs.notifyObservers(promise, "setup-request-promise");
 
     gScript.addMessageListener("offer-received", function offerReceivedHandler() {
       gScript.removeMessageListener("offer-received", offerReceivedHandler);
       info("An offer is received.");
     });
 
--- a/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html
+++ b/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html
@@ -20,18 +20,17 @@
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
 var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver.html");
 var nonReceiverUrl = SimpleTest.getTestFileURL("file_presentation_non_receiver.html");
 
 var isReceiverFinished = false;
 var isNonReceiverFinished = false;
 
-var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-          .getService(SpecialPowers.Ci.nsIObserverService);
+var obs = SpecialPowers.Services.obs;
 var receiverIframe;
 
 function setup() {
   return new Promise(function(aResolve, aReject) {
     gScript.sendAsyncMessage("trigger-device-add");
 
     // Create a receiver OOP iframe.
     receiverIframe = document.createElement("iframe");
@@ -64,24 +63,24 @@ function setup() {
         isReceiverFinished = true;
 
         if (isNonReceiverFinished) {
           teardown();
         }
       }
     });
 
-    var promise = new Promise(function(aResolve, aReject) {
+    var promise = new Promise(function(aInnerResolve, aInnerReject) {
       document.body.appendChild(receiverIframe);
       receiverIframe.addEventListener("mozbrowserloadstart", function() {
         var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
         mm.loadFrameScript("data:,(" + loadPrivilegedScriptTest.toString() + ")();", false);
       }, {once: true});
 
-      aResolve(receiverIframe);
+      aInnerResolve(receiverIframe);
     });
     obs.notifyObservers(promise, "setup-request-promise");
 
     // Create a non-receiver OOP iframe.
     var nonReceiverIframe = document.createElement("iframe");
     nonReceiverIframe.setAttribute("remote", "true");
     nonReceiverIframe.setAttribute("mozbrowser", "true");
     nonReceiverIframe.setAttribute("src", nonReceiverUrl);
--- a/dom/presentation/tests/mochitest/test_presentation_fingerprinting_resistance.html
+++ b/dom/presentation/tests/mochitest/test_presentation_fingerprinting_resistance.html
@@ -73,22 +73,22 @@ let testRequestAndReceiver = (request) =
     iframe.setAttribute("mozbrowser", "true");
     iframe.setAttribute("mozpresentation", kReceiverUrl);
     iframe.setAttribute("remote", "false");
     iframe.addEventListener("mozbrowsershowmodalprompt", (event) => {
       SimpleTest.is(event.detail.message, "true", "navigator.presentation.receiver");
       resolve(iframe);
     }, {once: true});
 
-    let promise = new Promise((resolve) => {
+    let promise = new Promise((aInnerResolve) => {
       document.body.appendChild(iframe);
-      resolve(iframe);
+      aInnerResolve(iframe);
     });
 
-    let obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"].getService(SpecialPowers.Ci.nsIObserverService);
+    let obs = SpecialPowers.Services.obs;
     obs.notifyObservers(promise, "setup-request-promise");
   });
 
   request.start().then((connection) => {
     SimpleTest.ok(connection, "PresentationRequest.start");
   }).catch((error) => {
     SimpleTest.ok(false, "PresentationRequest.start: " + error);
     teardown();
--- a/dom/presentation/tests/mochitest/test_presentation_receiver_auxiliary_navigation.js
+++ b/dom/presentation/tests/mochitest/test_presentation_receiver_auxiliary_navigation.js
@@ -1,70 +1,65 @@
 "use strict";
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
 var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver_auxiliary_navigation.html");
 
-var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-          .getService(SpecialPowers.Ci.nsIObserverService);
+var obs = SpecialPowers.Services.obs;
 
 function setup() {
-  return new Promise(function(aResolve, aReject) {
-    gScript.sendAsyncMessage("trigger-device-add");
+  gScript.sendAsyncMessage("trigger-device-add");
 
-    var iframe = document.createElement("iframe");
-    iframe.setAttribute("mozbrowser", "true");
-    iframe.setAttribute("mozpresentation", receiverUrl);
-    var oop = !location.pathname.includes("_inproc");
-    iframe.setAttribute("remote", oop);
-    iframe.setAttribute("src", receiverUrl);
+  var iframe = document.createElement("iframe");
+  iframe.setAttribute("mozbrowser", "true");
+  iframe.setAttribute("mozpresentation", receiverUrl);
+  var oop = !location.pathname.includes("_inproc");
+  iframe.setAttribute("remote", oop);
+  iframe.setAttribute("src", receiverUrl);
 
-    // This event is triggered when the iframe calls "postMessage".
-    iframe.addEventListener("mozbrowsershowmodalprompt", function listener(aEvent) {
-      var message = aEvent.detail.message;
-      if (/^OK /.exec(message)) {
-        ok(true, "Message from iframe: " + message);
-      } else if (/^KO /.exec(message)) {
-        ok(false, "Message from iframe: " + message);
-      } else if (/^INFO /.exec(message)) {
-        info("Message from iframe: " + message);
-      } else if (/^COMMAND /.exec(message)) {
-        var command = JSON.parse(message.replace(/^COMMAND /, ""));
-        gScript.sendAsyncMessage(command.name, command.data);
-      } else if (/^DONE$/.exec(message)) {
-        ok(true, "Messaging from iframe complete.");
-        iframe.removeEventListener("mozbrowsershowmodalprompt", listener);
+  // This event is triggered when the iframe calls "postMessage".
+  iframe.addEventListener("mozbrowsershowmodalprompt", function listener(aEvent) {
+    var message = aEvent.detail.message;
+    if (/^OK /.exec(message)) {
+      ok(true, "Message from iframe: " + message);
+    } else if (/^KO /.exec(message)) {
+      ok(false, "Message from iframe: " + message);
+    } else if (/^INFO /.exec(message)) {
+      info("Message from iframe: " + message);
+    } else if (/^COMMAND /.exec(message)) {
+      var command = JSON.parse(message.replace(/^COMMAND /, ""));
+      gScript.sendAsyncMessage(command.name, command.data);
+    } else if (/^DONE$/.exec(message)) {
+      ok(true, "Messaging from iframe complete.");
+      iframe.removeEventListener("mozbrowsershowmodalprompt", listener);
 
-        teardown();
-      }
-    });
-
-    var promise = new Promise(function(aResolve, aReject) {
-      document.body.appendChild(iframe);
+      teardown();
+    }
+  });
 
-      aResolve(iframe);
-    });
-    obs.notifyObservers(promise, "setup-request-promise");
+  var promise = new Promise(function(aResolve, aReject) {
+    document.body.appendChild(iframe);
 
-    aResolve();
+    aResolve(iframe);
   });
+  obs.notifyObservers(promise, "setup-request-promise");
 }
 
 function teardown() {
   gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
     gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage("teardown");
 }
 
 function runTests() {
-  setup().then();
+  setup();
 }
 
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPermissions([
   {type: "presentation-device-manage", allow: false, context: document},
   {type: "browser", allow: true, context: document},
 ], function() {
   SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
--- a/dom/presentation/tests/mochitest/test_presentation_tcp_receiver.html
+++ b/dom/presentation/tests/mochitest/test_presentation_tcp_receiver.html
@@ -15,81 +15,76 @@
 <pre id="test"></pre>
 <script type="application/javascript">
 
 "use strict";
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
 var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver.html");
 
-var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-          .getService(SpecialPowers.Ci.nsIObserverService);
+var obs = SpecialPowers.Services.obs;
 
 function setup() {
-  return new Promise(function(aResolve, aReject) {
-    gScript.sendAsyncMessage("trigger-device-add");
+  gScript.sendAsyncMessage("trigger-device-add");
 
-    var iframe = document.createElement("iframe");
-    iframe.setAttribute("mozbrowser", "true");
-    iframe.setAttribute("mozpresentation", receiverUrl);
-    iframe.setAttribute("src", receiverUrl);
+  var iframe = document.createElement("iframe");
+  iframe.setAttribute("mozbrowser", "true");
+  iframe.setAttribute("mozpresentation", receiverUrl);
+  iframe.setAttribute("src", receiverUrl);
 
-    // This event is triggered when the iframe calls "postMessage".
-    iframe.addEventListener("mozbrowsershowmodalprompt", function listener(aEvent) {
-      var message = aEvent.detail.message;
-      if (/^OK /.exec(message)) {
-        ok(true, "Message from iframe: " + message);
-      } else if (/^KO /.exec(message)) {
-        ok(false, "Message from iframe: " + message);
-      } else if (/^INFO /.exec(message)) {
-        info("Message from iframe: " + message);
-      } else if (/^COMMAND /.exec(message)) {
-        var command = JSON.parse(message.replace(/^COMMAND /, ""));
-        gScript.sendAsyncMessage(command.name, command.data);
-      } else if (/^DONE$/.exec(message)) {
-        ok(true, "Messaging from iframe complete.");
-        iframe.removeEventListener("mozbrowsershowmodalprompt", listener);
+  // This event is triggered when the iframe calls "postMessage".
+  iframe.addEventListener("mozbrowsershowmodalprompt", function listener(aEvent) {
+    var message = aEvent.detail.message;
+    if (/^OK /.exec(message)) {
+      ok(true, "Message from iframe: " + message);
+    } else if (/^KO /.exec(message)) {
+      ok(false, "Message from iframe: " + message);
+    } else if (/^INFO /.exec(message)) {
+      info("Message from iframe: " + message);
+    } else if (/^COMMAND /.exec(message)) {
+      var command = JSON.parse(message.replace(/^COMMAND /, ""));
+      gScript.sendAsyncMessage(command.name, command.data);
+    } else if (/^DONE$/.exec(message)) {
+      ok(true, "Messaging from iframe complete.");
+      iframe.removeEventListener("mozbrowsershowmodalprompt", listener);
 
-        teardown();
-      }
-    });
-
-    var promise = new Promise(function(aResolve, aReject) {
-      document.body.appendChild(iframe);
+      teardown();
+    }
+  });
 
-      aResolve(iframe);
-    });
-    obs.notifyObservers(promise, "setup-request-promise");
+  var promise = new Promise(function(aResolve, aReject) {
+    document.body.appendChild(iframe);
 
-    gScript.addMessageListener("offer-received", function offerReceivedHandler() {
-      gScript.removeMessageListener("offer-received", offerReceivedHandler);
-      info("An offer is received.");
-    });
+    aResolve(iframe);
+  });
+  obs.notifyObservers(promise, "setup-request-promise");
 
-    gScript.addMessageListener("answer-sent", function answerSentHandler(aIsValid) {
-      gScript.removeMessageListener("answer-sent", answerSentHandler);
-      ok(aIsValid, "A valid answer is sent.");
-    });
+  gScript.addMessageListener("offer-received", function offerReceivedHandler() {
+    gScript.removeMessageListener("offer-received", offerReceivedHandler);
+    info("An offer is received.");
+  });
 
-    gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
-      gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
-      is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
-    });
+  gScript.addMessageListener("answer-sent", function answerSentHandler(aIsValid) {
+    gScript.removeMessageListener("answer-sent", answerSentHandler);
+    ok(aIsValid, "A valid answer is sent.");
+  });
 
-    gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
-      gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
-      info("Data notification is enabled for data transport channel.");
-    });
+  gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
+    gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
+    is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
+  });
 
-    gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
-      gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
-      is(aReason, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
-    });
+  gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
+    gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
+    info("Data notification is enabled for data transport channel.");
+  });
 
-    aResolve();
+  gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
+    gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
+    is(aReason, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
   });
 }
 
 function testIncomingSessionRequest() {
   return new Promise(function(aResolve, aReject) {
     gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
       gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
       info("Trying to launch receiver page.");
@@ -109,18 +104,18 @@ function teardown() {
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage("teardown");
 }
 
 function runTests() {
-  setup().
-  then(testIncomingSessionRequest);
+  setup();
+  testIncomingSessionRequest();
 }
 
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPermissions([
   {type: "presentation-device-manage", allow: false, context: document},
   {type: "browser", allow: true, context: document},
 ], function() {
   SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
--- a/dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_error.html
+++ b/dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_error.html
@@ -12,60 +12,55 @@
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for connection establishing errors of B2G Presentation API at receiver side</a>
 <script type="application/javascript">
 
 "use strict";
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
 var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver_establish_connection_error.html");
 
-var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-          .getService(SpecialPowers.Ci.nsIObserverService);
+var obs = SpecialPowers.Services.obs;
 
 function setup() {
-  return new Promise(function(aResolve, aReject) {
-    gScript.sendAsyncMessage("trigger-device-add");
+  gScript.sendAsyncMessage("trigger-device-add");
 
-    var iframe = document.createElement("iframe");
-    iframe.setAttribute("src", receiverUrl);
-    iframe.setAttribute("mozbrowser", "true");
-    iframe.setAttribute("mozpresentation", receiverUrl);
+  var iframe = document.createElement("iframe");
+  iframe.setAttribute("src", receiverUrl);
+  iframe.setAttribute("mozbrowser", "true");
+  iframe.setAttribute("mozpresentation", receiverUrl);
 
-    // This event is triggered when the iframe calls "alert".
-    iframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(evt) {
-      var message = evt.detail.message;
-      if (/^OK /.exec(message)) {
-        ok(true, message.replace(/^OK /, ""));
-      } else if (/^KO /.exec(message)) {
-        ok(false, message.replace(/^KO /, ""));
-      } else if (/^INFO /.exec(message)) {
-        info(message.replace(/^INFO /, ""));
-      } else if (/^COMMAND /.exec(message)) {
-        var command = JSON.parse(message.replace(/^COMMAND /, ""));
-        gScript.sendAsyncMessage(command.name, command.data);
-      } else if (/^DONE$/.exec(message)) {
-        iframe.removeEventListener("mozbrowsershowmodalprompt",
-                                   receiverListener);
-        teardown();
-      }
-    });
+  // This event is triggered when the iframe calls "alert".
+  iframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(evt) {
+    var message = evt.detail.message;
+    if (/^OK /.exec(message)) {
+      ok(true, message.replace(/^OK /, ""));
+    } else if (/^KO /.exec(message)) {
+      ok(false, message.replace(/^KO /, ""));
+    } else if (/^INFO /.exec(message)) {
+      info(message.replace(/^INFO /, ""));
+    } else if (/^COMMAND /.exec(message)) {
+      var command = JSON.parse(message.replace(/^COMMAND /, ""));
+      gScript.sendAsyncMessage(command.name, command.data);
+    } else if (/^DONE$/.exec(message)) {
+      iframe.removeEventListener("mozbrowsershowmodalprompt",
+                                 receiverListener);
+      teardown();
+    }
+  });
 
-    var promise = new Promise(function(aResolve, aReject) {
-      document.body.appendChild(iframe);
-
-      aResolve(iframe);
-    });
-    obs.notifyObservers(promise, "setup-request-promise");
+  var promise = new Promise(function(aResolve, aReject) {
+    document.body.appendChild(iframe);
 
-    gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
-      gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
-      is(aReason, 0x80004004 /* NS_ERROR_ABORT */, "The control channel is closed abnormally.");
-    });
+    aResolve(iframe);
+  });
+  obs.notifyObservers(promise, "setup-request-promise");
 
-    aResolve();
+  gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
+    gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
+    is(aReason, 0x80004004 /* NS_ERROR_ABORT */, "The control channel is closed abnormally.");
   });
 }
 
 function testIncomingSessionRequest() {
   return new Promise(function(aResolve, aReject) {
     gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
       gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
       info("Trying to launch receiver page.");
@@ -83,18 +78,18 @@ function teardown() {
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage("teardown");
 }
 
 function runTests() {
-  setup().
-  then(testIncomingSessionRequest);
+  setup();
+  testIncomingSessionRequest();
 }
 
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPermissions([
   {type: "presentation-device-manage", allow: false, context: document},
   {type: "browser", allow: true, context: document},
 ], function() {
   SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
--- a/dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_timeout.html
+++ b/dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_timeout.html
@@ -11,30 +11,25 @@
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for connection establishing timeout of B2G Presentation API at receiver side</a>
 <script type="application/javascript">
 
 "use strict";
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
 
-var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-          .getService(SpecialPowers.Ci.nsIObserverService);
+var obs = SpecialPowers.Services.obs;
 
 function setup() {
-  return new Promise(function(aResolve, aReject) {
-    gScript.sendAsyncMessage("trigger-device-add");
+  gScript.sendAsyncMessage("trigger-device-add");
 
-    var promise = new Promise(function(aResolve, aReject) {
-      // In order to trigger timeout, do not resolve the promise.
-    });
-    obs.notifyObservers(promise, "setup-request-promise");
-
-    aResolve();
+  var promise = new Promise(function(aResolve, aReject) {
+    // In order to trigger timeout, do not resolve the promise.
   });
+  obs.notifyObservers(promise, "setup-request-promise");
 }
 
 function testIncomingSessionRequestReceiverLaunchTimeout() {
   return new Promise(function(aResolve, aReject) {
     gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
       gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
       info("Trying to launch receiver page.");
     });
@@ -55,18 +50,18 @@ function teardown() {
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage("teardown");
 }
 
 function runTests() {
-  setup().
-  then(testIncomingSessionRequestReceiverLaunchTimeout).
+  setup();
+  testIncomingSessionRequestReceiverLaunchTimeout().
   then(teardown);
 }
 
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPermissions([
   {type: "presentation-device-manage", allow: false, context: document},
 ], function() {
   SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
--- a/dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_unknown_content_type.js
+++ b/dom/presentation/tests/mochitest/test_presentation_tcp_receiver_establish_connection_unknown_content_type.js
@@ -1,38 +1,33 @@
 "use strict";
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
 var receiverUrl = SimpleTest.getTestFileURL("file_presentation_unknown_content_type.test");
 
-var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-          .getService(SpecialPowers.Ci.nsIObserverService);
+var obs = SpecialPowers.Services.obs;
 
 var receiverIframe;
 
 function setup() {
-  return new Promise(function(aResolve, aReject) {
-    gScript.sendAsyncMessage("trigger-device-add");
-
-    receiverIframe = document.createElement("iframe");
-    receiverIframe.setAttribute("mozbrowser", "true");
-    receiverIframe.setAttribute("mozpresentation", receiverUrl);
-    receiverIframe.setAttribute("src", receiverUrl);
-    var oop = !location.pathname.includes("_inproc");
-    receiverIframe.setAttribute("remote", oop);
+  gScript.sendAsyncMessage("trigger-device-add");
 
-    var promise = new Promise(function(aResolve, aReject) {
-      document.body.appendChild(receiverIframe);
+  receiverIframe = document.createElement("iframe");
+  receiverIframe.setAttribute("mozbrowser", "true");
+  receiverIframe.setAttribute("mozpresentation", receiverUrl);
+  receiverIframe.setAttribute("src", receiverUrl);
+  var oop = !location.pathname.includes("_inproc");
+  receiverIframe.setAttribute("remote", oop);
 
-      aResolve(receiverIframe);
-    });
-    obs.notifyObservers(promise, "setup-request-promise");
+  var promise = new Promise(function(aResolve, aReject) {
+    document.body.appendChild(receiverIframe);
 
-    aResolve();
+    aResolve(receiverIframe);
   });
+  obs.notifyObservers(promise, "setup-request-promise");
 }
 
 function testIncomingSessionRequestReceiverLaunchUnknownContentType() {
   let promise = Promise.all([
     new Promise(function(aResolve, aReject) {
       gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
         gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
         info("Trying to launch receiver page.");
@@ -62,19 +57,19 @@ function teardown() {
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage("teardown");
 }
 
 function runTests() {
-  setup().
-  then(testIncomingSessionRequestReceiverLaunchUnknownContentType).
-  then(teardown);
+  setup();
+
+  testIncomingSessionRequestReceiverLaunchUnknownContentType().then(teardown);
 }
 
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPermissions([
   {type: "presentation-device-manage", allow: false, context: document},
   {type: "browser", allow: true, context: document},
 ], function() {
   SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
--- a/dom/presentation/tests/mochitest/test_presentation_tcp_receiver_oop.html
+++ b/dom/presentation/tests/mochitest/test_presentation_tcp_receiver_oop.html
@@ -19,119 +19,114 @@
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
 var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver.html");
 var nonReceiverUrl = SimpleTest.getTestFileURL("file_presentation_non_receiver.html");
 
 var isReceiverFinished = false;
 var isNonReceiverFinished = false;
 
-var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-          .getService(SpecialPowers.Ci.nsIObserverService);
+var obs = SpecialPowers.Services.obs;
 
 function setup() {
-  return new Promise(function(aResolve, aReject) {
-    gScript.sendAsyncMessage("trigger-device-add");
+  gScript.sendAsyncMessage("trigger-device-add");
 
-    // Create a receiver OOP iframe.
-    var receiverIframe = document.createElement("iframe");
-    receiverIframe.setAttribute("remote", "true");
-    receiverIframe.setAttribute("mozbrowser", "true");
-    receiverIframe.setAttribute("mozpresentation", receiverUrl);
-    receiverIframe.setAttribute("src", receiverUrl);
+  // Create a receiver OOP iframe.
+  var receiverIframe = document.createElement("iframe");
+  receiverIframe.setAttribute("remote", "true");
+  receiverIframe.setAttribute("mozbrowser", "true");
+  receiverIframe.setAttribute("mozpresentation", receiverUrl);
+  receiverIframe.setAttribute("src", receiverUrl);
 
-    // This event is triggered when the iframe calls "alert".
-    receiverIframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(aEvent) {
-      var message = aEvent.detail.message;
-      if (/^OK /.exec(message)) {
-        ok(true, "Message from iframe: " + message);
-      } else if (/^KO /.exec(message)) {
-        ok(false, "Message from iframe: " + message);
-      } else if (/^INFO /.exec(message)) {
-        info("Message from iframe: " + message);
-      } else if (/^COMMAND /.exec(message)) {
-        var command = JSON.parse(message.replace(/^COMMAND /, ""));
-        gScript.sendAsyncMessage(command.name, command.data);
-      } else if (/^DONE$/.exec(message)) {
-        ok(true, "Messaging from iframe complete.");
-        receiverIframe.removeEventListener("mozbrowsershowmodalprompt", receiverListener);
+  // This event is triggered when the iframe calls "alert".
+  receiverIframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(aEvent) {
+    var message = aEvent.detail.message;
+    if (/^OK /.exec(message)) {
+      ok(true, "Message from iframe: " + message);
+    } else if (/^KO /.exec(message)) {
+      ok(false, "Message from iframe: " + message);
+    } else if (/^INFO /.exec(message)) {
+      info("Message from iframe: " + message);
+    } else if (/^COMMAND /.exec(message)) {
+      var command = JSON.parse(message.replace(/^COMMAND /, ""));
+      gScript.sendAsyncMessage(command.name, command.data);
+    } else if (/^DONE$/.exec(message)) {
+      ok(true, "Messaging from iframe complete.");
+      receiverIframe.removeEventListener("mozbrowsershowmodalprompt", receiverListener);
 
-        isReceiverFinished = true;
+      isReceiverFinished = true;
 
-        if (isNonReceiverFinished) {
-          teardown();
-        }
+      if (isNonReceiverFinished) {
+        teardown();
       }
-    });
+    }
+  });
 
-    var promise = new Promise(function(aResolve, aReject) {
-      document.body.appendChild(receiverIframe);
+  var promise = new Promise(function(aResolve, aReject) {
+    document.body.appendChild(receiverIframe);
 
-      aResolve(receiverIframe);
-    });
-    obs.notifyObservers(promise, "setup-request-promise");
+    aResolve(receiverIframe);
+  });
+  obs.notifyObservers(promise, "setup-request-promise");
 
-    // Create a non-receiver OOP iframe.
-    var nonReceiverIframe = document.createElement("iframe");
-    nonReceiverIframe.setAttribute("remote", "true");
-    nonReceiverIframe.setAttribute("mozbrowser", "true");
-    nonReceiverIframe.setAttribute("src", nonReceiverUrl);
+  // Create a non-receiver OOP iframe.
+  var nonReceiverIframe = document.createElement("iframe");
+  nonReceiverIframe.setAttribute("remote", "true");
+  nonReceiverIframe.setAttribute("mozbrowser", "true");
+  nonReceiverIframe.setAttribute("src", nonReceiverUrl);
 
-    // This event is triggered when the iframe calls "alert".
-    nonReceiverIframe.addEventListener("mozbrowsershowmodalprompt", function nonReceiverListener(aEvent) {
-      var message = aEvent.detail.message;
-      if (/^OK /.exec(message)) {
-        ok(true, "Message from iframe: " + message);
-      } else if (/^KO /.exec(message)) {
-        ok(false, "Message from iframe: " + message);
-      } else if (/^INFO /.exec(message)) {
-        info("Message from iframe: " + message);
-      } else if (/^COMMAND /.exec(message)) {
-        var command = JSON.parse(message.replace(/^COMMAND /, ""));
-        gScript.sendAsyncMessage(command.name, command.data);
-      } else if (/^DONE$/.exec(message)) {
-        ok(true, "Messaging from iframe complete.");
-        nonReceiverIframe.removeEventListener("mozbrowsershowmodalprompt", nonReceiverListener);
+  // This event is triggered when the iframe calls "alert".
+  nonReceiverIframe.addEventListener("mozbrowsershowmodalprompt", function nonReceiverListener(aEvent) {
+    var message = aEvent.detail.message;
+    if (/^OK /.exec(message)) {
+      ok(true, "Message from iframe: " + message);
+    } else if (/^KO /.exec(message)) {
+      ok(false, "Message from iframe: " + message);
+    } else if (/^INFO /.exec(message)) {
+      info("Message from iframe: " + message);
+    } else if (/^COMMAND /.exec(message)) {
+      var command = JSON.parse(message.replace(/^COMMAND /, ""));
+      gScript.sendAsyncMessage(command.name, command.data);
+    } else if (/^DONE$/.exec(message)) {
+      ok(true, "Messaging from iframe complete.");
+      nonReceiverIframe.removeEventListener("mozbrowsershowmodalprompt", nonReceiverListener);
 
-        isNonReceiverFinished = true;
+      isNonReceiverFinished = true;
 
-        if (isReceiverFinished) {
-          teardown();
-        }
+      if (isReceiverFinished) {
+        teardown();
       }
-    });
-
-    document.body.appendChild(nonReceiverIframe);
+    }
+  });
 
-    gScript.addMessageListener("offer-received", function offerReceivedHandler() {
-      gScript.removeMessageListener("offer-received", offerReceivedHandler);
-      info("An offer is received.");
-    });
+  document.body.appendChild(nonReceiverIframe);
 
-    gScript.addMessageListener("answer-sent", function answerSentHandler(aIsValid) {
-      gScript.removeMessageListener("answer-sent", answerSentHandler);
-      ok(aIsValid, "A valid answer is sent.");
-    });
+  gScript.addMessageListener("offer-received", function offerReceivedHandler() {
+    gScript.removeMessageListener("offer-received", offerReceivedHandler);
+    info("An offer is received.");
+  });
+
+  gScript.addMessageListener("answer-sent", function answerSentHandler(aIsValid) {
+    gScript.removeMessageListener("answer-sent", answerSentHandler);
+    ok(aIsValid, "A valid answer is sent.");
+  });
 
-    gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
-      gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
-      is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
-    });
+  gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
+    gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
+    is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
+  });
 
-    gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
-      gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
-      info("Data notification is enabled for data transport channel.");
-    });
+  gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
+    gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
+    info("Data notification is enabled for data transport channel.");
+  });
 
-    gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
-      gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
-      is(aReason, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
-    });
-
-    aResolve();
+  gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
+    gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
+    is(aReason, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
   });
 }
 
 function testIncomingSessionRequest() {
   return new Promise(function(aResolve, aReject) {
     gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
       gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
       info("Trying to launch receiver page.");
@@ -149,18 +144,18 @@ function teardown() {
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage("teardown");
 }
 
 function runTests() {
-  setup().
-  then(testIncomingSessionRequest);
+  setup();
+  testIncomingSessionRequest();
 }
 
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPermissions([
   {type: "presentation-device-manage", allow: false, context: document},
   {type: "browser", allow: true, context: document},
 ], function() {
   SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
--- a/dom/presentation/tests/mochitest/test_presentation_terminate.js
+++ b/dom/presentation/tests/mochitest/test_presentation_terminate.js
@@ -60,18 +60,17 @@ function setup() {
       }
     });
 
     var promise = new Promise(function(aResolve, aReject) {
       document.body.appendChild(receiverIframe);
       aResolve(receiverIframe);
     });
 
-    var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-                           .getService(SpecialPowers.Ci.nsIObserverService);
+    var obs = SpecialPowers.Services.obs;
     obs.notifyObservers(promise, "setup-request-promise");
   });
 
   gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
     debug("Got message: promise-setup-ready");
     gScript.removeMessageListener("promise-setup-ready",
                                   promiseSetupReadyHandler);
     gScript.sendAsyncMessage("trigger-on-session-request", receiverUrl);
--- a/dom/presentation/tests/mochitest/test_presentation_terminate_establish_connection_error.js
+++ b/dom/presentation/tests/mochitest/test_presentation_terminate_establish_connection_error.js
@@ -65,18 +65,17 @@ function setup() {
       }
     });
 
     var promise = new Promise(function(aResolve, aReject) {
       document.body.appendChild(receiverIframe);
       aResolve(receiverIframe);
     });
 
-    var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
-                           .getService(SpecialPowers.Ci.nsIObserverService);
+    var obs = SpecialPowers.Services.obs;
     obs.notifyObservers(promise, "setup-request-promise");
   });
 
   gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
     debug("Got message: promise-setup-ready");
     gScript.removeMessageListener("promise-setup-ready",
                                   promiseSetupReadyHandler);
     gScript.sendAsyncMessage("trigger-on-session-request", receiverUrl);
--- a/dom/presentation/tests/xpcshell/test_multicast_dns_device_provider.js
+++ b/dom/presentation/tests/xpcshell/test_multicast_dns_device_provider.js
@@ -243,17 +243,17 @@ function registerService() {
           this.serviceUnregistered++;
         }
       };
     },
     resolveService(serviceInfo, listener) {},
     serviceRegistered: 0,
     serviceUnregistered: 0
   };
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
 
   Assert.equal(mockObj.serviceRegistered, 0);
   Assert.equal(mockObj.serviceUnregistered, 0);
 
   // Register
   provider.listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
@@ -286,17 +286,17 @@ function noRegisterService() {
     startDiscovery(serviceType, listener) {},
     registerService(serviceInfo, listener) {
       deferred.resolve();
       Assert.ok(false, "should not register service if not discoverable");
     },
     resolveService(serviceInfo, listener) {},
   };
 
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
 
   // Try register
   provider.listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
                                             Ci.nsISupportsWeakReference]),
     addDevice(device) {},
     removeDevice(device) {},
@@ -332,17 +332,17 @@ function registerServiceDynamically() {
           this.serviceUnregistered++;
         }
       };
     },
     resolveService(serviceInfo, listener) {},
     serviceRegistered: 0,
     serviceUnregistered: 0
   };
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
 
   Assert.equal(mockObj.serviceRegistered, 0);
   Assert.equal(mockObj.serviceRegistered, 0);
 
   // Try Register
   provider.listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
@@ -402,17 +402,17 @@ function addDevice() {
       Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
       listener.onServiceResolved(createDevice(mockDevice.host,
                                               mockDevice.port,
                                               mockDevice.serviceName,
                                               mockDevice.serviceType));
     }
   };
 
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = new TestPresentationDeviceListener();
   Assert.equal(listener.count(), 0);
 
   // Start discovery
   provider.listener = listener;
   Assert.equal(listener.count(), 1);
 
@@ -452,17 +452,17 @@ function filterDevice() {
       Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
       listener.onServiceResolved(createDevice(mockDevice.host,
                                               mockDevice.port,
                                               mockDevice.serviceName,
                                               mockDevice.serviceType));
     }
   };
 
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
                                             Ci.nsISupportsWeakReference]),
     addDevice(device) {
       let tests = [
         { requestedUrl: "app://fling-player.gaiamobile.org/index.html", supported: true },
         { requestedUrl: "app://notification-receiver.gaiamobile.org/index.html", supported: true },
@@ -488,18 +488,16 @@ function filterDevice() {
 
   provider.listener = listener;
 }
 
 function handleSessionRequest() {
   Services.prefs.setBoolPref(PREF_DISCOVERY, true);
   Services.prefs.setBoolPref(PREF_DISCOVERABLE, false);
 
-  const testUrl = "http://example.com";
-  const testPresentationId = "test-presentation-id";
   const testDeviceName = "test-device-name";
 
   Services.prefs.setCharPref(PREF_DEVICENAME, testDeviceName);
 
   let mockDevice = createDevice("device.local",
                                 12345,
                                 "service.name",
                                 SERVICE_TYPE);
@@ -537,30 +535,30 @@ function handleSessionRequest() {
     },
     id: "",
     version: LATEST_VERSION,
     isCompatibleServer(version) {
       return this.version === version;
     }
   };
 
-  let contractHookSD = new ContractHook(SD_CONTRACT_ID, mockSDObj);
-  let contractHookServer = new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
+  new ContractHook(SD_CONTRACT_ID, mockSDObj);
+  new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
                                             Ci.nsISupportsWeakReference]),
     addDevice(device) {
       this.device = device;
     },
   };
 
   provider.listener = listener;
 
-  let controlChannel = listener.device.establishControlChannel();
+  listener.device.establishControlChannel();
 
   Assert.equal(mockServerObj.request.deviceInfo.id, mockDevice.host);
   Assert.equal(mockServerObj.request.deviceInfo.address, mockDevice.host);
   Assert.equal(mockServerObj.request.deviceInfo.port, mockDevice.port);
   Assert.equal(mockServerObj.id, testDeviceName);
 
   provider.listener = null;
 
@@ -603,18 +601,18 @@ function handleOnSessionRequest() {
     sessionRequest() {},
     close() {},
     id: "",
     version: LATEST_VERSION,
     port: 0,
     listener: null,
   };
 
-  let contractHookSD = new ContractHook(SD_CONTRACT_ID, mockSDObj);
-  let contractHookServer = new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
+  new ContractHook(SD_CONTRACT_ID, mockSDObj);
+  new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
                                             Ci.nsISupportsWeakReference]),
     addDevice(device) {},
     removeDevice(device) {},
     updateDevice(device) {},
     onSessionRequest(device, url, presentationId, controlChannel) {
@@ -670,18 +668,18 @@ function handleOnSessionRequestFromUnkno
     sessionRequest() {},
     close() {},
     id: "",
     version: LATEST_VERSION,
     port: 0,
     listener: null,
   };
 
-  let contractHookSD = new ContractHook(SD_CONTRACT_ID, mockSDObj);
-  let contractHookServer = new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
+  new ContractHook(SD_CONTRACT_ID, mockSDObj);
+  new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
                                             Ci.nsISupportsWeakReference]),
     addDevice(device) {
       Assert.ok(false, "shouldn't create any new device");
     },
     removeDevice(device) {
@@ -724,27 +722,26 @@ function handleOnSessionRequestFromUnkno
   provider.listener = null;
 
   run_next_test();
 }
 
 function noAddDevice() {
   Services.prefs.setBoolPref(PREF_DISCOVERY, false);
 
-  let mockDevice = createDevice("device.local", 12345, "service.name", SERVICE_TYPE);
   let mockObj = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
     startDiscovery(serviceType, listener) {
       Assert.ok(false, "shouldn't perform any device discovery");
     },
     registerService(serviceInfo, listener) {},
     resolveService(serviceInfo, listener) {
     }
   };
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
 
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
                                             Ci.nsISupportsWeakReference]),
     addDevice(device) {},
     removeDevice(device) {},
     updateDevice(device) {},
@@ -815,18 +812,18 @@ function ignoreIncompatibleDevice() {
     isCompatibleServer(version) {
       return false;
     },
     port: 54321,
     certFingerprint: "mock-cert-fingerprint",
     listener: null,
   };
 
-  let contractHookSD = new ContractHook(SD_CONTRACT_ID, mockSDObj);
-  let contractHookServer = new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
+  new ContractHook(SD_CONTRACT_ID, mockSDObj);
+  new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = new TestPresentationDeviceListener();
 
   // Register service
   provider.listener = listener;
 
   deferred.promise.then(function() {
     Assert.equal(mockServerObj.id, mockDevice.host);
@@ -900,18 +897,18 @@ function ignoreSelfDevice() {
     isCompatibleServer(version) {
       return this.version === version;
     },
     port: 54321,
     certFingerprint: "mock-cert-fingerprint",
     listener: null,
   };
 
-  let contractHookSD = new ContractHook(SD_CONTRACT_ID, mockSDObj);
-  let contractHookServer = new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
+  new ContractHook(SD_CONTRACT_ID, mockSDObj);
+  new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = new TestPresentationDeviceListener();
 
   // Register service
   provider.listener = listener;
   deferred.promise.then(() => {
     Assert.equal(mockServerObj.id, mockDevice.host);
 
@@ -952,17 +949,17 @@ function addDeviceDynamically() {
       Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
       listener.onServiceResolved(createDevice(mockDevice.host,
                                               mockDevice.port,
                                               mockDevice.serviceName,
                                               mockDevice.serviceType));
     }
   };
 
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = new TestPresentationDeviceListener();
   provider.listener = listener;
   Assert.equal(listener.count(), 0);
 
   // Enable discovery
   Services.prefs.setBoolPref(PREF_DISCOVERY, true);
   Assert.equal(listener.count(), 1);
@@ -1017,17 +1014,17 @@ function updateDevice() {
       } else if (serviceInfo.serviceName == "N2") {
         listener.onServiceResolved(mockDevice2);
       } else {
         Assert.ok(false);
       }
     }
   };
 
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
                                             Ci.nsISupportsWeakReference]),
 
     addDevice(device) {
       Assert.ok(!this.isDeviceAdded);
       Assert.equal(device.id, mockDevice1.host);
@@ -1108,17 +1105,17 @@ function diffDiscovery() {
       } else if (serviceInfo.serviceName == "N3") {
         listener.onServiceResolved(mockDevice3);
       } else {
         Assert.ok(false);
       }
     }
   };
 
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = new TestPresentationDeviceListener();
   Assert.equal(listener.count(), 0);
 
   // Start discovery
   provider.listener = listener; // discover: N1, N2
   Assert.equal(listener.count(), 2);
   Assert.equal(listener.devices["A.local"].name, mockDevice1.serviceName);
@@ -1187,17 +1184,17 @@ function serverClosed() {
       listener.onServiceResolved(createDevice(mockDevice.host,
                                               mockDevice.port,
                                               mockDevice.serviceName,
                                               mockDevice.serviceType));
     },
     serviceRegistered: 0,
     serviceUnregistered: 0
   };
-  let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
+  new ContractHook(SD_CONTRACT_ID, mockObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
 
   Assert.equal(mockObj.serviceRegistered, 0);
   Assert.equal(mockObj.serviceUnregistered, 0);
 
   // Register
   let listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
@@ -1267,18 +1264,18 @@ function serverRetry() {
     close() {},
     id: "",
     version: LATEST_VERSION,
     port: 0,
     certFingerprint: "mock-cert-fingerprint",
     listener: null,
   };
 
-  let contractHookSD = new ContractHook(SD_CONTRACT_ID, mockSDObj);
-  let contractHookServer = new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
+  new ContractHook(SD_CONTRACT_ID, mockSDObj);
+  new ContractHook(SERVER_CONTRACT_ID, mockServerObj);
   let provider = Cc[PROVIDER_CONTRACT_ID].createInstance(Ci.nsIPresentationDeviceProvider);
   let listener = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
                                             Ci.nsISupportsWeakReference]),
     addDevice(device) {},
     removeDevice(device) {},
     updateDevice(device) {},
     onSessionRequest(device, url, presentationId, controlChannel) {}
@@ -1288,17 +1285,17 @@ function serverRetry() {
 }
 
 function run_test() {
   // Need profile dir to store the key / cert
   do_get_profile();
   // Ensure PSM is initialized
   Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports);
 
-  let infoHook = new ContractHook(INFO_CONTRACT_ID, MockDNSServiceInfo);
+  new ContractHook(INFO_CONTRACT_ID, MockDNSServiceInfo);
 
   registerCleanupFunction(() => {
     Services.prefs.clearUserPref(PREF_DISCOVERY);
     Services.prefs.clearUserPref(PREF_DISCOVERABLE);
   });
 
   add_test(registerService);
   add_test(noRegisterService);
--- a/dom/presentation/tests/xpcshell/test_presentation_device_manager.js
+++ b/dom/presentation/tests/xpcshell/test_presentation_device_manager.js
@@ -150,17 +150,16 @@ function sessionRequest() {
 
     run_next_test();
   }, "presentation-session-request");
   manager.QueryInterface(Ci.nsIPresentationDeviceListener)
          .onSessionRequest(testDevice, testUrl, testPresentationId, testControlChannel);
 }
 
 function terminateRequest() {
-  let testUrl = "http://www.example.org/";
   let testPresentationId = "test-presentation-id";
   let testControlChannel = new TestPresentationControlChannel();
   let testIsFromReceiver = true;
   Services.obs.addObserver(function observer(subject, topic, data) {
     Services.obs.removeObserver(observer, topic);
 
     let request = subject.QueryInterface(Ci.nsIPresentationTerminateRequest);
 
--- a/dom/presentation/tests/xpcshell/test_presentation_state_machine.js
+++ b/dom/presentation/tests/xpcshell/test_presentation_state_machine.js
@@ -62,37 +62,37 @@ function launch() {
   Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
 
   controllerState.launch(testPresentationId, testUrl);
   mockReceiverChannel.notifyLaunch = function(presentationId, url) {
     Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
     Assert.equal(presentationId, testPresentationId, "expected presentationId received");
     Assert.equal(url, testUrl, "expected url received");
 
-    mockControllerChannel.notifyLaunch = function(presentationId) {
+    mockControllerChannel.notifyLaunch = function(presId) {
       Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
-      Assert.equal(presentationId, testPresentationId, "expected presentationId received from ack");
+      Assert.equal(presId, testPresentationId, "expected presentationId received from ack");
 
       run_next_test();
     };
   };
 }
 
 function terminateByController() {
   Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
   Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
 
   controllerState.terminate(testPresentationId);
   mockReceiverChannel.notifyTerminate = function(presentationId) {
     Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
     Assert.equal(presentationId, testPresentationId, "expected presentationId received");
 
-    mockControllerChannel.notifyTerminate = function(presentationId) {
+    mockControllerChannel.notifyTerminate = function(presId) {
       Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
-      Assert.equal(presentationId, testPresentationId, "expected presentationId received from ack");
+      Assert.equal(presId, testPresentationId, "expected presentationId received from ack");
 
       run_next_test();
     };
 
     receiverState.terminateAck(presentationId);
   };
 }
 
@@ -100,19 +100,19 @@ function terminateByReceiver() {
   Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
   Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
 
   receiverState.terminate(testPresentationId);
   mockControllerChannel.notifyTerminate = function(presentationId) {
     Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
     Assert.equal(presentationId, testPresentationId, "expected presentationId received");
 
-    mockReceiverChannel.notifyTerminate = function(presentationId) {
+    mockReceiverChannel.notifyTerminate = function(presId) {
       Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
-      Assert.equal(presentationId, testPresentationId, "expected presentationId received from ack");
+      Assert.equal(presId, testPresentationId, "expected presentationId received from ack");
       run_next_test();
     };
 
     controllerState.terminateAck(presentationId);
   };
 }
 
 function exchangeSDP() {
@@ -130,18 +130,18 @@ function exchangeSDP() {
     mockControllerChannel.notifyAnswer = function(answer) {
       Assert.equal(answer, testAnswer, "expected answer received");
 
       controllerState.updateIceCandidate(testIceCandidate);
       mockReceiverChannel.notifyIceCandidate = function(candidate) {
         Assert.equal(candidate, testIceCandidate, "expected ice candidate received in receiver");
 
         receiverState.updateIceCandidate(testIceCandidate);
-        mockControllerChannel.notifyIceCandidate = function(candidate) {
-          Assert.equal(candidate, testIceCandidate, "expected ice candidate received in controller");
+        mockControllerChannel.notifyIceCandidate = function(controllerCandidate) {
+          Assert.equal(controllerCandidate, testIceCandidate, "expected ice candidate received in controller");
 
           run_next_test();
         };
       };
     };
   };
 }
 
@@ -152,18 +152,18 @@ function disconnect() {
 
   mockReceiverChannel.notifyDisconnected = function(reason) {
     Assert.equal(reason, Cr.NS_OK, "receive close reason");
     Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
 
     receiverState.onChannelClosed(Cr.NS_OK, true);
     Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
 
-    mockControllerChannel.notifyDisconnected = function(reason) {
-      Assert.equal(reason, Cr.NS_OK, "receive close reason");
+    mockControllerChannel.notifyDisconnected = function(disconnectReason) {
+      Assert.equal(disconnectReason, Cr.NS_OK, "receive close reason");
       Assert.equal(controllerState.state, State.CLOSED, "controller in closed state");
 
       run_next_test();
     };
     controllerState.onChannelClosed(Cr.NS_OK, true);
   };
 }
 
@@ -178,18 +178,18 @@ function receiverDisconnect() {
 
   mockControllerChannel.notifyDisconnected = function(reason) {
     Assert.equal(reason, Cr.NS_OK, "receive close reason");
     Assert.equal(controllerState.state, State.CLOSED, "controller in closed state");
 
     controllerState.onChannelClosed(Cr.NS_OK, true);
     Assert.equal(controllerState.state, State.CLOSED, "controller in closed state");
 
-    mockReceiverChannel.notifyDisconnected = function(reason) {
-      Assert.equal(reason, Cr.NS_OK, "receive close reason");
+    mockReceiverChannel.notifyDisconnected = function(disconnectReason) {
+      Assert.equal(disconnectReason, Cr.NS_OK, "receive close reason");
       Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
 
       run_next_test();
     };
     receiverState.onChannelClosed(Cr.NS_OK, true);
   };
 }
 
@@ -205,18 +205,18 @@ function abnormalDisconnect() {
 
   mockReceiverChannel.notifyDisconnected = function(reason) {
     Assert.equal(reason, testErrorReason, "receive abnormal close reason");
     Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
 
     receiverState.onChannelClosed(Cr.NS_OK, true);
     Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
 
-    mockControllerChannel.notifyDisconnected = function(reason) {
-      Assert.equal(reason, testErrorReason, "receive abnormal close reason");
+    mockControllerChannel.notifyDisconnected = function(disconnectReason) {
+      Assert.equal(disconnectReason, testErrorReason, "receive abnormal close reason");
       Assert.equal(controllerState.state, State.CLOSED, "controller in closed state");
 
       run_next_test();
     };
     controllerState.onChannelClosed(Cr.NS_OK, true);
   };
 }