blob: 7c9245d811b8e49390dee22469d427c77995ab7f [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test() {
let suite = InspectorTest.createAsyncSuite("WI.incrementElementValue");
suite.addTestCase({
name: "incrementElementValue.numeric",
description: "Ensure that WI.incrementElementValue increments and decrements a numeric value.",
test(resolve, reject) {
let span = document.createElement("span");
span.contentEditable = true;
span.textContent = "font-size: 10px;";
document.body.append(span);
let selection = window.getSelection();
let textNode = span.firstChild;
selection.setBaseAndExtent(textNode, "font-size: ".length, textNode, "font-size: 10px".length);
WI.incrementElementValue(span, 0.1);
InspectorTest.expectEqual(span.textContent, "font-size: 10.1px;", `Should increment by 0.1.`);
WI.incrementElementValue(span, -1);
InspectorTest.expectEqual(span.textContent, "font-size: 9.1px;", `Should decrement by 1.`);
WI.incrementElementValue(span, 10);
InspectorTest.expectEqual(span.textContent, "font-size: 19.1px;", `Should increment by 10.`);
WI.incrementElementValue(span, -100);
InspectorTest.expectEqual(span.textContent, "font-size: -80.9px;", `Should decrement by 100.`);
resolve();
}
});
suite.addTestCase({
name: "incrementElementValue.nonNumeric",
description: "Ensure that WI.incrementElementValue does not change non-numeric values.",
test(resolve, reject) {
let span = document.createElement("span");
span.contentEditable = true;
span.textContent = "background-color";
document.body.append(span);
let selection = window.getSelection();
let textNode = span.firstChild;
selection.setBaseAndExtent(textNode, "background".length, textNode, "background-".length);
WI.incrementElementValue(span, 1);
InspectorTest.expectEqual(span.textContent, "background-color", `Text should not change.`);
resolve();
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Testing that WI.incrementElementValue works for numeric values.</p>
</body>
</html>