Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1803 from erikvold/1112466
Browse files Browse the repository at this point in the history
Bug 1112466 - Enable the cuddlefish tests in the travis test suite r=@jsantell
  • Loading branch information
erikvold committed Jan 5, 2015
2 parents fd369da + 30962cd commit da46381
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
8 changes: 5 additions & 3 deletions lib/toolkit/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
;(function(factory) { // Module boilerplate :(
if (typeof(require) === 'function') { // CommonJS
require("chrome").Cu.import(module.uri, exports);
} else if (~String(this).indexOf('BackstagePass')) { // JSM
}
else if (~String(this).indexOf('BackstagePass')) { // JSM
let module = { uri: __URI__, id: "toolkit/loader", exports: Object.create(null) }
factory(module);
Object.assign(this, module.exports);
this.EXPORTED_SYMBOLS = Object.getOwnPropertyNames(module.exports);
} else {
}
else {
throw Error("Loading environment is not supported");
}
})(function(module) {
})(module => {

'use strict';

Expand Down
42 changes: 33 additions & 9 deletions test/test-cuddlefish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,42 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';

const packaging = require('@loader/options');
const { Cc, Ci, Cu, CC, Cr, Cm, ChromeWorker, components } = require("chrome");

const packaging = require("@loader/options");
const app = require('sdk/system/xul-app');
const get = require;
const { resolve } = require;

const scriptLoader = Cc['@mozilla.org/moz/jssubscript-loader;1'].
getService(Ci.mozIJSSubScriptLoader);
const systemPrincipal = CC('@mozilla.org/systemprincipal;1', 'nsIPrincipal')();

function loadSandbox(uri) {
let proto = {
sandboxPrototype: {
loadSandbox: loadSandbox,
ChromeWorker: ChromeWorker
}
};
let sandbox = Cu.Sandbox(systemPrincipal, proto);
// Create a fake commonjs environnement just to enable loading loader.js
// correctly
sandbox.exports = {};
sandbox.module = { uri: uri, exports: sandbox.exports };
sandbox.require = function (id) {
if (id !== "chrome")
throw new Error("Bootstrap sandbox `require` method isn't implemented.");

return Object.freeze({ Cc: Cc, Ci: Ci, Cu: Cu, Cr: Cr, Cm: Cm,
CC: CC, components: components,
ChromeWorker: ChromeWorker });
};
scriptLoader.loadSubScript(uri, sandbox, 'UTF-8');
return sandbox;
}

exports['test loader'] = function(assert) {
let { Loader, Require, unload, override } = get('sdk/loader/cuddlefish');
let { Loader, Require, unload, override } = loadSandbox(resolve('sdk/loader/cuddlefish.js')).exports;
var prints = [];
function print(message) {
prints.push(message);
Expand Down Expand Up @@ -45,10 +75,4 @@ exports['test loader'] = function(assert) {
'loader.unload() must call listeners in LIFO order.');
};

if (packaging.isNative) {
module.exports = {
"test skip on jpm": (assert) => assert.pass("skipping this file with jpm")
};
}

require('sdk/test').run(exports);

0 comments on commit da46381

Please sign in to comment.