addon-sdk/test/head.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 const { utils: Cu } = Components;
     6 const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
     7 const LoaderModule = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {}).Loader;
     8 const { console } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
     9 let {
    10   Loader, main, Module, Require, unload
    11 } = LoaderModule;
    13 let CURRENT_DIR = gTestPath.replace(/\/[^\/]*\.js$/,'/');
    14 let loaders = [];
    16 // All tests are asynchronous.
    17 waitForExplicitFinish();
    19 let gEnableLogging = Services.prefs.getBoolPref("devtools.debugger.log");
    20 Services.prefs.setBoolPref("devtools.debugger.log", true);
    22 registerCleanupFunction(() => {
    23   info("finish() was called, cleaning up...");
    24   loaders.forEach(unload);
    25   Services.prefs.setBoolPref("devtools.debugger.log", gEnableLogging);
    26 });
    28 function makePaths (root) {
    29   return {
    30     './': CURRENT_DIR,
    31     '': 'resource://gre/modules/commonjs/'
    32   };
    33 }
    35 function makeLoader (options) {
    36   let { paths, globals } = options || {};
    38   // We have to have `console` as a global, otherwise
    39   // many SDK modules will fail
    40   // bug 961252
    41   let globalDefaults = {
    42     console: console
    43   };
    45   let loader = Loader({
    46     paths: paths || makePaths(),
    47     globals: extend({}, globalDefaults, globals) || null,
    48     modules: {
    49       // Needed because sdk/ modules reference utilities in
    50       // `toolkit/loader`, until Bug 961194 is completed
    51       'toolkit/loader': LoaderModule
    52     },
    53     // We need rootURI due to `sdk/self` (or are using native loader)
    54     // which overloads with pseudo modules
    55     // bug 961245
    56     rootURI: CURRENT_DIR,
    57     // We also need metadata dummy object
    58     // bug 961245
    59     metadata: {}
    60   });
    62   loaders.push(loader);
    63   return loader;
    64 }
    66 function isUUID (string) {
    67   return /^\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}$/.test(string);
    68 }
    70 function extend (...objs) {
    71   if (objs.length === 0 || objs.length === 1)
    72     return objs[0] || {};
    74   for (let i = objs.length; i > 1; i--) {
    75     for (var prop in objs[i - 1])
    76       objs[0][prop] = objs[i - 1][prop];
    77   }
    78   return objs[0];
    79 }

mercurial