Bug 1508984 - Enable ESLint for dom/tests/unit/ and dom/system (manual changes) r=Standard8,Ehsan
authorMuchtar Salimov <msalimov@myseneca.ca>
Fri, 18 Jan 2019 18:56:46 +0000
changeset 454578 eab01782e1aab26c84e09a6c2752d0ea998f6897
parent 454577 1b73f4cd7208ac91d88a0b1c98e87cd407f10f43
child 454579 4145884732caac4d1c9f4dcce9326bd0a0b1e79b
push id111289
push usercsabou@mozilla.com
push dateSat, 19 Jan 2019 10:14:46 +0000
treeherdermozilla-inbound@dbc87d86f411 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, Ehsan
bugs1508984
milestone66.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 1508984 - Enable ESLint for dom/tests/unit/ and dom/system (manual changes) r=Standard8,Ehsan Differential Revision: https://phabricator.services.mozilla.com/D13624
.eslintignore
dom/system/NetworkGeolocationProvider.js
dom/system/tests/file_bug1197901.html
dom/system/tests/test_bug1197901.html
dom/system/tests/worker_constants.js
dom/tests/unit/test_Fetch.js
dom/tests/unit/test_PromiseDebugging.js
dom/tests/unit/test_bug319968.js
dom/tests/unit/test_bug465752.js
dom/tests/unit/test_geolocation_position_unavailable.js
dom/tests/unit/test_geolocation_position_unavailable_wrap.js
dom/tests/unit/test_geolocation_provider.js
dom/tests/unit/test_geolocation_provider_timeout.js
dom/tests/unit/test_geolocation_reset_accuracy.js
dom/tests/unit/test_geolocation_reset_accuracy_wrap.js
dom/tests/unit/test_geolocation_timeout.js
dom/tests/unit/test_geolocation_timeout_wrap.js
dom/tests/unit/test_xhr_init.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -203,21 +203,19 @@ dom/quota/**
 dom/security/test/cors/**
 dom/security/test/csp/**
 dom/security/test/general/**
 dom/security/test/mixedcontentblocker/**
 dom/security/test/sri/**
 dom/serviceworkers/**
 dom/smil/**
 dom/svg/**
-dom/system/**
 dom/tests/browser/**
 dom/tests/html/**
 dom/tests/mochitest/**
-dom/tests/unit/**
 dom/u2f/**
 dom/url/**
 dom/vr/**
 dom/webauthn/**
 dom/webgpu/**
 dom/websocket/**
 dom/workers/**
 dom/worklet/**
--- a/dom/system/NetworkGeolocationProvider.js
+++ b/dom/system/NetworkGeolocationProvider.js
@@ -27,17 +27,17 @@ var gLoggingEnabled = false;
 
 var gLocationRequestTimeout = 5000;
 
 var gWifiScanningEnabled = true;
 
 function LOG(aMsg) {
   if (gLoggingEnabled) {
     aMsg = "*** WIFI GEO: " + aMsg + "\n";
-    Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(aMsg);
+    Services.console.logStringMessage(aMsg);
     dump(aMsg);
   }
 }
 
 function CachedRequest(loc, cellInfo, wifiList) {
   this.location = loc;
 
   let wifis = new Set();
@@ -129,18 +129,17 @@ var gDebugCacheReasoning = ""; // for lo
 // 1) do we have a cached request
 // 2) is the cached request better than what newCell and newWifiList will obtain
 // If the cached request exists, and we know it to have greater accuracy
 // by the nature of its origin (wifi/cell/geoip), use its cached location.
 //
 // If there is more source info than the cached request had, return false
 // In other cases, MLS is known to produce better/worse accuracy based on the
 // inputs, so base the decision on that.
-function isCachedRequestMoreAccurateThanServerRequest(newCell, newWifiList)
-{
+function isCachedRequestMoreAccurateThanServerRequest(newCell, newWifiList) {
   gDebugCacheReasoning = "";
   let isNetworkRequestCacheEnabled = true;
   try {
     // Mochitest needs this pref to simulate request failure
     isNetworkRequestCacheEnabled = Services.prefs.getBoolPref("geo.wifi.debug.requestCache.enabled");
     if (!isNetworkRequestCacheEnabled) {
       gCachedRequest = null;
     }
@@ -183,24 +182,23 @@ function isCachedRequestMoreAccurateThan
   gDebugCacheReasoning = "EqualCells:" + hasEqualCells + " EqualWifis:" + hasEqualWifis;
 
   if (gCachedRequest.isCellOnly()) {
     gDebugCacheReasoning += ", Cell only.";
     if (hasEqualCells) {
       return true;
     }
   } else if (gCachedRequest.isWifiOnly() && hasEqualWifis) {
-    gDebugCacheReasoning +=", Wifi only."
+    gDebugCacheReasoning += ", Wifi only.";
     return true;
   } else if (gCachedRequest.isCellAndWifi()) {
      gDebugCacheReasoning += ", Cache has Cell+Wifi.";
     if ((hasEqualCells && hasEqualWifis) ||
         (!newWifiList && hasEqualCells) ||
-        (!newCell && hasEqualWifis))
-    {
+        (!newCell && hasEqualWifis)) {
      return true;
     }
   }
 
   return false;
 }
 
 function WifiGeoCoordsObject(lat, lon, acc) {
@@ -213,157 +211,148 @@ function WifiGeoCoordsObject(lat, lon, a
   // of the JavaScript Coordinates object.
   this.altitude = NaN;
   this.altitudeAccuracy = NaN;
   this.heading = NaN;
   this.speed = NaN;
 }
 
 WifiGeoCoordsObject.prototype = {
-  QueryInterface:  ChromeUtils.generateQI([Ci.nsIDOMGeoPositionCoords])
+  QueryInterface:  ChromeUtils.generateQI([Ci.nsIDOMGeoPositionCoords]),
 };
 
 function WifiGeoPositionObject(lat, lng, acc) {
   this.coords = new WifiGeoCoordsObject(lat, lng, acc);
   this.address = null;
   this.timestamp = Date.now();
 }
 
 WifiGeoPositionObject.prototype = {
-  QueryInterface:   ChromeUtils.generateQI([Ci.nsIDOMGeoPosition])
+  QueryInterface:   ChromeUtils.generateQI([Ci.nsIDOMGeoPosition]),
 };
 
 function WifiGeoPositionProvider() {
-  try {
-    gLoggingEnabled = Services.prefs.getBoolPref("geo.wifi.logging.enabled");
-  } catch (e) {}
-
-  try {
-    gLocationRequestTimeout = Services.prefs.getIntPref("geo.wifi.timeToWaitBeforeSending");
-  } catch (e) {}
-
-  try {
-    gWifiScanningEnabled = Services.prefs.getBoolPref("geo.wifi.scan");
-  } catch (e) {}
+  gLoggingEnabled = Services.prefs.getBoolPref("geo.wifi.logging.enabled", false);
+  gLocationRequestTimeout = Services.prefs.getIntPref("geo.wifi.timeToWaitBeforeSending", 5000);
+  gWifiScanningEnabled = Services.prefs.getBoolPref("geo.wifi.scan", true);
 
   this.wifiService = null;
   this.timer = null;
   this.started = false;
 }
 
 WifiGeoPositionProvider.prototype = {
   classID:          Components.ID("{77DA64D3-7458-4920-9491-86CC9914F904}"),
   QueryInterface:   ChromeUtils.generateQI([Ci.nsIGeolocationProvider,
                                             Ci.nsIWifiListener,
                                             Ci.nsITimerCallback,
                                             Ci.nsIObserver]),
   listener: null,
 
-  resetTimer: function() {
+  resetTimer() {
     if (this.timer) {
       this.timer.cancel();
       this.timer = null;
     }
     // wifi thread triggers WifiGeoPositionProvider to proceed, with no wifi, do manual timeout
     this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     this.timer.initWithCallback(this,
                                 gLocationRequestTimeout,
                                 this.timer.TYPE_REPEATING_SLACK);
   },
 
-  startup:  function() {
+  startup() {
     if (this.started)
       return;
 
     this.started = true;
-    let self = this;
 
     if (gWifiScanningEnabled && Cc["@mozilla.org/wifi/monitor;1"]) {
       if (this.wifiService) {
         this.wifiService.stopWatching(this);
       }
       this.wifiService = Cc["@mozilla.org/wifi/monitor;1"].getService(Ci.nsIWifiMonitor);
       this.wifiService.startWatching(this);
     }
 
     this.resetTimer();
     LOG("startup called.");
   },
 
-  watch: function(c) {
+  watch(c) {
     this.listener = c;
   },
 
-  shutdown: function() {
+  shutdown() {
     LOG("shutdown called");
-    if (this.started == false) {
+    if (!this.started) {
       return;
     }
 
     // Without clearing this, we could end up using the cache almost indefinitely
     // TODO: add logic for cache lifespan, for now just be safe and clear it
     gCachedRequest = null;
 
     if (this.timer) {
       this.timer.cancel();
       this.timer = null;
     }
 
-    if(this.wifiService) {
+    if (this.wifiService) {
       this.wifiService.stopWatching(this);
       this.wifiService = null;
     }
 
     this.listener = null;
     this.started = false;
   },
 
-  setHighAccuracy: function(enable) {
+  setHighAccuracy(enable) {
   },
 
-  onChange: function(accessPoints) {
+  onChange(accessPoints) {
 
     // we got some wifi data, rearm the timer.
     this.resetTimer();
 
     function isPublic(ap) {
-      let mask = "_nomap"
+      let mask = "_nomap";
       let result = ap.ssid.indexOf(mask, ap.ssid.length - mask.length);
       if (result != -1) {
         LOG("Filtering out " + ap.ssid + " " + result);
         return false;
       }
       return true;
-    };
+    }
 
     function sort(a, b) {
       return b.signal - a.signal;
-    };
+    }
 
     function encode(ap) {
-      return { 'macAddress': ap.mac, 'signalStrength': ap.signal };
-    };
+      return { "macAddress": ap.mac, "signalStrength": ap.signal };
+    }
 
     let wifiData = null;
     if (accessPoints) {
       wifiData = accessPoints.filter(isPublic).sort(sort).map(encode);
     }
     this.sendLocationRequest(wifiData);
   },
 
-  onError: function (code) {
+  onError(code) {
     LOG("wifi error: " + code);
     this.sendLocationRequest(null);
   },
 
-  notify: function (timer) {
+  notify(timer) {
     this.sendLocationRequest(null);
   },
 
-  sendLocationRequest: function (wifiData) {
+  sendLocationRequest(wifiData) {
     let data = { cellTowers: undefined, wifiAccessPoints: undefined };
     if (wifiData && wifiData.length >= 2) {
       data.wifiAccessPoints = wifiData;
     }
 
     let useCached = isCachedRequestMoreAccurateThanServerRequest(data.cellTowers,
                                                                  data.wifiAccessPoints);
 
@@ -389,24 +378,24 @@ WifiGeoPositionProvider.prototype = {
       notifyPositionUnavailable(this.listener);
       return;
     }
     xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
     xhr.responseType = "json";
     xhr.mozBackgroundRequest = true;
     xhr.timeout = Services.prefs.getIntPref("geo.wifi.xhr.timeout");
     xhr.ontimeout = () => {
-      LOG("Location request XHR timed out.")
+      LOG("Location request XHR timed out.");
       notifyPositionUnavailable(this.listener);
     };
     xhr.onerror = () => {
       notifyPositionUnavailable(this.listener);
     };
     xhr.onload = () => {
-      LOG("server returned status: " + xhr.status + " --> " +  JSON.stringify(xhr.response));
+      LOG("server returned status: " + xhr.status + " --> " + JSON.stringify(xhr.response));
       if ((xhr.channel instanceof Ci.nsIHttpChannel && xhr.status != 200) ||
           !xhr.response || !xhr.response.location) {
         notifyPositionUnavailable(this.listener);
         return;
       }
 
       let newLocation = new WifiGeoPositionObject(xhr.response.location.lat,
                                                   xhr.response.location.lng,
@@ -422,12 +411,12 @@ WifiGeoPositionProvider.prototype = {
     LOG("sending " + requestData);
     xhr.send(requestData);
 
     function notifyPositionUnavailable(listener) {
       if (listener) {
         listener.notifyError(POSITION_UNAVAILABLE);
       }
     }
-  }
+  },
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiGeoPositionProvider]);
--- a/dom/system/tests/file_bug1197901.html
+++ b/dom/system/tests/file_bug1197901.html
@@ -1,16 +1,16 @@
 <pre>Sensor events testing</pre>
 <script>
 
-window.onmessage = function (event) {
+window.onmessage = function(event) {
   if (event.data.command == "addEventListener") {
     window.addEventListener(
       "devicemotion", function() {
           event.source.postMessage({ result: event.data.expected,
                                      message: event.data.message },
                                    "*");
         }
       );
   }
-}
+};
 
 </script>
--- a/dom/system/tests/test_bug1197901.html
+++ b/dom/system/tests/test_bug1197901.html
@@ -10,25 +10,25 @@ https://bugzilla.mozilla.org/show_bug.cg
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
   /** Test for Bug 1197901 **/
   SimpleTest.requestFlakyTimeout("requestFlakyTimeout is silly");
   SimpleTest.waitForExplicitFinish();
   window.onload = function() {
     SimpleTest.waitForFocus(function() {
-      SpecialPowers.pushPrefEnv({"set": [['device.sensors.test.events', true]]},
-                                doTest); 
+      SpecialPowers.pushPrefEnv({"set": [["device.sensors.test.events", true]]},
+                                doTest);
       }, window);
-  }
+  };
 
   function doTest() {
     window.onmessage = function(event) {
       ok(event.data.result, event.data.message);
-    }
+    };
 
     // Only same-origin iframe should get the events.
     var xo = document.getElementById("cross-origin");
     xo.contentWindow.postMessage(
       { command: "addEventListener",
         expected: false,
         message: "Cross-origin iframe shouldn't get the sensor events."},
       "*");
@@ -70,19 +70,19 @@ https://bugzilla.mozilla.org/show_bug.cg
               "*");
             setTimeout(function() {
               window.onmessage = null;
               win.close();
               win2.close();
               SimpleTest.finish();
             }, 500);
           }, win2);
-        }
+        };
       }, win);
-    }
+    };
   }
 
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
 <p id="display"></p>
 <div id="content" style="display: none">
--- a/dom/system/tests/worker_constants.js
+++ b/dom/system/tests/worker_constants.js
@@ -1,22 +1,23 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
+/* eslint-env mozilla/chrome-worker */
 
 function log(text) {
-  dump("WORKER "+text+"\n");
+  dump("WORKER " + text + "\n");
 }
 
 function send(message) {
   self.postMessage(message);
 }
 
 self.onmessage = function(msg) {
-  self.onmessage = function(msg) {
-    log("ignored message "+JSON.stringify(msg.data));
+  self.onmessage = function(msgInner) {
+    log("ignored message " + JSON.stringify(msgInner.data));
   };
   let { isDebugBuild, umask } = msg.data;
   try {
     test_name();
     test_xul();
     test_debugBuildWorkerThread(isDebugBuild);
     test_umaskWorkerThread(umask);
     test_bits();
@@ -29,40 +30,40 @@ self.onmessage = function(msg) {
   finish();
 };
 
 function finish() {
   send({kind: "finish"});
 }
 
 function ok(condition, description) {
-  send({kind: "ok", condition: condition, description:description});
+  send({kind: "ok", condition, description});
 }
 function is(a, b, description) {
-  send({kind: "is", a: a, b:b, description:description});
+  send({kind: "is", a, b, description});
 }
 function isnot(a, b, description) {
-  send({kind: "isnot", a: a, b:b, description:description});
+  send({kind: "isnot", a, b, description});
 }
 
 // Test that OS.Constants.Sys.Name is defined
 function test_name() {
   isnot(null, OS.Constants.Sys.Name, "OS.Constants.Sys.Name is defined");
 }
 
 // Test that OS.Constants.Sys.DEBUG is set properly in ChromeWorker thread
 function test_debugBuildWorkerThread(isDebugBuild) {
   is(isDebugBuild, !!OS.Constants.Sys.DEBUG, "OS.Constants.Sys.DEBUG is set properly on worker thread");
 }
 
 // Test that OS.Constants.Sys.umask is set properly in ChromeWorker thread
 function test_umaskWorkerThread(umask) {
   is(umask, OS.Constants.Sys.umask,
      "OS.Constants.Sys.umask is set properly on worker thread: " +
-     ("0000"+umask.toString(8)).slice(-4));
+     ("0000" + umask.toString(8)).slice(-4));
 }
 
 // Test that OS.Constants.Path.libxul lets us open libxul
 function test_xul() {
   let lib;
   isnot(null, OS.Constants.Path.libxul, "libxul is defined");
   try {
     lib = ctypes.open(OS.Constants.Path.libxul);
@@ -72,11 +73,11 @@ function test_xul() {
   }
   if (lib) {
     lib.close();
   }
   ok(true, "test_xul: opened libxul successfully");
 }
 
 // Check if the value of OS.Constants.Sys.bits is 32 or 64
-function test_bits(){
+function test_bits() {
   is(OS.Constants.Sys.bits, ctypes.int.ptr.size * 8, "OS.Constants.Sys.bits is either 32 or 64");
 }
--- a/dom/tests/unit/test_Fetch.js
+++ b/dom/tests/unit/test_Fetch.js
@@ -1,37 +1,37 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-Cu.importGlobalProperties(['fetch']);
+Cu.importGlobalProperties(["fetch"]);
 ChromeUtils.import("resource://testing-common/httpd.js");
 
 const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
   "nsIBinaryInputStream", "setInputStream");
 
 var server;
 
-function getBaseUrl () {
+function getBaseUrl() {
   return "http://localhost:" + server.identity.primaryPort;
 }
 
 // a way to create some test defaults
 function createTestData(testPath) {
   return {
-    testPath: testPath,
+    testPath,
     request: {
       headers: {},
       contentType: "application/json",
     },
     response: {
       headers: {},
       contentType: "application/json",
       body: "{\"Look\": \"Success!\"}",
       status: 200,
-      statusText: "OK"
+      statusText: "OK",
     },
   };
 }
 
 // read body and content type information from a request
 function readDataFromRequest(aRequest) {
   let requestData = {};
   if (aRequest.method == "POST" || aRequest.method == "PUT") {
@@ -85,17 +85,17 @@ add_test(function test_GetData() {
       writeDataToResponse(testData.response, aResponse);
     } catch (e) {
       do_report_unexpected_exception(e);
     }
   });
 
   // fetch, via GET, with some request headers set
   fetch(getBaseUrl() + testData.testPath, {headers: testData.request.headers})
-    .then(function(response){
+    .then(function(response) {
     // check response looks as expected
     Assert.ok(response.ok);
     Assert.equal(response.status, testData.response.status);
     Assert.equal(response.statusText, testData.response.statusText);
 
     // check a response header looks OK:
     Assert.equal(response.headers.get("Content-Type"),
                  testData.response.contentType);
@@ -105,17 +105,17 @@ add_test(function test_GetData() {
                  testData.response.contentType);
 
     // ensure response.text() returns a promise that resolves appropriately
     response.text().then(function(text) {
       Assert.equal(text, testData.response.body);
       do_test_finished();
       run_next_test();
     });
-  }).catch(function(e){
+  }).catch(function(e) {
     do_report_unexpected_exception(e);
     do_test_finished();
     run_next_test();
   });
 });
 
 // test a GET with no init
 add_test(function test_GetDataNoInit() {
@@ -128,28 +128,28 @@ add_test(function test_GetDataNoInit() {
       // send a response
       writeDataToResponse(testData.response, aResponse);
     } catch (e) {
       do_report_unexpected_exception(e);
     }
   });
 
   fetch(getBaseUrl() + testData.testPath, {headers: testData.request.headers})
-    .then(function(response){
+    .then(function(response) {
     // check response looks as expected
     Assert.ok(response.ok);
     Assert.equal(response.status, testData.response.status);
 
     // ensure response.text() returns a promise that resolves appropriately
     response.text().then(function(text) {
       Assert.equal(text, testData.response.body);
       do_test_finished();
       run_next_test();
     });
-  }).catch(function(e){
+  }).catch(function(e) {
     do_report_unexpected_exception(e);
     do_test_finished();
     run_next_test();
   });
 });
 
 // test some error responses
 add_test(function test_get40x() {
@@ -158,17 +158,17 @@ add_test(function test_get40x() {
   // prepare a response with some 40x error - a 404 will do
   let notFoundData = createTestData("/getNotFound");
   notFoundData.response.status = 404;
   notFoundData.response.statusText = "Not found";
   notFoundData.response.body = null;
 
   // No need to register a path handler - httpd will return 404 anyway.
   // Fetch, via GET, the resource that doesn't exist
-  fetch(getBaseUrl() + notFoundData.testPath).then(function(response){
+  fetch(getBaseUrl() + notFoundData.testPath).then(function(response) {
     Assert.equal(response.status, 404);
     do_test_finished();
     run_next_test();
   });
 });
 
 add_test(function test_get50x() {
   do_test_pending();
@@ -185,17 +185,17 @@ add_test(function test_get50x() {
       // send the error response
       writeDataToResponse(serverErrorData.response, aResponse);
     } catch (e) {
       do_report_unexpected_exception(e);
     }
   });
 
   // fetch, via GET, the resource that creates a server error
-  fetch(getBaseUrl() + serverErrorData.testPath).then(function(response){
+  fetch(getBaseUrl() + serverErrorData.testPath).then(function(response) {
     Assert.equal(response.status, 500);
     do_test_finished();
     run_next_test();
   });
 });
 
 // test a failure to connect
 add_test(function test_getTestFailedConnect() {
@@ -257,18 +257,18 @@ add_test(function test_PostJSONData() {
       Assert.ok(false);
     }
   });
 
   fetch(getBaseUrl() + testData.testPath, {
     method: "POST",
     body: testData.request.body,
     headers: {
-      'Content-Type': 'application/json'
-    }
+      "Content-Type": "application/json",
+    },
   }).then(function(aResponse) {
     Assert.ok(aResponse.ok);
     Assert.equal(aResponse.status, testData.response.status);
     Assert.equal(aResponse.statusText, testData.response.statusText);
 
     do_test_finished();
     run_next_test();
   }).catch(function(e) {
@@ -303,18 +303,18 @@ add_test(function test_PostTextData() {
       Assert.ok(false);
     }
   });
 
   fetch(getBaseUrl() + testData.testPath, {
     method: "POST",
     body: testData.request.body,
     headers: {
-      'Content-Type': testData.request.contentType
-    }
+      "Content-Type": testData.request.contentType,
+    },
   }).then(function(aResponse) {
     Assert.ok(aResponse.ok);
     Assert.equal(aResponse.status, testData.response.status);
     Assert.equal(aResponse.statusText, testData.response.statusText);
 
     // check the response header is set OK
     Assert.equal(aResponse.headers.get(responseHeaderName),
                  testData.response.headers[responseHeaderName]);
--- a/dom/tests/unit/test_PromiseDebugging.js
+++ b/dom/tests/unit/test_PromiseDebugging.js
@@ -1,20 +1,19 @@
-function run_test()
-{
+function run_test() {
     // Hack around Promise.jsm being stuck on my global
     Assert.equal(false, PromiseDebugging === undefined);
     var res;
-    var p = new Promise(function(resolve, reject) { res = resolve });
+    var p = new Promise(function(resolve, reject) { res = resolve; });
     var state = PromiseDebugging.getState(p);
     Assert.equal(state.state, "pending");
 
     do_test_pending();
 
     p.then(function() {
-        var state = PromiseDebugging.getState(p);
-        Assert.equal(state.state, "fulfilled");
-        Assert.equal(state.value, 5);
-	do_test_finished();
+        var state2 = PromiseDebugging.getState(p);
+        Assert.equal(state2.state, "fulfilled");
+        Assert.equal(state2.value, 5);
+        do_test_finished();
     });
 
     res(5);
 }
--- a/dom/tests/unit/test_bug319968.js
+++ b/dom/tests/unit/test_bug319968.js
@@ -1,17 +1,16 @@
 /* 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/.
  */
 
 Cu.importGlobalProperties(["DOMParser"]);
 
-function run_test()
-{
+function run_test() {
   var domParser = new DOMParser();
   var aDom = domParser.parseFromString("<root><feed><entry/><entry/></feed></root>",
                                        "application/xml");
   var feedList = aDom.getElementsByTagName("feed");
   Assert.notEqual(feedList, null);
   Assert.equal(feedList.length, 1);
   Assert.notEqual(feedList[0], null);
   Assert.equal(feedList[0].tagName, "feed");
--- a/dom/tests/unit/test_bug465752.js
+++ b/dom/tests/unit/test_bug465752.js
@@ -1,22 +1,20 @@
 /* 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/.
  */
+ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-function run_test()
-{
-  const ios = Cc["@mozilla.org/network/io-service;1"]
-                .getService(Ci.nsIIOService);
+function run_test() {
   const str = "javascript:10";
-  var uri = ios.newURI(str);
-  var uri2 = ios.newURI(str);
+  var uri = Services.io.newURI(str);
+  var uri2 = Services.io.newURI(str);
   const str2 = "http://example.org";
-  var uri3 = ios.newURI(str2);
+  var uri3 = Services.io.newURI(str2);
   Assert.ok(uri.equals(uri));
   Assert.ok(uri.equals(uri2));
   Assert.ok(uri2.equals(uri));
   Assert.ok(uri2.equals(uri2));
   Assert.ok(!uri3.equals(uri2));
   Assert.ok(!uri2.equals(uri3));
 
   var simple = Cc["@mozilla.org/network/simple-uri-mutator;1"]
--- a/dom/tests/unit/test_geolocation_position_unavailable.js
+++ b/dom/tests/unit/test_geolocation_position_unavailable.js
@@ -1,32 +1,31 @@
-function successCallback() {
-  Assert.ok(false);
-  do_test_finished();
-}
-
-function errorCallback(err) {
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+function successCallback() {
+  Assert.ok(false);
+  do_test_finished();
+}
+
+function errorCallback(err) {
   // PositionError has no interface object, so we can't get constants off that.
-  Assert.equal(err.POSITION_UNAVAILABLE, err.code);
-  Assert.equal(2, err.code);
-  do_test_finished();
-}
-
-function run_test()
-{
-  do_test_pending();
-
-  if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
-        .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
-    // XPCShell does not get a profile by default. The geolocation service
-    // depends on the settings service which uses IndexedDB and IndexedDB
-    // needs a place where it can store databases.
-    do_get_profile();
-
-    var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-    prefs.setBoolPref("geo.wifi.scan", false);
-    prefs.setCharPref("geo.wifi.uri", "UrlNotUsedHere:");
-    prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
-  }
-
-  geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
-  geolocation.getCurrentPosition(successCallback, errorCallback);
-}
+  Assert.equal(err.POSITION_UNAVAILABLE, err.code);
+  Assert.equal(2, err.code);
+  do_test_finished();
+}
+
+function run_test() {
+  do_test_pending();
+
+  if (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
+    // XPCShell does not get a profile by default. The geolocation service
+    // depends on the settings service which uses IndexedDB and IndexedDB
+    // needs a place where it can store databases.
+    do_get_profile();
+
+    Services.prefs.setBoolPref("geo.wifi.scan", false);
+    Services.prefs.setCharPref("geo.wifi.uri", "UrlNotUsedHere:");
+    Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+  }
+
+  var geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
+  geolocation.getCurrentPosition(successCallback, errorCallback);
+}
--- a/dom/tests/unit/test_geolocation_position_unavailable_wrap.js
+++ b/dom/tests/unit/test_geolocation_position_unavailable_wrap.js
@@ -1,8 +1,9 @@
-function run_test() {
-  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-  prefs.setBoolPref("geo.wifi.scan", false);
-
-  prefs.setCharPref("geo.wifi.uri", "UrlNotUsedHere");
-  prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
-  run_test_in_child("./test_geolocation_position_unavailable.js");
-}
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+function run_test() {
+  Services.prefs.setBoolPref("geo.wifi.scan", false);
+
+  Services.prefs.setCharPref("geo.wifi.uri", "UrlNotUsedHere");
+  Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+  run_test_in_child("./test_geolocation_position_unavailable.js");
+}
--- a/dom/tests/unit/test_geolocation_provider.js
+++ b/dom/tests/unit/test_geolocation_provider.js
@@ -1,87 +1,79 @@
 ChromeUtils.import("resource://testing-common/httpd.js");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var httpserver = null;
 var geolocation = null;
 var success = false;
-var watchId = -1;
+var watchID = -1;
 
 function terminate(succ) {
       success = succ;
       geolocation.clearWatch(watchID);
     }
 
-function successCallback(pos){ terminate(true); }
+function successCallback(pos) { terminate(true); }
 function errorCallback(pos) { terminate(false); }
 
 var observer = {
-    QueryInterface: function(iid) {
-    if (iid.equals(Ci.nsISupports) ||
-        iid.equals(Ci.nsIObserver))
-        return this;
-    throw Cr.NS_ERROR_NO_INTERFACE;
-    },
+    QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
 
-    observe: function(subject, topic, data) {
+    observe(subject, topic, data) {
         if (data == "shutdown") {
             Assert.ok(1);
             this._numProviders--;
             if (!this._numProviders) {
                 httpserver.stop(function() {
                         Assert.ok(success);
                         do_test_finished();
                     });
             }
-        }
-        else if (data == "starting") {
+        } else if (data == "starting") {
             Assert.ok(1);
             this._numProviders++;
         }
     },
 
     _numProviders: 0,
 };
 
-function geoHandler(metadata, response)
-{
+function geoHandler(metadata, response) {
     var georesponse = {
         status: "OK",
         location: {
             lat: 42,
             lng: 42,
         },
         accuracy: 42,
     };
   var position = JSON.stringify(georesponse);
   response.setStatusLine("1.0", 200, "OK");
   response.setHeader("Cache-Control", "no-cache", false);
   response.setHeader("Content-Type", "aplication/x-javascript", false);
   response.write(position);
 }
 
-function run_test()
-{
+function run_test() {
     // XPCShell does not get a profile by default. The geolocation service
     // depends on the settings service which uses IndexedDB and IndexedDB
     // needs a place where it can store databases.
     do_get_profile();
 
     // only kill this test when shutdown is called on the provider.
     do_test_pending();
 
     httpserver = new HttpServer();
     httpserver.registerPathHandler("/geo", geoHandler);
     httpserver.start(-1);
 
-    var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-    prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
-                      httpserver.identity.primaryPort + "/geo");
-    prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
-    prefs.setBoolPref("geo.wifi.scan", false);
+    Services.prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
+                               httpserver.identity.primaryPort + "/geo");
+    Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+    Services.prefs.setBoolPref("geo.wifi.scan", false);
 
     var obs = Cc["@mozilla.org/observer-service;1"].getService();
     obs = obs.QueryInterface(Ci.nsIObserverService);
     obs.addObserver(observer, "geolocation-device-events");
 
     geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
     watchID = geolocation.watchPosition(successCallback, errorCallback);
 }
--- a/dom/tests/unit/test_geolocation_provider_timeout.js
+++ b/dom/tests/unit/test_geolocation_provider_timeout.js
@@ -1,45 +1,44 @@
 ChromeUtils.import("resource://testing-common/httpd.js");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 
 var httpserver = null;
 var geolocation = null;
 
-function geoHandler(metadata, response)
-{
+function geoHandler(metadata, response) {
   response.processAsync();
 }
 
 function successCallback() {
   // The call shouldn't be sucessful.
   Assert.ok(false);
   do_test_finished();
 }
 
 function errorCallback() {
   Assert.ok(true);
   do_test_finished();
 }
 
-function run_test()
-{
+function run_test() {
   do_test_pending();
 
   // XPCShell does not get a profile by default. The geolocation service
   // depends on the settings service which uses IndexedDB and IndexedDB
   // needs a place where it can store databases.
   do_get_profile();
 
   httpserver = new HttpServer();
   httpserver.registerPathHandler("/geo", geoHandler);
   httpserver.start(-1);
-  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-  prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
-                      httpserver.identity.primaryPort + "/geo");
-  prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
-  prefs.setBoolPref("geo.wifi.scan", false);
+  Services.prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
+                             httpserver.identity.primaryPort + "/geo");
+  Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+  Services.prefs.setBoolPref("geo.wifi.scan", false);
 
   // Setting timeout to a very low value to ensure time out will happen.
-  prefs.setIntPref("geo.wifi.xhr.timeout", 5);
+  Services.prefs.setIntPref("geo.wifi.xhr.timeout", 5);
 
   geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
   geolocation.getCurrentPosition(successCallback, errorCallback);
 }
--- a/dom/tests/unit/test_geolocation_reset_accuracy.js
+++ b/dom/tests/unit/test_geolocation_reset_accuracy.js
@@ -1,109 +1,91 @@
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
 const providerContract = "@mozilla.org/geolocation/provider;1";
 
 const categoryName = "geolocation-provider";
 
 var provider = {
-  QueryInterface: function eventsink_qi(iid) {
-    if (iid.equals(Ci.nsISupports) ||
-        iid.equals(Ci.nsIFactory) ||
-        iid.equals(Ci.nsIGeolocationProvider))
-      return this;
-    throw Cr.NS_ERROR_NO_INTERFACE;
-  },
+  QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIGeolocationProvider"]),
   createInstance: function eventsink_ci(outer, iid) {
     if (outer)
       throw Cr.NS_ERROR_NO_AGGREGATION;
     return this.QueryInterface(iid);
   },
   lockFactory: function eventsink_lockf(lock) {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
-  startup: function() {
+  startup() {
   },
-  watch: function() {
+  watch() {
   },
-  shutdown: function() {
+  shutdown() {
   },
-  setHighAccuracy: function(enable) {
+  setHighAccuracy(enable) {
     this._isHigh = enable;
     if (enable) {
       this._seenHigh = true;
       executeSoon(stop_high_accuracy_watch);
     }
   },
   _isHigh: false,
-  _seenHigh: false
+  _seenHigh: false,
 };
 
-var runningInParent = true;
-try {
-  runningInParent = Cc["@mozilla.org/xre/runtime;1"].
-                    getService(Ci.nsIXULRuntime).processType
-                    == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
-}
-catch (e) { }
-
-function successCallback()
-{
+function successCallback() {
   Assert.ok(false);
   do_test_finished();
 }
 
-function errorCallback()
-{
+function errorCallback() {
   Assert.ok(false);
   do_test_finished();
 }
 
 var geolocation;
 var watchID2;
 
-function run_test()
-{
+function run_test() {
   if (runningInParent) {
     // XPCShell does not get a profile by default. The geolocation service
     // depends on the settings service which uses IndexedDB and IndexedDB
     // needs a place where it can store databases.
     do_get_profile();
 
     Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
       "Unit test geo provider", providerContract, provider);
-    var catMan = Cc["@mozilla.org/categorymanager;1"]
-                   .getService(Ci.nsICategoryManager);
-    catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
-                                               providerContract, false, true);
 
-    var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-    prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
-    prefs.setBoolPref("geo.wifi.scan", false);
+    Services.catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
+                                                        providerContract, false, true);
+
+    Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+    Services.prefs.setBoolPref("geo.wifi.scan", false);
   }
 
   do_test_pending();
 
   geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
-  let watchID1 = geolocation.watchPosition(successCallback, errorCallback);
+  geolocation.watchPosition(successCallback, errorCallback);
   watchID2 = geolocation.watchPosition(successCallback, errorCallback,
                                        {enableHighAccuracy: true});
 
   if (!runningInParent) {
-    do_await_remote_message('high_acc_enabled', stop_high_accuracy_watch);
+    do_await_remote_message("high_acc_enabled", stop_high_accuracy_watch);
   }
 }
 
 function stop_high_accuracy_watch() {
     geolocation.clearWatch(watchID2);
     check_results();
     do_test_finished();
 }
 
-function check_results()
-{
+function check_results() {
   if (runningInParent) {
     // check the provider was set to high accuracy during the test
     Assert.ok(provider._seenHigh);
     // check the provider is not currently set to high accuracy
     Assert.ok(!provider._isHigh);
   }
   do_test_finished();
 }
--- a/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js
+++ b/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js
@@ -1,68 +1,60 @@
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
 const providerContract = "@mozilla.org/geolocation/provider;1";
 
 const categoryName = "geolocation-provider";
 
 var provider = {
-  QueryInterface: function eventsink_qi(iid) {
-    if (iid.equals(Ci.nsISupports) ||
-        iid.equals(Ci.nsIFactory) ||
-        iid.equals(Ci.nsIGeolocationProvider))
-      return this;
-    throw Cr.NS_ERROR_NO_INTERFACE;
-  },
+  QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIGeolocationProvider"]),
   createInstance: function eventsink_ci(outer, iid) {
     if (outer)
       throw Cr.NS_ERROR_NO_AGGREGATION;
     return this.QueryInterface(iid);
   },
   lockFactory: function eventsink_lockf(lock) {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
-  startup: function() {
+  startup() {
   },
-  watch: function() {
+  watch() {
   },
-  shutdown: function() {
+  shutdown() {
   },
-  setHighAccuracy: function(enable) {
+  setHighAccuracy(enable) {
     this._isHigh = enable;
     if (enable) {
       this._seenHigh = true;
-      do_send_remote_message('high_acc_enabled');
+      do_send_remote_message("high_acc_enabled");
     }
   },
   _isHigh: false,
-  _seenHigh: false
+  _seenHigh: false,
 };
 
-function run_test()
-{
+function run_test() {
   // XPCShell does not get a profile by default. The geolocation service
   // depends on the settings service which uses IndexedDB and IndexedDB
   // needs a place where it can store databases.
   do_get_profile();
 
   Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
     "Unit test geo provider", providerContract, provider);
-  var catMan = Cc["@mozilla.org/categorymanager;1"]
-                 .getService(Ci.nsICategoryManager);
-  catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
-                                             providerContract, false, true);
 
-  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-  prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
-  prefs.setBoolPref("geo.wifi.scan", false);
+  Services.catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
+                                                      providerContract, false, true);
+
+  Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+  Services.prefs.setBoolPref("geo.wifi.scan", false);
 
   run_test_in_child("test_geolocation_reset_accuracy.js", check_results);
 }
 
-function check_results()
-{
+function check_results() {
   // check the provider was set to high accuracy during the test
   Assert.ok(provider._seenHigh);
   // check the provider is not currently set to high accuracy
   Assert.ok(!provider._isHigh);
 
   do_test_finished();
 }
--- a/dom/tests/unit/test_geolocation_timeout.js
+++ b/dom/tests/unit/test_geolocation_timeout.js
@@ -1,17 +1,18 @@
 ChromeUtils.import("resource://testing-common/httpd.js");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 
 var httpserver = null;
 var geolocation = null;
 var success = false;
 var watchId = -1;
 
-function geoHandler(metadata, response)
-{
+function geoHandler(metadata, response) {
     var georesponse = {
         status: "OK",
         location: {
             lat: 42,
             lng: 42,
         },
         accuracy: 42,
     };
@@ -31,32 +32,29 @@ function successCallback() {
   do_test_finished();
 }
 
 function errorCallback() {
   Assert.ok(true);
   do_test_finished();
 }
 
-function run_test()
-{
+function run_test() {
   do_test_pending();
 
-  if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
-        .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
+  if (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
     // XPCShell does not get a profile by default. The geolocation service
     // depends on the settings service which uses IndexedDB and IndexedDB
     // needs a place where it can store databases.
     do_get_profile();
 
     httpserver = new HttpServer();
     httpserver.registerPathHandler("/geo", geoHandler);
     httpserver.start(-1);
-    var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-    prefs.setBoolPref("geo.wifi.scan", false);
-    prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
-                      httpserver.identity.primaryPort + "/geo");
-    prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+    Services.prefs.setBoolPref("geo.wifi.scan", false);
+    Services.prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
+                               httpserver.identity.primaryPort + "/geo");
+    Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
   }
 
   geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
   geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 2000});
 }
--- a/dom/tests/unit/test_geolocation_timeout_wrap.js
+++ b/dom/tests/unit/test_geolocation_timeout_wrap.js
@@ -1,15 +1,16 @@
 ChromeUtils.import("resource://testing-common/httpd.js");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 
 var httpserver = null;
 
 function run_test() {
-  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-  prefs.setBoolPref("geo.wifi.scan", false);
+  Services.prefs.setBoolPref("geo.wifi.scan", false);
 
   httpserver = new HttpServer();
   httpserver.start(-1);
-  prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
-                    httpserver.identity.primaryPort + "/geo");
-  prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+  Services.prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
+                             httpserver.identity.primaryPort + "/geo");
+  Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
   run_test_in_child("./test_geolocation_timeout.js");
 }
--- a/dom/tests/unit/test_xhr_init.js
+++ b/dom/tests/unit/test_xhr_init.js
@@ -1,10 +1,9 @@
-function run_test()
-{
+function run_test() {
     Cu.importGlobalProperties(["XMLHttpRequest"]);
 
     var x = new XMLHttpRequest({mozAnon: true, mozSystem: false});
     Assert.ok(x.mozAnon);
     Assert.ok(x.mozSystem); // Because we're system principal
 
     x = new XMLHttpRequest({mozAnon: true});
     Assert.ok(x.mozAnon);