Bug 1134759 - Uplift the Add-on SDK to Firefox a=me

This commit is contained in:
Erik Vold 2015-02-25 18:53:25 -08:00
parent 478cf9bc98
commit 19219466a5
16 changed files with 116 additions and 47 deletions

View File

@ -1,6 +1,7 @@
sudo: false
language: node_js
node_js:
- "iojs"
- "0.10"
notifications:

View File

@ -17,12 +17,14 @@ If you have code that you'd like to contribute the Jetpack project, follow these
3. Make your changes, per the Overview
4. Write a test ([intro][test intro], [API][test API])
5. Submit pull request with changes and a title in a form of `Bug XXX - description`
6. Copy the pull request link from GitHub and paste it in as an attachment to the bug
7. Each pull request should idealy contain only one commit, so squash the commits if necessary.
8. Flag the attachment for code review from one of the Jetpack reviewers listed below.
6. Make sure that [Travis CI](https://travis-ci.org/mozilla/addon-sdk/branches) tests are passing for your branch.
7. Copy the pull request link from GitHub and paste it in as an attachment to the bug
8. Each pull request should idealy contain only one commit, so squash the commits if necessary.
9. Flag the attachment for code review from one of the Jetpack reviewers listed below.
This step is optional, but could speed things up.
9. Address any nits (ie style changes), or other issues mentioned in the review.
10. Finally, once review is approved, a team member will do the merging
10. Address any nits (ie style changes), or other issues mentioned in the review.
Finally, once review is approved, a team member will do the merging
## Good First Bugs

View File

@ -81,14 +81,12 @@ function startup(reason, options) Startup.onceInitialized.then(() => {
// Exports data to a pseudo module so that api-utils/l10n/core
// can get access to it
definePseudo(options.loader, '@l10n/data', data ? data : null);
return ready;
}).then(function() {
run(options);
return ready.then(() => run(options, !!data));
}).then(null, console.exception);
return void 0; // otherwise we raise a warning, see bug 910304
});
function run(options) {
function run(options, hasL10n) {
try {
// Try initializing HTML localization before running main module. Just print
// an exception in case of error, instead of preventing addon to be run.
@ -96,7 +94,7 @@ function run(options) {
// Do not enable HTML localization while running test as it is hard to
// disable. Because unit tests are evaluated in a another Loader who
// doesn't have access to this current loader.
if (options.main !== 'sdk/test/runner') {
if (hasL10n && options.main !== 'sdk/test/runner') {
require('../l10n/html').enable();
}
}

View File

@ -340,7 +340,7 @@ function getPotentialLeaks() {
let item = {
path: matches[1],
principal: details[1],
location: details[2] ? details[2].replace("\\", "/", "g") : undefined,
location: details[2] ? details[2].replace(/\\/g, "/") : undefined,
source: details[3] ? details[3].split(" -> ").reverse() : undefined,
toString: function() this.location
};
@ -364,8 +364,8 @@ function getPotentialLeaks() {
let item = {
path: matches[1],
location: details[1].replace("\\", "/", "g"),
source: [details[1].replace("\\", "/", "g")],
location: details[1].replace(/\\/g, "/"),
source: [details[1].replace(/\\/g, "/")],
toString: function() this.location
};

View File

@ -12,6 +12,7 @@ const { emit } = require("../event/core");
const { WindowTracker, windowIterator } = require("../deprecated/window-utils");
const { DOMEventAssembler } = require("../deprecated/events/assembler");
const { Class } = require("../core/heritage");
const { Cu } = require("chrome");
// Event emitter objects used to register listeners and emit events on them
// when they occur.
@ -42,6 +43,9 @@ const Observer = Class({
* Keyboard event being emitted.
*/
handleEvent(event) {
// Ignore events from windows in the child process as they can't be top-level
if (Cu.isCrossProcessWrapper(event.target))
return;
emit(this, event.type, event.target, event);
}
});

View File

@ -703,7 +703,8 @@ Loader.main = main;
const Module = iced(function Module(id, uri) {
return create(null, {
id: { enumerable: true, value: id },
exports: { enumerable: true, writable: true, value: create(null) },
exports: { enumerable: true, writable: true, value: create(null),
configurable: true },
uri: { value: uri }
});
});
@ -784,6 +785,7 @@ function Loader(options) {
}
}, modules);
const builtinModuleExports = modules;
modules = keys(modules).reduce(function(result, id) {
// We resolve `uri` from `id` since modules are cached by `uri`.
let uri = resolveURI(id, mapping);
@ -792,7 +794,16 @@ function Loader(options) {
if (isNative && !uri)
uri = id;
let module = Module(id, uri);
module.exports = freeze(modules[id]);
// Lazily expose built-in modules in order to
// allow them to be loaded lazily.
Object.defineProperty(module, "exports", {
enumerable: true,
get: function() {
return builtinModuleExports[id];
}
});
result[uri] = freeze(module);
return result;
}, {});

View File

@ -60,6 +60,7 @@ DEFAULT_NO_CONNECTIONS_PREFS = {
'browser.safebrowsing.gethashURL': 'http://localhost/safebrowsing-dummy/gethash',
'browser.safebrowsing.reportURL': 'http://localhost/safebrowsing-dummy/report',
'browser.safebrowsing.malware.reportURL': 'http://localhost/safebrowsing-dummy/malwarereport',
'browser.selfsupport.url': 'http://localhost/repair-dummy',
'browser.trackingprotection.gethashURL': 'http://localhost/safebrowsing-dummy/gethash',
'browser.trackingprotection.updateURL': 'http://localhost/safebrowsing-dummy/update',

View File

@ -10,7 +10,8 @@ const { fromIterator } = require('sdk/util/array');
const BUILTIN_SIDEBAR_MENUITEMS = exports.BUILTIN_SIDEBAR_MENUITEMS = [
'menu_socialSidebar',
'menu_historySidebar',
'menu_bookmarksSidebar'
'menu_bookmarksSidebar',
'menu_readingListSidebar'
];
function isSidebarShowing(window) {

View File

@ -129,8 +129,7 @@ exports.testDestroyEdgeCaseBugWithPrivateWindow = function(assert, done) {
assert.pass('onShow works for Sidebar');
loader.unload();
let sidebarMI = getSidebarMenuitems();
for (let mi of sidebarMI) {
for (let mi of getSidebarMenuitems()) {
assert.ok(BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) >= 0, 'the menuitem is for a built-in sidebar')
assert.ok(!isChecked(mi), 'no sidebar menuitem is checked');
}

View File

@ -0,0 +1,9 @@
/* 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.useFoo= function () {
return require('foo');
}

View File

@ -17,6 +17,7 @@
"browser.safebrowsing.gethashURL": "http://localhost/safebrowsing-dummy/gethash",
"browser.safebrowsing.reportURL": "http://localhost/safebrowsing-dummy/report",
"browser.safebrowsing.malware.reportURL": "http://localhost/safebrowsing-dummy/malwarereport",
"browser.selfsupport.url": "http://localhost/repair-dummy",
"browser.trackingprotection.gethashURL": "http://localhost/safebrowsing-dummy/gethash",
"browser.trackingprotection.updateURL": "http://localhost/safebrowsing-dummy/update",
"browser.newtabpage.directory.source": "data:application/json,{'jetpack':1}",

View File

@ -16,7 +16,8 @@ const { fromIterator } = require('sdk/util/array');
const BUILTIN_SIDEBAR_MENUITEMS = exports.BUILTIN_SIDEBAR_MENUITEMS = [
'menu_socialSidebar',
'menu_historySidebar',
'menu_bookmarksSidebar'
'menu_bookmarksSidebar',
'menu_readingListSidebar'
];
function isSidebarShowing(window) {

View File

@ -506,4 +506,22 @@ exports["test Cu.import in b2g style"] = (assert) => {
"Loader.Loader is a funciton");
};
exports['test lazy globals'] = function (assert) {
let uri = root + '/fixtures/loader/lazy/';
let gotFoo = false;
let foo = {};
let modules = {
get foo() {
gotFoo = true;
return foo;
}
};
let loader = Loader({ paths: { '': uri }, modules: modules});
assert.ok(!gotFoo, "foo hasn't been accessed during loader instanciation");
let program = main(loader, 'main');
assert.ok(!gotFoo, "foo hasn't been accessed during module loading");
assert.equal(program.useFoo(), foo, "foo mock works");
assert.ok(gotFoo, "foo has been accessed only when we first try to use it");
};
require('sdk/test').run(exports);

View File

@ -29,6 +29,17 @@ exports.testGetAndSet = function(assert) {
"preferences-service should read from " +
"application-wide preferences service");
// test getting a pref that does not exist,
// and where we provide no default
assert.equal(
prefs.get("test_dne_get_pref", "default"),
"default",
"default was used for a pref that does not exist");
assert.equal(
prefs.get("test_dne_get_pref"),
undefined,
"undefined was returned for a pref that does not exist with no default");
prefs.set("test_set_get_pref.integer", 1);
assert.equal(prefs.get("test_set_get_pref.integer"), 1,
"set/get integer preference should work");

View File

@ -96,9 +96,12 @@ exports.testSidebarBasicLifeCycle = function*(assert) {
sidebar.destroy();
sidebar.destroy();
let sidebarMI = getSidebarMenuitems();
for (let mi of sidebarMI) {
assert.ok(BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) >= 0, 'the menuitem is for a built-in sidebar')
for (let mi of getSidebarMenuitems()) {
let id = mi.getAttribute('id');
if (BUILTIN_SIDEBAR_MENUITEMS.indexOf(id) < 0) {
assert.fail('the menuitem "' + id + '" is not a built-in sidebar');
}
assert.ok(!isChecked(mi), 'no sidebar menuitem is checked');
}
@ -360,8 +363,7 @@ exports.testSidebarUnload = function*(assert) {
loader.unload();
let sidebarMI = getSidebarMenuitems();
for (let mi of sidebarMI) {
for (let mi of getSidebarMenuitems()) {
assert.ok(BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) >= 0, 'the menuitem is for a built-in sidebar')
assert.ok(!isChecked(mi), 'no sidebar menuitem is checked');
}
@ -598,9 +600,12 @@ exports.testDestroyEdgeCaseBug = function*(assert) {
yield sidebar.show();
loader.unload();
let sidebarMI = getSidebarMenuitems();
for (let mi of sidebarMI) {
assert.ok(BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) >= 0, 'the menuitem is for a built-in sidebar')
for (let mi of getSidebarMenuitems()) {
let id = mi.getAttribute('id');
if (BUILTIN_SIDEBAR_MENUITEMS.indexOf(id) < 0) {
assert.fail('the menuitem "' + id + '" is not a built-in sidebar');
}
assert.ok(!isChecked(mi), 'no sidebar menuitem is checked');
}
assert.ok(!window.document.getElementById(makeID(testName)), 'sidebar id DNE');
@ -762,6 +767,9 @@ exports.testURLSetterToSameValueReloadsSidebar = function*(assert) {
document = window.document;
assert.pass('new window was opened');
yield focus(window);
assert.pass('new window was focused');
yield sidebar1.show();
assert.equal(isShowing(sidebar1), true, 'the sidebar is showing');
@ -1490,23 +1498,29 @@ exports.testShowHideRawWindowArg = function*(assert) {
});
let mainWindow = getMostRecentBrowserWindow();
let newWindow = yield open().then(focus);
let newWindow = yield windowPromise(mainWindow.OpenBrowserWindow(), 'load');
assert.pass("Created the new window");
yield focus(newWindow);
assert.pass("Focused the new window");
yield focus(mainWindow);
assert.pass("Focused the old window");
yield sidebar.show(newWindow);
assert.pass('the sidebar was shown');
assert.ok(!isSidebarShowing(mainWindow), 'sidebar is not showing in main window');
assert.ok(isSidebarShowing(newWindow), 'sidebar is showing in new window');
assert.equal(isSidebarShowing(mainWindow), false, 'sidebar is not showing in main window');
assert.equal(isSidebarShowing(newWindow), true, 'sidebar is showing in new window');
assert.ok(isFocused(mainWindow), 'main window is still focused');
yield sidebar.hide(newWindow);
assert.ok(isFocused(mainWindow), 'main window is still focused');
assert.ok(!isSidebarShowing(mainWindow), 'sidebar is not showing in main window');
assert.ok(!isSidebarShowing(newWindow), 'sidebar is not showing in new window');
assert.equal(isFocused(mainWindow), true, 'main window is still focused');
assert.equal(isSidebarShowing(mainWindow), false, 'sidebar is not showing in main window');
assert.equal(isSidebarShowing(newWindow), false, 'sidebar is not showing in new window');
sidebar.destroy();
}
@ -1547,6 +1561,7 @@ before(exports, (name, assert) => {
});
after(exports, function*(name, assert) {
assert.pass("Cleaning new windows and tabs");
yield cleanUI();
assert.equal(isSidebarShowing(), false, 'no sidebar is showing');
});

View File

@ -5,10 +5,7 @@
const { Cu } = require('chrome');
const { Loader } = require('sdk/test/loader');
function gc() {
return new Promise(resolve => Cu.schedulePreciseGC(resolve));
};
const { gc } = require("sdk/test/memory");
exports['test adding item'] = function*(assert) {
let loader = Loader(module);
@ -121,31 +118,31 @@ exports['test adding non object or null item'] = function(assert) {
assert.throws(() => {
add(items, 'foo');
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
assert.throws(() => {
add(items, 0);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
assert.throws(() => {
add(items, undefined);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
assert.throws(() => {
add(items, null);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
assert.throws(() => {
add(items, true);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
};
@ -158,31 +155,31 @@ exports['test adding to non object or null item'] = function(assert) {
assert.throws(() => {
add('foo', item);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
assert.throws(() => {
add(0, item);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
assert.throws(() => {
add(undefined, item);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
assert.throws(() => {
add(null, item);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
assert.throws(() => {
add(true, item);
},
/^value is not a non-null object/,
/^\w+ is not a non-null object/,
'only non-null object are allowed');
};