browser_inspector_highlighter-geometry_05.js (3724B)
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 /* Globals defined in: devtools/client/inspector/test/head.js */ 6 7 "use strict"; 8 9 // Test that the arrows/handlers and offsetparent and currentnode elements of 10 // the geometry highlighter only appear when needed. 11 12 const TEST_URL = URL_ROOT + "doc_inspector_highlighter-geometry_02.html"; 13 const ID = "geometry-editor-"; 14 const { TYPES } = ChromeUtils.importESModule( 15 "resource://devtools/shared/highlighters.mjs" 16 ); 17 const HIGHLIGHTER_TYPE = TYPES.GEOMETRY; 18 19 const TEST_DATA = [ 20 { 21 selector: "body", 22 isOffsetParentVisible: false, 23 isCurrentNodeVisible: false, 24 hasVisibleArrowsAndHandlers: false, 25 }, 26 { 27 selector: "h1", 28 isOffsetParentVisible: false, 29 isCurrentNodeVisible: false, 30 hasVisibleArrowsAndHandlers: false, 31 }, 32 { 33 selector: ".absolute", 34 isOffsetParentVisible: false, 35 isCurrentNodeVisible: true, 36 hasVisibleArrowsAndHandlers: true, 37 }, 38 { 39 selector: "#absolute-container", 40 isOffsetParentVisible: false, 41 isCurrentNodeVisible: true, 42 hasVisibleArrowsAndHandlers: false, 43 }, 44 { 45 selector: ".absolute-bottom-right", 46 isOffsetParentVisible: true, 47 isCurrentNodeVisible: true, 48 hasVisibleArrowsAndHandlers: true, 49 }, 50 { 51 selector: ".absolute-width-margin", 52 isOffsetParentVisible: true, 53 isCurrentNodeVisible: true, 54 hasVisibleArrowsAndHandlers: true, 55 }, 56 { 57 selector: ".absolute-all-4", 58 isOffsetParentVisible: true, 59 isCurrentNodeVisible: true, 60 hasVisibleArrowsAndHandlers: true, 61 }, 62 { 63 selector: ".relative", 64 isOffsetParentVisible: true, 65 isCurrentNodeVisible: true, 66 hasVisibleArrowsAndHandlers: true, 67 }, 68 { 69 selector: ".static", 70 isOffsetParentVisible: false, 71 isCurrentNodeVisible: false, 72 hasVisibleArrowsAndHandlers: false, 73 }, 74 { 75 selector: ".static-size", 76 isOffsetParentVisible: false, 77 isCurrentNodeVisible: true, 78 hasVisibleArrowsAndHandlers: false, 79 }, 80 { 81 selector: ".fixed", 82 isOffsetParentVisible: false, 83 isCurrentNodeVisible: true, 84 hasVisibleArrowsAndHandlers: true, 85 }, 86 ]; 87 88 add_task(async function () { 89 const helper = await openInspectorForURL(TEST_URL).then( 90 getHighlighterHelperFor(HIGHLIGHTER_TYPE) 91 ); 92 93 helper.prefix = ID; 94 95 const { hide, finalize } = helper; 96 97 for (const data of TEST_DATA) { 98 await testNode(helper, data); 99 } 100 101 info("Hiding the highlighter"); 102 await hide(); 103 await finalize(); 104 }); 105 106 async function testNode(helper, data) { 107 const { selector } = data; 108 await helper.show(data.selector); 109 110 is( 111 await isOffsetParentVisible(helper), 112 data.isOffsetParentVisible, 113 "The offset-parent highlighter visibility is correct for node " + selector 114 ); 115 is( 116 await isCurrentNodeVisible(helper), 117 data.isCurrentNodeVisible, 118 "The current-node highlighter visibility is correct for node " + selector 119 ); 120 is( 121 await hasVisibleArrowsAndHandlers(helper), 122 data.hasVisibleArrowsAndHandlers, 123 "The arrows visibility is correct for node " + selector 124 ); 125 } 126 127 async function isOffsetParentVisible({ isElementHidden }) { 128 return !(await isElementHidden("offset-parent")); 129 } 130 131 async function isCurrentNodeVisible({ isElementHidden }) { 132 return !(await isElementHidden("current-node")); 133 } 134 135 async function hasVisibleArrowsAndHandlers({ isElementHidden }) { 136 for (const side of ["top", "left", "bottom", "right"]) { 137 const hidden = await isElementHidden("arrow-" + side); 138 if (!hidden) { 139 return !(await isElementHidden("handler-" + side)); 140 } 141 } 142 return false; 143 }