2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2005-03-25 06:41:33 +03:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2009-03-17 17:22:55 +03:00
|
|
|
/*
|
|
|
|
* This file contains common code that is loaded before each test file(s).
|
2006-09-12 10:19:26 +04:00
|
|
|
* See http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests
|
2009-03-17 17:22:55 +03:00
|
|
|
* for more information.
|
2006-09-12 10:19:26 +04:00
|
|
|
*/
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
var _quit = false;
|
2009-06-05 02:05:22 +04:00
|
|
|
var _passed = true;
|
2005-03-25 06:41:33 +03:00
|
|
|
var _tests_pending = 0;
|
2009-07-11 03:42:59 +04:00
|
|
|
var _cleanupFunctions = [];
|
2010-08-14 00:28:14 +04:00
|
|
|
var _pendingTimers = [];
|
2012-12-12 03:12:59 +04:00
|
|
|
var _profileInitialized = false;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2014-05-30 18:26:42 +04:00
|
|
|
// Register the testing-common resource protocol early, to have access to its
|
|
|
|
// modules.
|
|
|
|
_register_modules_protocol_handler();
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var _Promise = Components.utils.import("resource://gre/modules/Promise.jsm", {}).Promise;
|
2016-02-03 15:58:03 +03:00
|
|
|
var _PromiseTestUtils = Components.utils.import("resource://testing-common/PromiseTestUtils.jsm", {}).PromiseTestUtils;
|
2016-08-20 21:18:55 +03:00
|
|
|
Components.utils.importGlobalProperties(["XMLHttpRequest"]);
|
2014-04-15 20:51:20 +04:00
|
|
|
|
2014-05-30 18:26:42 +04:00
|
|
|
// Support a common assertion library, Assert.jsm.
|
2015-09-15 21:19:45 +03:00
|
|
|
var AssertCls = Components.utils.import("resource://testing-common/Assert.jsm", null).Assert;
|
2014-05-30 18:26:42 +04:00
|
|
|
// Pass a custom report function for xpcshell-test style reporting.
|
2015-09-15 21:19:45 +03:00
|
|
|
var Assert = new AssertCls(function(err, message, stack) {
|
2014-05-30 18:26:42 +04:00
|
|
|
if (err) {
|
|
|
|
do_report_result(false, err.message, err.stack);
|
|
|
|
} else {
|
|
|
|
do_report_result(true, message, stack);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-10-22 23:53:42 +04:00
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var _add_params = function (params) {
|
2013-07-23 06:44:25 +04:00
|
|
|
if (typeof _XPCSHELL_PROCESS != "undefined") {
|
2014-10-22 23:53:42 +04:00
|
|
|
params.xpcshell_process = _XPCSHELL_PROCESS;
|
2013-07-23 06:44:25 +04:00
|
|
|
}
|
2014-10-22 23:53:42 +04:00
|
|
|
};
|
2013-07-23 06:44:25 +04:00
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var _dumpLog = function (raw_msg) {
|
2015-09-04 21:37:32 +03:00
|
|
|
dump("\n" + JSON.stringify(raw_msg) + "\n");
|
2009-11-12 10:01:04 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var _LoggerClass = Components.utils.import("resource://testing-common/StructuredLog.jsm", null).StructuredLogger;
|
|
|
|
var _testLogger = new _LoggerClass("xpcshell/head.js", _dumpLog, [_add_params]);
|
2014-10-22 23:53:42 +04:00
|
|
|
|
2009-01-13 08:52:00 +03:00
|
|
|
// Disable automatic network detection, so tests work correctly when
|
|
|
|
// not connected to a network.
|
2015-01-25 10:34:40 +03:00
|
|
|
{
|
|
|
|
let ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService2);
|
2009-01-13 08:52:00 +03:00
|
|
|
ios.manageOfflineStatus = false;
|
|
|
|
ios.offline = false;
|
|
|
|
}
|
|
|
|
|
2012-12-08 02:12:02 +04:00
|
|
|
// Determine if we're running on parent or child
|
2015-09-15 21:19:45 +03:00
|
|
|
var runningInParent = true;
|
2010-12-11 04:17:25 +03:00
|
|
|
try {
|
2012-12-08 02:12:02 +04:00
|
|
|
runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
|
|
|
|
getService(Components.interfaces.nsIXULRuntime).processType
|
|
|
|
== Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
2015-09-05 04:36:52 +03:00
|
|
|
}
|
2012-12-08 02:12:02 +04:00
|
|
|
catch (e) { }
|
|
|
|
|
2013-06-26 17:56:11 +04:00
|
|
|
// Only if building of places is enabled.
|
|
|
|
if (runningInParent &&
|
|
|
|
"mozIAsyncHistory" in Components.interfaces) {
|
|
|
|
// Ensure places history is enabled for xpcshell-tests as some non-FF
|
|
|
|
// apps disable it.
|
2015-01-25 10:34:40 +03:00
|
|
|
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
prefs.setBoolPref("places.history.enabled", true);
|
2013-06-26 17:56:11 +04:00
|
|
|
}
|
|
|
|
|
2012-12-08 02:12:02 +04:00
|
|
|
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);
|
|
|
|
|
|
|
|
// Disable IPv6 lookups for 'localhost' on windows.
|
|
|
|
if ("@mozilla.org/windows-registry-key;1" in Components.classes) {
|
|
|
|
prefs.setCharPref("network.dns.ipv4OnlyDomains", "localhost");
|
2010-12-11 04:17:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
2013-08-15 22:48:12 +04:00
|
|
|
// Configure crash reporting, if possible
|
|
|
|
// We rely on the Python harness to set MOZ_CRASHREPORTER,
|
|
|
|
// MOZ_CRASHREPORTER_NO_REPORT, and handle checking for minidumps.
|
2010-08-12 12:55:28 +04:00
|
|
|
// Note that if we're in a child process, we don't want to init the
|
|
|
|
// crashreporter component.
|
2013-08-15 22:48:12 +04:00
|
|
|
try {
|
2012-12-08 02:12:02 +04:00
|
|
|
if (runningInParent &&
|
2010-08-12 12:55:28 +04:00
|
|
|
"@mozilla.org/toolkit/crash-reporter;1" in Components.classes) {
|
2015-01-25 10:34:40 +03:00
|
|
|
let crashReporter =
|
2010-08-12 12:55:28 +04:00
|
|
|
Components.classes["@mozilla.org/toolkit/crash-reporter;1"]
|
2015-01-25 10:34:40 +03:00
|
|
|
.getService(Components.interfaces.nsICrashReporter);
|
|
|
|
crashReporter.UpdateCrashEventsDir();
|
|
|
|
crashReporter.minidumpPath = do_get_minidumpdir();
|
2009-05-11 23:54:39 +04:00
|
|
|
}
|
|
|
|
}
|
2010-08-12 12:55:28 +04:00
|
|
|
catch (e) { }
|
2009-05-11 23:54:39 +04:00
|
|
|
|
2015-01-09 02:00:05 +03:00
|
|
|
// Configure a console listener so messages sent to it are logged as part
|
|
|
|
// of the test.
|
|
|
|
try {
|
|
|
|
let levelNames = {}
|
|
|
|
for (let level of ["debug", "info", "warn", "error"]) {
|
|
|
|
levelNames[Components.interfaces.nsIConsoleMessage[level]] = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
let listener = {
|
|
|
|
QueryInterface : function(iid) {
|
|
|
|
if (!iid.equals(Components.interfaces.nsISupports) &&
|
|
|
|
!iid.equals(Components.interfaces.nsIConsoleListener)) {
|
|
|
|
throw Components.results.NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
observe : function (msg) {
|
2015-09-05 04:36:52 +03:00
|
|
|
if (typeof do_print === "function")
|
|
|
|
do_print("CONSOLE_MESSAGE: (" + levelNames[msg.logLevel] + ") " + msg.toString());
|
2015-01-09 02:00:05 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
Components.classes["@mozilla.org/consoleservice;1"]
|
|
|
|
.getService(Components.interfaces.nsIConsoleService)
|
|
|
|
.registerListener(listener);
|
|
|
|
} catch (e) {}
|
2010-08-14 00:28:14 +04:00
|
|
|
/**
|
|
|
|
* Date.now() is not necessarily monotonically increasing (insert sob story
|
|
|
|
* about times not being the right tool to use for measuring intervals of time,
|
|
|
|
* robarnold can tell all), so be wary of error by erring by at least
|
|
|
|
* _timerFuzz ms.
|
|
|
|
*/
|
|
|
|
const _timerFuzz = 15;
|
|
|
|
|
|
|
|
function _Timer(func, delay) {
|
|
|
|
delay = Number(delay);
|
|
|
|
if (delay < 0)
|
|
|
|
do_throw("do_timeout() delay must be nonnegative");
|
2009-06-13 17:11:00 +04:00
|
|
|
|
2009-12-28 20:31:00 +03:00
|
|
|
if (typeof func !== "function")
|
2010-08-14 00:28:14 +04:00
|
|
|
do_throw("string callbacks no longer accepted; use a function!");
|
2009-12-28 20:31:00 +03:00
|
|
|
|
|
|
|
this._func = func;
|
2010-08-14 00:28:14 +04:00
|
|
|
this._start = Date.now();
|
|
|
|
this._delay = delay;
|
|
|
|
|
|
|
|
var timer = Components.classes["@mozilla.org/timer;1"]
|
|
|
|
.createInstance(Components.interfaces.nsITimer);
|
|
|
|
timer.initWithCallback(this, delay + _timerFuzz, timer.TYPE_ONE_SHOT);
|
|
|
|
|
2009-11-03 21:39:40 +03:00
|
|
|
// Keep timer alive until it fires
|
2010-08-14 00:28:14 +04:00
|
|
|
_pendingTimers.push(timer);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2010-08-14 00:28:14 +04:00
|
|
|
_Timer.prototype = {
|
2005-03-25 06:41:33 +03:00
|
|
|
QueryInterface: function(iid) {
|
2013-07-23 21:31:30 +04:00
|
|
|
if (iid.equals(Components.interfaces.nsITimerCallback) ||
|
|
|
|
iid.equals(Components.interfaces.nsISupports))
|
2005-03-25 06:41:33 +03:00
|
|
|
return this;
|
2009-06-13 17:11:00 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
2009-06-13 17:11:00 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
notify: function(timer) {
|
2010-08-14 00:28:14 +04:00
|
|
|
_pendingTimers.splice(_pendingTimers.indexOf(timer), 1);
|
|
|
|
|
|
|
|
// The current nsITimer implementation can undershoot, but even if it
|
|
|
|
// couldn't, paranoia is probably a virtue here given the potential for
|
|
|
|
// random orange on tinderboxen.
|
|
|
|
var end = Date.now();
|
|
|
|
var elapsed = end - this._start;
|
|
|
|
if (elapsed >= this._delay) {
|
|
|
|
try {
|
|
|
|
this._func.call(null);
|
|
|
|
} catch (e) {
|
2010-08-14 10:03:36 +04:00
|
|
|
do_throw("exception thrown from do_timeout callback: " + e);
|
2010-08-14 00:28:14 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Timer undershot, retry with a little overshoot to try to avoid more
|
|
|
|
// undershoots.
|
|
|
|
var newDelay = this._delay - elapsed;
|
|
|
|
do_timeout(newDelay, this._func);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-09-12 10:19:26 +04:00
|
|
|
function _do_main() {
|
2015-05-25 19:11:07 +03:00
|
|
|
if (_quit)
|
2005-03-25 06:41:33 +03:00
|
|
|
return;
|
|
|
|
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.info("running event loop");
|
2009-06-05 02:05:22 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
var thr = Components.classes["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService().currentThread;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-05-25 19:11:07 +03:00
|
|
|
while (!_quit)
|
2006-05-11 01:32:48 +04:00
|
|
|
thr.processNextEvent(true);
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
while (thr.hasPendingEvents())
|
2006-05-11 01:32:48 +04:00
|
|
|
thr.processNextEvent(true);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2006-09-12 10:19:26 +04:00
|
|
|
function _do_quit() {
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.info("exiting test");
|
2015-05-25 19:11:07 +03:00
|
|
|
_quit = true;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2010-10-19 13:18:40 +04:00
|
|
|
/**
|
|
|
|
* Overrides idleService with a mock. Idle is commonly used for maintenance
|
|
|
|
* tasks, thus if a test uses a service that requires the idle service, it will
|
|
|
|
* start handling them.
|
|
|
|
* This behaviour would cause random failures and slowdown tests execution,
|
|
|
|
* for example by running database vacuum or cleanups for each test.
|
|
|
|
*
|
|
|
|
* @note Idle service is overridden by default. If a test requires it, it will
|
|
|
|
* have to call do_get_idle() function at least once before use.
|
|
|
|
*/
|
2013-07-23 21:31:30 +04:00
|
|
|
var _fakeIdleService = {
|
2010-10-19 13:18:40 +04:00
|
|
|
get registrar() {
|
|
|
|
delete this.registrar;
|
|
|
|
return this.registrar =
|
|
|
|
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
},
|
|
|
|
contractID: "@mozilla.org/widget/idleservice;1",
|
2015-09-23 12:42:19 +03:00
|
|
|
get CID() {
|
|
|
|
return this.registrar.contractIDToCID(this.contractID);
|
|
|
|
},
|
2010-10-19 13:18:40 +04:00
|
|
|
|
|
|
|
activate: function FIS_activate()
|
|
|
|
{
|
|
|
|
if (!this.originalFactory) {
|
|
|
|
// Save original factory.
|
|
|
|
this.originalFactory =
|
|
|
|
Components.manager.getClassObject(Components.classes[this.contractID],
|
|
|
|
Components.interfaces.nsIFactory);
|
|
|
|
// Unregister original factory.
|
|
|
|
this.registrar.unregisterFactory(this.CID, this.originalFactory);
|
|
|
|
// Replace with the mock.
|
|
|
|
this.registrar.registerFactory(this.CID, "Fake Idle Service",
|
|
|
|
this.contractID, this.factory
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
deactivate: function FIS_deactivate()
|
|
|
|
{
|
|
|
|
if (this.originalFactory) {
|
|
|
|
// Unregister the mock.
|
|
|
|
this.registrar.unregisterFactory(this.CID, this.factory);
|
|
|
|
// Restore original factory.
|
|
|
|
this.registrar.registerFactory(this.CID, "Idle Service",
|
|
|
|
this.contractID, this.originalFactory);
|
|
|
|
delete this.originalFactory;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
factory: {
|
|
|
|
// nsIFactory
|
|
|
|
createInstance: function (aOuter, aIID)
|
|
|
|
{
|
|
|
|
if (aOuter) {
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
}
|
|
|
|
return _fakeIdleService.QueryInterface(aIID);
|
|
|
|
},
|
|
|
|
lockFactory: function (aLock) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (aIID.equals(Components.interfaces.nsIFactory) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// nsIIdleService
|
2015-09-23 12:42:19 +03:00
|
|
|
get idleTime() {
|
|
|
|
return 0;
|
|
|
|
},
|
2010-10-19 13:18:40 +04:00
|
|
|
addIdleObserver: function () {},
|
|
|
|
removeIdleObserver: function () {},
|
|
|
|
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
// Useful for testing purposes, see test_get_idle.js.
|
|
|
|
if (aIID.equals(Components.interfaces.nsIFactory)) {
|
|
|
|
return this.factory;
|
|
|
|
}
|
|
|
|
if (aIID.equals(Components.interfaces.nsIIdleService) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the idle service factory if needed and returns the service's handle.
|
|
|
|
* @return A handle to the idle service.
|
|
|
|
*/
|
|
|
|
function do_get_idle() {
|
|
|
|
_fakeIdleService.deactivate();
|
|
|
|
return Components.classes[_fakeIdleService.contractID]
|
|
|
|
.getService(Components.interfaces.nsIIdleService);
|
|
|
|
}
|
|
|
|
|
2012-05-15 20:53:28 +04:00
|
|
|
// Map resource://test/ to current working directory and
|
|
|
|
// resource://testing-common/ to the shared test modules directory.
|
|
|
|
function _register_protocol_handlers() {
|
2014-05-30 18:26:42 +04:00
|
|
|
let ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
let protocolHandler =
|
|
|
|
ios.getProtocolHandler("resource")
|
|
|
|
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
|
2012-06-30 00:27:11 +04:00
|
|
|
|
2014-05-30 18:26:42 +04:00
|
|
|
let curDirURI = ios.newFileURI(do_get_cwd());
|
|
|
|
protocolHandler.setSubstitution("test", curDirURI);
|
2012-06-30 00:27:11 +04:00
|
|
|
|
2014-05-30 18:26:42 +04:00
|
|
|
_register_modules_protocol_handler();
|
|
|
|
}
|
2012-06-30 00:27:11 +04:00
|
|
|
|
2014-05-30 18:26:42 +04:00
|
|
|
function _register_modules_protocol_handler() {
|
2015-10-07 00:00:29 +03:00
|
|
|
if (!_TESTING_MODULES_DIR) {
|
2014-05-30 18:26:42 +04:00
|
|
|
throw new Error("Please define a path where the testing modules can be " +
|
|
|
|
"found in a variable called '_TESTING_MODULES_DIR' before " +
|
|
|
|
"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);
|
|
|
|
|
|
|
|
let modulesFile = Components.classes["@mozilla.org/file/local;1"].
|
|
|
|
createInstance(Components.interfaces.nsILocalFile);
|
|
|
|
modulesFile.initWithPath(_TESTING_MODULES_DIR);
|
|
|
|
|
|
|
|
if (!modulesFile.exists()) {
|
|
|
|
throw new Error("Specified modules directory does not exist: " +
|
|
|
|
_TESTING_MODULES_DIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!modulesFile.isDirectory()) {
|
|
|
|
throw new Error("Specified modules directory is not a directory: " +
|
|
|
|
_TESTING_MODULES_DIR);
|
2010-02-23 16:11:37 +03:00
|
|
|
}
|
2014-05-30 18:26:42 +04:00
|
|
|
|
|
|
|
let modulesURI = ios.newFileURI(modulesFile);
|
|
|
|
|
|
|
|
protocolHandler.setSubstitution("testing-common", modulesURI);
|
2012-05-15 20:53:28 +04:00
|
|
|
}
|
|
|
|
|
2014-12-11 11:13:12 +03:00
|
|
|
/* Debugging support */
|
|
|
|
// Used locally and by our self-tests.
|
|
|
|
function _setupDebuggerServer(breakpointFiles, callback) {
|
2014-11-29 02:40:58 +03:00
|
|
|
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
|
|
|
// Always allow remote debugging.
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (env.get("DEVTOOLS_DEBUGGER_LOG_VERBOSE")) {
|
|
|
|
prefs.setBoolPref("devtools.debugger.log.verbose", true);
|
|
|
|
}
|
|
|
|
|
2015-12-15 19:14:31 +03:00
|
|
|
let require;
|
|
|
|
try {
|
|
|
|
({ require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {}));
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error("resource://devtools appears to be inaccessible from the " +
|
|
|
|
"xpcshell environment.\n" +
|
|
|
|
"This can usually be resolved by adding:\n" +
|
|
|
|
" firefox-appdir = browser\n" +
|
|
|
|
"to the xpcshell.ini manifest.\n" +
|
|
|
|
"It is possible for this to alter test behevior by " +
|
|
|
|
"triggering additional browser code to run, so check " +
|
|
|
|
"test behavior after making this change.\n" +
|
|
|
|
"See also https://bugzil.la/1215378.")
|
|
|
|
}
|
2015-08-10 15:38:56 +03:00
|
|
|
let { DebuggerServer } = require("devtools/server/main");
|
|
|
|
let { OriginalLocation } = require("devtools/server/actors/common");
|
2014-12-02 09:55:56 +03:00
|
|
|
DebuggerServer.init();
|
2014-11-29 02:40:58 +03:00
|
|
|
DebuggerServer.addBrowserActors();
|
|
|
|
DebuggerServer.addActors("resource://testing-common/dbg-actors.js");
|
2015-02-26 05:56:00 +03:00
|
|
|
DebuggerServer.allowChromeProcess = true;
|
2014-11-29 02:40:58 +03:00
|
|
|
|
|
|
|
// 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) {
|
|
|
|
case "devtools-thread-resumed":
|
|
|
|
// Exceptions in here aren't reported and block the debugger from
|
|
|
|
// resuming, so...
|
|
|
|
try {
|
|
|
|
// Add a breakpoint for the first line in our test files.
|
|
|
|
let threadActor = subject.wrappedJSObject;
|
2014-12-11 11:13:12 +03:00
|
|
|
for (let file of breakpointFiles) {
|
2015-11-16 18:22:49 +03:00
|
|
|
// Pass an empty `source` object to workaround `source` function assertion
|
|
|
|
let sourceActor = threadActor.sources.source({originalUrl: file, source: {}});
|
2015-03-26 22:15:36 +03:00
|
|
|
sourceActor._getOrCreateBreakpointActor(new OriginalLocation(sourceActor, 1));
|
2014-11-29 02:40:58 +03:00
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
do_print("Failed to initialize breakpoints: " + ex + "\n" + ex.stack);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "xpcshell-test-devtools-shutdown":
|
|
|
|
// the debugger has shutdown before we got a resume event - nothing
|
|
|
|
// special to do here.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (let topicToRemove of TOPICS) {
|
|
|
|
obsSvc.removeObserver(observe, topicToRemove);
|
|
|
|
}
|
2014-12-11 11:13:12 +03:00
|
|
|
callback();
|
2014-11-29 02:40:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
for (let topic of TOPICS) {
|
|
|
|
obsSvc.addObserver(observe, topic, false);
|
|
|
|
}
|
2014-12-11 11:13:12 +03:00
|
|
|
return DebuggerServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _initDebugging(port) {
|
|
|
|
let initialized = false;
|
|
|
|
let DebuggerServer = _setupDebuggerServer(_TEST_FILE, () => {initialized = true;});
|
2014-11-29 02:40:58 +03:00
|
|
|
|
|
|
|
do_print("");
|
|
|
|
do_print("*******************************************************************");
|
|
|
|
do_print("Waiting for the debugger to connect on port " + port)
|
|
|
|
do_print("")
|
|
|
|
do_print("To connect the debugger, open a Firefox instance, select 'Connect'");
|
|
|
|
do_print("from the Developer menu and specify the port as " + port);
|
|
|
|
do_print("*******************************************************************");
|
|
|
|
do_print("")
|
|
|
|
|
2015-01-26 21:47:13 +03:00
|
|
|
let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT");
|
|
|
|
let authenticator = new AuthenticatorType.Server();
|
2015-01-26 21:47:13 +03:00
|
|
|
authenticator.allowConnection = () => {
|
|
|
|
return DebuggerServer.AuthenticationResult.ALLOW;
|
|
|
|
};
|
2015-01-26 21:47:13 +03:00
|
|
|
|
2014-12-11 05:55:51 +03:00
|
|
|
let listener = DebuggerServer.createListener();
|
|
|
|
listener.portOrPath = port;
|
2015-01-26 21:47:13 +03:00
|
|
|
listener.authenticator = authenticator;
|
2014-12-11 05:55:51 +03:00
|
|
|
listener.open();
|
2014-11-29 02:40:58 +03:00
|
|
|
|
|
|
|
// spin an event loop until the debugger connects.
|
|
|
|
let thr = Components.classes["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService().currentThread;
|
|
|
|
while (!initialized) {
|
|
|
|
do_print("Still waiting for debugger to connect...");
|
|
|
|
thr.processNextEvent(true);
|
|
|
|
}
|
|
|
|
// NOTE: if you want to debug the harness itself, you can now add a 'debugger'
|
|
|
|
// statement anywhere and it will stop - but we've already added a breakpoint
|
|
|
|
// for the first line of the test scripts, so we just continue...
|
|
|
|
do_print("Debugger connected, starting test execution");
|
|
|
|
}
|
|
|
|
|
2012-05-15 20:53:28 +04:00
|
|
|
function _execute_test() {
|
2014-11-29 02:40:58 +03:00
|
|
|
// _JSDEBUGGER_PORT is dynamically defined by <runxpcshelltests.py>.
|
|
|
|
if (_JSDEBUGGER_PORT) {
|
|
|
|
try {
|
|
|
|
_initDebugging(_JSDEBUGGER_PORT);
|
|
|
|
} catch (ex) {
|
2015-12-15 19:14:31 +03:00
|
|
|
// Fail the test run immediately if debugging is requested but fails, so
|
|
|
|
// that the failure state is more obvious.
|
|
|
|
do_throw(`Failed to initialize debugging: ${ex}`, ex.stack);
|
2014-11-29 02:40:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-15 20:53:28 +04:00
|
|
|
_register_protocol_handlers();
|
2010-02-23 16:11:37 +03:00
|
|
|
|
2010-10-19 13:18:40 +04:00
|
|
|
// Override idle service by default.
|
|
|
|
// Call do_get_idle() to restore the factory and get the service.
|
|
|
|
_fakeIdleService.activate();
|
|
|
|
|
2016-02-03 15:58:03 +03:00
|
|
|
_PromiseTestUtils.init();
|
|
|
|
_PromiseTestUtils.Assert = Assert;
|
2014-04-15 20:51:20 +04:00
|
|
|
|
2016-06-08 16:41:04 +03:00
|
|
|
let coverageCollector = null;
|
|
|
|
if (typeof _JSCOV_DIR === 'string') {
|
|
|
|
let _CoverageCollector = Components.utils.import("resource://testing-common/CoverageUtils.jsm", {}).CoverageCollector;
|
|
|
|
coverageCollector = new _CoverageCollector(_JSCOV_DIR);
|
|
|
|
}
|
|
|
|
|
2009-06-13 17:11:00 +04:00
|
|
|
// _HEAD_FILES is dynamically defined by <runxpcshelltests.py>.
|
|
|
|
_load_files(_HEAD_FILES);
|
|
|
|
// _TEST_FILE is dynamically defined by <runxpcshelltests.py>.
|
|
|
|
_load_files(_TEST_FILE);
|
|
|
|
|
2015-05-25 19:11:07 +03:00
|
|
|
// Tack Assert.jsm methods to the current scope.
|
|
|
|
this.Assert = Assert;
|
|
|
|
for (let func in Assert) {
|
|
|
|
this[func] = Assert[func].bind(Assert);
|
|
|
|
}
|
|
|
|
|
2016-01-10 18:40:12 +03:00
|
|
|
if (_gTestHasOnly) {
|
|
|
|
_gTests = _gTests.filter(([props,]) => {
|
|
|
|
return ("_only" in props) && props._only;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-03-17 17:22:55 +03:00
|
|
|
try {
|
2013-05-03 20:08:30 +04:00
|
|
|
do_test_pending("MAIN run_test");
|
2015-04-02 20:02:18 +03:00
|
|
|
// Check if run_test() is defined. If defined, run it.
|
|
|
|
// Else, call run_next_test() directly to invoke tests
|
2015-09-05 04:36:52 +03:00
|
|
|
// added by add_test() and add_task().
|
2015-04-02 20:02:18 +03:00
|
|
|
if (typeof run_test === "function") {
|
|
|
|
run_test();
|
|
|
|
} else {
|
|
|
|
run_next_test();
|
|
|
|
}
|
2016-06-08 16:41:04 +03:00
|
|
|
|
|
|
|
if (coverageCollector != null) {
|
2016-06-28 01:17:41 +03:00
|
|
|
coverageCollector.recordTestCoverage(_TEST_FILE[0]);
|
2016-06-08 16:41:04 +03:00
|
|
|
}
|
|
|
|
|
2013-05-03 20:08:30 +04:00
|
|
|
do_test_finished("MAIN run_test");
|
2009-03-17 17:22:55 +03:00
|
|
|
_do_main();
|
2016-02-03 15:58:03 +03:00
|
|
|
_PromiseTestUtils.assertNoUncaughtRejections();
|
2009-03-17 17:22:55 +03:00
|
|
|
} catch (e) {
|
2009-06-05 02:05:22 +04:00
|
|
|
_passed = false;
|
2015-05-25 19:11:07 +03:00
|
|
|
// do_check failures are already logged and set _quit to true and throw
|
2010-03-08 21:26:54 +03:00
|
|
|
// NS_ERROR_ABORT. If both of those are true it is likely this exception
|
|
|
|
// has already been logged so there is no need to log it again. It's
|
|
|
|
// possible that this will mask an NS_ERROR_ABORT that happens after a
|
|
|
|
// do_check failure though.
|
2016-06-08 16:41:04 +03:00
|
|
|
if (coverageCollector != null) {
|
2016-06-28 01:17:41 +03:00
|
|
|
coverageCollector.recordTestCoverage(_TEST_FILE[0]);
|
2016-06-08 16:41:04 +03:00
|
|
|
}
|
|
|
|
|
2015-05-25 19:11:07 +03:00
|
|
|
if (!_quit || e != Components.results.NS_ERROR_ABORT) {
|
2014-10-22 23:53:42 +04:00
|
|
|
let extra = {};
|
2012-03-04 07:19:04 +04:00
|
|
|
if (e.fileName) {
|
2014-10-22 23:53:42 +04:00
|
|
|
extra.source_file = e.fileName;
|
2012-03-04 07:19:04 +04:00
|
|
|
if (e.lineNumber) {
|
2014-10-22 23:53:42 +04:00
|
|
|
extra.line_number = e.lineNumber;
|
2011-12-28 20:57:28 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-10-22 23:53:42 +04:00
|
|
|
extra.source_file = "xpcshell/head.js";
|
2011-12-28 20:57:28 +04:00
|
|
|
}
|
2014-10-22 23:53:42 +04:00
|
|
|
let message = _exception_message(e);
|
2010-03-08 21:26:54 +03:00
|
|
|
if (e.stack) {
|
2014-10-22 23:53:42 +04:00
|
|
|
extra.stack = _format_stack(e.stack);
|
2010-03-08 21:26:54 +03:00
|
|
|
}
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.error(message, extra);
|
2010-03-08 21:26:54 +03:00
|
|
|
}
|
2009-03-17 17:22:55 +03:00
|
|
|
}
|
|
|
|
|
2016-06-08 16:41:04 +03:00
|
|
|
if (coverageCollector != null) {
|
|
|
|
coverageCollector.finalize();
|
|
|
|
}
|
|
|
|
|
2009-06-13 17:11:00 +04:00
|
|
|
// _TAIL_FILES is dynamically defined by <runxpcshelltests.py>.
|
|
|
|
_load_files(_TAIL_FILES);
|
|
|
|
|
2009-07-11 03:42:59 +04:00
|
|
|
// Execute all of our cleanup functions.
|
2014-03-31 06:36:00 +04:00
|
|
|
let reportCleanupError = function(ex) {
|
|
|
|
let stack, filename;
|
|
|
|
if (ex && typeof ex == "object" && "stack" in ex) {
|
|
|
|
stack = ex.stack;
|
|
|
|
} else {
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
}
|
|
|
|
if (stack instanceof Components.interfaces.nsIStackFrame) {
|
|
|
|
filename = stack.filename;
|
|
|
|
} else if (ex.fileName) {
|
|
|
|
filename = ex.fileName;
|
|
|
|
}
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.error(_exception_message(ex),
|
|
|
|
{
|
|
|
|
stack: _format_stack(stack),
|
|
|
|
source_file: filename
|
|
|
|
});
|
2014-03-31 06:36:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
let func;
|
|
|
|
while ((func = _cleanupFunctions.pop())) {
|
|
|
|
let result;
|
|
|
|
try {
|
|
|
|
result = func();
|
|
|
|
} catch (ex) {
|
|
|
|
reportCleanupError(ex);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (result && typeof result == "object"
|
|
|
|
&& "then" in result && typeof result.then == "function") {
|
|
|
|
// This is a promise, wait until it is satisfied before proceeding
|
|
|
|
let complete = false;
|
|
|
|
let promise = result.then(null, reportCleanupError);
|
|
|
|
promise = promise.then(() => complete = true);
|
2016-02-01 19:25:19 +03:00
|
|
|
let thr = Components.classes["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService().currentThread;
|
2014-03-31 06:36:00 +04:00
|
|
|
while (!complete) {
|
|
|
|
thr.processNextEvent(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-11 03:42:59 +04:00
|
|
|
|
2010-10-19 13:18:40 +04:00
|
|
|
// Restore idle service to avoid leaks.
|
|
|
|
_fakeIdleService.deactivate();
|
|
|
|
|
2016-02-03 14:35:07 +03:00
|
|
|
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", null);
|
|
|
|
obs.notifyObservers(null, "profile-change-teardown", null);
|
|
|
|
obs.notifyObservers(null, "profile-before-change", null);
|
2016-06-15 13:49:04 +03:00
|
|
|
obs.notifyObservers(null, "profile-before-change-qm", null);
|
2016-02-03 14:35:07 +03:00
|
|
|
|
|
|
|
_profileInitialized = false;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:58:03 +03:00
|
|
|
try {
|
|
|
|
_PromiseTestUtils.ensureDOMPromiseRejectionsProcessed();
|
|
|
|
_PromiseTestUtils.assertNoUncaughtRejections();
|
|
|
|
_PromiseTestUtils.assertNoMoreExpectedRejections();
|
|
|
|
} finally {
|
|
|
|
// It's important to terminate the module to avoid crashes on shutdown.
|
|
|
|
_PromiseTestUtils.uninit();
|
|
|
|
}
|
2009-03-17 17:22:55 +03:00
|
|
|
}
|
|
|
|
|
2009-06-13 17:11:00 +04:00
|
|
|
/**
|
|
|
|
* Loads files.
|
|
|
|
*
|
|
|
|
* @param aFiles Array of files to load.
|
|
|
|
*/
|
|
|
|
function _load_files(aFiles) {
|
2014-10-22 23:53:42 +04:00
|
|
|
function load_file(element, index, array) {
|
2013-07-23 06:44:25 +04:00
|
|
|
try {
|
|
|
|
load(element);
|
2013-11-22 10:36:16 +04:00
|
|
|
} catch (e) {
|
2014-10-22 23:53:42 +04:00
|
|
|
let extra = {
|
|
|
|
source_file: element
|
|
|
|
}
|
|
|
|
if (e.stack) {
|
|
|
|
extra.stack = _format_stack(e.stack);
|
|
|
|
}
|
|
|
|
_testLogger.error(_exception_message(e), extra);
|
2013-07-23 06:44:25 +04:00
|
|
|
}
|
2009-06-13 17:11:00 +04:00
|
|
|
}
|
|
|
|
|
2014-10-22 23:53:42 +04:00
|
|
|
aFiles.forEach(load_file);
|
2009-06-13 17:11:00 +04:00
|
|
|
}
|
|
|
|
|
2013-06-07 20:43:48 +04:00
|
|
|
function _wrap_with_quotes_if_necessary(val) {
|
|
|
|
return typeof val == "string" ? '"' + val + '"' : val;
|
|
|
|
}
|
2009-03-17 17:22:55 +03:00
|
|
|
|
2006-09-12 10:19:26 +04:00
|
|
|
/************** Functions to be used from the tests **************/
|
|
|
|
|
2011-09-07 08:26:20 +04:00
|
|
|
/**
|
|
|
|
* Prints a message to the output log.
|
|
|
|
*/
|
2014-10-22 23:53:42 +04:00
|
|
|
function do_print(msg, data) {
|
2013-06-07 20:43:48 +04:00
|
|
|
msg = _wrap_with_quotes_if_necessary(msg);
|
2014-10-22 23:53:42 +04:00
|
|
|
data = data ? data : null;
|
|
|
|
_testLogger.info(msg, data);
|
2011-09-07 08:26:20 +04:00
|
|
|
}
|
|
|
|
|
2010-08-14 00:28:14 +04:00
|
|
|
/**
|
|
|
|
* Calls the given function at least the specified number of milliseconds later.
|
|
|
|
* The callback will not undershoot the given time, but it might overshoot --
|
|
|
|
* don't expect precision!
|
|
|
|
*
|
|
|
|
* @param delay : uint
|
|
|
|
* the number of milliseconds to delay
|
|
|
|
* @param callback : function() : void
|
|
|
|
* the function to call
|
|
|
|
*/
|
2009-12-28 20:31:00 +03:00
|
|
|
function do_timeout(delay, func) {
|
2010-08-14 00:28:14 +04:00
|
|
|
new _Timer(func, Number(delay));
|
2006-09-12 10:19:26 +04:00
|
|
|
}
|
|
|
|
|
2013-05-03 20:08:30 +04:00
|
|
|
function do_execute_soon(callback, aName) {
|
|
|
|
let funcName = (aName ? aName : callback.name);
|
|
|
|
do_test_pending(funcName);
|
2009-08-06 18:25:16 +04:00
|
|
|
var tm = Components.classes["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIThreadManager);
|
|
|
|
|
|
|
|
tm.mainThread.dispatch({
|
|
|
|
run: function() {
|
2010-03-08 21:26:54 +03:00
|
|
|
try {
|
|
|
|
callback();
|
|
|
|
} catch (e) {
|
2015-05-25 19:11:07 +03:00
|
|
|
// do_check failures are already logged and set _quit to true and throw
|
2010-03-08 21:26:54 +03:00
|
|
|
// NS_ERROR_ABORT. If both of those are true it is likely this exception
|
|
|
|
// has already been logged so there is no need to log it again. It's
|
|
|
|
// possible that this will mask an NS_ERROR_ABORT that happens after a
|
|
|
|
// do_check failure though.
|
2015-05-25 19:11:07 +03:00
|
|
|
if (!_quit || e != Components.results.NS_ERROR_ABORT) {
|
2014-10-22 23:53:42 +04:00
|
|
|
let stack = e.stack ? _format_stack(e.stack) : null;
|
|
|
|
_testLogger.testStatus(_TEST_NAME,
|
|
|
|
funcName,
|
2015-02-02 21:32:49 +03:00
|
|
|
'FAIL',
|
|
|
|
'PASS',
|
2014-10-22 23:53:42 +04:00
|
|
|
_exception_message(e),
|
|
|
|
stack);
|
2010-03-08 21:26:54 +03:00
|
|
|
_do_quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
2013-05-03 20:08:30 +04:00
|
|
|
do_test_finished(funcName);
|
2010-03-08 21:26:54 +03:00
|
|
|
}
|
2009-08-06 18:25:16 +04:00
|
|
|
}
|
|
|
|
}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2013-05-08 06:37:49 +04:00
|
|
|
/**
|
|
|
|
* Shows an error message and the current stack and aborts the test.
|
|
|
|
*
|
|
|
|
* @param error A message string or an Error object.
|
|
|
|
* @param stack null or nsIStackFrame object or a string containing
|
|
|
|
* \n separated stack lines (as in Error().stack).
|
|
|
|
*/
|
|
|
|
function do_throw(error, stack) {
|
|
|
|
let filename = "";
|
2013-07-13 20:37:13 +04:00
|
|
|
// If we didn't get passed a stack, maybe the error has one
|
|
|
|
// otherwise get it from our call context
|
|
|
|
stack = stack || error.stack || Components.stack.caller;
|
2009-06-05 02:05:22 +04:00
|
|
|
|
2013-05-08 06:37:49 +04:00
|
|
|
if (stack instanceof Components.interfaces.nsIStackFrame)
|
|
|
|
filename = stack.filename;
|
2013-07-13 20:37:13 +04:00
|
|
|
else if (error.fileName)
|
|
|
|
filename = error.fileName;
|
|
|
|
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.error(_exception_message(error),
|
|
|
|
{
|
|
|
|
source_file: filename,
|
|
|
|
stack: _format_stack(stack)
|
|
|
|
});
|
|
|
|
_abort_failed_test();
|
|
|
|
}
|
2013-05-08 06:37:49 +04:00
|
|
|
|
2014-10-22 23:53:42 +04:00
|
|
|
function _abort_failed_test() {
|
|
|
|
// Called to abort the test run after all failures are logged.
|
2013-07-13 20:37:13 +04:00
|
|
|
_passed = false;
|
|
|
|
_do_quit();
|
|
|
|
throw Components.results.NS_ERROR_ABORT;
|
|
|
|
}
|
2013-05-08 06:37:49 +04:00
|
|
|
|
2013-07-23 06:44:25 +04:00
|
|
|
function _format_stack(stack) {
|
2014-06-20 22:23:00 +04:00
|
|
|
let normalized;
|
2013-05-08 06:37:49 +04:00
|
|
|
if (stack instanceof Components.interfaces.nsIStackFrame) {
|
2014-06-20 22:23:00 +04:00
|
|
|
let frames = [];
|
|
|
|
for (let frame = stack; frame; frame = frame.caller) {
|
|
|
|
frames.push(frame.filename + ":" + frame.name + ":" + frame.lineNumber);
|
2013-05-08 06:37:49 +04:00
|
|
|
}
|
2014-06-20 22:23:00 +04:00
|
|
|
normalized = frames.join("\n");
|
|
|
|
} else {
|
|
|
|
normalized = "" + stack;
|
2013-07-13 20:37:13 +04:00
|
|
|
}
|
2014-06-20 22:23:00 +04:00
|
|
|
return _Task.Debugging.generateReadableStack(normalized, " ");
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2013-07-13 20:37:13 +04:00
|
|
|
// Make a nice display string from an object that behaves
|
|
|
|
// like Error
|
|
|
|
function _exception_message(ex) {
|
|
|
|
let message = "";
|
|
|
|
if (ex.name) {
|
|
|
|
message = ex.name + ": ";
|
|
|
|
}
|
|
|
|
if (ex.message) {
|
|
|
|
message += ex.message;
|
|
|
|
}
|
|
|
|
if (ex.fileName) {
|
|
|
|
message += (" at " + ex.fileName);
|
|
|
|
if (ex.lineNumber) {
|
|
|
|
message += (":" + ex.lineNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (message !== "") {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
// Force ex to be stringified
|
|
|
|
return "" + ex;
|
|
|
|
}
|
|
|
|
|
2009-11-05 23:06:00 +03:00
|
|
|
function do_report_unexpected_exception(ex, text) {
|
2014-10-22 23:53:42 +04:00
|
|
|
let filename = Components.stack.caller.filename;
|
2009-11-05 23:06:00 +03:00
|
|
|
text = text ? text + " - " : "";
|
|
|
|
|
|
|
|
_passed = false;
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.error(text + "Unexpected exception " + _exception_message(ex),
|
|
|
|
{
|
|
|
|
source_file: filename,
|
|
|
|
stack: _format_stack(ex.stack)
|
|
|
|
});
|
2009-11-05 23:06:00 +03:00
|
|
|
_do_quit();
|
|
|
|
throw Components.results.NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_note_exception(ex, text) {
|
2014-10-22 23:53:42 +04:00
|
|
|
let filename = Components.stack.caller.filename;
|
|
|
|
_testLogger.info(text + "Swallowed exception " + _exception_message(ex),
|
|
|
|
{
|
|
|
|
source_file: filename,
|
|
|
|
stack: _format_stack(ex.stack)
|
|
|
|
});
|
2009-11-05 23:06:00 +03:00
|
|
|
}
|
|
|
|
|
2011-02-21 03:54:14 +03:00
|
|
|
function _do_check_neq(left, right, stack, todo) {
|
2014-05-30 18:26:42 +04:00
|
|
|
Assert.notEqual(left, right);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2011-02-21 03:54:14 +03:00
|
|
|
function do_check_neq(left, right, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
_do_check_neq(left, right, stack, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function todo_check_neq(left, right, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
_do_check_neq(left, right, stack, true);
|
|
|
|
}
|
|
|
|
|
2013-01-15 04:15:58 +04:00
|
|
|
function do_report_result(passed, text, stack, todo) {
|
2015-04-29 18:32:05 +03:00
|
|
|
while (stack.filename.includes("head.js") && stack.caller) {
|
2014-07-10 04:24:59 +04:00
|
|
|
stack = stack.caller;
|
|
|
|
}
|
2014-10-22 23:53:42 +04:00
|
|
|
|
|
|
|
let name = _gRunningTest ? _gRunningTest.name : stack.name;
|
|
|
|
let message;
|
|
|
|
if (name) {
|
|
|
|
message = "[" + name + " : " + stack.lineNumber + "] " + text;
|
|
|
|
} else {
|
|
|
|
message = text;
|
|
|
|
}
|
|
|
|
|
2013-01-15 04:15:58 +04:00
|
|
|
if (passed) {
|
|
|
|
if (todo) {
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.testStatus(_TEST_NAME,
|
|
|
|
name,
|
|
|
|
"PASS",
|
|
|
|
"FAIL",
|
|
|
|
message,
|
|
|
|
_format_stack(stack));
|
|
|
|
_abort_failed_test();
|
2011-02-21 03:54:14 +03:00
|
|
|
} else {
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.testStatus(_TEST_NAME,
|
|
|
|
name,
|
|
|
|
"PASS",
|
|
|
|
"PASS",
|
|
|
|
message);
|
2013-01-15 04:15:58 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (todo) {
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.testStatus(_TEST_NAME,
|
|
|
|
name,
|
|
|
|
"FAIL",
|
|
|
|
"FAIL",
|
|
|
|
message);
|
2011-02-21 03:54:14 +03:00
|
|
|
} else {
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.testStatus(_TEST_NAME,
|
|
|
|
name,
|
|
|
|
"FAIL",
|
|
|
|
"PASS",
|
|
|
|
message,
|
|
|
|
_format_stack(stack));
|
|
|
|
_abort_failed_test();
|
2011-02-21 03:54:14 +03:00
|
|
|
}
|
2009-06-05 02:05:22 +04:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2013-01-15 04:15:58 +04:00
|
|
|
function _do_check_eq(left, right, stack, todo) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
2013-06-07 20:43:48 +04:00
|
|
|
var text = _wrap_with_quotes_if_necessary(left) + " == " +
|
|
|
|
_wrap_with_quotes_if_necessary(right);
|
2013-01-15 04:15:58 +04:00
|
|
|
do_report_result(left == right, text, stack, todo);
|
|
|
|
}
|
|
|
|
|
2011-02-21 03:54:14 +03:00
|
|
|
function do_check_eq(left, right, stack) {
|
2014-05-30 18:26:42 +04:00
|
|
|
Assert.equal(left, right);
|
2011-02-21 03:54:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function todo_check_eq(left, right, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
_do_check_eq(left, right, stack, true);
|
|
|
|
}
|
|
|
|
|
2008-07-16 09:45:42 +04:00
|
|
|
function do_check_true(condition, stack) {
|
2015-06-20 00:27:37 +03:00
|
|
|
Assert.ok(condition, stack);
|
2006-07-17 00:47:13 +04:00
|
|
|
}
|
|
|
|
|
2011-02-21 03:54:14 +03:00
|
|
|
function todo_check_true(condition, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
todo_check_eq(condition, true, stack);
|
|
|
|
}
|
|
|
|
|
2008-07-16 09:45:42 +04:00
|
|
|
function do_check_false(condition, stack) {
|
2014-05-30 18:26:42 +04:00
|
|
|
Assert.ok(!condition, stack);
|
2006-12-15 05:13:54 +03:00
|
|
|
}
|
|
|
|
|
2011-02-21 03:54:14 +03:00
|
|
|
function todo_check_false(condition, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
todo_check_eq(condition, false, stack);
|
|
|
|
}
|
|
|
|
|
2014-05-30 18:26:42 +04:00
|
|
|
function do_check_null(condition, stack) {
|
|
|
|
Assert.equal(condition, null);
|
2012-06-01 21:23:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function todo_check_null(condition, stack=Components.stack.caller) {
|
|
|
|
todo_check_eq(condition, null, stack);
|
|
|
|
}
|
2014-05-30 18:26:42 +04:00
|
|
|
function do_check_matches(pattern, value) {
|
|
|
|
Assert.deepEqual(pattern, value);
|
2013-01-15 04:15:58 +04:00
|
|
|
}
|
|
|
|
|
2013-09-06 19:06:22 +04:00
|
|
|
// Check that |func| throws an nsIException that has
|
|
|
|
// |Components.results[resultName]| as the value of its 'result' property.
|
|
|
|
function do_check_throws_nsIException(func, resultName,
|
|
|
|
stack=Components.stack.caller, todo=false)
|
|
|
|
{
|
|
|
|
let expected = Components.results[resultName];
|
|
|
|
if (typeof expected !== 'number') {
|
|
|
|
do_throw("do_check_throws_nsIException requires a Components.results" +
|
|
|
|
" property name, not " + uneval(resultName), stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
let msg = ("do_check_throws_nsIException: func should throw" +
|
|
|
|
" an nsIException whose 'result' is Components.results." +
|
|
|
|
resultName);
|
|
|
|
|
|
|
|
try {
|
|
|
|
func();
|
|
|
|
} catch (ex) {
|
|
|
|
if (!(ex instanceof Components.interfaces.nsIException) ||
|
|
|
|
ex.result !== expected) {
|
|
|
|
do_report_result(false, msg + ", threw " + legible_exception(ex) +
|
|
|
|
" instead", stack, todo);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_report_result(true, msg, stack, todo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call this here, not in the 'try' clause, so do_report_result's own
|
|
|
|
// throw doesn't get caught by our 'catch' clause.
|
|
|
|
do_report_result(false, msg + ", but returned normally", stack, todo);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Produce a human-readable form of |exception|. This looks up
|
|
|
|
// Components.results values, tries toString methods, and so on.
|
|
|
|
function legible_exception(exception)
|
|
|
|
{
|
|
|
|
switch (typeof exception) {
|
|
|
|
case 'object':
|
|
|
|
if (exception instanceof Components.interfaces.nsIException) {
|
|
|
|
return "nsIException instance: " + uneval(exception.toString());
|
|
|
|
}
|
|
|
|
return exception.toString();
|
|
|
|
|
|
|
|
case 'number':
|
|
|
|
for (let name in Components.results) {
|
|
|
|
if (exception === Components.results[name]) {
|
|
|
|
return "Components.results." + name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall through.
|
|
|
|
default:
|
|
|
|
return uneval(exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-06 19:06:23 +04:00
|
|
|
function do_check_instanceof(value, constructor,
|
|
|
|
stack=Components.stack.caller, todo=false) {
|
|
|
|
do_report_result(value instanceof constructor,
|
|
|
|
"value should be an instance of " + constructor.name,
|
|
|
|
stack, todo);
|
|
|
|
}
|
|
|
|
|
|
|
|
function todo_check_instanceof(value, constructor,
|
|
|
|
stack=Components.stack.caller) {
|
|
|
|
do_check_instanceof(value, constructor, stack, true);
|
|
|
|
}
|
|
|
|
|
2013-05-03 20:08:30 +04:00
|
|
|
function do_test_pending(aName) {
|
2009-06-05 02:05:22 +04:00
|
|
|
++_tests_pending;
|
|
|
|
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.info("(xpcshell/head.js) | test" +
|
|
|
|
(aName ? " " + aName : "") +
|
|
|
|
" pending (" + _tests_pending + ")");
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2013-05-03 20:08:30 +04:00
|
|
|
function do_test_finished(aName) {
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.info("(xpcshell/head.js) | test" +
|
|
|
|
(aName ? " " + aName : "") +
|
|
|
|
" finished (" + _tests_pending + ")");
|
2005-03-25 06:41:33 +03:00
|
|
|
if (--_tests_pending == 0)
|
2006-09-12 10:19:26 +04:00
|
|
|
_do_quit();
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2006-12-15 05:13:54 +03:00
|
|
|
|
2009-03-21 18:20:00 +03:00
|
|
|
function do_get_file(path, allowNonexistent) {
|
2007-01-31 10:22:12 +03:00
|
|
|
try {
|
2009-03-21 18:20:00 +03:00
|
|
|
let lf = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties)
|
|
|
|
.get("CurWorkD", Components.interfaces.nsILocalFile);
|
|
|
|
|
|
|
|
let bits = path.split("/");
|
|
|
|
for (let i = 0; i < bits.length; i++) {
|
|
|
|
if (bits[i]) {
|
|
|
|
if (bits[i] == "..")
|
|
|
|
lf = lf.parent;
|
|
|
|
else
|
|
|
|
lf.append(bits[i]);
|
|
|
|
}
|
2008-07-24 19:33:41 +04:00
|
|
|
}
|
2007-02-03 04:46:09 +03:00
|
|
|
|
2009-06-05 02:05:22 +04:00
|
|
|
if (!allowNonexistent && !lf.exists()) {
|
|
|
|
// Not using do_throw(): caller will continue.
|
|
|
|
_passed = false;
|
|
|
|
var stack = Components.stack.caller;
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.error("[" + stack.name + " : " + stack.lineNumber + "] " +
|
|
|
|
lf.path + " does not exist");
|
2007-06-08 02:34:06 +04:00
|
|
|
}
|
2009-03-21 18:20:00 +03:00
|
|
|
|
|
|
|
return lf;
|
2007-06-08 02:34:06 +04:00
|
|
|
}
|
2009-06-05 02:05:22 +04:00
|
|
|
catch (ex) {
|
2009-03-21 18:20:00 +03:00
|
|
|
do_throw(ex.toString(), Components.stack.caller);
|
|
|
|
}
|
2009-06-05 02:05:22 +04:00
|
|
|
|
2009-03-21 18:20:00 +03:00
|
|
|
return null;
|
|
|
|
}
|
2007-02-03 04:46:09 +03:00
|
|
|
|
2009-03-21 18:20:00 +03:00
|
|
|
// do_get_cwd() isn't exactly self-explanatory, so provide a helper
|
|
|
|
function do_get_cwd() {
|
|
|
|
return do_get_file("");
|
2007-01-31 06:25:46 +03:00
|
|
|
}
|
2007-05-09 14:48:21 +04:00
|
|
|
|
2010-06-25 18:43:25 +04:00
|
|
|
function do_load_manifest(path) {
|
2007-05-09 14:48:21 +04:00
|
|
|
var lf = do_get_file(path);
|
|
|
|
const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
|
|
|
|
do_check_true(Components.manager instanceof nsIComponentRegistrar);
|
2009-06-05 02:05:22 +04:00
|
|
|
// Previous do_check_true() is not a test check.
|
2007-05-09 14:48:21 +04:00
|
|
|
Components.manager.autoRegister(lf);
|
|
|
|
}
|
2007-08-04 03:00:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a DOM document.
|
|
|
|
*
|
|
|
|
* @param aPath File path to the document.
|
|
|
|
* @param aType Content type to use in DOMParser.
|
|
|
|
*
|
|
|
|
* @return nsIDOMDocument from the file.
|
|
|
|
*/
|
|
|
|
function do_parse_document(aPath, aType) {
|
|
|
|
switch (aType) {
|
|
|
|
case "application/xhtml+xml":
|
|
|
|
case "application/xml":
|
|
|
|
case "text/xml":
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-06-05 02:05:22 +04:00
|
|
|
do_throw("type: expected application/xhtml+xml, application/xml or text/xml," +
|
|
|
|
" got '" + aType + "'",
|
|
|
|
Components.stack.caller);
|
2007-08-04 03:00:39 +04:00
|
|
|
}
|
|
|
|
|
2016-08-20 21:18:55 +03:00
|
|
|
let file = do_get_file(aPath),
|
|
|
|
ios = Components.classes['@mozilla.org/network/io-service;1']
|
|
|
|
.getService(Components.interfaces.nsIIOService),
|
|
|
|
url = ios.newFileURI(file).spec;
|
|
|
|
file = null;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("GET", url);
|
|
|
|
xhr.responseType = "document";
|
|
|
|
xhr.onerror = reject;
|
|
|
|
xhr.onload = () => {
|
|
|
|
resolve(xhr.response);
|
|
|
|
};
|
|
|
|
xhr.send();
|
|
|
|
});
|
2007-08-04 03:00:39 +04:00
|
|
|
}
|
2009-07-11 03:42:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a function that will run when the test harness is done running all
|
|
|
|
* tests.
|
|
|
|
*
|
|
|
|
* @param aFunction
|
|
|
|
* The function to be called when the test harness has finished running.
|
|
|
|
*/
|
|
|
|
function do_register_cleanup(aFunction)
|
|
|
|
{
|
|
|
|
_cleanupFunctions.push(aFunction);
|
|
|
|
}
|
2009-05-14 15:37:40 +04:00
|
|
|
|
2013-07-16 20:38:35 +04:00
|
|
|
/**
|
|
|
|
* Returns the directory for a temp dir, which is created by the
|
|
|
|
* test harness. Every test gets its own temp dir.
|
|
|
|
*
|
|
|
|
* @return nsILocalFile of the temporary directory
|
|
|
|
*/
|
|
|
|
function do_get_tempdir() {
|
|
|
|
let env = Components.classes["@mozilla.org/process/environment;1"]
|
|
|
|
.getService(Components.interfaces.nsIEnvironment);
|
|
|
|
// the python harness sets this in the environment for us
|
|
|
|
let path = env.get("XPCSHELL_TEST_TEMP_DIR");
|
|
|
|
let file = Components.classes["@mozilla.org/file/local;1"]
|
|
|
|
.createInstance(Components.interfaces.nsILocalFile);
|
|
|
|
file.initWithPath(path);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2013-11-21 21:22:18 +04:00
|
|
|
/**
|
|
|
|
* Returns the directory for crashreporter minidumps.
|
|
|
|
*
|
|
|
|
* @return nsILocalFile of the minidump directory
|
|
|
|
*/
|
|
|
|
function do_get_minidumpdir() {
|
|
|
|
let env = Components.classes["@mozilla.org/process/environment;1"]
|
|
|
|
.getService(Components.interfaces.nsIEnvironment);
|
|
|
|
// the python harness may set this in the environment for us
|
|
|
|
let path = env.get("XPCSHELL_MINIDUMP_DIR");
|
|
|
|
if (path) {
|
|
|
|
let file = Components.classes["@mozilla.org/file/local;1"]
|
|
|
|
.createInstance(Components.interfaces.nsILocalFile);
|
|
|
|
file.initWithPath(path);
|
|
|
|
return file;
|
|
|
|
} else {
|
|
|
|
return do_get_tempdir();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 15:37:40 +04:00
|
|
|
/**
|
|
|
|
* Registers a directory with the profile service,
|
|
|
|
* and return the directory as an nsILocalFile.
|
|
|
|
*
|
2015-04-21 17:30:36 +03:00
|
|
|
* @param notifyProfileAfterChange Whether to notify for "profile-after-change".
|
2009-05-14 15:37:40 +04:00
|
|
|
* @return nsILocalFile of the profile directory.
|
|
|
|
*/
|
2015-04-21 17:30:36 +03:00
|
|
|
function do_get_profile(notifyProfileAfterChange = false) {
|
2013-01-08 19:13:44 +04:00
|
|
|
if (!runningInParent) {
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.info("Ignoring profile creation from child process.");
|
2013-01-08 19:13:44 +04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-05-14 15:37:40 +04:00
|
|
|
let env = Components.classes["@mozilla.org/process/environment;1"]
|
|
|
|
.getService(Components.interfaces.nsIEnvironment);
|
|
|
|
// the python harness sets this in the environment for us
|
|
|
|
let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
|
|
|
|
let file = Components.classes["@mozilla.org/file/local;1"]
|
|
|
|
.createInstance(Components.interfaces.nsILocalFile);
|
|
|
|
file.initWithPath(profd);
|
|
|
|
|
|
|
|
let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties);
|
|
|
|
let provider = {
|
|
|
|
getFile: function(prop, persistent) {
|
|
|
|
persistent.value = true;
|
2010-09-16 02:55:08 +04:00
|
|
|
if (prop == "ProfD" || prop == "ProfLD" || prop == "ProfDS" ||
|
|
|
|
prop == "ProfLDS" || prop == "TmpD") {
|
2009-05-14 15:37:40 +04:00
|
|
|
return file.clone();
|
|
|
|
}
|
2014-08-28 11:09:00 +04:00
|
|
|
return null;
|
2009-05-14 15:37:40 +04:00
|
|
|
},
|
|
|
|
QueryInterface: function(iid) {
|
2010-04-01 15:29:13 +04:00
|
|
|
if (iid.equals(Components.interfaces.nsIDirectoryServiceProvider) ||
|
2009-05-14 15:37:40 +04:00
|
|
|
iid.equals(Components.interfaces.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
dirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
|
|
|
|
.registerProvider(provider);
|
2012-03-02 21:36:53 +04:00
|
|
|
|
2012-12-12 03:12:59 +04:00
|
|
|
let obsSvc = Components.classes["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Components.interfaces.nsIObserverService);
|
|
|
|
|
2014-02-19 03:58:03 +04:00
|
|
|
// We need to update the crash events directory when the profile changes.
|
|
|
|
if (runningInParent &&
|
|
|
|
"@mozilla.org/toolkit/crash-reporter;1" in Components.classes) {
|
|
|
|
let crashReporter =
|
|
|
|
Components.classes["@mozilla.org/toolkit/crash-reporter;1"]
|
|
|
|
.getService(Components.interfaces.nsICrashReporter);
|
|
|
|
crashReporter.UpdateCrashEventsDir();
|
|
|
|
}
|
|
|
|
|
2012-12-12 03:12:59 +04:00
|
|
|
if (!_profileInitialized) {
|
|
|
|
obsSvc.notifyObservers(null, "profile-do-change", "xpcshell-do-get-profile");
|
|
|
|
_profileInitialized = true;
|
2015-04-21 17:30:36 +03:00
|
|
|
if (notifyProfileAfterChange) {
|
|
|
|
obsSvc.notifyObservers(null, "profile-after-change", "xpcshell-do-get-profile");
|
|
|
|
}
|
2012-12-12 03:12:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The methods of 'provider' will retain this scope so null out everything
|
2012-03-02 21:36:53 +04:00
|
|
|
// to avoid spurious leak reports.
|
|
|
|
env = null;
|
|
|
|
profd = null;
|
|
|
|
dirSvc = null;
|
|
|
|
provider = null;
|
2012-12-12 03:12:59 +04:00
|
|
|
obsSvc = null;
|
2009-05-14 15:37:40 +04:00
|
|
|
return file.clone();
|
|
|
|
}
|
2009-10-17 11:05:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function loads head.js (this file) in the child process, so that all
|
|
|
|
* functions defined in this file (do_throw, etc) are available to subsequent
|
|
|
|
* sendCommand calls. It also sets various constants used by these functions.
|
|
|
|
*
|
|
|
|
* (Note that you may use sendCommand without calling this function first; you
|
|
|
|
* simply won't have any of the functions in this file available.)
|
|
|
|
*/
|
|
|
|
function do_load_child_test_harness()
|
|
|
|
{
|
|
|
|
// Make sure this isn't called from child process
|
2012-12-08 02:12:02 +04:00
|
|
|
if (!runningInParent) {
|
2009-10-17 11:05:27 +04:00
|
|
|
do_throw("run_test_in_child cannot be called from child!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow to be called multiple times, but only run once
|
|
|
|
if (typeof do_load_child_test_harness.alreadyRun != "undefined")
|
|
|
|
return;
|
|
|
|
do_load_child_test_harness.alreadyRun = 1;
|
|
|
|
|
2009-11-12 10:01:04 +03:00
|
|
|
_XPCSHELL_PROCESS = "parent";
|
2012-05-10 21:10:14 +04:00
|
|
|
|
|
|
|
let command =
|
2013-04-15 04:49:40 +04:00
|
|
|
"const _HEAD_JS_PATH=" + uneval(_HEAD_JS_PATH) + "; "
|
|
|
|
+ "const _HEAD_FILES=" + uneval(_HEAD_FILES) + "; "
|
2015-08-20 23:06:00 +03:00
|
|
|
+ "const _MOZINFO_JS_PATH=" + uneval(_MOZINFO_JS_PATH) + "; "
|
2013-04-15 04:49:40 +04:00
|
|
|
+ "const _TAIL_FILES=" + uneval(_TAIL_FILES) + "; "
|
2014-11-05 04:02:13 +03:00
|
|
|
+ "const _TEST_NAME=" + uneval(_TEST_NAME) + "; "
|
2014-11-29 02:40:58 +03:00
|
|
|
// We'll need more magic to get the debugger working in the child
|
|
|
|
+ "const _JSDEBUGGER_PORT=0; "
|
2012-05-10 21:10:14 +04:00
|
|
|
+ "const _XPCSHELL_PROCESS='child';";
|
|
|
|
|
2016-06-08 16:41:04 +03:00
|
|
|
if (typeof _JSCOV_DIR === 'string') {
|
|
|
|
command += " const _JSCOV_DIR=" + uneval(_JSCOV_DIR) + ";";
|
|
|
|
}
|
|
|
|
|
2015-10-07 00:00:29 +03:00
|
|
|
if (_TESTING_MODULES_DIR) {
|
2013-04-15 04:49:40 +04:00
|
|
|
command += " const _TESTING_MODULES_DIR=" + uneval(_TESTING_MODULES_DIR) + ";";
|
2012-05-10 21:10:14 +04:00
|
|
|
}
|
|
|
|
|
2013-04-15 04:49:40 +04:00
|
|
|
command += " load(_HEAD_JS_PATH);";
|
2012-05-10 21:10:14 +04:00
|
|
|
sendCommand(command);
|
2009-10-17 11:05:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs an entire xpcshell unit test in a child process (rather than in chrome,
|
|
|
|
* which is the default).
|
|
|
|
*
|
2015-06-03 05:41:00 +03:00
|
|
|
* This function returns immediately, before the test has completed.
|
2009-10-17 11:05:27 +04:00
|
|
|
*
|
|
|
|
* @param testFile
|
|
|
|
* The name of the script to run. Path format same as load().
|
|
|
|
* @param optionalCallback.
|
|
|
|
* Optional function to be called (in parent) when test on child is
|
|
|
|
* complete. If provided, the function must call do_test_finished();
|
2015-06-03 05:41:00 +03:00
|
|
|
* @return Promise Resolved when the test in the child is complete.
|
2009-10-17 11:05:27 +04:00
|
|
|
*/
|
2015-06-03 05:41:00 +03:00
|
|
|
function run_test_in_child(testFile, optionalCallback)
|
2009-10-17 11:05:27 +04:00
|
|
|
{
|
2015-06-03 05:41:00 +03:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
var callback = () => {
|
|
|
|
resolve();
|
|
|
|
if (typeof optionalCallback == 'undefined') {
|
|
|
|
do_test_finished();
|
|
|
|
} else {
|
|
|
|
optionalCallback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
do_load_child_test_harness();
|
|
|
|
|
|
|
|
var testPath = do_get_file(testFile).path.replace(/\\/g, "/");
|
|
|
|
do_test_pending("run in child");
|
|
|
|
sendCommand("_testLogger.info('CHILD-TEST-STARTED'); "
|
|
|
|
+ "const _TEST_FILE=['" + testPath + "']; "
|
|
|
|
+ "_execute_test(); "
|
|
|
|
+ "_testLogger.info('CHILD-TEST-COMPLETED');",
|
|
|
|
callback);
|
|
|
|
});
|
2009-10-17 11:05:27 +04:00
|
|
|
}
|
|
|
|
|
2013-11-02 17:37:46 +04:00
|
|
|
/**
|
|
|
|
* Execute a given function as soon as a particular cross-process message is received.
|
|
|
|
* Must be paired with do_send_remote_message or equivalent ProcessMessageManager calls.
|
2015-06-03 05:41:00 +03:00
|
|
|
*
|
|
|
|
* @param optionalCallback
|
|
|
|
* Optional callback that is invoked when the message is received. If provided,
|
|
|
|
* the function must call do_test_finished().
|
|
|
|
* @return Promise Promise that is resolved when the message is received.
|
2013-11-02 17:37:46 +04:00
|
|
|
*/
|
2015-06-03 05:41:00 +03:00
|
|
|
function do_await_remote_message(name, optionalCallback)
|
2013-11-02 17:37:46 +04:00
|
|
|
{
|
2015-06-03 05:41:00 +03:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
var listener = {
|
|
|
|
receiveMessage: function(message) {
|
|
|
|
if (message.name == name) {
|
|
|
|
mm.removeMessageListener(name, listener);
|
|
|
|
resolve();
|
|
|
|
if (optionalCallback) {
|
|
|
|
optionalCallback();
|
|
|
|
} else {
|
|
|
|
do_test_finished();
|
|
|
|
}
|
|
|
|
}
|
2013-11-02 17:37:46 +04:00
|
|
|
}
|
2015-06-03 05:41:00 +03:00
|
|
|
};
|
2013-11-02 17:37:46 +04:00
|
|
|
|
2015-06-03 05:41:00 +03:00
|
|
|
var mm;
|
|
|
|
if (runningInParent) {
|
|
|
|
mm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIMessageBroadcaster);
|
|
|
|
} else {
|
|
|
|
mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
|
|
|
|
}
|
|
|
|
do_test_pending();
|
|
|
|
mm.addMessageListener(name, listener);
|
|
|
|
});
|
2013-11-02 17:37:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously send a message to all remote processes. Pairs with do_await_remote_message
|
|
|
|
* or equivalent ProcessMessageManager listeners.
|
|
|
|
*/
|
|
|
|
function do_send_remote_message(name) {
|
|
|
|
var mm;
|
|
|
|
var sender;
|
|
|
|
if (runningInParent) {
|
|
|
|
mm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIMessageBroadcaster);
|
|
|
|
sender = 'broadcastAsyncMessage';
|
|
|
|
} else {
|
|
|
|
mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
|
|
|
|
sender = 'sendAsyncMessage';
|
|
|
|
}
|
|
|
|
mm[sender](name);
|
|
|
|
}
|
2011-04-19 00:31:20 +04:00
|
|
|
|
2016-01-10 18:40:12 +03:00
|
|
|
/**
|
|
|
|
* Helper function to add the _only property to add_task/add_test function when
|
|
|
|
* running it as add_task.only(...).
|
|
|
|
*
|
|
|
|
* @param addFunc
|
|
|
|
* The parent function to call, e.g. add_task or add_test.
|
|
|
|
* @param funcOrProperties
|
|
|
|
* A function to be run or an object represents test properties.
|
|
|
|
* @param func
|
|
|
|
* A function to be run only if the funcOrProperies is not a function.
|
|
|
|
*/
|
|
|
|
function _add_only(addFunc, funcOrProperties, func) {
|
|
|
|
_gTestHasOnly = true;
|
|
|
|
if (typeof funcOrProperties == "function") {
|
|
|
|
func = funcOrProperties;
|
|
|
|
funcOrProperties = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof funcOrProperties == "object") {
|
|
|
|
funcOrProperties._only = true;
|
|
|
|
}
|
|
|
|
return addFunc(funcOrProperties, func);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to skip the test using e.g. add_task.skip(...)
|
|
|
|
*
|
|
|
|
* @param addFunc
|
|
|
|
* The parent function to call, e.g. add_task or add_test.
|
|
|
|
* @param funcOrProperties
|
|
|
|
* A function to be run or an object represents test properties.
|
|
|
|
* @param func
|
|
|
|
* A function to be run only if the funcOrProperies is not a function.
|
|
|
|
*/
|
|
|
|
function _add_skip(addFunc, funcOrProperties, func) {
|
|
|
|
if (typeof funcOrProperties == "function") {
|
|
|
|
func = funcOrProperties;
|
|
|
|
funcOrProperties = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof funcOrProperties == "object") {
|
|
|
|
funcOrProperties.skip_if = () => true;
|
|
|
|
}
|
|
|
|
return addFunc(funcOrProperties, func);
|
|
|
|
}
|
|
|
|
|
2011-04-19 00:31:20 +04:00
|
|
|
/**
|
|
|
|
* Add a test function to the list of tests that are to be run asynchronously.
|
|
|
|
*
|
2015-04-27 21:39:00 +03:00
|
|
|
* @param funcOrProperties
|
|
|
|
* A function to be run or an object represents test properties.
|
|
|
|
* Supported properties:
|
|
|
|
* skip_if : An arrow function which has an expression to be
|
|
|
|
* evaluated whether the test is skipped or not.
|
|
|
|
* @param func
|
|
|
|
* A function to be run only if the funcOrProperies is not a function.
|
|
|
|
*
|
2011-04-19 00:31:20 +04:00
|
|
|
* Each test function must call run_next_test() when it's done. Test files
|
|
|
|
* should call run_next_test() in their run_test function to execute all
|
|
|
|
* async tests.
|
|
|
|
*
|
|
|
|
* @return the test function that was passed in.
|
|
|
|
*/
|
2015-09-15 21:19:45 +03:00
|
|
|
var _gTests = [];
|
2015-04-27 21:39:00 +03:00
|
|
|
function add_test(funcOrProperties, func) {
|
|
|
|
if (typeof funcOrProperties == "function") {
|
|
|
|
_gTests.push([{ _isTask: false }, funcOrProperties]);
|
|
|
|
} else if (typeof funcOrProperties == "object") {
|
|
|
|
funcOrProperties._isTask = false;
|
|
|
|
_gTests.push([funcOrProperties, func]);
|
|
|
|
} else {
|
|
|
|
do_throw("add_test() should take a function or an object and a function");
|
|
|
|
}
|
2011-04-19 00:31:20 +04:00
|
|
|
return func;
|
|
|
|
}
|
2016-01-10 18:40:12 +03:00
|
|
|
add_test.only = _add_only.bind(undefined, add_test);
|
|
|
|
add_test.skip = _add_skip.bind(undefined, add_test);
|
2011-04-19 00:31:20 +04:00
|
|
|
|
2012-12-11 22:53:43 +04:00
|
|
|
/**
|
|
|
|
* Add a test function which is a Task function.
|
|
|
|
*
|
2015-04-27 21:39:00 +03:00
|
|
|
* @param funcOrProperties
|
|
|
|
* A generator function to be run or an object represents test
|
|
|
|
* properties.
|
|
|
|
* Supported properties:
|
|
|
|
* skip_if : An arrow function which has an expression to be
|
|
|
|
* evaluated whether the test is skipped or not.
|
|
|
|
* @param func
|
|
|
|
* A generator function to be run only if the funcOrProperies is not a
|
|
|
|
* function.
|
|
|
|
*
|
2012-12-11 22:53:43 +04:00
|
|
|
* Task functions are functions fed into Task.jsm's Task.spawn(). They are
|
|
|
|
* generators that emit promises.
|
|
|
|
*
|
|
|
|
* If an exception is thrown, a do_check_* comparison fails, or if a rejected
|
|
|
|
* promise is yielded, the test function aborts immediately and the test is
|
|
|
|
* reported as a failure.
|
|
|
|
*
|
|
|
|
* Unlike add_test(), there is no need to call run_next_test(). The next test
|
|
|
|
* will run automatically as soon the task function is exhausted. To trigger
|
|
|
|
* premature (but successful) termination of the function, simply return or
|
|
|
|
* throw a Task.Result instance.
|
|
|
|
*
|
|
|
|
* Example usage:
|
|
|
|
*
|
2015-04-27 21:39:00 +03:00
|
|
|
* add_task(function* test() {
|
2012-12-11 22:53:43 +04:00
|
|
|
* let result = yield Promise.resolve(true);
|
|
|
|
*
|
|
|
|
* do_check_true(result);
|
|
|
|
*
|
|
|
|
* let secondary = yield someFunctionThatReturnsAPromise(result);
|
|
|
|
* do_check_eq(secondary, "expected value");
|
|
|
|
* });
|
|
|
|
*
|
2015-04-27 21:39:00 +03:00
|
|
|
* add_task(function* test_early_return() {
|
2012-12-11 22:53:43 +04:00
|
|
|
* let result = yield somethingThatReturnsAPromise();
|
|
|
|
*
|
|
|
|
* if (!result) {
|
|
|
|
* // Test is ended immediately, with success.
|
|
|
|
* return;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* do_check_eq(result, "foo");
|
|
|
|
* });
|
2015-04-27 21:39:00 +03:00
|
|
|
*
|
|
|
|
* add_task({
|
|
|
|
* skip_if: () => !("@mozilla.org/telephony/volume-service;1" in Components.classes),
|
|
|
|
* }, function* test_volume_service() {
|
|
|
|
* let volumeService = Cc["@mozilla.org/telephony/volume-service;1"]
|
|
|
|
* .getService(Ci.nsIVolumeService);
|
|
|
|
* ...
|
|
|
|
* });
|
2012-12-11 22:53:43 +04:00
|
|
|
*/
|
2015-04-27 21:39:00 +03:00
|
|
|
function add_task(funcOrProperties, func) {
|
|
|
|
if (typeof funcOrProperties == "function") {
|
|
|
|
_gTests.push([{ _isTask: true }, funcOrProperties]);
|
|
|
|
} else if (typeof funcOrProperties == "object") {
|
|
|
|
funcOrProperties._isTask = true;
|
|
|
|
_gTests.push([funcOrProperties, func]);
|
|
|
|
} else {
|
|
|
|
do_throw("add_task() should take a function or an object and a function");
|
|
|
|
}
|
2012-12-11 22:53:43 +04:00
|
|
|
}
|
2016-01-10 18:40:12 +03:00
|
|
|
add_task.only = _add_only.bind(undefined, add_task);
|
|
|
|
add_task.skip = _add_skip.bind(undefined, add_task);
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var _Task = Components.utils.import("resource://gre/modules/Task.jsm", {}).Task;
|
2014-06-09 16:43:00 +04:00
|
|
|
_Task.Debugging.maintainStack = true;
|
|
|
|
|
2012-12-11 22:53:43 +04:00
|
|
|
|
2011-04-19 00:31:20 +04:00
|
|
|
/**
|
|
|
|
* Runs the next test function from the list of async tests.
|
|
|
|
*/
|
2015-09-15 21:19:45 +03:00
|
|
|
var _gRunningTest = null;
|
|
|
|
var _gTestIndex = 0; // The index of the currently running test.
|
|
|
|
var _gTaskRunning = false;
|
2016-01-10 18:40:12 +03:00
|
|
|
var _gTestHasOnly = false;
|
2011-04-19 00:31:20 +04:00
|
|
|
function run_next_test()
|
|
|
|
{
|
2014-02-13 04:47:29 +04:00
|
|
|
if (_gTaskRunning) {
|
|
|
|
throw new Error("run_next_test() called from an add_task() test function. " +
|
|
|
|
"run_next_test() should not be called from inside add_task() " +
|
|
|
|
"under any circumstances!");
|
|
|
|
}
|
2015-09-05 04:36:52 +03:00
|
|
|
|
2011-04-19 00:31:20 +04:00
|
|
|
function _run_next_test()
|
|
|
|
{
|
2012-12-11 22:53:43 +04:00
|
|
|
if (_gTestIndex < _gTests.length) {
|
2016-02-03 15:58:03 +03:00
|
|
|
// Check for uncaught rejections as early and often as possible.
|
|
|
|
_PromiseTestUtils.assertNoUncaughtRejections();
|
2015-04-27 21:39:00 +03:00
|
|
|
let _properties;
|
|
|
|
[_properties, _gRunningTest,] = _gTests[_gTestIndex++];
|
|
|
|
if (typeof(_properties.skip_if) == "function" && _properties.skip_if()) {
|
|
|
|
let _condition = _properties.skip_if.toSource().replace(/\(\)\s*=>\s*/, "");
|
|
|
|
let _message = _gRunningTest.name
|
|
|
|
+ " skipped because the following conditions were"
|
|
|
|
+ " met: (" + _condition + ")";
|
|
|
|
_testLogger.testStatus(_TEST_NAME,
|
|
|
|
_gRunningTest.name,
|
|
|
|
"SKIP",
|
|
|
|
"SKIP",
|
|
|
|
_message);
|
|
|
|
do_execute_soon(run_next_test);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-22 23:53:42 +04:00
|
|
|
_testLogger.info(_TEST_NAME + " | Starting " + _gRunningTest.name);
|
2013-05-03 20:08:30 +04:00
|
|
|
do_test_pending(_gRunningTest.name);
|
2012-12-11 22:53:43 +04:00
|
|
|
|
2015-04-27 21:39:00 +03:00
|
|
|
if (_properties._isTask) {
|
2014-02-13 04:47:29 +04:00
|
|
|
_gTaskRunning = true;
|
2016-02-03 15:58:03 +03:00
|
|
|
_Task.spawn(_gRunningTest).then(() => {
|
|
|
|
_gTaskRunning = false;
|
|
|
|
run_next_test();
|
|
|
|
}, ex => {
|
|
|
|
_gTaskRunning = false;
|
|
|
|
try {
|
|
|
|
do_report_unexpected_exception(ex);
|
|
|
|
} catch (ex) {
|
|
|
|
// The above throws NS_ERROR_ABORT and we don't want this to show up
|
|
|
|
// as an unhandled rejection later.
|
|
|
|
}
|
|
|
|
});
|
2012-12-11 22:53:43 +04:00
|
|
|
} else {
|
|
|
|
// Exceptions do not kill asynchronous tests, so they'll time out.
|
|
|
|
try {
|
|
|
|
_gRunningTest();
|
|
|
|
} catch (e) {
|
|
|
|
do_throw(e);
|
|
|
|
}
|
2011-04-19 00:31:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For sane stacks during failures, we execute this code soon, but not now.
|
|
|
|
// We do this now, before we call do_test_finished(), to ensure the pending
|
|
|
|
// counter (_tests_pending) never reaches 0 while we still have tests to run
|
|
|
|
// (do_execute_soon bumps that counter).
|
2013-05-03 20:08:30 +04:00
|
|
|
do_execute_soon(_run_next_test, "run_next_test " + _gTestIndex);
|
2011-04-19 00:31:20 +04:00
|
|
|
|
2012-12-11 22:53:43 +04:00
|
|
|
if (_gRunningTest !== null) {
|
2011-04-19 00:31:20 +04:00
|
|
|
// Close the previous test do_test_pending call.
|
2013-05-03 20:08:30 +04:00
|
|
|
do_test_finished(_gRunningTest.name);
|
2011-04-19 00:31:20 +04:00
|
|
|
}
|
|
|
|
}
|
2013-07-01 17:43:17 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
} catch (e) { }
|
2014-08-08 19:46:25 +04:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2014-08-26 00:23:47 +04:00
|
|
|
prefs.setCharPref("media.gmp-manager.url.override", "http://%(server)s/dummy-gmp-manager.xml");
|
2015-09-10 20:57:39 +03:00
|
|
|
prefs.setCharPref("extensions.systemAddon.update.url", "http://%(server)s/dummy-system-addons.xml");
|
2015-01-09 13:18:00 +03:00
|
|
|
prefs.setCharPref("browser.selfsupport.url", "https://%(server)s/selfsupport-dummy/");
|
2015-04-14 17:49:57 +03:00
|
|
|
prefs.setCharPref("toolkit.telemetry.server", "https://%(server)s/telemetry-dummy");
|
2015-07-20 09:46:00 +03:00
|
|
|
prefs.setCharPref("browser.search.geoip.url", "https://%(server)s/geoip-dummy");
|
2014-08-08 19:46:25 +04:00
|
|
|
}
|
|
|
|
} catch (e) { }
|
2015-04-01 06:01:04 +03:00
|
|
|
|
|
|
|
// Make tests run consistently on DevEdition (which has a lightweight theme
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
} catch (e) { }
|
2015-08-20 23:06:00 +03:00
|
|
|
|
|
|
|
function _load_mozinfo() {
|
|
|
|
let mozinfoFile = Components.classes["@mozilla.org/file/local;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIFile);
|
|
|
|
mozinfoFile.initWithPath(_MOZINFO_JS_PATH);
|
|
|
|
let stream = Components.classes["@mozilla.org/network/file-input-stream;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIFileInputStream);
|
|
|
|
stream.init(mozinfoFile, -1, 0, 0);
|
|
|
|
let json = Components.classes["@mozilla.org/dom/json;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIJSON);
|
|
|
|
let mozinfo = json.decodeFromStream(stream, stream.available());
|
|
|
|
stream.close();
|
|
|
|
return mozinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.defineProperty(this, "mozinfo", {
|
|
|
|
configurable: true,
|
|
|
|
get() {
|
|
|
|
let _mozinfo = _load_mozinfo();
|
|
|
|
Object.defineProperty(this, "mozinfo", {
|
|
|
|
configurable: false,
|
|
|
|
value: _mozinfo
|
|
|
|
});
|
|
|
|
return _mozinfo;
|
|
|
|
}
|
|
|
|
});
|