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

Commit

Permalink
Fix bug 819578, Default styles in panels should only be applied once
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell committed Mar 19, 2013
1 parent 4e4e29d commit ad2aba3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/sdk/panel.js
Expand Up @@ -289,6 +289,8 @@ const Panel = Symbiont.resolve({
* text color.
*/
_applyStyleToDocument: function _applyStyleToDocument() {
if (this._defaultStyleApplied)
return;
try {
let win = this._xulPanel.ownerDocument.defaultView;
let node = win.document.getAnonymousElementByAttribute(
Expand All @@ -309,6 +311,7 @@ const Panel = Symbiont.resolve({
container.insertBefore(style, container.firstChild);
else
container.appendChild(style);
this._defaultStyleApplied = true;
}
catch(e) {
console.error("Unable to apply panel style");
Expand Down
28 changes: 28 additions & 0 deletions test/test-panel.js
Expand Up @@ -658,6 +658,34 @@ function testShowPanel(assert, panel) {
return promise;
}

exports['test Style Applied Only Once'] = function (assert, done) {
let loader = Loader(module);
let panel = loader.require("sdk/panel").Panel({
contentURL: "data:text/html;charset=utf-8,",
contentScript:
'self.port.on("check",function() { self.port.emit("count", document.getElementsByTagName("style").length); });' +
'self.port.on("ping", function (count) { self.port.emit("pong", count); });'
});

panel.port.on('count', function (styleCount) {
assert.equal(styleCount, 1, 'should only have one style');
done();
});

panel.port.on('pong', function (counter) {
panel[--counter % 2 ? 'hide' : 'show']();
panel.port.emit(!counter ? 'check' : 'ping', counter);
});

panel.on('show', init);
panel.show();

function init () {
panel.removeListener('show', init);
panel.port.emit('ping', 10);
}
};

try {
require("sdk/panel");
}
Expand Down

0 comments on commit ad2aba3

Please sign in to comment.