summaryrefslogtreecommitdiffstats
path: root/addon-sdk/test/head.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /addon-sdk/test/head.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'addon-sdk/test/head.js')
-rw-r--r--addon-sdk/test/head.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/addon-sdk/test/head.js b/addon-sdk/test/head.js
new file mode 100644
index 000000000..2afb673e7
--- /dev/null
+++ b/addon-sdk/test/head.js
@@ -0,0 +1,79 @@
+/* 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/. */
+
+const { utils: Cu } = Components;
+const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+const LoaderModule = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {}).Loader;
+const { console } = Cu.import("resource://gre/modules/Console.jsm", {});
+var {
+ Loader, main, Module, Require, unload
+} = LoaderModule;
+
+var CURRENT_DIR = gTestPath.replace(/\/[^\/]*\.js$/,'/');
+var loaders = [];
+
+// All tests are asynchronous.
+waitForExplicitFinish();
+
+var gEnableLogging = Services.prefs.getBoolPref("devtools.debugger.log");
+Services.prefs.setBoolPref("devtools.debugger.log", true);
+
+registerCleanupFunction(() => {
+ info("finish() was called, cleaning up...");
+ loaders.forEach(unload);
+ Services.prefs.setBoolPref("devtools.debugger.log", gEnableLogging);
+});
+
+function makePaths (root) {
+ return {
+ './': CURRENT_DIR,
+ '': 'resource://gre/modules/commonjs/'
+ };
+}
+
+function makeLoader (options) {
+ let { paths, globals } = options || {};
+
+ // We have to have `console` as a global, otherwise
+ // many SDK modules will fail
+ // bug 961252
+ let globalDefaults = {
+ console: console
+ };
+
+ let loader = Loader({
+ paths: paths || makePaths(),
+ globals: extend({}, globalDefaults, globals) || null,
+ modules: {
+ // Needed because sdk/ modules reference utilities in
+ // `toolkit/loader`, until Bug 961194 is completed
+ 'toolkit/loader': LoaderModule
+ },
+ // We need rootURI due to `sdk/self` (or are using native loader)
+ // which overloads with pseudo modules
+ // bug 961245
+ rootURI: CURRENT_DIR,
+ // We also need metadata dummy object
+ // bug 961245
+ metadata: {}
+ });
+
+ loaders.push(loader);
+ return loader;
+}
+
+function isUUID (string) {
+ return /^\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}$/.test(string);
+}
+
+function extend (...objs) {
+ if (objs.length === 0 || objs.length === 1)
+ return objs[0] || {};
+
+ for (let i = objs.length; i > 1; i--) {
+ for (var prop in objs[i - 1])
+ objs[0][prop] = objs[i - 1][prop];
+ }
+ return objs[0];
+}