browser_inspector_highlighter-rulers_01.js (3557B)
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 the creation of the geometry highlighter elements. 8 9 const TEST_URL = 10 "data:text/html;charset=utf-8," + 11 "<div style='position:absolute;left: 0; top: 0; " + 12 "width: 40000px; height: 8000px'></div>"; 13 14 const ID = "rulers-highlighter-"; 15 16 // Maximum size, in pixel, for the horizontal ruler and vertical ruler 17 // used by RulersHighlighter 18 const RULERS_MAX_X_AXIS = 10000; 19 const RULERS_MAX_Y_AXIS = 15000; 20 // Number of steps after we add a text in RulersHighliter; 21 // currently the unit is in pixel. 22 const RULERS_TEXT_STEP = 100; 23 24 const { TYPES } = ChromeUtils.importESModule( 25 "resource://devtools/shared/highlighters.mjs" 26 ); 27 28 add_task(async function () { 29 const { inspector, highlighterTestFront } = 30 await openInspectorForURL(TEST_URL); 31 const front = inspector.inspectorFront; 32 33 const highlighter = await front.getHighlighterByType(TYPES.RULERS); 34 35 await isHiddenByDefault(highlighter, inspector, highlighterTestFront); 36 await isVisibleAfterShow(highlighter, inspector, highlighterTestFront); 37 await hasRightLabelsContent(highlighter, inspector, highlighterTestFront); 38 await isHiddenAfterHide(highlighter, inspector, highlighterTestFront); 39 40 await highlighter.finalize(); 41 }); 42 43 async function isHiddenByDefault( 44 highlighterFront, 45 inspector, 46 highlighterTestFront 47 ) { 48 info("Checking the highlighter is hidden by default"); 49 50 const hidden = await isRulerHidden(highlighterFront, highlighterTestFront); 51 ok(hidden, "highlighter is hidden by default"); 52 } 53 54 async function isVisibleAfterShow( 55 highlighterFront, 56 inspector, 57 highlighterTestFront 58 ) { 59 info("Checking the highlighter is displayed when asked"); 60 // the rulers doesn't need any node, but as highligher it seems mandatory 61 // ones, so the body is given 62 const body = await getNodeFront("body", inspector); 63 await highlighterFront.show(body); 64 65 const hidden = await isRulerHidden(highlighterFront, highlighterTestFront); 66 ok(!hidden, "highlighter is visible after show"); 67 } 68 69 async function isHiddenAfterHide( 70 highlighterFront, 71 inspector, 72 highlighterTestFront 73 ) { 74 info("Checking that the highlighter is hidden after disabling it"); 75 await highlighterFront.hide(); 76 77 const hidden = await isRulerHidden(highlighterFront, highlighterTestFront); 78 ok(hidden, "highlighter is hidden"); 79 } 80 81 async function hasRightLabelsContent( 82 highlighterFront, 83 inspector, 84 highlighterTestFront 85 ) { 86 info("Checking the rulers have the proper text, based on rulers' size"); 87 88 const contentX = await highlighterTestFront.getHighlighterNodeTextContent( 89 `${ID}x-axis-text`, 90 highlighterFront 91 ); 92 const contentY = await highlighterTestFront.getHighlighterNodeTextContent( 93 `${ID}y-axis-text`, 94 highlighterFront 95 ); 96 97 let expectedX = ""; 98 for (let i = RULERS_TEXT_STEP; i < RULERS_MAX_X_AXIS; i += RULERS_TEXT_STEP) { 99 expectedX += i; 100 } 101 102 is(contentX, expectedX, "x axis text content is correct"); 103 104 let expectedY = ""; 105 for (let i = RULERS_TEXT_STEP; i < RULERS_MAX_Y_AXIS; i += RULERS_TEXT_STEP) { 106 expectedY += i; 107 } 108 109 is(contentY, expectedY, "y axis text content is correct"); 110 } 111 112 async function isRulerHidden(highlighterFront, highlighterTestFront) { 113 const hidden = await highlighterTestFront.getHighlighterNodeAttribute( 114 ID + "elements", 115 "hidden", 116 highlighterFront 117 ); 118 return hidden === "true"; 119 }