browser_inspector_highlighter-02.js (6765B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 // Test that the highlighter is correctly displayed over a variety of elements 8 9 const TEST_URI = URL_ROOT + "doc_inspector_highlighter.html"; 10 11 add_task(async function () { 12 const { inspector, highlighterTestFront } = 13 await openInspectorForURL(TEST_URI); 14 const { waitForHighlighterTypeShown } = getHighlighterTestHelpers(inspector); 15 16 info("Selecting the simple, non-transformed DIV"); 17 await selectAndHighlightNode("#simple-div", inspector); 18 19 let isVisible = await highlighterTestFront.isHighlighting(); 20 ok(isVisible, "The highlighter is shown"); 21 ok( 22 await highlighterTestFront.assertHighlightedNode("#simple-div"), 23 "The highlighter's outline corresponds to the simple div" 24 ); 25 await isNodeCorrectlyHighlighted(highlighterTestFront, "#simple-div"); 26 27 info("Selecting the rotated DIV"); 28 await selectAndHighlightNode("#rotated-div", inspector); 29 30 isVisible = await highlighterTestFront.isHighlighting(); 31 ok(isVisible, "The highlighter is shown"); 32 info( 33 "Check that the highlighter is displayed at the expected position for rotated div" 34 ); 35 await isNodeCorrectlyHighlighted(highlighterTestFront, "#rotated-div"); 36 37 info("Selecting the zero width height DIV"); 38 await selectAndHighlightNode("#widthHeightZero-div", inspector); 39 40 isVisible = await highlighterTestFront.isHighlighting(); 41 ok(isVisible, "The highlighter is shown"); 42 info( 43 "Check that the highlighter is displayed at the expected position for a zero width height div" 44 ); 45 await isNodeCorrectlyHighlighted( 46 highlighterTestFront, 47 "#widthHeightZero-div" 48 ); 49 50 const ulNodeFront = await getNodeFront("ul", inspector); 51 const { nodes: ulChildren } = await inspector.walker.children(ulNodeFront); 52 const ulBeforeNodeFront = ulChildren[0]; 53 is( 54 ulBeforeNodeFront.displayName, 55 "::before", 56 "Got expexected ul::before pseudo element" 57 ); 58 59 info("Highlighting the ul::before node"); 60 let onHighlighterShown = waitForHighlighterTypeShown( 61 inspector.highlighters.TYPES.BOXMODEL 62 ); 63 64 await selectNode(ulBeforeNodeFront, inspector, "test-highlight"); 65 await onHighlighterShown; 66 is( 67 await getHighlighterInfobarText(), 68 "ul#pseudo::before100 × 50", 69 `::before is properly displayed` 70 ); 71 72 const { nodes: ulBeforeChildren } = 73 await inspector.walker.children(ulBeforeNodeFront); 74 const ulBeforeMarkerNodeFront = ulBeforeChildren[0]; 75 is( 76 ulBeforeMarkerNodeFront.displayName, 77 "::marker", 78 "Got expexected ul::before::marker pseudo element" 79 ); 80 81 info("Highlighting the ul::before::marker node"); 82 onHighlighterShown = waitForHighlighterTypeShown( 83 inspector.highlighters.TYPES.BOXMODEL 84 ); 85 86 await selectNode(ulBeforeMarkerNodeFront, inspector, "test-highlight"); 87 await onHighlighterShown; 88 ok( 89 // We can't set dimensions on the ::marker, and since they will vary from platform to 90 // platform we can't check the content properly. Just make sure the infobar starts with 91 // the expected text 92 (await getHighlighterInfobarText()).startsWith("ul#pseudo::before::marker"), 93 `::before::marker is properly displayed (${await getHighlighterInfobarText()})` 94 ); 95 96 info("Highlighting the dialog::backdrop node"); 97 const dialogNodeFront = await getNodeFront("dialog", inspector); 98 const { nodes: dialogChildren } = 99 await inspector.walker.children(dialogNodeFront); 100 const dialogBackdropNodeFront = dialogChildren[0]; 101 onHighlighterShown = waitForHighlighterTypeShown( 102 inspector.highlighters.TYPES.BOXMODEL 103 ); 104 await selectNode(dialogBackdropNodeFront, inspector, "test-highlight"); 105 await onHighlighterShown; 106 is( 107 await getHighlighterInfobarText(), 108 "dialog::backdrop85 × 333", 109 `::backdrop is properly displayed` 110 ); 111 112 info("Check highlighting for ::view-transition pseudo elements"); 113 const onMarkupMutation = inspector.once("markupmutation"); 114 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => { 115 const document = content.document; 116 content.testTransition = document.startViewTransition(() => { 117 document.querySelector("#simple-div").replaceChildren("updated"); 118 }); 119 await content.testTransition.ready; 120 await content.testTransition.updateCallbackDone; 121 }); 122 await onMarkupMutation; 123 124 const htmlNodeFront = await getNodeFront("html", inspector); 125 const htmlContainer = await getContainerForNodeFront( 126 htmlNodeFront, 127 inspector 128 ); 129 130 const viewTransitionMarkupNodeEl = htmlContainer.children.childNodes[2]; 131 is( 132 viewTransitionMarkupNodeEl.textContent, 133 "::view-transition", 134 "Got ::view-transition node" 135 ); 136 137 info("Highlighting the ::view-transition node"); 138 onHighlighterShown = waitForHighlighterTypeShown( 139 inspector.highlighters.TYPES.BOXMODEL 140 ); 141 await selectNode( 142 viewTransitionMarkupNodeEl.container.node, 143 inspector, 144 "test-highlight" 145 ); 146 await onHighlighterShown; 147 148 ok( 149 // Make sure the infobar starts with the expected text 150 (await getHighlighterInfobarText()).startsWith("html::view-transition"), 151 `::view-transition is properly displayed (${await getHighlighterInfobarText()})` 152 ); 153 154 info("Expand ::view-transition node"); 155 await expandContainer(inspector, viewTransitionMarkupNodeEl.container); 156 const viewTransitionGroupRootEl = 157 viewTransitionMarkupNodeEl.container.children.childNodes[0]; 158 is( 159 viewTransitionGroupRootEl.textContent, 160 "::view-transition-group(root)", 161 "Got ::view-transition-group(root) node" 162 ); 163 164 info("Highlighting the ::view-transition-group(root) node"); 165 onHighlighterShown = waitForHighlighterTypeShown( 166 inspector.highlighters.TYPES.BOXMODEL 167 ); 168 await selectNode( 169 viewTransitionGroupRootEl.container.node, 170 inspector, 171 "test-highlight" 172 ); 173 await onHighlighterShown; 174 175 ok( 176 // Make sure the infobar starts with the expected text 177 (await getHighlighterInfobarText()).startsWith( 178 "html::view-transition-group(root)" 179 ), 180 `::view-transition-group(root) is properly displayed (${await getHighlighterInfobarText()})` 181 ); 182 183 // Cancel transition 184 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => { 185 content.testTransition.skipTransition(); 186 delete content.testTransition; 187 }); 188 }); 189 190 async function getHighlighterInfobarText() { 191 return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { 192 return content.document 193 .getConnectedShadowRoots() 194 .find(root => 195 root.querySelector( 196 ".highlighter-container.box-model .box-model-infobar-text" 197 ) 198 )?.textContent; 199 }); 200 }