Bug 1083391: Only send panel show/hide events after the panel's document is ready. r=erikvold

This commit is contained in:
Dave Townsend 2014-10-20 11:52:27 -07:00
Родитель 84b3ef779d
Коммит 9245e53a8b
2 изменённых файлов: 75 добавлений и 7 удалений

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

@ -137,6 +137,7 @@ const Panel = Class({
position: Object.freeze({}),
contextMenu: false
}, panelContract(options));
model.ready = false;
models.set(this, model);
if (model.contentStyle || model.contentStyleFile) {
@ -300,15 +301,30 @@ let ready = filter(panelEvents, ({type, target}) =>
let start = filter(panelEvents, ({type}) => type === "document-element-inserted");
// Forward panel show / hide events to panel's own event listeners.
on(shows, "data", ({target}) => emit(panelFor(target), "show"));
on(shows, "data", ({target}) => {
let panel = panelFor(target);
if (modelFor(panel).ready)
emit(panel, "show");
});
on(hides, "data", ({target}) => emit(panelFor(target), "hide"));
on(hides, "data", ({target}) => {
let panel = panelFor(target);
if (modelFor(panel).ready)
emit(panel, "hide");
});
on(ready, "data", ({target}) => {
let panel = panelFor(target);
let window = domPanel.getContentDocument(target).defaultView;
workerFor(panel).attach(window);
if (!modelFor(panel).ready) {
modelFor(panel).ready = true;
if (viewFor(panel).state == "open")
emit(panel, "show");
}
});
on(start, "data", ({target}) => {

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

@ -281,17 +281,28 @@ exports["test Hide Before Show"] = function(assert, done) {
const { Panel } = require('sdk/panel');
let showCalled = false;
let panel = Panel({
let hideCalled = false;
let panel1 = Panel({
onShow: function () {
showCalled = true;
},
onHide: function () {
assert.ok(!showCalled, 'must not emit show if was hidden before');
done();
hideCalled = true;
}
});
panel.show();
panel.hide();
panel1.show();
panel1.hide();
let panel2 = Panel({
onShow: function () {
assert.ok(!showCalled, 'should not emit show');
assert.ok(!hideCalled, 'should not emit hide');
panel1.destroy();
panel2.destroy();
done();
},
});
panel2.show();
};
exports["test Several Show Hides"] = function(assert, done) {
@ -1279,6 +1290,47 @@ exports["test panel addon global object"] = function*(assert) {
loader.unload();
}
exports["test panel load doesn't show"] = function*(assert) {
let loader = Loader(module);
let showCount = 0;
let panel = loader.require("sdk/panel").Panel({
contentScript: "addEventListener('load', function(event) { self.postMessage('load'); });",
contentScriptWhen: "start",
contentURL: "data:text/html;charset=utf-8,",
});
let shown = defer();
let messaged = defer();
panel.once("show", function() {
shown.resolve();
});
panel.once("message", function() {
messaged.resolve();
});
panel.show();
yield all([shown.promise, messaged.promise]);
assert.ok(true, "Saw panel display");
panel.on("show", function() {
assert.fail("Should not have seen another show event")
});
messaged = defer();
panel.once("message", function() {
assert.ok(true, "Saw panel reload");
messaged.resolve();
});
panel.contentURL = "data:text/html;charset=utf-8,<html/>";
yield messaged.promise;
loader.unload();
}
if (isWindowPBSupported) {
exports.testGetWindow = function(assert, done) {
let activeWindow = getMostRecentBrowserWindow();