browser_rules_print_media_simulation.js (3076B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test print media simulation. 7 8 // Load the test page under .com TLD, to make the inner .org iframe remote with 9 // Fission. 10 const TEST_URI = URL_ROOT_COM_SSL + "doc_print_media_simulation.html"; 11 12 add_task(async function () { 13 await addTab(TEST_URI); 14 const { inspector, view } = await openRuleView(); 15 16 info("Check that the print simulation button exists"); 17 const button = inspector.panelDoc.querySelector("#print-simulation-toggle"); 18 ok(button, "The print simulation button exists"); 19 20 is( 21 button.getAttribute("aria-pressed"), 22 "false", 23 "The print button is not pressed" 24 ); 25 26 // Helper to retrieve the background-color property of the selected element 27 // All the test elements are expected to have a single background-color rule 28 // for this test. 29 const ruleViewHasColor = async color => 30 (await getPropertiesForRuleIndex(view, 1)).has("background-color:" + color); 31 32 info("Select a div that will change according to print simulation"); 33 await selectNode("div", inspector); 34 ok( 35 await ruleViewHasColor("#f00"), 36 "The rule view shows the expected initial rule" 37 ); 38 is( 39 getRuleViewAncestorRulesDataElementByIndex(view, 1), 40 null, 41 "No media query information are displayed initially" 42 ); 43 44 info("Click on the button and wait for print media to be applied"); 45 button.click(); 46 47 await waitFor(() => button.getAttribute("aria-pressed") === "true"); 48 ok(true, "The button is now pressed"); 49 50 await waitFor(() => ruleViewHasColor("#00f")); 51 ok( 52 true, 53 "The rules view was updated with the rule view from the print media query" 54 ); 55 is( 56 getRuleViewAncestorRulesDataTextByIndex(view, 1), 57 "@media print {", 58 "Media queries information are displayed" 59 ); 60 61 info("Select the node from the remote iframe"); 62 await selectNodeInFrames(["iframe", "html"], inspector); 63 64 ok( 65 await ruleViewHasColor("#0ff"), 66 "The simulation is also applied on the remote iframe" 67 ); 68 is( 69 getRuleViewAncestorRulesDataTextByIndex(view, 1), 70 "@media print {", 71 "Media queries information are displayed for the node on the remote iframe as well" 72 ); 73 74 info("Select the top level div again"); 75 await selectNode("div", inspector); 76 77 info("Click the button again to disable print simulation"); 78 button.click(); 79 80 await waitFor(() => button.getAttribute("aria-pressed") === "false"); 81 ok(true, "The button is no longer checked"); 82 83 await waitFor(() => ruleViewHasColor("#f00")); 84 is( 85 getRuleViewAncestorRulesDataElementByIndex(view, 1), 86 null, 87 "media query is no longer displayed" 88 ); 89 90 info("Select the node from the remote iframe again"); 91 await selectNodeInFrames(["iframe", "html"], inspector); 92 93 await waitFor(() => ruleViewHasColor("#ff0")); 94 ok(true, "The simulation stopped on the remote iframe as well"); 95 is( 96 getRuleViewAncestorRulesDataElementByIndex(view, 1), 97 null, 98 "media query is no longer displayed on the remote iframe as well" 99 ); 100 });