зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1437584 - Enable ESLint rule mozilla/use-services for testing/. r=jmaher
MozReview-Commit-ID: DMkgj5UAId4 --HG-- extra : rebase_source : 155f657e68f04850e878535afdb1421933b4a13b
This commit is contained in:
Родитель
9fd4018d70
Коммит
01319d9d04
|
@ -45,7 +45,6 @@ module.exports = {
|
|||
"files": [
|
||||
"extensions/pref/**",
|
||||
"mobile/android/**",
|
||||
"testing/**",
|
||||
],
|
||||
"rules": {
|
||||
"mozilla/use-services": "off",
|
||||
|
|
|
@ -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;
|
||||
|
@ -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");
|
||||
|
||||
|
@ -83,12 +82,11 @@ 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;
|
||||
|
@ -96,4 +94,3 @@ this.makeFakeAppDir = function() {
|
|||
dump("Successfully installed fake UAppDir\n");
|
||||
return Promise.resolve(appD.path);
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -139,4 +140,3 @@ this.updateAppInfo = function(options) {
|
|||
// code may already have looked up |Cc[cid]|.
|
||||
Cc.initialize(Cc[cid], cid);
|
||||
};
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
@ -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).
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -46,8 +46,6 @@ function SpecialPowersAPI() {
|
|||
this._pendingPermissions = [];
|
||||
this._applyingPermissions = false;
|
||||
this._observingPermissions = false;
|
||||
this._fm = null;
|
||||
this._cb = null;
|
||||
}
|
||||
|
||||
function bindDOMWindowUtils(aWindow) {
|
||||
|
@ -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;
|
||||
},
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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, {});
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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
|
||||
|
|
|
@ -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"); }
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -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) {
|
||||
|
@ -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";
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 + "_";
|
||||
|
@ -922,4 +914,3 @@ function dumpLine(str) {
|
|||
dump(str);
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -40,17 +40,13 @@
|
|||
These files did not have a license
|
||||
*/
|
||||
|
||||
function canQuitApplication() {
|
||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
if (!os) {
|
||||
return true;
|
||||
}
|
||||
/* import-globals-from pageloader.js */
|
||||
|
||||
function canQuitApplication() {
|
||||
try {
|
||||
var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
|
||||
.createInstance(Components.interfaces.nsISupportsPRBool);
|
||||
os.notifyObservers(cancelQuit, "quit-application-requested");
|
||||
Services.obs.notifyObservers(cancelQuit, "quit-application-requested");
|
||||
|
||||
// Something aborted the quit process.
|
||||
if (cancelQuit.data) {
|
||||
|
@ -72,12 +68,10 @@ function goQuitApplication() {
|
|||
var forceQuit;
|
||||
|
||||
if (kAppStartup in Components.classes) {
|
||||
appService = Components.classes[kAppStartup].
|
||||
getService(Components.interfaces.nsIAppStartup);
|
||||
appService = Services.startup;
|
||||
forceQuit = Components.interfaces.nsIAppStartup.eForceQuit;
|
||||
} else if (kAppShell in Components.classes) {
|
||||
appService = Components.classes[kAppShell].
|
||||
getService(Components.interfaces.nsIAppShellService);
|
||||
appService = Services.appShell;
|
||||
forceQuit = Components.interfaces.nsIAppShellService.eForceQuit;
|
||||
} else {
|
||||
throw "goQuitApplication: no AppStartup/appShell";
|
||||
|
@ -91,4 +85,3 @@ function goQuitApplication() {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,8 +116,9 @@ MozFileLogger.close = function() {
|
|||
};
|
||||
|
||||
try {
|
||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
var filename = prefs.getCharPref("talos.logfile");
|
||||
// ChromeUtils is not available in this scope.
|
||||
// eslint-disable-next-line mozilla/use-chromeutils-import
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
var filename = Services.prefs.getCharPref("talos.logfile");
|
||||
MozFileLogger.init(filename);
|
||||
} catch (ex) {} // pref does not exist, return empty string
|
||||
|
|
|
@ -44,6 +44,7 @@ var Profiler;
|
|||
} catch (e) {}
|
||||
|
||||
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"); }
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ var Profiler;
|
|||
} catch (e) {}
|
||||
|
||||
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"); }
|
||||
|
||||
|
|
|
@ -41,8 +41,10 @@ function dumpConsoleAndQuit() {
|
|||
|
||||
try {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
|
||||
consoleService.getMessageArray(messages, {});
|
||||
// ChromeUtils is not available in this scope.
|
||||
// eslint-disable-next-line mozilla/use-chromeutils-import
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Services.console.getMessageArray(messages, {});
|
||||
} catch (ex) {
|
||||
dumpLog(ex + "\n");
|
||||
}
|
||||
|
|
|
@ -3,20 +3,16 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// This file is loaded as a framescript
|
||||
/* global docShell */
|
||||
// eslint-env mozilla/frame-script
|
||||
|
||||
/* globals docShell */
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function canQuitApplication() {
|
||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
if (!os) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
|
||||
.createInstance(Components.interfaces.nsISupportsPRBool);
|
||||
os.notifyObservers(cancelQuit, "quit-application-requested");
|
||||
Services.obs.notifyObservers(cancelQuit, "quit-application-requested");
|
||||
|
||||
// Something aborted the quit process.
|
||||
if (cancelQuit.data) {
|
||||
|
@ -24,14 +20,12 @@ function canQuitApplication() {
|
|||
}
|
||||
} catch (ex) {
|
||||
}
|
||||
os.notifyObservers(null, "quit-application-granted");
|
||||
Services.obs.notifyObservers(null, "quit-application-granted");
|
||||
return true;
|
||||
}
|
||||
|
||||
function goQuitApplication(waitForSafeBrowsing) {
|
||||
var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
|
||||
.getService(Components.interfaces.nsIXULRuntime);
|
||||
if (xulRuntime.processType == xulRuntime.PROCESS_TYPE_CONTENT) {
|
||||
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
|
||||
// If we're running in a remote browser, emit an event for a
|
||||
// frame script to pick up to quit the whole browser.
|
||||
var event = new content.CustomEvent("TalosQuitApplication", {bubbles: true, detail: {waitForSafeBrowsing}});
|
||||
|
@ -61,12 +55,9 @@ function goQuitApplication(waitForSafeBrowsing) {
|
|||
var appService;
|
||||
|
||||
if (kAppStartup in Components.classes) {
|
||||
appService = Components.classes[kAppStartup].
|
||||
getService(Components.interfaces.nsIAppStartup);
|
||||
|
||||
appService = Services.startup;
|
||||
} else if (kAppShell in Components.classes) {
|
||||
appService = Components.classes[kAppShell].
|
||||
getService(Components.interfaces.nsIAppShellService);
|
||||
appService = Services.appShell;
|
||||
} else {
|
||||
throw "goQuitApplication: no AppStartup/appShell";
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ var Profiler;
|
|||
} catch (e) {}
|
||||
|
||||
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"); }
|
||||
|
||||
|
|
|
@ -1057,8 +1057,7 @@ async _consoleOpenWithCachedMessagesTest() {
|
|||
};
|
||||
this._config = config;
|
||||
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
this._win = wm.getMostRecentWindow("navigator:browser");
|
||||
this._win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
this._dampTab = this._win.gBrowser.selectedTab;
|
||||
this._win.gBrowser.selectedBrowser.focus(); // Unfocus the URL bar to avoid caret blink
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ var Profiler;
|
|||
} catch (e) {}
|
||||
|
||||
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"); }
|
||||
|
||||
|
|
|
@ -683,8 +683,7 @@ Tart.prototype = {
|
|||
};
|
||||
this._config = config;
|
||||
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
this._win = wm.getMostRecentWindow("navigator:browser");
|
||||
this._win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
this._tartTab = this._win.gBrowser.selectedTab;
|
||||
this._win.gBrowser.selectedBrowser.focus(); // Unfocus the URL bar to avoid caret blink
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
* 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 check_profile_dir(profd) {
|
||||
Assert.ok(profd.exists());
|
||||
Assert.ok(profd.isDirectory());
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Ci.nsIProperties);
|
||||
let profd2 = dirSvc.get("ProfD", Ci.nsIFile);
|
||||
let profd2 = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
Assert.ok(profd2.exists());
|
||||
Assert.ok(profd2.isDirectory());
|
||||
// make sure we got the same thing back...
|
||||
|
@ -21,10 +21,8 @@ function check_do_get_profile(fireProfileAfterChange) {
|
|||
]);
|
||||
const expectedTopics = new Map(observedTopics);
|
||||
|
||||
const obs = Cc["@mozilla.org/observer-service;1"]
|
||||
.getService(Ci.nsIObserverService);
|
||||
for (let [topic, ] of observedTopics) {
|
||||
obs.addObserver(() => {
|
||||
Services.obs.addObserver(() => {
|
||||
let val = observedTopics.get(topic) + 1;
|
||||
observedTopics.set(topic, val);
|
||||
}, topic);
|
||||
|
|
|
@ -35,9 +35,9 @@ var _XPCSHELL_PROCESS;
|
|||
|
||||
// Register the testing-common resource protocol early, to have access to its
|
||||
// modules.
|
||||
var _Services = ChromeUtils.import("resource://gre/modules/Services.jsm", {}).Services;
|
||||
_register_modules_protocol_handler();
|
||||
|
||||
var _Promise = ChromeUtils.import("resource://gre/modules/Promise.jsm", {}).Promise;
|
||||
var _PromiseTestUtils = ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", {}).PromiseTestUtils;
|
||||
var _Task = ChromeUtils.import("resource://gre/modules/Task.jsm", {}).Task;
|
||||
|
||||
|
@ -71,19 +71,18 @@ var _testLogger = new _LoggerClass("xpcshell/head.js", _dumpLog, [_add_params]);
|
|||
|
||||
// Disable automatic network detection, so tests work correctly when
|
||||
// not connected to a network.
|
||||
{
|
||||
let ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
ios.manageOfflineStatus = false;
|
||||
ios.offline = false;
|
||||
}
|
||||
_Services.io.manageOfflineStatus = false;
|
||||
_Services.io.offline = false;
|
||||
|
||||
// Determine if we're running on parent or child
|
||||
var runningInParent = true;
|
||||
try {
|
||||
// Don't use Services.appinfo here as it disables replacing appinfo with stubs
|
||||
// for test usage.
|
||||
// eslint-disable-next-line mozilla/use-services
|
||||
runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
|
||||
getService(Components.interfaces.nsIXULRuntime).processType
|
||||
== Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
getService(Components.interfaces.nsIXULRuntime).processType
|
||||
== Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
} catch (e) { }
|
||||
|
||||
// Only if building of places is enabled.
|
||||
|
@ -91,23 +90,18 @@ if (runningInParent &&
|
|||
"mozIAsyncHistory" in Components.interfaces) {
|
||||
// Ensure places history is enabled for xpcshell-tests as some non-FF
|
||||
// apps disable it.
|
||||
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.setBoolPref("places.history.enabled", true);
|
||||
_Services.prefs.setBoolPref("places.history.enabled", true);
|
||||
}
|
||||
|
||||
try {
|
||||
if (runningInParent) {
|
||||
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
// disable necko IPC security checks for xpcshell, as they lack the
|
||||
// docshells needed to pass them
|
||||
prefs.setBoolPref("network.disable.ipc.security", true);
|
||||
_Services.prefs.setBoolPref("network.disable.ipc.security", true);
|
||||
|
||||
// Disable IPv6 lookups for 'localhost' on windows.
|
||||
if ("@mozilla.org/windows-registry-key;1" in Components.classes) {
|
||||
prefs.setCharPref("network.dns.ipv4OnlyDomains", "localhost");
|
||||
_Services.prefs.setCharPref("network.dns.ipv4OnlyDomains", "localhost");
|
||||
}
|
||||
}
|
||||
} catch (e) { }
|
||||
|
@ -149,6 +143,9 @@ try {
|
|||
info("CONSOLE_MESSAGE: (" + levelNames[msg.logLevel] + ") " + msg.toString());
|
||||
}
|
||||
};
|
||||
// Don't use _Services.console here as it causes one of the devtools tests
|
||||
// to fail, probably due to initializing Services.console too early.
|
||||
// eslint-disable-next-line mozilla/use-services
|
||||
Components.classes["@mozilla.org/consoleservice;1"]
|
||||
.getService(Components.interfaces.nsIConsoleService)
|
||||
.registerListener(listener);
|
||||
|
@ -331,13 +328,11 @@ function do_get_idle() {
|
|||
// Map resource://test/ to current working directory and
|
||||
// resource://testing-common/ to the shared test modules directory.
|
||||
function _register_protocol_handlers() {
|
||||
let ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
let protocolHandler =
|
||||
ios.getProtocolHandler("resource")
|
||||
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
|
||||
_Services.io.getProtocolHandler("resource")
|
||||
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
|
||||
|
||||
let curDirURI = ios.newFileURI(do_get_cwd());
|
||||
let curDirURI = _Services.io.newFileURI(do_get_cwd());
|
||||
protocolHandler.setSubstitution("test", curDirURI);
|
||||
|
||||
_register_modules_protocol_handler();
|
||||
|
@ -350,11 +345,9 @@ function _register_modules_protocol_handler() {
|
|||
"head.js is included.");
|
||||
}
|
||||
|
||||
let ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
let protocolHandler =
|
||||
ios.getProtocolHandler("resource")
|
||||
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
|
||||
_Services.io.getProtocolHandler("resource")
|
||||
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
|
||||
|
||||
let modulesFile = Components.classes["@mozilla.org/file/local;1"].
|
||||
createInstance(Components.interfaces.nsIFile);
|
||||
|
@ -370,7 +363,7 @@ function _register_modules_protocol_handler() {
|
|||
_TESTING_MODULES_DIR);
|
||||
}
|
||||
|
||||
let modulesURI = ios.newFileURI(modulesFile);
|
||||
let modulesURI = _Services.io.newFileURI(modulesFile);
|
||||
|
||||
protocolHandler.setSubstitution("testing-common", modulesURI);
|
||||
}
|
||||
|
@ -378,20 +371,17 @@ function _register_modules_protocol_handler() {
|
|||
/* Debugging support */
|
||||
// Used locally and by our self-tests.
|
||||
function _setupDebuggerServer(breakpointFiles, callback) {
|
||||
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
// Always allow remote debugging.
|
||||
prefs.setBoolPref("devtools.debugger.remote-enabled", true);
|
||||
_Services.prefs.setBoolPref("devtools.debugger.remote-enabled", true);
|
||||
|
||||
// for debugging-the-debugging, let an env var cause log spew.
|
||||
let env = Components.classes["@mozilla.org/process/environment;1"]
|
||||
.getService(Components.interfaces.nsIEnvironment);
|
||||
if (env.get("DEVTOOLS_DEBUGGER_LOG")) {
|
||||
prefs.setBoolPref("devtools.debugger.log", true);
|
||||
_Services.prefs.setBoolPref("devtools.debugger.log", true);
|
||||
}
|
||||
if (env.get("DEVTOOLS_DEBUGGER_LOG_VERBOSE")) {
|
||||
prefs.setBoolPref("devtools.debugger.log.verbose", true);
|
||||
_Services.prefs.setBoolPref("devtools.debugger.log.verbose", true);
|
||||
}
|
||||
|
||||
let require;
|
||||
|
@ -417,9 +407,6 @@ function _setupDebuggerServer(breakpointFiles, callback) {
|
|||
|
||||
// An observer notification that tells us when we can "resume" script
|
||||
// execution.
|
||||
let obsSvc = Components.classes["@mozilla.org/observer-service;1"].
|
||||
getService(Components.interfaces.nsIObserverService);
|
||||
|
||||
const TOPICS = ["devtools-thread-resumed", "xpcshell-test-devtools-shutdown"];
|
||||
let observe = function(subject, topic, data) {
|
||||
switch (topic) {
|
||||
|
@ -444,13 +431,13 @@ function _setupDebuggerServer(breakpointFiles, callback) {
|
|||
break;
|
||||
}
|
||||
for (let topicToRemove of TOPICS) {
|
||||
obsSvc.removeObserver(observe, topicToRemove);
|
||||
_Services.obs.removeObserver(observe, topicToRemove);
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
for (let topic of TOPICS) {
|
||||
obsSvc.addObserver(observe, topic);
|
||||
_Services.obs.addObserver(observe, topic);
|
||||
}
|
||||
return DebuggerServer;
|
||||
}
|
||||
|
@ -619,12 +606,10 @@ function _execute_test() {
|
|||
if (_profileInitialized) {
|
||||
// Since we have a profile, we will notify profile shutdown topics at
|
||||
// the end of the current test, to ensure correct cleanup on shutdown.
|
||||
let obs = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
obs.notifyObservers(null, "profile-change-net-teardown");
|
||||
obs.notifyObservers(null, "profile-change-teardown");
|
||||
obs.notifyObservers(null, "profile-before-change");
|
||||
obs.notifyObservers(null, "profile-before-change-qm");
|
||||
_Services.obs.notifyObservers(null, "profile-change-net-teardown");
|
||||
_Services.obs.notifyObservers(null, "profile-change-teardown");
|
||||
_Services.obs.notifyObservers(null, "profile-before-change");
|
||||
_Services.obs.notifyObservers(null, "profile-before-change-qm");
|
||||
|
||||
_profileInitialized = false;
|
||||
}
|
||||
|
@ -694,10 +679,8 @@ function do_timeout(delay, func) {
|
|||
function executeSoon(callback, aName) {
|
||||
let funcName = (aName ? aName : callback.name);
|
||||
do_test_pending(funcName);
|
||||
var tm = Components.classes["@mozilla.org/thread-manager;1"]
|
||||
.getService(Components.interfaces.nsIThreadManager);
|
||||
|
||||
tm.dispatchToMainThread({
|
||||
_Services.tm.dispatchToMainThread({
|
||||
run() {
|
||||
try {
|
||||
callback();
|
||||
|
@ -982,9 +965,7 @@ function do_test_finished(aName) {
|
|||
|
||||
function do_get_file(path, allowNonexistent) {
|
||||
try {
|
||||
let lf = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties)
|
||||
.get("CurWorkD", Components.interfaces.nsIFile);
|
||||
let lf = _Services.dirsvc.get("CurWorkD", Components.interfaces.nsIFile);
|
||||
|
||||
let bits = path.split("/");
|
||||
for (let i = 0; i < bits.length; i++) {
|
||||
|
@ -1046,10 +1027,8 @@ function do_parse_document(aPath, aType) {
|
|||
Components.stack.caller);
|
||||
}
|
||||
|
||||
let file = do_get_file(aPath),
|
||||
ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService),
|
||||
url = ios.newFileURI(file).spec;
|
||||
let file = do_get_file(aPath);
|
||||
let url = _Services.io.newFileURI(file).spec;
|
||||
file = null;
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
@ -1131,8 +1110,6 @@ function do_get_profile(notifyProfileAfterChange = false) {
|
|||
.createInstance(Components.interfaces.nsIFile);
|
||||
file.initWithPath(profd);
|
||||
|
||||
let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties);
|
||||
let provider = {
|
||||
getFile(prop, persistent) {
|
||||
persistent.value = true;
|
||||
|
@ -1150,11 +1127,8 @@ function do_get_profile(notifyProfileAfterChange = false) {
|
|||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
|
||||
.registerProvider(provider);
|
||||
|
||||
let obsSvc = Components.classes["@mozilla.org/observer-service;1"].
|
||||
getService(Components.interfaces.nsIObserverService);
|
||||
_Services.dirsvc.QueryInterface(Components.interfaces.nsIDirectoryService)
|
||||
.registerProvider(provider);
|
||||
|
||||
// We need to update the crash events directory when the profile changes.
|
||||
if (runningInParent &&
|
||||
|
@ -1166,10 +1140,10 @@ function do_get_profile(notifyProfileAfterChange = false) {
|
|||
}
|
||||
|
||||
if (!_profileInitialized) {
|
||||
obsSvc.notifyObservers(null, "profile-do-change", "xpcshell-do-get-profile");
|
||||
_Services.obs.notifyObservers(null, "profile-do-change", "xpcshell-do-get-profile");
|
||||
_profileInitialized = true;
|
||||
if (notifyProfileAfterChange) {
|
||||
obsSvc.notifyObservers(null, "profile-after-change", "xpcshell-do-get-profile");
|
||||
_Services.obs.notifyObservers(null, "profile-after-change", "xpcshell-do-get-profile");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1177,9 +1151,7 @@ function do_get_profile(notifyProfileAfterChange = false) {
|
|||
// to avoid spurious leak reports.
|
||||
env = null;
|
||||
profd = null;
|
||||
dirSvc = null;
|
||||
provider = null;
|
||||
obsSvc = null;
|
||||
return file.clone();
|
||||
}
|
||||
|
||||
|
@ -1493,26 +1465,20 @@ try {
|
|||
if (runningInParent) {
|
||||
// Always use network provider for geolocation tests
|
||||
// so we bypass the OSX dialog raised by the corelocation provider
|
||||
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
prefs.setBoolPref("geo.provider.testing", true);
|
||||
_Services.prefs.setBoolPref("geo.provider.testing", true);
|
||||
}
|
||||
} catch (e) { }
|
||||
// We need to avoid hitting the network with certain components.
|
||||
try {
|
||||
if (runningInParent) {
|
||||
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
prefs.setCharPref("media.gmp-manager.url.override", "http://%(server)s/dummy-gmp-manager.xml");
|
||||
prefs.setCharPref("media.gmp-manager.updateEnabled", false);
|
||||
prefs.setCharPref("extensions.systemAddon.update.url", "http://%(server)s/dummy-system-addons.xml");
|
||||
prefs.setCharPref("extensions.shield-recipe-client.api_url",
|
||||
"https://%(server)s/selfsupport-dummy/");
|
||||
prefs.setCharPref("toolkit.telemetry.server", "https://%(server)s/telemetry-dummy");
|
||||
prefs.setCharPref("browser.search.geoip.url", "https://%(server)s/geoip-dummy");
|
||||
prefs.setCharPref("browser.safebrowsing.downloads.remote.url", "https://%(server)s/safebrowsing-dummy");
|
||||
_Services.prefs.setCharPref("media.gmp-manager.url.override", "http://%(server)s/dummy-gmp-manager.xml");
|
||||
_Services.prefs.setCharPref("media.gmp-manager.updateEnabled", false);
|
||||
_Services.prefs.setCharPref("extensions.systemAddon.update.url", "http://%(server)s/dummy-system-addons.xml");
|
||||
_Services.prefs.setCharPref("extensions.shield-recipe-client.api_url",
|
||||
"https://%(server)s/selfsupport-dummy/");
|
||||
_Services.prefs.setCharPref("toolkit.telemetry.server", "https://%(server)s/telemetry-dummy");
|
||||
_Services.prefs.setCharPref("browser.search.geoip.url", "https://%(server)s/geoip-dummy");
|
||||
_Services.prefs.setCharPref("browser.safebrowsing.downloads.remote.url", "https://%(server)s/safebrowsing-dummy");
|
||||
}
|
||||
} catch (e) { }
|
||||
|
||||
|
@ -1520,11 +1486,8 @@ try {
|
|||
// selected by default).
|
||||
try {
|
||||
if (runningInParent) {
|
||||
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
prefs.deleteBranch("lightweightThemes.selectedThemeID");
|
||||
prefs.deleteBranch("browser.devedition.theme.enabled");
|
||||
_Services.prefs.deleteBranch("lightweightThemes.selectedThemeID");
|
||||
_Services.prefs.deleteBranch("browser.devedition.theme.enabled");
|
||||
}
|
||||
} catch (e) { }
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче