Skip to content

Commit

Permalink
[css-typed-om] Ensure properties works with css-wide keywords / var refs
Browse files Browse the repository at this point in the history
There are two things that should always be supported with any property:
- css-wide keywords like 'initial'
- var refs like 'var(--A)'

This patch adds tests to ensure that this works for all the different
types of properties. Unfortunately, supporting this in shorthands
is quite difficult (we get shorthands as strings, so to reify them
we have to parse, but we can't parse in reification) so we'll leave
that for the future.

Bug: 816722
Change-Id: I1d344b73d011db81cfc3880be54823302534fd36
Reviewed-on: https://chromium-review.googlesource.com/942121
Commit-Queue: Darren Shen <[email protected]>
Reviewed-by: nainar <[email protected]>
Cr-Commit-Position: refs/heads/master@{#540055}
  • Loading branch information
darrnshn authored and chromium-wpt-export-bot committed Mar 1, 2018
1 parent 66ffd92 commit 9c3df0e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<meta charset="utf-8">
<title>Normalization of raw CSS tokens tests</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#normalize-tokens">
<script src="//resources/testharness.js"></script>
<script src="//resources/testharnessreport.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/testhelper.js"></script>
<body>
<script>
Expand Down Expand Up @@ -55,6 +55,15 @@
assert_string_normalizes_to(t, 'color', value, new CSSUnparsedValue(expectedResult));
}, 'Normalizing "' + value + '" on a CSS property returns correct CSSUnparsedValue');

test(t => {
assert_string_normalizes_to(t, 'margin', value, new CSSUnparsedValue(expectedResult));
assert_false(true);
}, 'Normalizing "' + value + '" on a shorthand returns correct CSSUnparsedValue');

test(t => {
assert_string_normalizes_to(t, 'transition-duration', value, new CSSUnparsedValue(expectedResult));
}, 'Normalizing "' + value + '" on a list-valued property returns correct CSSUnparsedValue');

test(t => {
assert_string_normalizes_to(t, '--X', value, new CSSUnparsedValue(expectedResult));
}, 'Normalizing "' + value + '" on a custom property returns correct CSSUnparsedValue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script>
'use strict';

runPropertyTests('background', []);
runUnsupportedPropertyTests('background', [
'green', 'content-box radial-gradient(crimson, skyblue)',
'no-repeat url("http://foo.com")',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
]);
}

runPropertyTests('margin', []);
runUnsupportedPropertyTests('margin',
['1px', '1px 2px 3px 4px']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const gCssWideKeywordsExamples = [
},
];

const gVarReferenceExamples = [
{
description: 'a var() reference',
input: new CSSUnparsedValue([' ', new CSSVariableReferenceValue('--A')])
},
];

const gTestSyntaxExamples = {
'<length>': {
description: 'a length',
Expand Down Expand Up @@ -329,6 +336,13 @@ function runPropertyTests(propertyName, testCases) {
() => {}, // could be anything
'CSS-wide keywords');

// Every property should support values containing var() references.
testPropertyValid(propertyName,
gVarReferenceExamples,
null, // should be as specified
() => {}, // could compute to anything
'var() references');

for (const testCase of testCases) {
// <image> is a special case
if (testCase.syntax === '<image>') {
Expand Down

0 comments on commit 9c3df0e

Please sign in to comment.