Commit 3ab9404e authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

The empty string is a not a valid <length> for SVGLength

SVGLength::SetValueAsString was allowing "" to "reset" the value without
signaling an error. Because of how the handling of removeAttribute works
we can't shut down this entirely, but still need to handle the null
string resulting from that.

Convert svg/custom/invalid-length-units.html to testharness.js. (This
test had one item for "" and " ".)

Bug: 779454
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I055b77b07d833a252b325df8fc1a908271c86005
Reviewed-on: https://chromium-review.googlesource.com/746707Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#512871}
parent 64946f11
......@@ -90,6 +90,12 @@ test(function() {
assert_equals(length.valueInSpecifiedUnits, 2);
assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
assert_throws("SyntaxError", function() { length.valueAsString = ''; });
assert_equals(length.valueAsString, "2px");
assert_equals(length.value, 2);
assert_equals(length.valueInSpecifiedUnits, 2);
assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
// Check setting invalid 'value' arguments.
assert_throws(new TypeError(), function() { length.value = NaN; });
assert_throws(new TypeError(), function() { length.value = Infinity; });
......@@ -104,4 +110,4 @@ test(function() {
assert_equals(length.valueInSpecifiedUnits, 2);
assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
});
</script>
\ No newline at end of file
</script>
CONSOLE ERROR: line 1: Error: <rect> attribute x: Expected length, " ".
CONSOLE ERROR: line 1: Error: <rect> attribute x: Expected length, "foo".
CONSOLE ERROR: line 1: Error: <rect> attribute x: Expected length, "10foo".
CONSOLE ERROR: line 1: Error: <rect> attribute x: Expected length, "px".
CONSOLE ERROR: line 1: Error: <rect> attribute x: Expected length, "10 % ".
CONSOLE ERROR: line 1: Error: <rect> attribute x: Expected length, "10 %".
CONSOLE ERROR: line 1: Error: <rect> attribute x: Expected length, "10 px ".
CONSOLE ERROR: line 1: Error: <rect> attribute x: Expected length, "10 px".
Tests handling of invalid SVG length units.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS rect.setAttribute('x', ''); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', ' '); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', 'foo'); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', '10foo'); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', 'px'); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', '10px '); rect.x.baseVal.valueAsString is '10px'
PASS rect.setAttribute('x', '10% '); rect.x.baseVal.valueAsString is '10%'
PASS rect.setAttribute('x', '10 % '); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', '10 %'); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', '10 px '); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', '10 px'); rect.x.baseVal.valueAsString is '0'
PASS rect.setAttribute('x', '10'); rect.x.baseVal.valueAsString is '10'
PASS rect.setAttribute('x', '10%'); rect.x.baseVal.valueAsString is '10%'
PASS rect.setAttribute('x', '10em'); rect.x.baseVal.valueAsString is '10em'
PASS rect.setAttribute('x', '10ex'); rect.x.baseVal.valueAsString is '10ex'
PASS rect.setAttribute('x', '10px'); rect.x.baseVal.valueAsString is '10px'
PASS rect.setAttribute('x', '10cm'); rect.x.baseVal.valueAsString is '10cm'
PASS rect.setAttribute('x', '10mm'); rect.x.baseVal.valueAsString is '10mm'
PASS rect.setAttribute('x', '10pt'); rect.x.baseVal.valueAsString is '10pt'
PASS rect.setAttribute('x', '10pc'); rect.x.baseVal.valueAsString is '10pc'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script src="script-tests/invalid-length-units.js"></script>
</body>
</html>
<!DOCTYPE html>
<title>Invalid SVG length units</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<svg height="0"><rect/></svg>
<script>
function test_length_value(lengthString, expectedString) {
test(function() {
let rect = document.querySelector('rect');
rect.setAttribute('x', "1234");
rect.setAttribute('x', lengthString);
assert_equals(rect.x.baseVal.valueAsString, expectedString);
}, document.title + ', "' + lengthString + '"');
}
// Invalid
test_length_value("", "0");
test_length_value(" ", "0");
test_length_value("foo", "0");
test_length_value("10foo", "0");
test_length_value("px", "0");
test_length_value("10 % ", "0");
test_length_value("10 %", "0");
test_length_value("10 px ", "0");
test_length_value("10 px", "0");
// Valid
test_length_value("10px ", "10px");
test_length_value("10% ", "10%");
test_length_value("10", "10");
test_length_value("10%", "10%");
test_length_value("10em", "10em");
test_length_value("10ex", "10ex");
test_length_value("10px", "10px");
test_length_value("10cm", "10cm");
test_length_value("10mm", "10mm");
test_length_value("10pt", "10pt");
test_length_value("10pc", "10pc");
</script>
description("Tests handling of invalid SVG length units.");
var svgNS = "http://www.w3.org/2000/svg";
var svgRoot = document.createElementNS(svgNS, "svg");
document.documentElement.appendChild(svgRoot);
rect = document.createElementNS(svgNS, "rect");
svgRoot.appendChild(rect);
function trySettingLength(length, expected)
{
rect.setAttribute('x', "1234");
shouldBe("rect.setAttribute('x', '" + length + "'); rect.x.baseVal.valueAsString", expected);
}
trySettingLength("", "'0'");
trySettingLength(" ", "'0'");
trySettingLength("foo", "'0'");
trySettingLength("10foo", "'0'");
trySettingLength("px", "'0'");
trySettingLength("10px ", "'10px'");
trySettingLength("10% ", "'10%'");
trySettingLength("10 % ", "'0'");
trySettingLength("10 %", "'0'");
trySettingLength("10 px ", "'0'");
trySettingLength("10 px", "'0'");
trySettingLength("10", "'10'");
trySettingLength("10%", "'10%'");
trySettingLength("10em", "'10em'");
trySettingLength("10ex", "'10ex'");
trySettingLength("10px", "'10px'");
trySettingLength("10cm", "'10cm'");
trySettingLength("10mm", "'10mm'");
trySettingLength("10pt", "'10pt'");
trySettingLength("10pc", "'10pc'");
document.documentElement.removeChild(svgRoot);
var successfullyParsed = true;
<!DOCTYPE html>
<title>Empty string length value</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<svg width="" height="">
<rect width="100" height="100" fill="green"/>
</svg>
<script>
test(function() {
let bounds = document.querySelector('svg').getBoundingClientRect();
assert_greater_than(bounds.width, 0);
assert_greater_than(bounds.height, 0);
});
</script>
......@@ -136,7 +136,10 @@ float SVGLength::ScaleByPercentage(float input) const {
}
SVGParsingError SVGLength::SetValueAsString(const String& string) {
if (string.IsEmpty()) {
// TODO(fs): Preferably we wouldn't need to special-case the null
// string (which we'll get for example for removeAttribute.)
// Hopefully work on crbug.com/225807 can help here.
if (string.IsNull()) {
value_ =
CSSPrimitiveValue::Create(0, CSSPrimitiveValue::UnitType::kUserUnits);
return SVGParseStatus::kNoError;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment