Skip to content

Commit

Permalink
Bug 1179013: Uplift Add-on SDK. a=me
Browse files Browse the repository at this point in the history
mozilla/addon-sdk@d8ba328...96ae8d9

--HG--
extra : commitid : a69qoBWTUP
extra : rebase_source : 7d0464d7fa1af660b5971bda97786112b0c76053
  • Loading branch information
Mossop committed Jun 30, 2015
1 parent 033be4e commit a184de4
Show file tree
Hide file tree
Showing 77 changed files with 1,593 additions and 1,752 deletions.
7 changes: 4 additions & 3 deletions addon-sdk/moz.build
Expand Up @@ -29,7 +29,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != "gonk":

EXTRA_JS_MODULES.commonjs.sdk.deprecated += [
'source/lib/sdk/deprecated/api-utils.js',
'source/lib/sdk/deprecated/memory.js',
'source/lib/sdk/deprecated/sync-worker.js',
'source/lib/sdk/deprecated/unit-test-finder.js',
'source/lib/sdk/deprecated/unit-test.js',
Expand Down Expand Up @@ -258,6 +257,10 @@ EXTRA_JS_MODULES.commonjs.sdk.content += [
'source/lib/sdk/content/worker.js',
]

EXTRA_JS_MODULES.commonjs.sdk.content.sandbox += [
'source/lib/sdk/content/sandbox/events.js',
]

EXTRA_JS_MODULES.commonjs.sdk['context-menu'] += [
'source/lib/sdk/context-menu/context.js',
'source/lib/sdk/context-menu/core.js',
Expand Down Expand Up @@ -307,7 +310,6 @@ EXTRA_JS_MODULES.commonjs.sdk.input += [
EXTRA_JS_MODULES.commonjs.sdk.io += [
'source/lib/sdk/io/buffer.js',
'source/lib/sdk/io/byte-streams.js',
'source/lib/sdk/io/data.js',
'source/lib/sdk/io/file.js',
'source/lib/sdk/io/fs.js',
'source/lib/sdk/io/stream.js',
Expand Down Expand Up @@ -453,7 +455,6 @@ EXTRA_JS_MODULES.commonjs.sdk.url += [

EXTRA_JS_MODULES.commonjs.sdk.util += [
'source/lib/sdk/util/array.js',
'source/lib/sdk/util/bond.js',
'source/lib/sdk/util/collection.js',
'source/lib/sdk/util/contract.js',
'source/lib/sdk/util/deprecate.js',
Expand Down
2 changes: 1 addition & 1 deletion addon-sdk/source/.travis.yml
@@ -1,7 +1,7 @@
sudo: false
language: node_js
node_js:
- "0.10"
- "0.12"

env:
- JPM_FX_DEBUG=0
Expand Down
9 changes: 5 additions & 4 deletions addon-sdk/source/bin/jpm-test.js
Expand Up @@ -17,12 +17,13 @@ exports.run = function(type) {
return new Promise(function(resolve) {
type = type || "";
[
(!isDebug && /^(modules)?$/.test(type)) && require.resolve("../bin/node-scripts/test.modules"),
(!isDebug && /^(addons)?$/.test(type)) && require.resolve("../bin/node-scripts/test.addons"),
(/^(examples)?$/.test(type)) && require.resolve("../bin/node-scripts/test.examples"),
(!isDebug && /^(firefox-bin)?$/.test(type)) && require.resolve("../bin/node-scripts/test.firefox-bin"),
(!isDebug && /^(docs)?$/.test(type)) && require.resolve("../bin/node-scripts/test.docs"),
(!isDebug && /^(ini)?$/.test(type)) && require.resolve("../bin/node-scripts/test.ini"),
].sort().forEach(function(filepath) {
(/^(examples)?$/.test(type)) && require.resolve("../bin/node-scripts/test.examples"),
(!isDebug && /^(addons)?$/.test(type)) && require.resolve("../bin/node-scripts/test.addons"),
(!isDebug && /^(modules)?$/.test(type)) && require.resolve("../bin/node-scripts/test.modules"),
].forEach(function(filepath) {
filepath && mocha.addFile(filepath);
})

Expand Down
37 changes: 37 additions & 0 deletions addon-sdk/source/bin/node-scripts/test.firefox-bin.js
@@ -0,0 +1,37 @@
/* 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/. */
"use strict";

var fs = require("fs");
var Promise = require("promise");
var chai = require("chai");
var expect = chai.expect;
var normalizeBinary = require("fx-runner/lib/utils").normalizeBinary;

//var firefox_binary = process.env["JPM_FIREFOX_BINARY"] || normalizeBinary("nightly");

describe("Checking Firefox binary", function () {

it("using matching fx-runner version with jpm", function () {
var sdkPackageJSON = require("../../package.json");
var jpmPackageINI = require("jpm/package.json");
expect(sdkPackageJSON.devDependencies["fx-runner"]).to.be.equal(jpmPackageINI.dependencies["fx-runner"]);
});

it("exists", function (done) {
var useEnvVar = new Promise(function(resolve) {
resolve(process.env["JPM_FIREFOX_BINARY"]);
});

var firefox_binary = process.env["JPM_FIREFOX_BINARY"] ? useEnvVar : normalizeBinary("nightly");
firefox_binary.then(function(path) {
expect(path).to.be.ok;
fs.exists(path, function (exists) {
expect(exists).to.be.ok;
done();
});
})
});

});
33 changes: 31 additions & 2 deletions addon-sdk/source/bin/node-scripts/test.ini.js
Expand Up @@ -11,6 +11,7 @@ var expect = chai.expect;
var ini = require("./update-ini");

var addonINI = path.resolve("./test/addons/jetpack-addon.ini");
var packageINI = path.resolve("./test/jetpack-package.ini");

describe("Checking ini files", function () {

Expand All @@ -20,15 +21,43 @@ describe("Checking ini files", function () {
if (err) {
throw err;
}
var text = data.toString();
// filter comments
var text = data.toString().split("\n").filter(function(line) {
return !/^\s*#/.test(line);
}).join("\n");
var expected = "";

ini.makeAddonIniContent()
.then(function(contents) {
expected = contents;

setTimeout(function end() {
expect(expected.trim()).to.be.equal(text.trim());
expect(text.trim()).to.be.equal(expected.trim());
done();
});
});
});

});

it("Check test/jetpack-package.ini", function (done) {

fs.readFile(packageINI, function (err, data) {
if (err) {
throw err;
}
// filter comments
var text = data.toString().split("\n").filter(function(line) {
return !/^\s*#/.test(line);
}).join("\n");
var expected = "";

ini.makePackageIniContent()
.then(function(contents) {
expected = contents;

setTimeout(function end() {
expect(text.trim()).to.be.equal(expected.trim());
done();
});
});
Expand Down
85 changes: 84 additions & 1 deletion addon-sdk/source/bin/node-scripts/update-ini.js
Expand Up @@ -11,6 +11,14 @@ var parser = require("ini-parser");

var addonINI = path.resolve("./test/addons/jetpack-addon.ini");
var addonsDir = path.resolve("./test/addons/");
var packageINI = path.resolve("./test/jetpack-package.ini");
var packageDir = path.resolve("./test/");
var packageIgnorables = [ "addons", "preferences" ];
var packageSupportFiles = [
"fixtures.js",
"test-context-menu.html",
"util.js"
]

function updateAddonINI() {
return new Promise(function(resolve) {
Expand All @@ -32,16 +40,18 @@ function makeAddonIniContent() {
var result = {};

fs.readdir(addonsDir, function(err, files) {
// get a list of folders
var folders = files.filter(function(file) {
return fs.statSync(path.resolve(addonsDir, file)).isDirectory();
}).sort();

// copy any related data from the existing ini
folders.forEach(function(folder) {
var oldData = data[folder + ".xpi"];
result[folder] = oldData ? oldData : {};
});

// build ini file
// build a new ini file
var contents = [];
Object.keys(result).sort().forEach(function(key) {
contents.push("[" + key + ".xpi]");
Expand All @@ -56,3 +66,76 @@ function makeAddonIniContent() {
});
}
exports.makeAddonIniContent = makeAddonIniContent;

function makePackageIniContent() {
return new Promise(function(resolve) {
var data = parser.parse(fs.readFileSync(packageINI, { encoding: "utf8" }).toString());
var result = {};

fs.readdir(packageDir, function(err, files) {
// get a list of folders
var folders = files.filter(function(file) {
var ignore = (packageIgnorables.indexOf(file) >= 0);
var isDir = fs.statSync(path.resolve(packageDir, file)).isDirectory();
return (isDir && !ignore);
}).sort();

// get a list of "test-"" files
var files = files.filter(function(file) {
var ignore = !/^test\-.*\.js$/i.test(file);
var isDir = fs.statSync(path.resolve(packageDir, file)).isDirectory();
return (!isDir && !ignore);
}).sort();

// get a list of the support files
var support_files = packageSupportFiles.map(function(file) {
return " " + file;
});
folders.forEach(function(folder) {
support_files.push(" " + folder + "/**");
});
support_files = support_files.sort();

// copy any related data from the existing ini
files.forEach(function(file) {
var oldData = data[file];
result[file] = oldData ? oldData : {};
});

// build a new ini file
var contents = [
"[DEFAULT]",
"support-files ="
];
support_files.forEach(function(support_file) {
contents.push(support_file);
});
contents.push("");

Object.keys(result).sort().forEach(function(key) {
contents.push("[" + key + "]");
Object.keys(result[key]).forEach(function(dataKey) {
contents.push(dataKey + " = " + result[key][dataKey]);
});
});
contents = contents.join("\n") + "\n";

return resolve(contents);
});
});
}
exports.makePackageIniContent = makePackageIniContent;

function updatePackageINI() {
return new Promise(function(resolve) {
console.log("Start updating " + packageINI);

makeAddonIniContent().
then(function(contents) {
fs.writeFileSync(packageINI, contents, { encoding: "utf8" });
console.log("Done updating " + packageINI);
resolve();
});
})
}
exports.updatePackageINI = updatePackageINI;
3 changes: 3 additions & 0 deletions addon-sdk/source/bin/node-scripts/utils.js
Expand Up @@ -65,6 +65,9 @@ function run (cmd, options, p) {
if (p) {
proc.stdout.pipe(p.stdout);
}
else if (!isDebug) {
proc.stdout.pipe(DEFAULT_PROCESS.stdout);
}
else {
proc.stdout.on("data", function (data) {
data = (data || "") + "";
Expand Down
10 changes: 5 additions & 5 deletions addon-sdk/source/gulpfile.js
Expand Up @@ -28,7 +28,11 @@ gulp.task('test:modules', function(done) {
});

gulp.task('test:ini', function(done) {
test("ini").catch(console.error).then(done);
require("./bin/jpm-test").run("ini").catch(console.error).then(done);
});

gulp.task('test:firefox-bin', function(done) {
require("./bin/jpm-test").run("firefox-bin").catch(console.error).then(done);
});

gulp.task('patch:clean', function(done) {
Expand All @@ -38,7 +42,3 @@ gulp.task('patch:clean', function(done) {
gulp.task('patch:apply', function(done) {
patch.apply().catch(console.error).then(done);
});

gulp.task('update:ini', function(done) {
ini.updateAddonINI().catch(console.error).then(done);
});
5 changes: 1 addition & 4 deletions addon-sdk/source/lib/sdk/console/traceback.js
@@ -1,19 +1,16 @@
/* 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/. */

"use strict";

module.metadata = {
"stability": "experimental"
};

const { Cc, Ci, components } = require("chrome");
const { Ci, components } = require("chrome");
const { parseStack, sourceURI } = require("toolkit/loader");
const { readURISync } = require("../net/url");

exports.sourceURI = sourceURI

function safeGetFileLine(path, line) {
try {
var scheme = require("../url").URL(path).scheme;
Expand Down
11 changes: 9 additions & 2 deletions addon-sdk/source/lib/sdk/content/sandbox.js
Expand Up @@ -10,6 +10,7 @@ module.metadata = {
const { Class } = require('../core/heritage');
const { EventTarget } = require('../event/target');
const { on, off, emit } = require('../event/core');
const { events } = require('./sandbox/events');
const { requiresAddonGlobal } = require('./utils');
const { delay: async } = require('../lang/functional');
const { Ci, Cu, Cc } = require('chrome');
Expand All @@ -20,8 +21,7 @@ const { merge } = require('../util/object');
const { getTabForContentWindow } = require('../tabs/utils');
const { getInnerId } = require('../window/utils');
const { PlainTextConsole } = require('../console/plain-text');
const { data } = require('../self');
const { isChildLoader } = require('../remote/core');
const { data } = require('../self');const { isChildLoader } = require('../remote/core');
// WeakMap of sandboxes so we can access private values
const sandboxes = new WeakMap();

Expand Down Expand Up @@ -166,6 +166,7 @@ const WorkerSandbox = Class({
get top() top,
get parent() parent
});

// Use the Greasemonkey naming convention to provide access to the
// unwrapped window object so the content script can access document
// JavaScript values.
Expand Down Expand Up @@ -261,6 +262,11 @@ const WorkerSandbox = Class({
win.console = con;
};

emit(events, "content-script-before-inserted", {
window: window,
worker: worker
});

// The order of `contentScriptFile` and `contentScript` evaluation is
// intentional, so programs can load libraries like jQuery from script URLs
// and use them in scripts.
Expand All @@ -273,6 +279,7 @@ const WorkerSandbox = Class({

if (contentScriptFile)
importScripts.apply(null, [this].concat(contentScriptFile));

if (contentScript) {
evaluateIn(
this,
Expand Down
Expand Up @@ -2,6 +2,11 @@
* 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/. */

exports.minimalTest = function(test) {
test.assert(true);
"use strict";

module.metadata = {
"stability": "experimental"
};

const events = {};
exports.events = events;

0 comments on commit a184de4

Please sign in to comment.