summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_devedition.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /browser/base/content/test/general/browser_devedition.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'browser/base/content/test/general/browser_devedition.js')
-rw-r--r--browser/base/content/test/general/browser_devedition.js129
1 files changed, 129 insertions, 0 deletions
diff --git a/browser/base/content/test/general/browser_devedition.js b/browser/base/content/test/general/browser_devedition.js
new file mode 100644
index 000000000..06ee42e7e
--- /dev/null
+++ b/browser/base/content/test/general/browser_devedition.js
@@ -0,0 +1,129 @@
+/*
+ * Testing changes for Developer Edition theme.
+ * A special stylesheet should be added to the browser.xul document
+ * when the firefox-devedition@mozilla.org lightweight theme
+ * is applied.
+ */
+
+const PREF_LWTHEME_USED_THEMES = "lightweightThemes.usedThemes";
+const PREF_DEVTOOLS_THEME = "devtools.theme";
+const {LightweightThemeManager} = Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", {});
+
+LightweightThemeManager.clearBuiltInThemes();
+LightweightThemeManager.addBuiltInTheme(dummyLightweightTheme("firefox-devedition@mozilla.org"));
+
+registerCleanupFunction(() => {
+ // Set preferences back to their original values
+ LightweightThemeManager.currentTheme = null;
+ Services.prefs.clearUserPref(PREF_DEVTOOLS_THEME);
+ Services.prefs.clearUserPref(PREF_LWTHEME_USED_THEMES);
+
+ LightweightThemeManager.currentTheme = null;
+ LightweightThemeManager.clearBuiltInThemes();
+});
+
+add_task(function* startTests() {
+ Services.prefs.setCharPref(PREF_DEVTOOLS_THEME, "dark");
+
+ info ("Setting the current theme to null");
+ LightweightThemeManager.currentTheme = null;
+ ok (!DevEdition.isStyleSheetEnabled, "There is no devedition style sheet when no lw theme is applied.");
+
+ info ("Adding a lightweight theme.");
+ LightweightThemeManager.currentTheme = dummyLightweightTheme("preview0");
+ ok (!DevEdition.isStyleSheetEnabled, "The devedition stylesheet has been removed when a lightweight theme is applied.");
+
+ info ("Applying the devedition lightweight theme.");
+ let onAttributeAdded = waitForBrightTitlebarAttribute();
+ LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme("firefox-devedition@mozilla.org");
+ ok (DevEdition.isStyleSheetEnabled, "The devedition stylesheet has been added when the devedition lightweight theme is applied");
+ yield onAttributeAdded;
+ is (document.documentElement.getAttribute("brighttitlebarforeground"), "true",
+ "The brighttitlebarforeground attribute is set on the window.");
+
+ info ("Unapplying all themes.");
+ LightweightThemeManager.currentTheme = null;
+ ok (!DevEdition.isStyleSheetEnabled, "There is no devedition style sheet when no lw theme is applied.");
+
+ info ("Applying the devedition lightweight theme.");
+ onAttributeAdded = waitForBrightTitlebarAttribute();
+ LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme("firefox-devedition@mozilla.org");
+ ok (DevEdition.isStyleSheetEnabled, "The devedition stylesheet has been added when the devedition lightweight theme is applied");
+ yield onAttributeAdded;
+ ok (document.documentElement.hasAttribute("brighttitlebarforeground"),
+ "The brighttitlebarforeground attribute is set on the window with dark devtools theme.");
+});
+
+add_task(function* testDevtoolsTheme() {
+ info ("Checking stylesheet and :root attributes based on devtools theme.");
+ Services.prefs.setCharPref(PREF_DEVTOOLS_THEME, "light");
+ is (document.documentElement.getAttribute("devtoolstheme"), "light",
+ "The documentElement has an attribute based on devtools theme.");
+ ok (DevEdition.isStyleSheetEnabled, "The devedition stylesheet is still there with the light devtools theme.");
+ ok (!document.documentElement.hasAttribute("brighttitlebarforeground"),
+ "The brighttitlebarforeground attribute is not set on the window with light devtools theme.");
+
+ Services.prefs.setCharPref(PREF_DEVTOOLS_THEME, "dark");
+ is (document.documentElement.getAttribute("devtoolstheme"), "dark",
+ "The documentElement has an attribute based on devtools theme.");
+ ok (DevEdition.isStyleSheetEnabled, "The devedition stylesheet is still there with the dark devtools theme.");
+ is (document.documentElement.getAttribute("brighttitlebarforeground"), "true",
+ "The brighttitlebarforeground attribute is set on the window with dark devtools theme.");
+
+ Services.prefs.setCharPref(PREF_DEVTOOLS_THEME, "foobar");
+ is (document.documentElement.getAttribute("devtoolstheme"), "light",
+ "The documentElement has 'light' as a default for the devtoolstheme attribute");
+ ok (DevEdition.isStyleSheetEnabled, "The devedition stylesheet is still there with the foobar devtools theme.");
+ ok (!document.documentElement.hasAttribute("brighttitlebarforeground"),
+ "The brighttitlebarforeground attribute is not set on the window with light devtools theme.");
+});
+
+function dummyLightweightTheme(id) {
+ return {
+ id: id,
+ name: id,
+ headerURL: "resource:///chrome/browser/content/browser/defaultthemes/devedition.header.png",
+ iconURL: "resource:///chrome/browser/content/browser/defaultthemes/devedition.icon.png",
+ textcolor: "red",
+ accentcolor: "blue"
+ };
+}
+
+add_task(function* testLightweightThemePreview() {
+ info ("Setting devedition to current and the previewing others");
+ LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme("firefox-devedition@mozilla.org");
+ ok (DevEdition.isStyleSheetEnabled, "The devedition stylesheet is enabled.");
+ LightweightThemeManager.previewTheme(dummyLightweightTheme("preview0"));
+ ok (!DevEdition.isStyleSheetEnabled, "The devedition stylesheet is not enabled after a lightweight theme preview.");
+ LightweightThemeManager.resetPreview();
+ LightweightThemeManager.previewTheme(dummyLightweightTheme("preview1"));
+ ok (!DevEdition.isStyleSheetEnabled, "The devedition stylesheet is not enabled after a second lightweight theme preview.");
+ LightweightThemeManager.resetPreview();
+ ok (DevEdition.isStyleSheetEnabled, "The devedition stylesheet is enabled again after resetting the preview.");
+ LightweightThemeManager.currentTheme = null;
+ ok (!DevEdition.isStyleSheetEnabled, "The devedition stylesheet is gone after removing the current theme.");
+
+ info ("Previewing the devedition theme");
+ LightweightThemeManager.previewTheme(LightweightThemeManager.getUsedTheme("firefox-devedition@mozilla.org"));
+ ok (DevEdition.isStyleSheetEnabled, "The devedition stylesheet is enabled.");
+ LightweightThemeManager.previewTheme(dummyLightweightTheme("preview2"));
+ LightweightThemeManager.resetPreview();
+ ok (!DevEdition.isStyleSheetEnabled, "The devedition stylesheet is now disabled after resetting the preview.");
+});
+
+// Use a mutation observer to wait for the brighttitlebarforeground
+// attribute to change. Using this instead of waiting for the load
+// event on the DevEdition styleSheet.
+function waitForBrightTitlebarAttribute() {
+ return new Promise((resolve, reject) => {
+ let mutationObserver = new MutationObserver(function (mutations) {
+ for (let mutation of mutations) {
+ if (mutation.attributeName == "brighttitlebarforeground") {
+ mutationObserver.disconnect();
+ resolve();
+ }
+ }
+ });
+ mutationObserver.observe(document.documentElement, { attributes: true });
+ });
+}