Browse files

Merge pull request #584 from ZER0/contentStyle/Bug789981

Fix Bug 789981 - CSS Style Sheets don't deactivate on addon uninstall r=@Gozala
  • Loading branch information...
2 parents f7a5edd + b9ff9da commit 4c747e8255351f607dde618ae4d8989cf1c959f6 @ZER0 ZER0 committed Oct 2, 2012
Showing with 47 additions and 0 deletions.
  1. +7 −0 packages/addon-kit/lib/page-mod.js
  2. +40 −0 packages/addon-kit/tests/test-page-mod.js
View
7 packages/addon-kit/lib/page-mod.js
@@ -333,6 +333,13 @@ const PageModManager = Registry.resolve({
for (let rule in RULES) {
delete RULES[rule];
}
+
+ // We need to do some cleaning er PageMods, like unregistering any
+ // `contentStyle*`
+ this._registry.forEach(function(pageMod) {
+ pageMod.destroy();
+ });
+
this._registryDestructor();
},
_onContentWindow: function _onContentWindow(document) {
View
40 packages/addon-kit/tests/test-page-mod.js
@@ -11,6 +11,7 @@ const tabs = require("tabs");
const timer = require("timer");
const { Cc, Ci } = require("chrome");
const windowUtils = require('api-utils/window/utils');
+const { getTabContentWindow, getActiveTab } = require("api-utils/tabs/utils");
/* XXX This can be used to delay closing the test Firefox instance for interactive
* testing or visual inspection. This test is registered first so that it runs
@@ -740,3 +741,42 @@ exports.testPageModCssDestroy = function(test) {
}
);
};
+
+exports.testPageModCssAutomaticDestroy = function(test) {
+ test.waitUntilDone();
+ let loader = Loader(module);
+
+ let pageMod = loader.require("page-mod").PageMod({
+ include: "data:*",
+ contentStyle: "div { width: 100px!important; }"
+ });
+
+ tabs.open({
+ url: "data:text/html;charset=utf-8,<div style='width:200px'>css test</div>",
+
+ onReady: function onReady(tab) {
+ let browserWindow = require('api-utils/window-utils').activeBrowserWindow;
+ let win = getTabContentWindow(getActiveTab(browserWindow));
+
+ let div = win.document.querySelector("div"),
+ style = win.getComputedStyle(div);
+
+ test.assertEqual(
+ style.width,
+ "100px",
+ "PageMod contentStyle worked"
+ );
+
+ loader.unload();
+
+ test.assertEqual(
+ style.width,
+ "200px",
+ "PageMod contentStyle is removed after loader's unload"
+ );
+
+ tab.close();
+ test.done();
+ }
+ });
+};

0 comments on commit 4c747e8

Please sign in to comment.