Bug 1192281: Uplift Add-on SDK to fx-team. a=me

96ae8d914f...5ac44b7e08

--HG--
extra : commitid : DzwgczbnJ1H
extra : rebase_source : 2eaa3d5d735e05f90393e0bc08e2780947a782e2
This commit is contained in:
Dave Townsend 2015-09-04 14:49:04 -07:00
Родитель 166cfe1acd
Коммит 9ecc0c6c97
7 изменённых файлов: 113 добавлений и 14 удалений

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

@ -223,6 +223,20 @@ function show(panel, options, anchor) {
} }
exports.show = show exports.show = show
function onPanelClick(event) {
let { target, metaKey, ctrlKey, shiftKey, button } = event;
let accel = platform === "darwin" ? metaKey : ctrlKey;
let isLeftClick = button === 0;
let isMiddleClick = button === 1;
if ((isLeftClick && (accel || shiftKey)) || isMiddleClick) {
let link = target.closest('a');
if (link && link.href)
getMostRecentBrowserWindow().openUILink(link.href, event)
}
}
function setupPanelFrame(frame) { function setupPanelFrame(frame) {
frame.setAttribute("flex", 1); frame.setAttribute("flex", 1);
frame.setAttribute("transparent", "transparent"); frame.setAttribute("transparent", "transparent");
@ -301,6 +315,8 @@ function make(document) {
panel.addEventListener("popupshown", onPanelStateChange, false); panel.addEventListener("popupshown", onPanelStateChange, false);
panel.addEventListener("popuphidden", onPanelStateChange, false); panel.addEventListener("popuphidden", onPanelStateChange, false);
panel.addEventListener("click", onPanelClick, false);
// Panel content document can be either in panel `viewFrame` or in // Panel content document can be either in panel `viewFrame` or in
// a `backgroundFrame` depending on panel state. Listeners are set // a `backgroundFrame` depending on panel state. Listeners are set
// on both to avoid setting and removing listeners on panel state changes. // on both to avoid setting and removing listeners on panel state changes.

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

@ -13,14 +13,14 @@ const { getTabs, closeTab } = require("../tabs/utils");
const { windows: getWindows } = require("../window/utils"); const { windows: getWindows } = require("../window/utils");
const { close: closeWindow } = require("../window/helpers"); const { close: closeWindow } = require("../window/helpers");
const { isGenerator } = require("../lang/type"); const { isGenerator } = require("../lang/type");
const { env } = require("../system/environment");
const { Task } = require("resource://gre/modules/Task.jsm"); const { Task } = require("resource://gre/modules/Task.jsm");
function getTestNames (exports) const getTestNames = (exports) =>
Object.keys(exports).filter(name => /^test/.test(name)) Object.keys(exports).filter(name => /^test/.test(name));
function isTestAsync (fn) fn.length > 1 const isTestAsync = ({length}) => length > 1;
function isHelperAsync (fn) fn.length > 2 const isHelperAsync = ({length}) => length > 2;
/* /*
* Takes an `exports` object of a test file and a function `beforeFn` * Takes an `exports` object of a test file and a function `beforeFn`
@ -195,3 +195,5 @@ let cleanUI = function cleanUI() {
return promise; return promise;
} }
exports.cleanUI = cleanUI; exports.cleanUI = cleanUI;
exports.isTravisCI = ("TRAVIS" in env && "CI" in env);

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

@ -1234,6 +1234,33 @@ exports['test active tab properties defined on popup closed'] = function (assert
}); });
}; };
// related to bug 922956
// https://bugzilla.mozilla.org/show_bug.cgi?id=922956
exports["test ready event after window.open"] = function (assert, done) {
setPref(OPEN_IN_NEW_WINDOW_PREF, 2);
setPref(DISABLE_POPUP_PREF, false);
let firstRun = true;
tabs.on('ready', function onReady(tab) {
if (firstRun) {
assert.pass("tab ready callback after 1st window.open");
firstRun = false;
tab.close();
}
else {
assert.pass("tab ready callback after 2nd window.open");
tabs.removeListener('ready', onReady);
tab.close(done);
}
});
tabs.activeTab.attach({
contentScript: "window.open('about:blank');" +
"window.open('about:blank', '', " +
"'width=800,height=600,resizable=no,status=no,location=no');"
});
}
after(exports, function*(name, assert) { after(exports, function*(name, assert) {
resetPopupPrefs(); resetPopupPrefs();
yield cleanUI(); yield cleanUI();

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

@ -6,6 +6,7 @@
require("sdk/context-menu"); require("sdk/context-menu");
const { defer } = require("sdk/core/promise"); const { defer } = require("sdk/core/promise");
const { isTravisCI } = require("sdk/test/utils");
const packaging = require('@loader/options'); const packaging = require('@loader/options');
// These should match the same constants in the module. // These should match the same constants in the module.
@ -3752,7 +3753,7 @@ exports.testPredicateContextTargetValueNotSet = function (assert, done) {
}); });
}; };
if (packaging.isNative) { if (isTravisCI) {
module.exports = { module.exports = {
"test skip on jpm": (assert) => assert.pass("skipping this file with jpm") "test skip on jpm": (assert) => assert.pass("skipping this file with jpm")
}; };

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

@ -22,7 +22,8 @@ const { getMostRecentBrowserWindow } = require('sdk/window/utils');
const { URL } = require('sdk/url'); const { URL } = require('sdk/url');
const { wait } = require('./event/helpers'); const { wait } = require('./event/helpers');
const packaging = require('@loader/options'); const packaging = require('@loader/options');
const { cleanUI, after } = require("sdk/test/utils"); const { cleanUI, after, isTravisCI } = require("sdk/test/utils");
const { platform } = require('sdk/system');
const fixtures = require('./fixtures') const fixtures = require('./fixtures')
@ -1315,12 +1316,64 @@ exports["test Panel without contentURL and contentScriptWhen=start should show"]
loader.unload(); loader.unload();
} }
exports["test Panel links"] = function*(assert) {
const loader = Loader(module);
const { Panel } = loader.require('sdk/panel');
const { getActiveView } = loader.require('sdk/view/core');
const tabs = loader.require('sdk/tabs');
const synthesizeClick = (panel, options) => {
let { contentWindow } = getActiveView(panel).querySelector('iframe');
let event = new contentWindow.MouseEvent('click', options);
contentWindow.document.querySelector('a').dispatchEvent(event);
}
const linkURL = 'data:text/html;charset=utf-8,' +
encodeURIComponent('<html><a href="#">foo</a></html>');
const contentURL = 'data:text/html;charset=utf-8,' +
encodeURIComponent(`<html><a href="${linkURL}">page</a></html>`);
let panel = Panel({
contentURL,
contentScript: Isolate(() => self.postMessage(document.URL))
});
panel.show();
let url = yield wait(panel, 'message');
assert.equal(url, contentURL,
'content URL loaded');
synthesizeClick(panel, { bubbles: true });
url = yield wait(panel, 'message');
assert.equal(url, linkURL,
'link URL loaded in the panel after click');
synthesizeClick(panel, {
bubbles: true,
[platform === 'darwin' ? 'metaKey' : 'ctrlKey']: true
});
let tab = yield wait(tabs, 'ready');
assert.equal(tab.url, linkURL + '#',
'link URL loaded in a new tab after click + accel');
loader.unload();
}
after(exports, function*(name, assert) { after(exports, function*(name, assert) {
yield cleanUI(); yield cleanUI();
assert.pass("ui was cleaned."); assert.pass("ui was cleaned.");
}); });
if (packaging.isNative) { if (isTravisCI) {
module.exports = { module.exports = {
"test skip on jpm": (assert) => assert.pass("skipping this file with jpm") "test skip on jpm": (assert) => assert.pass("skipping this file with jpm")
}; };

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

@ -312,10 +312,10 @@ exports.testUnloadOfDynamicPrefGeneration = function*(assert) {
yield promise; yield promise;
// reopen the add-on prefs page // reopen the add-on prefs page
({ tabId, document }) = yield open(addon); ({ tabId, document } = yield open(addon));
// confirm dynamic pref generation did not occur // confirm dynamic pref generation did not occur
({ promise, resolve }) = defer(); ({ promise, resolve } = defer());
results = document.querySelectorAll("*[data-jetpack-id=\"" + id + "\"]"); results = document.querySelectorAll("*[data-jetpack-id=\"" + id + "\"]");
assert.equal(0, results.length, "the prefs were not setup after unload"); assert.equal(0, results.length, "the prefs were not setup after unload");
modelFor(getTabForId(tabId)).close(resolve); modelFor(getTabForId(tabId)).close(resolve);

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

@ -25,11 +25,11 @@ exports["test makeFilters no method filter"] = (assert) => {
testFiles.forEach(f => assert.ok(fileFilter(f), "using filter 'i' on filename " + f + " works")); testFiles.forEach(f => assert.ok(fileFilter(f), "using filter 'i' on filename " + f + " works"));
testMethods.forEach(m => assert.ok(testFilter(m), "using filter 'i' on method name " + m + " works")); testMethods.forEach(m => assert.ok(testFilter(m), "using filter 'i' on method name " + m + " works"));
({ fileFilter, testFilter }) = makeFilters({ filter: "i:" }); ({ fileFilter, testFilter } = makeFilters({ filter: "i:" }));
testFiles.forEach(f => assert.ok(fileFilter(f), "using filter 'i:' on filename " + f + " works")); testFiles.forEach(f => assert.ok(fileFilter(f), "using filter 'i:' on filename " + f + " works"));
testMethods.forEach(m => assert.ok(testFilter(m), "using filter 'i:' on method name " + m + " works")); testMethods.forEach(m => assert.ok(testFilter(m), "using filter 'i:' on method name " + m + " works"));
({ fileFilter, testFilter }) = makeFilters({ filter: "z:" }); ({ fileFilter, testFilter } = makeFilters({ filter: "z:" }));
testFiles.forEach(f => assert.ok(!fileFilter(f), "using filter 'z:' on filename " + f + " dnw")); testFiles.forEach(f => assert.ok(!fileFilter(f), "using filter 'z:' on filename " + f + " dnw"));
testMethods.forEach(m => assert.ok(testFilter(m), "using filter 'z:' on method name " + m + " works")); testMethods.forEach(m => assert.ok(testFilter(m), "using filter 'z:' on method name " + m + " works"));
} }
@ -39,7 +39,7 @@ exports["test makeFilters no file filter"] = (assert) => {
testFiles.forEach(f => assert.ok(fileFilter(f), "using filter ':i' on filename " + f + " works")); testFiles.forEach(f => assert.ok(fileFilter(f), "using filter ':i' on filename " + f + " works"));
testMethods.forEach(m => assert.ok(testFilter(m), "using filter ':i' on method name " + m + " works")); testMethods.forEach(m => assert.ok(testFilter(m), "using filter ':i' on method name " + m + " works"));
({ fileFilter, testFilter }) = makeFilters({ filter: ":z" }); ({ fileFilter, testFilter } = makeFilters({ filter: ":z" }));
testFiles.forEach(f => assert.ok(fileFilter(f), "using filter ':z' on filename " + f + " works")); testFiles.forEach(f => assert.ok(fileFilter(f), "using filter ':z' on filename " + f + " works"));
testMethods.forEach(m => assert.ok(!testFilter(m), "using filter ':z' on method name " + m + " dnw")); testMethods.forEach(m => assert.ok(!testFilter(m), "using filter ':z' on method name " + m + " dnw"));
} }
@ -49,7 +49,7 @@ exports["test makeFilters both filters"] = (assert) => {
testFiles.forEach(f => assert.ok(fileFilter(f), "using filter 'i:i' on filename " + f + " works")); testFiles.forEach(f => assert.ok(fileFilter(f), "using filter 'i:i' on filename " + f + " works"));
testMethods.forEach(m => assert.ok(testFilter(m), "using filter 'i:i' on method name " + m + " works")); testMethods.forEach(m => assert.ok(testFilter(m), "using filter 'i:i' on method name " + m + " works"));
({ fileFilter, testFilter }) = makeFilters({ filter: "z:z" }); ({ fileFilter, testFilter } = makeFilters({ filter: "z:z" }));
testFiles.forEach(f => assert.ok(!fileFilter(f), "using filter 'z:z' on filename " + f + " dnw")); testFiles.forEach(f => assert.ok(!fileFilter(f), "using filter 'z:z' on filename " + f + " dnw"));
testMethods.forEach(m => assert.ok(!testFilter(m), "using filter 'z:z' on method name " + m + " dnw")); testMethods.forEach(m => assert.ok(!testFilter(m), "using filter 'z:z' on method name " + m + " dnw"));
} }