browser_page_style.js (2031B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that the Page Style browser menu actions make it to the viewport, instead of 7 // applying to the RDM UI. 8 9 const TEST_URL = `${URL_ROOT}page_style.html`; 10 11 addRDMTask(TEST_URL, async function ({ ui }) { 12 // Store the RDM body text color for later. 13 const rdmWindow = ui.toolWindow; 14 const rdmTextColor = rdmWindow.getComputedStyle( 15 rdmWindow.document.body 16 ).color; 17 18 info( 19 "Trigger the no page style action and wait for the text color to change" 20 ); 21 let onPageColorChanged = waitForContentPageTextColor(ui, "rgb(0, 0, 0)"); 22 let menuItem = document.querySelector("#menu_pageStyleNoStyle"); 23 menuItem.click(); 24 let color = await onPageColorChanged; 25 26 is( 27 color, 28 "rgb(0, 0, 0)", 29 "The text color is black, so the style was disabled" 30 ); 31 32 info("Check that the RDM page style wasn't disabled"); 33 is( 34 rdmWindow.getComputedStyle(rdmWindow.document.body).color, 35 rdmTextColor, 36 "The color of the text in the RDM window is correct, so that style still applies" 37 ); 38 39 info( 40 "Trigger the page style back and wait for the text color to change again" 41 ); 42 onPageColorChanged = waitForContentPageTextColor(ui, "rgb(255, 0, 0)"); 43 menuItem = document.querySelector("#menu_pageStylePersistentOnly"); 44 menuItem.click(); 45 color = await onPageColorChanged; 46 47 is( 48 color, 49 "rgb(255, 0, 0)", 50 "The text color is red, so the style was enabled" 51 ); 52 }); 53 54 function waitForContentPageTextColor(ui, expectedColor) { 55 return SpecialPowers.spawn( 56 ui.getViewportBrowser(), 57 [{ expectedColor }], 58 function (args) { 59 return new Promise(resolve => { 60 const interval = content.setInterval(() => { 61 const color = content.getComputedStyle(content.document.body).color; 62 if (color === args.expectedColor) { 63 content.clearInterval(interval); 64 resolve(color); 65 } 66 }, 200); 67 }); 68 } 69 ); 70 }