Bug 1128478 - sdk/panel's show/hide events not emitted if contentScriptWhen != 'ready'. r=erikvold, a=sledru
authorRob Wu <rob@robwu.nl>
Tue, 17 Feb 2015 03:57:00 -0500
changeset 245417 c2a6bab25617
parent 245416 47ec64cc562f
child 245418 67d9db36737e
push id662
push userryanvm@gmail.com
push date2015-02-20 00:54 +0000
treeherdermozilla-release@a2ffa9047bf4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserikvold, sledru
bugs1128478
milestone36.0
Bug 1128478 - sdk/panel's show/hide events not emitted if contentScriptWhen != 'ready'. r=erikvold, a=sledru
addon-sdk/source/lib/sdk/panel.js
addon-sdk/source/test/test-panel.js
--- a/addon-sdk/source/lib/sdk/panel.js
+++ b/addon-sdk/source/lib/sdk/panel.js
@@ -292,16 +292,19 @@ let hides = filter(panelEvents, ({type})
 
 // Panel events emitted after content inside panel is ready. For different
 // panels ready may mean different state based on `contentScriptWhen` attribute.
 // Weather given event represents readyness is detected by `getAttachEventType`
 // helper function.
 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");
 
 // Forward panel show / hide events to panel's own event listeners.
 on(shows, "data", ({target}) => {
   let panel = panelFor(target);
   if (modelFor(panel).ready)
@@ -314,16 +317,20 @@ on(hides, "data", ({target}) => {
     emit(panel, "hide");
 });
 
 on(ready, "data", ({target}) => {
   let panel = panelFor(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;
 
     if (viewFor(panel).state == "open")
       emit(panel, "show");
   }
 });
--- a/addon-sdk/source/test/test-panel.js
+++ b/addon-sdk/source/test/test-panel.js
@@ -1288,17 +1288,16 @@ exports["test panel addon global object"
   assert.pass("Received an event from the document");
 
   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();
@@ -1326,16 +1325,34 @@ exports["test panel load doesn't show"] 
   });
 
   panel.contentURL = "data:text/html;charset=utf-8,<html/>";
 
   yield messaged.promise;
   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 (isWindowPBSupported) {
   exports.testGetWindow = function(assert, done) {
     let activeWindow = getMostRecentBrowserWindow();
     open(null, { features: {
       toolbar: true,
       chrome: true,
       private: true
     } }).then(window => {