mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Update web-platform-tests to revision 84af6c875d378944b39d895acdcfc170736b2d3d
This commit is contained in:
parent
d0bd2d5e44
commit
b81cdc75ce
246 changed files with 10836 additions and 1337 deletions
|
@ -0,0 +1,180 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>Test handling of attributes that map to dimension properties</title>
|
||||
<link rel="help"
|
||||
href="https://html.spec.whatwg.org/multipage/rendering.html#maps-to-the-dimension-property">
|
||||
<link rel="help"
|
||||
href="https://html.spec.whatwg.org/multipage/rendering.html#maps-to-the-dimension-property-(ignoring-zero)">
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<body>
|
||||
<!-- We need a place to put our elements so they're bound to a document and
|
||||
have computed style, but we don't want percentages resolved to lengths,
|
||||
so need to make sure they have no CSS boxes -->
|
||||
<div id="container" style="display: none"></div>
|
||||
<script>
|
||||
/*
|
||||
* This test tests
|
||||
*
|
||||
* https://html.spec.whatwg.org/multipage/rendering.html#maps-to-the-dimension-property
|
||||
* and
|
||||
* https://html.spec.whatwg.org/multipage/rendering.html#maps-to-the-dimension-property-(ignoring-zero)
|
||||
* for various elements and various values.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Array of input/output pairs. The input is the string to use as the
|
||||
* attribute value. The output is the string expected as the computed style
|
||||
* for the relevant CSS property.
|
||||
*/
|
||||
const valid_values = [
|
||||
// Valid values
|
||||
[ "200", "200px" ],
|
||||
[ "1007", "1007px" ],
|
||||
[ " 00523 ", "523px" ],
|
||||
[ "200.25", "200.25px" ],
|
||||
[ "200.", "200px" ],
|
||||
[ "+200", "200px" ],
|
||||
[ "200in", "200px" ],
|
||||
[ "200.25in", "200.25px" ],
|
||||
[ " +200in ", "200px" ],
|
||||
[ " +200.25in ", "200.25px" ],
|
||||
[ "200 %", "200px" ],
|
||||
[ "200 abc", "200px" ],
|
||||
[ "200%", "200%" ],
|
||||
[ "200%abc", "200%" ],
|
||||
[ "+200%", "200%" ],
|
||||
[ "200.25%", "200.25%" ],
|
||||
// https://github.com/whatwg/html/issues/4736 tracks the fact that "200.%"
|
||||
// should probably be mapped as "200%", not "200px".
|
||||
[ "200.%", "200px" ],
|
||||
[ " +200.25% ", "200.25%" ],
|
||||
[ " +200.25%abc", "200.25%" ],
|
||||
];
|
||||
|
||||
/*
|
||||
* Values that are only valid for the not-ignoring-zero case.
|
||||
*/
|
||||
const zero_values = [
|
||||
[ "0", "0px" ],
|
||||
[ "+0", "0px" ],
|
||||
[ "0%", "0%" ],
|
||||
[ "+0%", "0%" ],
|
||||
[ "0px", "0px" ],
|
||||
];
|
||||
|
||||
/*
|
||||
* Array of invalid values. These should lead to the default value of the
|
||||
* relevant CSS property.
|
||||
*/
|
||||
const invalid_values = [
|
||||
"-0",
|
||||
"-0%",
|
||||
"-200",
|
||||
"-200px",
|
||||
" -200",
|
||||
"+-200",
|
||||
"-+200",
|
||||
"-200%"
|
||||
];
|
||||
|
||||
const valid_values_with_0 =
|
||||
valid_values.concat(zero_values);
|
||||
const invalid_values_with_0 =
|
||||
invalid_values.concat(zero_values.map((v) => v[0]));
|
||||
|
||||
function newElem(name) {
|
||||
return () => document.createElement(name);
|
||||
}
|
||||
|
||||
function newImageInput() {
|
||||
return () => {
|
||||
var elem = newElem("input")();
|
||||
elem.type = "image";
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Array of tests. Each test consists of the following information:
|
||||
*
|
||||
* 1) An element creation function.
|
||||
* 2) The name of the attribute to set (and CSS property to get).
|
||||
* 3) A boolean indicating whether 0 is a valid value for the dimension
|
||||
* attribute.
|
||||
*/
|
||||
const tests = [
|
||||
[ newElem("hr"), "width", true ],
|
||||
[ newElem("iframe"), "width", true ],
|
||||
[ newElem("iframe"), "height", true ],
|
||||
[ newImageInput(), "width", true ],
|
||||
[ newImageInput(), "height", true ],
|
||||
[ newElem("marquee"), "width", true ],
|
||||
[ newElem("marquee"), "height", true ],
|
||||
[ newElem("video"), "width", true ],
|
||||
[ newElem("video"), "height", true ],
|
||||
[ newElem("object"), "width", true ],
|
||||
[ newElem("object"), "height", true ],
|
||||
[ newElem("embed"), "width", true ],
|
||||
[ newElem("embed"), "height", true ],
|
||||
[ newElem("img"), "width", true ],
|
||||
[ newElem("img"), "height", true ],
|
||||
[ newElem("td"), "width", false ],
|
||||
[ newElem("td"), "height", false ],
|
||||
// https://github.com/whatwg/html/issues/4715 tracks the fact that for
|
||||
// <table width> and <table height> the "0 is valid" boolean should probably
|
||||
// be true.
|
||||
[ newElem("table"), "width", false ],
|
||||
[ newElem("table"), "height", false ],
|
||||
// https://github.com/whatwg/html/issues/4716 tracks the fact that for the
|
||||
// <tr height> case that "0 is valid" boolean should probably be true.
|
||||
[ newElem("tr"), "height", false ],
|
||||
// https://github.com/whatwg/html/issues/4717 tracks the fact that for the
|
||||
// <col width> case that "0 is valid" boolean should probably be true.
|
||||
[ newElem("col"), "width", false ],
|
||||
];
|
||||
|
||||
|
||||
function style(element) {
|
||||
return element.ownerDocument.defaultView.getComputedStyle(element);
|
||||
}
|
||||
|
||||
const container = document.getElementById("container");
|
||||
|
||||
for (let [ctor, attr, zero_allowed] of tests) {
|
||||
let valid, invalid;
|
||||
if (zero_allowed) {
|
||||
valid = valid_values_with_0;
|
||||
invalid = invalid_values;
|
||||
} else {
|
||||
valid = valid_values;
|
||||
invalid = invalid_values_with_0;
|
||||
}
|
||||
for (let [value, result] of valid) {
|
||||
let elem = ctor();
|
||||
test(function() {
|
||||
this.add_cleanup(() => elem.remove());
|
||||
elem.setAttribute(attr, value);
|
||||
assert_equals(elem.getAttribute(attr), value);
|
||||
container.appendChild(elem);
|
||||
assert_equals(style(elem)[attr], result);
|
||||
}, `<${elem.localName} ${attr}="${value}"> mapping`);
|
||||
}
|
||||
|
||||
let default_elem = ctor();
|
||||
container.appendChild(default_elem);
|
||||
let defaultVal = style(default_elem)[attr];
|
||||
default_elem.remove();
|
||||
for (let value of invalid) {
|
||||
let elem = ctor();
|
||||
test(function() {
|
||||
this.add_cleanup(() => elem.remove());
|
||||
elem.setAttribute(attr, value);
|
||||
assert_equals(elem.getAttribute(attr), value);
|
||||
container.appendChild(elem);
|
||||
assert_equals(style(elem)[attr], defaultVal);
|
||||
}, `<${elem.localName} ${attr}="${value}"> mapping`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue