Commit 9a4cbea6 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Add per-property tests.

Currently, we don't have any test coverage over properties. In our
existing tests, we only use 'canonical' test properties like 'width'.
This means that it's possible that other properties (e.g. 'height')
might not work and we still pass the tests.

We add a bunch of new files, each representing a property. Think of
these as metadata for the properties. For example, each file contains
the values that are valid for that property. We then have a test suite
that uses this metadata to generate appropriate tests.

More properties will be coming.

There is a test failure involving setting margin-top to unitless zero.

Bug: 774887
Change-Id: I8f8463c8f608454ef177e81ace21fe1eeb66f897
Reviewed-on: https://chromium-review.googlesource.com/882901
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarnainar <nainar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534623}
parent 611472bd
<!doctype html>
<meta charset="utf-8">
<title>'display' property</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-get">
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-set">
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#property-stle-value-normalization">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<script src="resources/testsuite.js"></script>
<body>
<div id="log">
<script>
'use strict';
runPropertyTests('display', [
{
specified: '<ident>',
examples: [new CSSKeywordValue('none'), new CSSKeywordValue('block')]
},
]);
</script>
This is a testharness.js-based test.
FAIL Can set 'margin-top' to unitless zero Failed to execute 'set' on 'StylePropertyMap': Invalid type for property
PASS Can get a CSSKeywordValue from 'margin-top'
FAIL Can set 'margin-top' to a CSSKeywordValue Failed to execute 'set' on 'StylePropertyMap': Invalid type for property
PASS Can get a percent CSSUnitValue from 'margin-top'
PASS Can set 'margin-top' to a percent CSSUnitValue
PASS Can get a length CSSUnitValue from 'margin-top'
PASS Can set 'margin-top' to a length CSSUnitValue
Harness: the test ran to completion.
<!doctype html>
<meta charset="utf-8">
<title>'margin-top' property</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-get">
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-set">
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#property-stle-value-normalization">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<script src="resources/testsuite.js"></script>
<body>
<div id="log">
<script>
'use strict';
runPropertyTests('margin-top', [
{ specified: '0' },
{ specified: '<ident>', examples: [new CSSKeywordValue('auto')] },
{ specified: '<percentage>' },
{ specified: '<length>' },
]);
</script>
function testGet(propertyName, values, description) {
test(t => {
let element = createDivWithStyle(t);
let styleMap = element.attributeStyleMap;
for (const styleValue of values) {
element.style[propertyName] = styleValue.toString();
getComputedStyle(element); // Force a style recalc.
const result = styleMap.get(propertyName);
assert_style_value_equals(result, styleValue);
}
}, `Can get ${description} from '${propertyName}'`);
}
function testSet(propertyName, values, description) {
test(t => {
let element = createDivWithStyle(t);
let styleMap = element.attributeStyleMap;
for (const styleValue of values) {
styleMap.set(propertyName, styleValue);
getComputedStyle(element); // Force a style recalc.
assert_equals(element.style[propertyName], styleValue.toString());
}
}, `Can set '${propertyName}' to ${description}`);
}
function testGetSet(propertyName, values, description) {
testGet(propertyName, values, description);
testSet(propertyName, values, description);
}
function runPropertyTests(propertyName, testCases) {
for (const testCase of testCases) {
if (testCase.specified == '0') {
testSet(propertyName, [
new CSSUnitValue(0, 'number'),
], 'unitless zero');
} else if (testCase.specified === '<length>') {
testGetSet(propertyName, [
new CSSUnitValue(0, 'px'),
new CSSUnitValue(-3.14, 'em'),
new CSSUnitValue(3.14, 'cm'),
], 'a length CSSUnitValue');
} else if (testCase.specified == '<percentage>') {
testGetSet(propertyName, [
new CSSUnitValue(0, 'percent'),
new CSSUnitValue(-3.14, 'percent'),
new CSSUnitValue(3.14, 'percent'),
], 'a percent CSSUnitValue');
} else if (testCase.specified == '<ident>') {
if (!testCase.examples) {
throw new Error('<ident> tests require examples');
}
testGetSet(propertyName, testCase.examples,
'a CSSKeywordValue');
}
}
}
......@@ -1703,6 +1703,7 @@
field_template: "<length>",
default_value: "Length(kFixed)",
converter: "ConvertQuirkyLength",
typedom_types: ["Length", "Percent"]
},
{
name: "marker-end",
......
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