Bug 966416 - Uplift Add-on SDK to Firefox

This commit is contained in:
Erik Vold 2014-02-01 16:05:39 -08:00
Родитель 1bcd3ceed8
Коммит 5daec585b5
10 изменённых файлов: 107 добавлений и 4 удалений

Просмотреть файл

@ -18,7 +18,7 @@
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>21.0</em:minVersion>
<em:maxVersion>25.0a1</em:maxVersion>
<em:maxVersion>29.0a1</em:maxVersion>
</Description>
</em:targetApplication>

Просмотреть файл

@ -266,7 +266,7 @@ exports.Reactor = Reactor;
*/
function stripListeners (object) {
return Object.keys(object).reduce((agg, key) => {
return Object.keys(object || {}).reduce((agg, key) => {
if (!EVENT_TYPE_PATTERN.test(key))
agg[key] = object[key];
return agg;

Просмотреть файл

@ -9,7 +9,7 @@ const { id: jetpackId} = require('../self');
const OPTIONS_DISPLAYED = "addon-options-displayed";
function onOptionsDisplayed({ subjec: document, data: addonId }) {
function onOptionsDisplayed({ subject: document, data: addonId }) {
if (addonId !== jetpackId)
return;
let query = 'setting[data-jetpack-id="' + jetpackId + '"][pref-name], ' +

Просмотреть файл

@ -693,7 +693,9 @@ const Loader = iced(function Loader(options) {
} = override({
paths: {},
modules: {},
globals: {},
globals: {
console: console
},
resolve: options.isNative ?
exports.nodeResolve :
exports.resolve,

Просмотреть файл

@ -0,0 +1,5 @@
# 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/.
somePreference_title=A

Просмотреть файл

@ -0,0 +1,57 @@
/* 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';
const { Cu } = require('chrome');
const sp = require('sdk/simple-prefs');
const app = require('sdk/system/xul-app');
const self = require('sdk/self');
const tabs = require('sdk/tabs');
const { preferencesBranch } = require('sdk/self');
const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {});
exports.testAOMLocalization = function(assert, done) {
tabs.open({
url: 'about:addons',
onReady: function(tab) {
tab.attach({
contentScriptWhen: 'end',
contentScript: 'function onLoad() {\n' +
'unsafeWindow.removeEventListener("load", onLoad, false);\n' +
'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {\n' +
'unsafeWindow.gViewController.viewObjects.detail.node.addEventListener("ViewChanged", function whenViewChanges() {\n' +
'unsafeWindow.gViewController.viewObjects.detail.node.removeEventListener("ViewChanged", whenViewChanges, false);\n' +
'setTimeout(function() {\n' + // TODO: figure out why this is necessary..
'self.postMessage({\n' +
'somePreference: getAttributes(unsafeWindow.document.querySelector("setting[data-jetpack-id=\'' + self.id + '\']"))\n' +
'});\n' +
'}, 250);\n' +
'}, false);\n' +
'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);\n' +
'});\n' +
'function getAttributes(ele) {\n' +
'if (!ele) return {};\n' +
'return {\n' +
'title: ele.getAttribute("title")\n' +
'}\n' +
'}\n' +
'}\n' +
// Wait for the load event ?
'if (document.readyState == "complete") {\n' +
'onLoad()\n' +
'} else {\n' +
'unsafeWindow.addEventListener("load", onLoad, false);\n' +
'}\n',
onMessage: function(msg) {
// test somePreference
assert.equal(msg.somePreference.title, 'A', 'somePreference title is correct');
tab.close(done);
}
});
}
});
}
require('sdk/test/runner').runTestsFromModule(module);

Просмотреть файл

@ -0,0 +1,10 @@
{
"id": "test-simple-prefs-l10n",
"preferences": [{
"name": "somePreference",
"title": "some-title",
"description": "Some short description for the preference",
"type": "string",
"value": "TEST"
}]
}

6
addon-sdk/source/test/fixtures/loader/globals/main.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
/* 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';
exports.console = console;

Просмотреть файл

@ -327,4 +327,20 @@ exports['test invisibleToDebugger: true'] = function (assert) {
}
};
exports['test console global by default'] = function (assert) {
let uri = root + '/fixtures/loader/globals/';
let loader = Loader({ paths: { '': uri }});
let program = main(loader, 'main');
assert.ok(typeof program.console === 'object', 'global `console` exists');
assert.ok(typeof program.console.log === 'function', 'global `console.log` exists');
let loader2 = Loader({ paths: { '': uri }, globals: { console: fakeConsole }});
let program2 = main(loader2, 'main');
assert.equal(program2.console, fakeConsole,
'global console can be overridden with Loader options');
function fakeConsole () {};
};
require('test').run(exports);

Просмотреть файл

@ -965,6 +965,13 @@ exports['test emits on url changes'] = function (assert, done) {
});
};
exports['test panel can be constructed without any arguments'] = function (assert) {
const { Panel } = require('sdk/panel');
let panel = Panel();
assert.ok(true, "Creating a panel with no arguments does not throw");
};
if (isWindowPBSupported) {
exports.testGetWindow = function(assert, done) {
let activeWindow = getMostRecentBrowserWindow();