From 2b0445fe18f960f475f92864db8f4c4319f13acb Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Mon, 11 Dec 2017 20:19:38 +0000 Subject: [PATCH] Bug 1424879 - Enable mozilla/use-services for xpcom/. r=froydnj MozReview-Commit-ID: FnQDHG3w6RQ --HG-- extra : rebase_source : 7b7b16775eaad6022f544f7a65e8d950a3d6fdd0 --- .eslintrc.js | 1 - xpcom/tests/unit/test_bug121341.js | 8 +++----- xpcom/tests/unit/test_bug332389.js | 6 +++--- xpcom/tests/unit/test_bug364285-1.js | 6 +++--- xpcom/tests/unit/test_bug374754.js | 12 ++++++------ xpcom/tests/unit/test_bug656331.js | 18 ++++++++---------- xpcom/tests/unit/test_file_createUnique.js | 5 +++-- xpcom/tests/unit/test_file_equality.js | 5 +++-- xpcom/tests/unit/test_file_renameTo.js | 6 +++--- xpcom/tests/unit/test_hidden_files.js | 5 +++-- xpcom/tests/unit/test_home.js | 5 +++-- xpcom/tests/unit/test_iniProcessor.js | 2 ++ xpcom/tests/unit/test_versioncomparator.js | 9 ++++----- 13 files changed, 44 insertions(+), 44 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 32f95ec78773..f8ce72467733 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -41,7 +41,6 @@ module.exports = { "security/**", "testing/**", "tools/profiler/**", - "xpcom/**" ], "rules": { "mozilla/use-services": "off", diff --git a/xpcom/tests/unit/test_bug121341.js b/xpcom/tests/unit/test_bug121341.js index ce7b509900dd..471bdb804327 100644 --- a/xpcom/tests/unit/test_bug121341.js +++ b/xpcom/tests/unit/test_bug121341.js @@ -1,12 +1,10 @@ Cu.import("resource://gre/modules/NetUtil.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); function run_test() { - var ios = Components.classes["@mozilla.org/network/io-service;1"]. - getService(Components.interfaces.nsIIOService); - var dataFile = do_get_file("data/bug121341.properties"); var channel = NetUtil.newChannel({ - uri: ios.newFileURI(dataFile, null, null), + uri: Services.io.newFileURI(dataFile, null, null), loadUsingSystemPrincipal: true }); var inp = channel.open2(); @@ -53,7 +51,7 @@ function run_test() { dataFile = do_get_file("data/bug121341-2.properties"); var channel2 = NetUtil.newChannel({ - uri: ios.newFileURI(dataFile, null, null), + uri: Services.io.newFileURI(dataFile, null, null), loadUsingSystemPrincipal: true }); inp = channel2.open2(); diff --git a/xpcom/tests/unit/test_bug332389.js b/xpcom/tests/unit/test_bug332389.js index caa82ebe0000..21bbeebd95e7 100644 --- a/xpcom/tests/unit/test_bug332389.js +++ b/xpcom/tests/unit/test_bug332389.js @@ -1,7 +1,7 @@ +Cu.import("resource://gre/modules/Services.jsm"); + function run_test() { - var f = - Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties).get("CurProcD", Ci.nsIFile); + var f = Services.dirsvc.get("CurProcD", Ci.nsIFile); var terminated = false; for (var i = 0; i < 100; i++) { diff --git a/xpcom/tests/unit/test_bug364285-1.js b/xpcom/tests/unit/test_bug364285-1.js index 92cec2cba093..34dab354698e 100644 --- a/xpcom/tests/unit/test_bug364285-1.js +++ b/xpcom/tests/unit/test_bug364285-1.js @@ -1,3 +1,5 @@ +Cu.import("resource://gre/modules/Services.jsm"); + var nameArray = [ "ascii", // ASCII "fran\u00E7ais", // Latin-1 @@ -9,9 +11,7 @@ var nameArray = [ ]; function getTempDir() { - var dirService = Cc["@mozilla.org/file/directory_service;1"] - .getService(Ci.nsIProperties); - return dirService.get("TmpD", Ci.nsIFile); + return Services.dirsvc.get("TmpD", Ci.nsIFile); } function create_file(fileName) { diff --git a/xpcom/tests/unit/test_bug374754.js b/xpcom/tests/unit/test_bug374754.js index 0952e93f772e..28c0e2459260 100644 --- a/xpcom/tests/unit/test_bug374754.js +++ b/xpcom/tests/unit/test_bug374754.js @@ -1,3 +1,5 @@ +Cu.import("resource://gre/modules/Services.jsm"); + var addedTopic = "xpcom-category-entry-added"; var removedTopic = "xpcom-category-entry-removed"; var testCategory = "bug-test-category"; @@ -20,9 +22,8 @@ var observer = { if (topic == "timer-callback") { do_check_eq(result, expected); - var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); - observerService.removeObserver(this, addedTopic); - observerService.removeObserver(this, removedTopic); + Services.obs.removeObserver(this, addedTopic); + Services.obs.removeObserver(this, removedTopic); do_test_finished(); @@ -42,9 +43,8 @@ var observer = { function run_test() { do_test_pending(); - var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); - observerService.addObserver(observer, addedTopic); - observerService.addObserver(observer, removedTopic); + Services.obs.addObserver(observer, addedTopic); + Services.obs.addObserver(observer, removedTopic); var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); categoryManager.addCategoryEntry(testCategory, testEntry, testValue, false, true); diff --git a/xpcom/tests/unit/test_bug656331.js b/xpcom/tests/unit/test_bug656331.js index 820724e2e289..501d4010db7a 100644 --- a/xpcom/tests/unit/test_bug656331.js +++ b/xpcom/tests/unit/test_bug656331.js @@ -1,4 +1,5 @@ -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); /* global registerAppManifest */ @@ -19,9 +20,7 @@ const kConsoleListener = { }; function run_test() { - let cs = Components.classes["@mozilla.org/consoleservice;1"]. - getService(Ci.nsIConsoleService); - cs.registerListener(kConsoleListener); + Services.console.registerListener(kConsoleListener); let manifest = do_get_file("components/bug656331.manifest"); registerAppManifest(manifest); @@ -29,10 +28,9 @@ function run_test() { do_check_false("{f18fb09b-28b4-4435-bc5b-8027f18df743}" in Components.classesByID); do_test_pending(); - Components.classes["@mozilla.org/thread-manager;1"]. - getService(Ci.nsIThreadManager).dispatchToMainThread(function() { - cs.unregisterListener(kConsoleListener); - do_check_true(gFound); - do_test_finished(); - }); + Services.tm.dispatchToMainThread(function() { + Services.console.unregisterListener(kConsoleListener); + do_check_true(gFound); + do_test_finished(); + }); } diff --git a/xpcom/tests/unit/test_file_createUnique.js b/xpcom/tests/unit/test_file_createUnique.js index 566ee9f7af11..5d26a63b69b2 100644 --- a/xpcom/tests/unit/test_file_createUnique.js +++ b/xpcom/tests/unit/test_file_createUnique.js @@ -3,13 +3,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/. */ +Cu.import("resource://gre/modules/Services.jsm"); + function run_test() { // Generate a leaf name that is 255 characters long. var longLeafName = new Array(256).join("T"); // Generate the path for a file located in a directory with a long name. - var tempFile = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); + var tempFile = Services.dirsvc.get("TmpD", Ci.nsIFile); tempFile.append(longLeafName); tempFile.append("test.txt"); diff --git a/xpcom/tests/unit/test_file_equality.js b/xpcom/tests/unit/test_file_equality.js index 821e4788b903..42d235c4bc41 100644 --- a/xpcom/tests/unit/test_file_equality.js +++ b/xpcom/tests/unit/test_file_equality.js @@ -6,14 +6,15 @@ var LocalFile = CC("@mozilla.org/file/local;1", "nsIFile", "initWithPath"); +Cu.import("resource://gre/modules/Services.jsm"); + function run_test() { test_normalized_vs_non_normalized(); } function test_normalized_vs_non_normalized() { // get a directory that exists on all platforms - var dirProvider = Components.classes["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); - var tmp1 = dirProvider.get("TmpD", Ci.nsIFile); + var tmp1 = Services.dirsvc.get("TmpD", Ci.nsIFile); var exists = tmp1.exists(); do_check_true(exists); if (!exists) diff --git a/xpcom/tests/unit/test_file_renameTo.js b/xpcom/tests/unit/test_file_renameTo.js index 2de7965ab73a..694771730b76 100644 --- a/xpcom/tests/unit/test_file_renameTo.js +++ b/xpcom/tests/unit/test_file_renameTo.js @@ -3,11 +3,11 @@ * 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.import("resource://gre/modules/Services.jsm"); + function run_test() { // Create the base directory. - let base = Cc["@mozilla.org/file/directory_service;1"] - .getService(Ci.nsIProperties) - .get("TmpD", Ci.nsIFile); + let base = Services.dirsvc.get("TmpD", Ci.nsIFile); base.append("renameTesting"); if (base.exists()) { base.remove(true); diff --git a/xpcom/tests/unit/test_hidden_files.js b/xpcom/tests/unit/test_hidden_files.js index e3e8be9b5da0..9a4ce2ad59cf 100644 --- a/xpcom/tests/unit/test_hidden_files.js +++ b/xpcom/tests/unit/test_hidden_files.js @@ -2,10 +2,11 @@ const NS_OS_TEMP_DIR = "TmpD"; const CWD = do_get_cwd(); +Cu.import("resource://gre/modules/Services.jsm"); + var hiddenUnixFile; function createUNIXHiddenFile() { - var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); - var tmpDir = dirSvc.get(NS_OS_TEMP_DIR, Ci.nsIFile); + var tmpDir = Services.dirsvc.get(NS_OS_TEMP_DIR, Ci.nsIFile); hiddenUnixFile = tmpDir.clone(); hiddenUnixFile.append(".foo"); // we don't care if this already exists because we don't care diff --git a/xpcom/tests/unit/test_home.js b/xpcom/tests/unit/test_home.js index 2d6d3a00614b..3d931758bd42 100644 --- a/xpcom/tests/unit/test_home.js +++ b/xpcom/tests/unit/test_home.js @@ -1,3 +1,5 @@ +Cu.import("resource://gre/modules/Services.jsm"); + const CWD = do_get_cwd(); function checkOS(os) { const nsILocalFile_ = "nsILocalFile" + os; @@ -10,8 +12,7 @@ const isWin = checkOS("Win"); function run_test() { var envVar = isWin ? "USERPROFILE" : "HOME"; - var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); - var homeDir = dirSvc.get("Home", Ci.nsIFile); + var homeDir = Services.dirsvc.get("Home", Ci.nsIFile); var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment); var expected = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); diff --git a/xpcom/tests/unit/test_iniProcessor.js b/xpcom/tests/unit/test_iniProcessor.js index 9424f164dc88..b76cbc6627d9 100644 --- a/xpcom/tests/unit/test_iniProcessor.js +++ b/xpcom/tests/unit/test_iniProcessor.js @@ -125,6 +125,8 @@ var testdata = [ testdata.push( { filename: "data/iniparser16-utf8BOM.ini", reference: testdata[15].reference } ); + // Intentional test for appInfo that can't be preloaded. + // eslint-disable-next-line mozilla/use-services let os = Cc["@mozilla.org/xre/app-info;1"] .getService(Ci.nsIXULRuntime).OS; if ("WINNT" === os) { diff --git a/xpcom/tests/unit/test_versioncomparator.js b/xpcom/tests/unit/test_versioncomparator.js index 46e178bcbc57..4acd565edf75 100644 --- a/xpcom/tests/unit/test_versioncomparator.js +++ b/xpcom/tests/unit/test_versioncomparator.js @@ -1,3 +1,5 @@ +Cu.import("resource://gre/modules/Services.jsm"); + // Versions to test listed in ascending order, none can be equal var comparisons = [ "0.9", @@ -29,12 +31,9 @@ var equality = [ ]; function run_test() { - var vc = Components.classes["@mozilla.org/xpcom/version-comparator;1"] - .getService(Components.interfaces.nsIVersionComparator); - for (var i = 0; i < comparisons.length; i++) { for (var j = 0; j < comparisons.length; j++) { - var result = vc.compare(comparisons[i], comparisons[j]); + var result = Services.vc.compare(comparisons[i], comparisons[j]); if (i == j) { if (result != 0) do_throw(comparisons[i] + " should be the same as itself"); @@ -49,7 +48,7 @@ function run_test() { for (i = 0; i < equality.length; i++) { for (j = 0; j < equality.length; j++) { - if (vc.compare(equality[i], equality[j]) != 0) + if (Services.vc.compare(equality[i], equality[j]) != 0) do_throw(equality[i] + " should equal " + equality[j]); } }