From a12b9e7b37ba56bda1511affd2636c953472c6a8 Mon Sep 17 00:00:00 2001 From: Muchtar Salimov Date: Fri, 18 Jan 2019 18:56:46 +0000 Subject: [PATCH] Bug 1508984 - Enable ESLint for dom/tests/unit/ and dom/system (manual changes) r=Standard8,Ehsan Differential Revision: https://phabricator.services.mozilla.com/D13624 --HG-- extra : moz-landing-system : lando --- .eslintignore | 2 - dom/system/NetworkGeolocationProvider.js | 67 ++++++++----------- dom/system/tests/file_bug1197901.html | 4 +- dom/system/tests/test_bug1197901.html | 12 ++-- dom/system/tests/worker_constants.js | 17 ++--- dom/tests/unit/test_Fetch.js | 28 ++++---- dom/tests/unit/test_PromiseDebugging.js | 13 ++-- dom/tests/unit/test_bug319968.js | 3 +- dom/tests/unit/test_bug465752.js | 12 ++-- .../test_geolocation_position_unavailable.js | 61 +++++++++-------- ...t_geolocation_position_unavailable_wrap.js | 17 ++--- dom/tests/unit/test_geolocation_provider.js | 32 ++++----- .../unit/test_geolocation_provider_timeout.js | 19 +++--- .../unit/test_geolocation_reset_accuracy.js | 56 ++++++---------- .../test_geolocation_reset_accuracy_wrap.js | 40 +++++------ dom/tests/unit/test_geolocation_timeout.js | 20 +++--- .../unit/test_geolocation_timeout_wrap.js | 11 +-- dom/tests/unit/test_xhr_init.js | 3 +- 18 files changed, 182 insertions(+), 235 deletions(-) diff --git a/.eslintignore b/.eslintignore index e7999a5eafee..fefc7a1f8a69 100644 --- a/.eslintignore +++ b/.eslintignore @@ -208,11 +208,9 @@ 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/** diff --git a/dom/system/NetworkGeolocationProvider.js b/dom/system/NetworkGeolocationProvider.js index 59c5abf726bf..e7505cd10f91 100644 --- a/dom/system/NetworkGeolocationProvider.js +++ b/dom/system/NetworkGeolocationProvider.js @@ -32,7 +32,7 @@ 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); } } @@ -134,8 +134,7 @@ var gDebugCacheReasoning = ""; // for logging the caching logic // 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 { @@ -188,14 +187,13 @@ function isCachedRequestMoreAccurateThanServerRequest(newCell, newWifiList) 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; } } @@ -218,7 +216,7 @@ function WifiGeoCoordsObject(lat, lon, acc) { } WifiGeoCoordsObject.prototype = { - QueryInterface: ChromeUtils.generateQI([Ci.nsIDOMGeoPositionCoords]) + QueryInterface: ChromeUtils.generateQI([Ci.nsIDOMGeoPositionCoords]), }; function WifiGeoPositionObject(lat, lng, acc) { @@ -228,21 +226,13 @@ function WifiGeoPositionObject(lat, lng, acc) { } 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; @@ -257,7 +247,7 @@ WifiGeoPositionProvider.prototype = { Ci.nsIObserver]), listener: null, - resetTimer: function() { + resetTimer() { if (this.timer) { this.timer.cancel(); this.timer = null; @@ -269,12 +259,11 @@ WifiGeoPositionProvider.prototype = { 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) { @@ -288,13 +277,13 @@ WifiGeoPositionProvider.prototype = { 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; } @@ -307,7 +296,7 @@ WifiGeoPositionProvider.prototype = { this.timer = null; } - if(this.wifiService) { + if (this.wifiService) { this.wifiService.stopWatching(this); this.wifiService = null; } @@ -316,31 +305,31 @@ WifiGeoPositionProvider.prototype = { 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) { @@ -349,16 +338,16 @@ WifiGeoPositionProvider.prototype = { 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; @@ -394,14 +383,14 @@ WifiGeoPositionProvider.prototype = { 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); @@ -427,7 +416,7 @@ WifiGeoPositionProvider.prototype = { listener.notifyError(POSITION_UNAVAILABLE); } } - } + }, }; this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiGeoPositionProvider]); diff --git a/dom/system/tests/file_bug1197901.html b/dom/system/tests/file_bug1197901.html index 44e63c3c16ad..e4ca9fd380a1 100644 --- a/dom/system/tests/file_bug1197901.html +++ b/dom/system/tests/file_bug1197901.html @@ -1,7 +1,7 @@
Sensor events testing
diff --git a/dom/system/tests/test_bug1197901.html b/dom/system/tests/test_bug1197901.html index 43686d915bab..ec885bb13878 100644 --- a/dom/system/tests/test_bug1197901.html +++ b/dom/system/tests/test_bug1197901.html @@ -15,15 +15,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1197901 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"); @@ -75,9 +75,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1197901 SimpleTest.finish(); }, 500); }, win2); - } + }; }, win); - } + }; } diff --git a/dom/system/tests/worker_constants.js b/dom/system/tests/worker_constants.js index 62d79fe54ae0..8c4004527f45 100644 --- a/dom/system/tests/worker_constants.js +++ b/dom/system/tests/worker_constants.js @@ -1,8 +1,9 @@ /* 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) { @@ -10,8 +11,8 @@ function send(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 { @@ -34,13 +35,13 @@ function 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 @@ -57,7 +58,7 @@ function test_debugBuildWorkerThread(isDebugBuild) { 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 @@ -77,6 +78,6 @@ function test_xul() { } // 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"); } diff --git a/dom/tests/unit/test_Fetch.js b/dom/tests/unit/test_Fetch.js index a061c400f6e5..76bb0d5dd8d2 100644 --- a/dom/tests/unit/test_Fetch.js +++ b/dom/tests/unit/test_Fetch.js @@ -1,7 +1,7 @@ /* 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", @@ -9,14 +9,14 @@ const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream 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", @@ -26,7 +26,7 @@ function createTestData(testPath) { contentType: "application/json", body: "{\"Look\": \"Success!\"}", status: 200, - statusText: "OK" + statusText: "OK", }, }; } @@ -90,7 +90,7 @@ add_test(function test_GetData() { // 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); @@ -110,7 +110,7 @@ add_test(function test_GetData() { do_test_finished(); run_next_test(); }); - }).catch(function(e){ + }).catch(function(e) { do_report_unexpected_exception(e); do_test_finished(); run_next_test(); @@ -133,7 +133,7 @@ add_test(function test_GetDataNoInit() { }); 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); @@ -144,7 +144,7 @@ add_test(function test_GetDataNoInit() { do_test_finished(); run_next_test(); }); - }).catch(function(e){ + }).catch(function(e) { do_report_unexpected_exception(e); do_test_finished(); run_next_test(); @@ -163,7 +163,7 @@ add_test(function test_get40x() { // 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(); @@ -190,7 +190,7 @@ add_test(function test_get50x() { }); // 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(); @@ -262,8 +262,8 @@ add_test(function test_PostJSONData() { 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); @@ -308,8 +308,8 @@ add_test(function test_PostTextData() { 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); diff --git a/dom/tests/unit/test_PromiseDebugging.js b/dom/tests/unit/test_PromiseDebugging.js index 571eb466a34c..e00fadc8f3ab 100644 --- a/dom/tests/unit/test_PromiseDebugging.js +++ b/dom/tests/unit/test_PromiseDebugging.js @@ -1,19 +1,18 @@ -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); diff --git a/dom/tests/unit/test_bug319968.js b/dom/tests/unit/test_bug319968.js index 9296ad3786bb..b5adef5efe83 100644 --- a/dom/tests/unit/test_bug319968.js +++ b/dom/tests/unit/test_bug319968.js @@ -5,8 +5,7 @@ Cu.importGlobalProperties(["DOMParser"]); -function run_test() -{ +function run_test() { var domParser = new DOMParser(); var aDom = domParser.parseFromString("", "application/xml"); diff --git a/dom/tests/unit/test_bug465752.js b/dom/tests/unit/test_bug465752.js index 164e6076c5af..3a8d913040d5 100644 --- a/dom/tests/unit/test_bug465752.js +++ b/dom/tests/unit/test_bug465752.js @@ -2,16 +2,14 @@ * 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)); diff --git a/dom/tests/unit/test_geolocation_position_unavailable.js b/dom/tests/unit/test_geolocation_position_unavailable.js index de0a5fd5e026..2af6ead4a42a 100644 --- 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); +} diff --git a/dom/tests/unit/test_geolocation_position_unavailable_wrap.js b/dom/tests/unit/test_geolocation_position_unavailable_wrap.js index b9818c5ff139..25b098973297 100644 --- 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"); +} diff --git a/dom/tests/unit/test_geolocation_provider.js b/dom/tests/unit/test_geolocation_provider.js index a479827748b8..eaa1a3cd8b2d 100644 --- a/dom/tests/unit/test_geolocation_provider.js +++ b/dom/tests/unit/test_geolocation_provider.js @@ -1,27 +1,23 @@ 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--; @@ -31,8 +27,7 @@ var observer = { do_test_finished(); }); } - } - else if (data == "starting") { + } else if (data == "starting") { Assert.ok(1); this._numProviders++; } @@ -41,8 +36,7 @@ var observer = { _numProviders: 0, }; -function geoHandler(metadata, response) -{ +function geoHandler(metadata, response) { var georesponse = { status: "OK", location: { @@ -58,8 +52,7 @@ function geoHandler(metadata, response) 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. @@ -72,11 +65,10 @@ function run_test() 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); diff --git a/dom/tests/unit/test_geolocation_provider_timeout.js b/dom/tests/unit/test_geolocation_provider_timeout.js index 32718af83172..4b6bb784bceb 100644 --- a/dom/tests/unit/test_geolocation_provider_timeout.js +++ b/dom/tests/unit/test_geolocation_provider_timeout.js @@ -1,10 +1,11 @@ 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(); } @@ -19,8 +20,7 @@ function errorCallback() { do_test_finished(); } -function run_test() -{ +function run_test() { do_test_pending(); // XPCShell does not get a profile by default. The geolocation service @@ -31,14 +31,13 @@ function run_test() 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); diff --git a/dom/tests/unit/test_geolocation_reset_accuracy.js b/dom/tests/unit/test_geolocation_reset_accuracy.js index a2c0378dc359..a93a0944534a 100644 --- a/dom/tests/unit/test_geolocation_reset_accuracy.js +++ b/dom/tests/unit/test_geolocation_reset_accuracy.js @@ -1,16 +1,12 @@ +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; @@ -19,13 +15,13 @@ var provider = { 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; @@ -33,25 +29,15 @@ var provider = { } }, _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(); } @@ -59,8 +45,7 @@ function errorCallback() 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 @@ -69,25 +54,23 @@ function run_test() 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); } } @@ -97,8 +80,7 @@ function stop_high_accuracy_watch() { 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); diff --git a/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js b/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js index 9ab05f8c70b0..dbd776c1cc29 100644 --- a/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js +++ b/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js @@ -1,16 +1,12 @@ +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; @@ -19,25 +15,24 @@ var provider = { 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. @@ -45,20 +40,17 @@ function run_test() 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 diff --git a/dom/tests/unit/test_geolocation_timeout.js b/dom/tests/unit/test_geolocation_timeout.js index e47593aa2e49..db67af7437be 100644 --- a/dom/tests/unit/test_geolocation_timeout.js +++ b/dom/tests/unit/test_geolocation_timeout.js @@ -1,12 +1,13 @@ 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: { @@ -36,12 +37,10 @@ function errorCallback() { 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. @@ -50,11 +49,10 @@ function run_test() 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); diff --git a/dom/tests/unit/test_geolocation_timeout_wrap.js b/dom/tests/unit/test_geolocation_timeout_wrap.js index 5c2deceada9b..d9c5bd230733 100644 --- 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"); } diff --git a/dom/tests/unit/test_xhr_init.js b/dom/tests/unit/test_xhr_init.js index a0cf851dd2e3..31886a4b0851 100644 --- a/dom/tests/unit/test_xhr_init.js +++ b/dom/tests/unit/test_xhr_init.js @@ -1,5 +1,4 @@ -function run_test() -{ +function run_test() { Cu.importGlobalProperties(["XMLHttpRequest"]); var x = new XMLHttpRequest({mozAnon: true, mozSystem: false});