Bug 910193 - Uplift Add-on SDK to Firefox

This commit is contained in:
Wes Kocher 2013-08-28 05:22:52 -07:00
Родитель bfa66ae5ef
Коммит e016a24dc0
4 изменённых файлов: 97 добавлений и 40 удалений

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

@ -236,7 +236,12 @@ function make(document) {
let viewFrame = createFrame(panel, frameOptions);
setupPanelFrame(viewFrame);
function onDisplayChange({type}) {
function onDisplayChange({type, target}) {
// Events from child element like <select /> may propagate (dropdowns are
// popups too), in which case frame loader shouldn't be swapped.
// See Bug 886329
if (target !== this) return;
try { swapFrameLoaders(backgroundFrame, viewFrame); }
catch(error) { console.exception(error); }
events.emit(type, { subject: panel });

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

@ -5,7 +5,8 @@
const { defer } = require('../core/promise');
const events = require('../system/events');
const { open: openWindow, onFocus, getToplevelWindow } = require('./utils');
const { open: openWindow, onFocus, getToplevelWindow,
isInteractive } = require('./utils');
function open(uri, options) {
return promise(openWindow.apply(null, arguments), 'load');
@ -36,6 +37,18 @@ function focus(window) {
}
exports.focus = focus;
function ready(window) {
let { promise: result, resolve } = defer();
if (isInteractive(window))
resolve(window);
else
resolve(promise(window, 'DOMContentLoaded'));
return result;
}
exports.ready = ready;
function promise(target, evt, capture) {
let deferred = defer();
capture = !!capture;
@ -47,4 +60,4 @@ function promise(target, evt, capture) {
return deferred.promise;
}
exports.promise = promise;
exports.promise = promise;

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

@ -1,27 +1,27 @@
/* 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 errors = require("sdk/deprecated/errors");
const errors = require("sdk/deprecated/errors");
exports.testCatchAndLog = function(test) {
exports.testCatchAndLog = function(assert) {
var caught = [];
function dummyLog(e) { caught.push(e); }
var wrapped = errors.catchAndLog(function(x) {
throw Error("blah" + x + this);
},
"boop",
dummyLog);
test.assertEqual(wrapped.call("hi", 1), "boop",
"exceptions should be trapped, def. resp. returned");
test.assertEqual(caught.length, 1,
"logging function should be called");
test.assertEqual(caught[0].message, "blah1hi",
"args and this should be passed to wrapped func");
throw Error("blah" + x + this);
}, "boop", dummyLog);
assert.equal(wrapped.call("hi", 1), "boop",
"exceptions should be trapped, def. resp. returned");
assert.equal(caught.length, 1,
"logging function should be called");
assert.equal(caught[0].message, "blah1hi",
"args and this should be passed to wrapped func");
};
exports.testCatchAndLogProps = function(test) {
exports.testCatchAndLogProps = function(assert) {
var caught = [];
function dummyLog(e) { caught.push(e); }
@ -33,38 +33,40 @@ exports.testCatchAndLogProps = function(test) {
errors.catchAndLogProps(thing, "foo", "ugh", dummyLog);
test.assertEqual(thing.foo(1), "ugh",
assert.equal(thing.foo(1), "ugh",
"props should be wrapped");
test.assertEqual(caught.length, 1,
assert.equal(caught.length, 1,
"logging function should be called");
test.assertEqual(caught[0].message, "nowai1",
assert.equal(caught[0].message, "nowai1",
"args should be passed to wrapped func");
test.assertRaises(function() { thing.bar(); },
"blah",
"non-wrapped props should be wrapped");
assert.throws(function() { thing.bar(); },
/blah/,
"non-wrapped props should be wrapped");
errors.catchAndLogProps(thing, ["bar", "baz"], "err", dummyLog);
test.assert((thing.bar() == thing.baz()) &&
assert.ok((thing.bar() == thing.baz()) &&
(thing.bar() == "err"),
"multiple props should be wrapped if array passed in");
};
exports.testCatchAndReturn = function(test) {
exports.testCatchAndReturn = function(assert) {
var wrapped = errors.catchAndReturn(function(x) {
if (x == 1)
return "one";
if (x == 2)
throw new Error("two");
return this + x;
});
if (x == 1)
return "one";
if (x == 2)
throw new Error("two");
return this + x;
});
test.assertEqual(wrapped(1).returnValue, "one",
"arg should be passed; return value should be returned");
test.assert(wrapped(2).exception, "exception should be returned");
test.assertEqual(wrapped(2).exception.message, "two", "message is correct");
test.assert(wrapped(2).exception.fileName.indexOf("test-errors.js") != -1,
"filename is present");
test.assert(wrapped(2).exception.stack, "stack is available");
test.assertEqual(wrapped.call("hi", 3).returnValue, "hi3",
"`this` should be set correctly");
assert.equal(wrapped(1).returnValue, "one",
"arg should be passed; return value should be returned");
assert.ok(wrapped(2).exception, "exception should be returned");
assert.equal(wrapped(2).exception.message, "two", "message is correct");
assert.ok(wrapped(2).exception.fileName.indexOf("test-errors.js") != -1,
"filename is present");
assert.ok(wrapped(2).exception.stack, "stack is available");
assert.equal(wrapped.call("hi", 3).returnValue, "hi3",
"`this` should be set correctly");
};
require("sdk/test").run(exports);

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

@ -14,7 +14,7 @@ const { Loader } = require('sdk/test/loader');
const { LoaderWithHookedConsole } = require("sdk/test/loader");
const timer = require("sdk/timers");
const self = require('sdk/self');
const { open, close, focus } = require('sdk/window/helpers');
const { open, close, focus, ready } = require('sdk/window/helpers');
const { isPrivate } = require('sdk/private-browsing');
const { isWindowPBSupported, isGlobalPBSupported } = require('sdk/private-browsing/utils');
const { defer, all } = require('sdk/core/promise');
@ -896,6 +896,43 @@ exports['test passing DOM node as first argument'] = function (assert, done) {
panel.show(widgetNode);
};
// This test is checking that `onpupshowing` events emitted by panel's children
// are not considered.
// See Bug 886329
exports['test nested popups'] = function (assert, done) {
let loader = Loader(module);
let { Panel } = loader.require('sdk/panel');
let { getActiveView } = loader.require('sdk/view/core');
let url = '<select><option>1<option>2<option>3</select>';
let getContentWindow = panel => {
return getActiveView(panel).querySelector('iframe').contentWindow;
}
let panel = Panel({
contentURL: 'data:text/html;charset=utf-8,' + encodeURIComponent(url),
onShow: () => {
ready(getContentWindow(panel)).then(({ window, document }) => {
let select = document.querySelector('select');
let event = document.createEvent('UIEvent');
event.initUIEvent('popupshowing', true, true, window, null);
select.dispatchEvent(event);
assert.equal(
select,
getContentWindow(panel).document.querySelector('select'),
'select is still loaded in panel'
);
done();
});
}
});
panel.show();
};
if (isWindowPBSupported) {
exports.testGetWindow = function(assert, done) {
let activeWindow = getMostRecentBrowserWindow();