diff --git a/toolkit/components/extensions/test/browser/browser.ini b/toolkit/components/extensions/test/browser/browser.ini index 2c48f11304b8..001648be41c5 100644 --- a/toolkit/components/extensions/test/browser/browser.ini +++ b/toolkit/components/extensions/test/browser/browser.ini @@ -1,3 +1,8 @@ +[DEFAULT] +support-files = + head.js + [browser_ext_themes_chromeparity.js] [browser_ext_themes_dynamic_updates.js] [browser_ext_themes_lwtsupport.js] +[browser_ext_themes_persistence.js] diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_lwtsupport.js b/toolkit/components/extensions/test/browser/browser_ext_themes_lwtsupport.js index 5e2e0a351fd4..21bd1f4a2643 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_lwtsupport.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_lwtsupport.js @@ -1,14 +1,5 @@ "use strict"; -const BACKGROUND = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; -const ACCENT_COLOR = "#a14040"; -const TEXT_COLOR = "#fac96e"; - -function hexToRGB(hex) { - hex = parseInt((hex.indexOf("#") > -1 ? hex.substring(1) : hex), 16); - return [hex >> 16, (hex & 0x00FF00) >> 8, (hex & 0x0000FF)]; -} - add_task(function* setup() { yield SpecialPowers.pushPrefEnv({ set: [["extensions.webextensions.themes.enabled", true]], diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_persistence.js b/toolkit/components/extensions/test/browser/browser_ext_themes_persistence.js new file mode 100644 index 000000000000..ef1abeb3ea34 --- /dev/null +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_persistence.js @@ -0,0 +1,51 @@ +"use strict"; + +// This test checks whether applied WebExtension themes are persisted and applied +// on newly opened windows. + +add_task(function* setup() { + yield SpecialPowers.pushPrefEnv({ + set: [["extensions.webextensions.themes.enabled", true]], + }); +}); + +add_task(function* test_multiple_windows() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + "theme": { + "images": { + "headerURL": BACKGROUND, + }, + "colors": { + "accentcolor": ACCENT_COLOR, + "textcolor": TEXT_COLOR, + }, + }, + }, + }); + + yield extension.startup(); + + let docEl = window.document.documentElement; + let style = window.getComputedStyle(docEl); + + Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set"); + Assert.equal(docEl.getAttribute("lwthemetextcolor"), "bright", + "LWT text color attribute should be set"); + Assert.equal(style.backgroundImage, 'url("' + BACKGROUND.replace(/"/g, '\\"') + '")', + "Expected background image"); + + // Now we'll open a new window to see if the theme is also applied there. + let window2 = yield BrowserTestUtils.openNewBrowserWindow(); + docEl = window2.document.documentElement; + style = window2.getComputedStyle(docEl); + + Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set"); + Assert.equal(docEl.getAttribute("lwthemetextcolor"), "bright", + "LWT text color attribute should be set"); + Assert.equal(style.backgroundImage, 'url("' + BACKGROUND.replace(/"/g, '\\"') + '")', + "Expected background image"); + + yield BrowserTestUtils.closeWindow(window2); + yield extension.unload(); +}); diff --git a/toolkit/components/extensions/test/browser/head.js b/toolkit/components/extensions/test/browser/head.js new file mode 100644 index 000000000000..821f5d0c02d0 --- /dev/null +++ b/toolkit/components/extensions/test/browser/head.js @@ -0,0 +1,8 @@ +const BACKGROUND = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; +const ACCENT_COLOR = "#a14040"; +const TEXT_COLOR = "#fac96e"; + +function hexToRGB(hex) { + hex = parseInt((hex.indexOf("#") > -1 ? hex.substring(1) : hex), 16); + return [hex >> 16, (hex & 0x00FF00) >> 8, (hex & 0x0000FF)]; +}