/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Globals defined in: devtools/client/inspector/test/head.js */ "use strict"; // Test that the geometry highlighter labels are correct. const TEST_URL = `data:text/html;charset=utf-8,
test element
relative
`; const ID = "geometry-editor-"; const HIGHLIGHTER_TYPE = "GeometryEditorHighlighter"; const POSITIONED_ELEMENT_TESTS = [ { selector: "#positioned", expectedLabels: [ { side: "left", visible: true, label: "5rem" }, { side: "top", visible: true, label: "30px" }, { side: "right", visible: true, label: "300px" }, { side: "bottom", visible: true, label: "10em" }, ], }, { selector: "#positioned2", expectedLabels: [ { side: "left", visible: false }, { side: "top", visible: true, label: "5vmin" }, { side: "right", visible: true, label: "10%" }, { side: "bottom", visible: false }, ], }, { selector: "#relative", expectedLabels: [ { side: "left", visible: true, label: "20px" }, { side: "top", visible: true, label: "10px" }, { side: "right", visible: false }, { side: "bottom", visible: false }, ], }, { selector: "#relative2", expectedLabels: [ { side: "left", visible: false }, { side: "top", visible: true, label: "0px" }, { side: "right", visible: false }, { side: "bottom", visible: false }, ], }, ]; add_task(async function () { const helper = await openInspectorForURL(TEST_URL).then( getHighlighterHelperFor(HIGHLIGHTER_TYPE) ); helper.prefix = ID; const { finalize } = helper; await positionLabelsAreCorrect(helper); await finalize(); }); async function positionLabelsAreCorrect({ show, hide, isElementHidden, getElementTextContent, }) { info("Highlight nodes and check position labels"); for (const { selector, expectedLabels } of POSITIONED_ELEMENT_TESTS) { info("Testing node " + selector); await show(selector); for (const { side, visible, label } of expectedLabels) { const id = "label-" + side; const hidden = await isElementHidden(id); if (visible) { ok(!hidden, "The " + side + " label is visible"); const value = await getElementTextContent(id); is(value, label, "The " + side + " label textcontent is correct"); } else { ok(hidden, "The " + side + " label is hidden"); } } info("Hiding the highlighter"); await hide(); } }