Bug 1420485 - Added new tabs.insertCSS test case to ensure that the injected CSS are cleaned up. r=mixedpuppy, a=RyanVM
authorLuca Greco <lgreco@mozilla.com>
Mon, 27 Nov 2017 15:38:45 +0100
changeset 454714 24e9a78c27eb173d9eba4b0ab029b318a03bd97c
parent 454713 9d8a25ef4fd74e465fcc75a7fc12c6671024a88f
child 454715 dbc6d70aff8771875986647eaa24f35da0882061
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, RyanVM
bugs1420485
milestone59.0
Bug 1420485 - Added new tabs.insertCSS test case to ensure that the injected CSS are cleaned up. r=mixedpuppy, a=RyanVM MozReview-Commit-ID: EPTTA2MnZ6O
browser/components/extensions/test/browser/browser_ext_tabs_insertCSS.js
--- a/browser/components/extensions/test/browser/browser_ext_tabs_insertCSS.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_insertCSS.js
@@ -106,8 +106,52 @@ add_task(async function testExecuteScrip
   await BrowserTestUtils.removeTab(tab);
 
   // Make sure that we're not holding on to references to closed message
   // managers.
   is(MessageChannel.messageManagers.size, messageManagersSize, "Message manager count");
   is(MessageChannel.responseManagers.size, responseManagersSize, "Response manager count");
   is(MessageChannel.pendingResponses.size, 0, "Pending response count");
 });
+
+add_task(async function testInsertCSS_cleanup() {
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://mochi.test:8888/", true);
+
+  async function background() {
+    await browser.tabs.insertCSS({code: "* { background: rgb(42, 42, 42) }"});
+    await browser.tabs.insertCSS({file: "customize_fg_color.css"});
+
+    browser.test.notifyPass("insertCSS");
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "permissions": ["http://mochi.test/"],
+    },
+    background,
+    files: {
+      "customize_fg_color.css": `* { color: rgb(255, 0, 0) }`,
+    },
+  });
+
+  await extension.startup();
+
+  await extension.awaitFinish("insertCSS");
+
+  const getTabContentComputedStyle = async () => {
+    let computedStyle = content.getComputedStyle(content.document.body);
+    return [computedStyle.backgroundColor, computedStyle.color];
+  };
+
+  const appliedStyles = await ContentTask.spawn(tab.linkedBrowser, null, getTabContentComputedStyle);
+
+  is(appliedStyles[0], "rgb(42, 42, 42)", "The injected CSS code has been applied as expected");
+  is(appliedStyles[1], "rgb(255, 0, 0)", "The injected CSS file has been applied as expected");
+
+  await extension.unload();
+
+  const unloadedStyles = await ContentTask.spawn(tab.linkedBrowser, null, getTabContentComputedStyle);
+
+  is(unloadedStyles[0], "rgba(0, 0, 0, 0)", "The injected CSS code has been removed as expected");
+  is(unloadedStyles[1], "rgb(0, 0, 0)", "The injected CSS file has been removed as expected");
+
+  await BrowserTestUtils.removeTab(tab);
+});