Skip to content

Commit

Permalink
Bug 1437584 - Enable ESLint rule mozilla/use-services for testing/. r…
Browse files Browse the repository at this point in the history
…=jmaher

MozReview-Commit-ID: DMkgj5UAId4

--HG--
extra : rebase_source : 155f657e68f04850e878535afdb1421933b4a13b
  • Loading branch information
Standard8 committed Feb 12, 2018
1 parent 9fd4018 commit 01319d9
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 219 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module.exports = {
"files": [
"extensions/pref/**",
"mobile/android/**",
"testing/**",
],
"rules": {
"mozilla/use-services": "off",
Expand Down
11 changes: 4 additions & 7 deletions testing/modules/AppData.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ this.EXPORTED_SYMBOLS = [

ChromeUtils.import("resource://gre/modules/osfile.jsm");
ChromeUtils.import("resource://gre/modules/Promise.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");

// Reference needed in order for fake app dir provider to be active.
var gFakeAppDirectoryProvider;
Expand All @@ -29,9 +30,7 @@ var gFakeAppDirectoryProvider;
*/
this.makeFakeAppDir = function() {
let dirMode = OS.Constants.libc.S_IRWXU;
let dirService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);
let baseFile = dirService.get("ProfD", Ci.nsIFile);
let baseFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
let appD = baseFile.clone();
appD.append("UAppData");

Expand Down Expand Up @@ -83,17 +82,15 @@ this.makeFakeAppDir = function() {
};

// Register the new provider.
dirService.QueryInterface(Ci.nsIDirectoryService)
.registerProvider(provider);
Services.dirsvc.registerProvider(provider);

// And undefine the old one.
try {
dirService.undefine("UAppData");
Services.dirsvc.undefine("UAppData");
} catch (ex) {}

gFakeAppDirectoryProvider = provider;

dump("Successfully installed fake UAppDir\n");
return Promise.resolve(appD.path);
};

2 changes: 1 addition & 1 deletion testing/modules/AppInfo.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
let origPlatformInfo = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIPlatformInfo);

// eslint-disable-next-line mozilla/use-services
let origRuntime = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULRuntime);

Expand Down Expand Up @@ -139,4 +140,3 @@ this.updateAppInfo = function(options) {
// code may already have looked up |Cc[cid]|.
Cc.initialize(Cc[cid], cid);
};

29 changes: 8 additions & 21 deletions testing/specialpowers/content/SpecialPowersObserver.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ const CHILD_LOGGER_SCRIPT = "chrome://specialpowers/content/MozillaLogger.js";


// Glue to add in the observer API to this object. This allows us to share code with chrome tests
var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserverAPI.js");
Services.scriptloader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserverAPI.js");

/* XPCOM gunk */
this.SpecialPowersObserver = function SpecialPowersObserver() {
Expand Down Expand Up @@ -108,13 +106,9 @@ SpecialPowersObserver.prototype.init = function() {
obs.addObserver(this, "chrome-document-global-created");

// Register special testing modules.
var testsURI = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get("ProfD", Ci.nsIFile);
var testsURI = Services.dirsvc.get("ProfD", Ci.nsIFile);
testsURI.append("tests.manifest");
var ioSvc = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var manifestFile = ioSvc.newFileURI(testsURI).
var manifestFile = Services.io.newFileURI(testsURI).
QueryInterface(Ci.nsIFileURL).file;

Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
Expand Down Expand Up @@ -170,11 +164,8 @@ SpecialPowersObserver.prototype._addProcessCrashObservers = function() {
return;
}

var obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);

obs.addObserver(this, "plugin-crashed");
obs.addObserver(this, "ipc:content-shutdown");
Services.obs.addObserver(this, "plugin-crashed");
Services.obs.addObserver(this, "ipc:content-shutdown");
this._processCrashObserversRegistered = true;
};

Expand All @@ -183,11 +174,8 @@ SpecialPowersObserver.prototype._removeProcessCrashObservers = function() {
return;
}

var obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);

obs.removeObserver(this, "plugin-crashed");
obs.removeObserver(this, "ipc:content-shutdown");
Services.obs.removeObserver(this, "plugin-crashed");
Services.obs.removeObserver(this, "ipc:content-shutdown");
this._processCrashObserversRegistered = false;
};

Expand Down Expand Up @@ -237,8 +225,7 @@ SpecialPowersObserver.prototype.receiveMessage = function(aMessage) {
}
break;
case "SpecialPowers.Quit":
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
appStartup.quit(Ci.nsIAppStartup.eForceQuit);
Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
break;
case "SpecialPowers.Focus":
aMessage.target.focus();
Expand Down
57 changes: 15 additions & 42 deletions testing/specialpowers/content/specialpowersAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ function SpecialPowersAPI() {
this._pendingPermissions = [];
this._applyingPermissions = false;
this._observingPermissions = false;
this._fm = null;
this._cb = null;
}

function bindDOMWindowUtils(aWindow) {
Expand Down Expand Up @@ -1620,9 +1618,7 @@ SpecialPowersAPI.prototype = {

isMainProcess() {
try {
return Cc["@mozilla.org/xre/app-info;1"].
getService(Ci.nsIXULRuntime).
processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
} catch (e) { }
return true;
},
Expand All @@ -1633,9 +1629,7 @@ SpecialPowersAPI.prototype = {
if (this._xpcomabi != null)
return this._xpcomabi;

var xulRuntime = Cc["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo)
.QueryInterface(Components.interfaces.nsIXULRuntime);
var xulRuntime = Services.appinfo.QueryInterface(Components.interfaces.nsIXULRuntime);

this._xpcomabi = xulRuntime.XPCOMABI;
return this._xpcomabi;
Expand All @@ -1659,23 +1653,15 @@ SpecialPowersAPI.prototype = {
if (this._os != null)
return this._os;

var xulRuntime = Cc["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo)
.QueryInterface(Components.interfaces.nsIXULRuntime);

this._os = xulRuntime.OS;
this._os = Services.appinfo.OS;
return this._os;
},

addSystemEventListener(target, type, listener, useCapture) {
Cc["@mozilla.org/eventlistenerservice;1"].
getService(Ci.nsIEventListenerService).
addSystemEventListener(target, type, listener, useCapture);
Services.els.addSystemEventListener(target, type, listener, useCapture);
},
removeSystemEventListener(target, type, listener, useCapture) {
Cc["@mozilla.org/eventlistenerservice;1"].
getService(Ci.nsIEventListenerService).
removeSystemEventListener(target, type, listener, useCapture);
Services.els.removeSystemEventListener(target, type, listener, useCapture);
},

// helper method to check if the event is consumed by either default group's
Expand Down Expand Up @@ -1746,28 +1732,22 @@ SpecialPowersAPI.prototype = {
return obj;
},

get focusManager() {
if (this._fm != null)
return this._fm;

this._fm = Components.classes["@mozilla.org/focus-manager;1"].
getService(Components.interfaces.nsIFocusManager);

return this._fm;
},

getFocusedElementForWindow(targetWindow, aDeep) {
var outParam = {};
this.focusManager.getFocusedElementForWindow(targetWindow, aDeep, outParam);
Services.focus.getFocusedElementForWindow(targetWindow, aDeep, outParam);
return outParam.value;
},

get focusManager() {
return Services.focus;
},

activeWindow() {
return this.focusManager.activeWindow;
return Services.focus.activeWindow;
},

focusedWindow() {
return this.focusManager.focusedWindow;
return Services.focus.focusedWindow;
},

focus(aWindow) {
Expand All @@ -1791,11 +1771,8 @@ SpecialPowersAPI.prototype = {
},

getClipboardData(flavor, whichClipboard) {
if (this._cb == null)
this._cb = Components.classes["@mozilla.org/widget/clipboard;1"].
getService(Components.interfaces.nsIClipboard);
if (whichClipboard === undefined)
whichClipboard = this._cb.kGlobalClipboard;
whichClipboard = Services.clipboard.kGlobalClipboard;

var xferable = Components.classes["@mozilla.org/widget/transferable;1"].
createInstance(Components.interfaces.nsITransferable);
Expand All @@ -1805,7 +1782,7 @@ SpecialPowersAPI.prototype = {
xferable.init(this._getDocShell(typeof(window) == "undefined" ? content.window : window)
.QueryInterface(Components.interfaces.nsILoadContext));
xferable.addDataFlavor(flavor);
this._cb.getData(xferable, whichClipboard);
Services.clipboard.getData(xferable, whichClipboard);
var data = {};
try {
xferable.getTransferData(flavor, data, {});
Expand All @@ -1824,11 +1801,7 @@ SpecialPowersAPI.prototype = {
},

supportsSelectionClipboard() {
if (this._cb == null) {
this._cb = Components.classes["@mozilla.org/widget/clipboard;1"].
getService(Components.interfaces.nsIClipboard);
}
return this._cb.supportsSelectionClipboard();
return Services.clipboard.supportsSelectionClipboard();
},

swapFactoryRegistration(cid, contractID, newFactory, oldFactory) {
Expand Down
6 changes: 3 additions & 3 deletions testing/talos/talos/pageloader/chrome/MozillaFileLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* MozillaFileLogger, a log listener that can write to a local file.
*/

ChromeUtils.import("resource://gre/modules/Services.jsm");

// double logging to account for normal mode and ipc mode (mobile_profile only)
// Ideally we would remove the dump() and just do ipc logging
function dumpLog(msg) {
Expand Down Expand Up @@ -78,8 +80,6 @@ MozillaFileLogger.close = function() {
};

try {
var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
var filename = prefs.getCharPref("talos.logfile");
var filename = Services.prefs.getCharPref("talos.logfile");
MozillaFileLogger.init(filename);
} catch (ex) {} // pref does not exist, return empty string
1 change: 1 addition & 0 deletions testing/talos/talos/pageloader/chrome/Profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var Profiler;

/* eslint-disable mozilla/use-chromeutils-import */
try {
// eslint-disable-next-line mozilla/use-services
_profiler = Components.classes["@mozilla.org/tools/profiler;1"].getService(Components.interfaces.nsIProfiler);
} catch (ex) { (typeof(dumpLog) == "undefined" ? dump : dumpLog)(ex + "\n"); }

Expand Down
21 changes: 6 additions & 15 deletions testing/talos/talos/pageloader/chrome/pageloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ var browserWindow = null;
var recordedName = null;
var pageUrls;

// the io service
var gIOS = null;

/**
* SingleTimeout class. Allow to register one and only one callback using
* setTimeout at a time.
Expand Down Expand Up @@ -156,10 +153,7 @@ function plInit() {
forceCC = false;
}

gIOS = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);

var fileURI = gIOS.newURI(manifestURI);
var fileURI = Services.io.newURI(manifestURI);
pages = plLoadURLsFromURI(fileURI);

if (!pages) {
Expand All @@ -181,8 +175,6 @@ function plInit() {
}

// Create a new chromed browser window for content
var wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Ci.nsIWindowWatcher);
var blank = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
blank.data = "about:blank";
Expand All @@ -192,7 +184,7 @@ function plInit() {
toolbars = "titlebar,resizable";
}

browserWindow = wwatch.openWindow(null, "chrome://browser/content/", "_blank",
browserWindow = Services.ww.openWindow(null, "chrome://browser/content/", "_blank",
`chrome,${toolbars},dialog=no,width=${winWidth},height=${winHeight}`, blank);

gPaintWindow = browserWindow;
Expand Down Expand Up @@ -833,7 +825,7 @@ function plLoadURLsFromURI(manifestUri) {
return null;
}

var subManifest = gIOS.newURI(items[1], null, manifestUri);
var subManifest = Services.io.newURI(items[1], null, manifestUri);
if (subManifest == null) {
dumpLine("tp: invalid URI on line " + manifestUri.spec + ":" + lineNo + " : '" + line.value + "'");
return null;
Expand Down Expand Up @@ -886,7 +878,7 @@ function plLoadURLsFromURI(manifestUri) {
var url;

if (!baseVsRef) {
url = gIOS.newURI(urlspec, null, manifestUri);
url = Services.io.newURI(urlspec, null, manifestUri);

if (pageFilterRegexp && !pageFilterRegexp.test(url.spec))
continue;
Expand All @@ -898,13 +890,13 @@ function plLoadURLsFromURI(manifestUri) {
// page; later on this 'pre' is used when recording the actual time value/result; because in
// the results we use the url as the results key; but we might use the same test page as a reference
// page in the same test suite, so we need to add a prefix so this results key is always unique
url = gIOS.newURI(urlspecBase, null, manifestUri);
url = Services.io.newURI(urlspecBase, null, manifestUri);
if (pageFilterRegexp && !pageFilterRegexp.test(url.spec))
continue;
var pre = "base_page_" + baseVsRefIndex + "_";
url_array.push({ url, flags, pre });

url = gIOS.newURI(urlspecRef, null, manifestUri);
url = Services.io.newURI(urlspecRef, null, manifestUri);
if (pageFilterRegexp && !pageFilterRegexp.test(url.spec))
continue;
pre = "ref_page_" + baseVsRefIndex + "_";
Expand All @@ -922,4 +914,3 @@ function dumpLine(str) {
dump(str);
dump("\n");
}

Loading

0 comments on commit 01319d9

Please sign in to comment.