/* 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(function* () {
let helper = yield openInspectorForURL(TEST_URL)
.then(getHighlighterHelperFor(HIGHLIGHTER_TYPE));
helper.prefix = ID;
let { finalize } = helper;
yield positionLabelsAreCorrect(helper);
yield finalize();
});
function* positionLabelsAreCorrect(
{show, hide, isElementHidden, getElementTextContent}
) {
info("Highlight nodes and check position labels");
for (let {selector, expectedLabels} of POSITIONED_ELEMENT_TESTS) {
info("Testing node " + selector);
yield show(selector);
for (let {side, visible, label} of expectedLabels) {
let id = "label-" + side;
let hidden = yield isElementHidden(id);
if (visible) {
ok(!hidden, "The " + side + " label is visible");
let value = yield getElementTextContent(id);
is(value, label, "The " + side + " label textcontent is correct");
} else {
ok(hidden, "The " + side + " label is hidden");
}
}
info("Hiding the highlighter");
yield hide();
}
}