Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1854 from Rob--W/panel-show-at-DOMContentLoaded
Browse files Browse the repository at this point in the history
Bug 1128478 - sdk/panel's show/hide events not emitted if contentScriptWhen != 'ready' r=erikvold
  • Loading branch information
erikvold committed Feb 4, 2015
2 parents 0ddcbe6 + 6bcbca9 commit ad36ca4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/sdk/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ let hides = filter(panelEvents, ({type}) => type === "popuphidden");
let ready = filter(panelEvents, ({type, target}) =>
getAttachEventType(modelFor(panelFor(target))) === type);

// Panel event emitted when the contents of the panel has been loaded.
let readyToShow = filter(panelEvents, ({type}) => type === "DOMContentLoaded");

// Styles should be always added as soon as possible, and doesn't makes them
// depends on `contentScriptWhen`
let start = filter(panelEvents, ({type}) => type === "document-element-inserted");
Expand All @@ -317,6 +320,10 @@ on(ready, "data", ({target}) => {
let window = domPanel.getContentDocument(target).defaultView;

workerFor(panel).attach(window);
});

on(readyToShow, "data", ({target}) => {
let panel = panelFor(target);

if (!modelFor(panel).ready) {
modelFor(panel).ready = true;
Expand Down
19 changes: 18 additions & 1 deletion test/test-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,6 @@ exports["test panel addon global object"] = function*(assert) {
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",
Expand Down Expand Up @@ -1335,6 +1334,24 @@ exports["test panel load doesn't show"] = function*(assert) {
loader.unload();
}

exports["test Panel without contentURL and contentScriptWhen=start should show"] = function*(assert) {
let loader = Loader(module);

let panel = loader.require("sdk/panel").Panel({
contentScriptWhen: "start",
// No contentURL, the bug only shows up when contentURL is not explicitly set.
});

yield new Promise(resolve => {
panel.once("show", resolve);
panel.show();
});

assert.pass("Received show event");

loader.unload();
}

if (packaging.isNative) {
module.exports = {
"test skip on jpm": (assert) => assert.pass("skipping this file with jpm")
Expand Down

0 comments on commit ad36ca4

Please sign in to comment.