browser_fontinspector_theme-change.js (1907B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 requestLongerTimeout(2); 6 7 // Test that the preview images are updated when the theme changes. 8 9 const { 10 getTheme, 11 setTheme, 12 } = require("resource://devtools/client/shared/theme.js"); 13 14 const TEST_URI = URL_ROOT + "doc_browser_fontinspector.html"; 15 const originalTheme = getTheme(); 16 17 add_task(async function () { 18 const { inspector, view } = await openFontInspectorForURL(TEST_URI); 19 const viewDoc = view.document; 20 21 await selectNode(".normal-text", inspector); 22 await expandFontsAccordion(viewDoc); 23 const allFontsEls = getAllFontsEls(viewDoc); 24 const fontEl = allFontsEls[0]; 25 26 // Store the original preview URI for later comparison. 27 const originalURI = fontEl.querySelector(".font-preview").src; 28 const newTheme = originalTheme === "light" ? "dark" : "light"; 29 30 info(`Original theme was '${originalTheme}'.`); 31 32 await setThemeAndWaitForUpdate(newTheme, inspector); 33 34 info("Wait until the preview image changed"); 35 await waitFor( 36 () => fontEl.querySelector(".font-preview").src !== originalURI 37 ); 38 isnot( 39 fontEl.querySelector(".font-preview").src, 40 originalURI, 41 "The preview image changed with the theme." 42 ); 43 44 await setThemeAndWaitForUpdate(originalTheme, inspector); 45 is( 46 fontEl.querySelector(".font-preview").src, 47 originalURI, 48 "The preview image is correct after the original theme was restored." 49 ); 50 }); 51 52 /** 53 * Sets the current theme and waits for fontinspector-updated event. 54 * 55 * @param {string} theme - the new theme 56 * @param {object} inspector - the inspector panel 57 */ 58 async function setThemeAndWaitForUpdate(theme, inspector) { 59 const onUpdated = inspector.once("fontinspector-updated"); 60 61 info(`Setting theme to '${theme}'.`); 62 setTheme(theme); 63 64 info("Waiting for font-inspector to update."); 65 await onUpdated; 66 }