Commit 1beb3de2 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Untentative CSSPositionValue tests.

We untentative CSSPositionValue tests. We also split happy and sad tests

Spec: https://drafts.css-houdini.org/css-typed-om-1/#positionvalue-objects

TBR=nainar@chromium.org

Bug: 774887
Change-Id: I33052e0dc6400f5de693da9449d769012919dee3
Reviewed-on: https://chromium-review.googlesource.com/894748Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533204}
parent 101743db
<!doctype html>
<meta charset="utf-8">
<title>CSSPositionValue Error Handling</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#positionvalue-objects">
<meta name="assert" content="Test CSSPositionValue constructor and attributes error handling" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="log">
<script>
'use strict';
const gTestArguments = [
{
description: 'a keyword',
value: 'auto',
},
{
description: 'a double',
value: 3.14,
},
{
description: 'a unitless zero',
value: 0,
},
{
description: 'a string length',
value: '10px',
},
{
description: 'a number CSSUnitValue',
value: CSS.number(10),
},
{
description: 'a time CSSUnitValue',
value: CSS.s(10),
},
{
description: 'a CSSMathValue of angle type',
value: new CSSMathSum(CSS.deg(1)),
},
];
for (const {value, description} of gTestArguments) {
test(() => {
assert_throws(new TypeError(), () => new CSSPositionValue(value, CSS.px(0)));
assert_throws(new TypeError(), () => new CSSPositionValue(CSS.px(0), value));
}, `Constructing a CSSPositionValue with ${description} throws a TypeError`);
test(() => {
let position = new CSSPositionValue(CSS.px(0), CSS.px(0));
assert_throws(new TypeError(), () => position.x = value);
assert_equals(position.x.value, 0,
'X member should not have changed');
}, `Updating CSSPositionValue.x with ${description} throws a TypeError`);
test(() => {
let position = new CSSPositionValue(CSS.px(0), CSS.px(0));
assert_throws(new TypeError(), () => position.y = value);
assert_equals(position.y.value, 0,
'Y member should not have changed');
}, `Updating CSSPositionValue.y with ${description} throws a TypeError`);
}
</script>
<!doctype html>
<meta charset="utf-8">
<title>CSSPositionValue</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#positionvalue-objects">
<meta name="assert" content="Test CSSPositionValue constructor and attributes" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/testhelper.js"></script>
<body>
<div id="log">
<script>
'use strict';
const gTestArguments = [
{
description: 'a length CSSUnitValue' ,
value: CSS.px(1),
},
{
description: 'a percent CSSUnitValue' ,
value: CSS.percent(10),
},
{
description: 'a CSSMathValue of length type' ,
value: new CSSMathSum(CSS.px(1)),
},
{
description: 'a CSSMathValue of percent type' ,
value: new CSSMathSum(CSS.percent(1)),
},
];
for (const {value, description} of gTestArguments) {
test(() => {
const position = new CSSPositionValue(value, value);
assert_style_value_equals(position.x, value,
'X member should be same as passed in constructor');
assert_style_value_equals(position.y, value,
'Y member should be same as passed in constructor');
}, 'CSSPositionValue can be constructed from ' + description);
}
for (const {value, description} of gTestArguments) {
test(() => {
let position = new CSSPositionValue(CSS.px(0), CSS.px(0));
position.x = value;
assert_style_value_equals(position.x, value,
'X member should be updated to new value');
}, 'CSSPositionValue.x can be updated to ' + description);
test(() => {
let position = new CSSPositionValue(CSS.px(0), CSS.px(0));
position.y = value;
assert_style_value_equals(position.y, value,
'Y member should be updated to new value');
}, 'CSSPositionValue.y can be updated to ' + description);
}
</script>
<!doctype html>
<meta charset="utf-8">
<title>CSSPositionValue tests</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#positionvalue-objects">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/testhelper.js"></script>
<script>
'use strict';
const gInvalidTestCases = [
{ value: 'auto', desc: 'a keyword'},
{ value: 10, desc: 'a double'},
{ value: 0, desc: 'a unitless zero'},
{ value: '10px', desc: 'a string length'},
{ value: CSS.number(10), desc: 'a number CSSUnitValue'},
{ value: CSS.s(10), desc: 'a time dimension CSSUnitValue'},
{ value: new CSSMathSum(CSS.deg(1)), desc: 'a CSSMathValue of angle type' },
];
for (const {value, desc} of gInvalidTestCases) {
test(() => {
assert_throws(new TypeError(), () => new CSSPositionValue(value, CSS.px(0)));
assert_throws(new TypeError(), () => new CSSPositionValue(CSS.px(0), value));
}, 'Constructing a CSSPositionValue with ' + desc + ' throws a TypeError');
}
for (const attr of ['x', 'y']) {
for (const {value, desc} of gInvalidTestCases) {
test(() => {
const position = new CSSPositionValue(CSS.px(0), CSS.px(0));
assert_throws(new TypeError(), () => position[attr] = value);
assert_style_value_equals(position[attr], CSS.px(0));
}, 'Updating CSSPositionValue.' + attr + ' with ' + desc + ' throws a TypeError');
}
}
const gValidTestCases = [
{ value: CSS.px(1), desc: 'a length CSSUnitValue' },
{ value: CSS.percent(10), desc: 'a percent CSSUnitValue' },
{ value: new CSSMathSum(CSS.px(1)), desc: 'a CSSMathValue of length type' },
{ value: new CSSMathSum(CSS.percent(1)), desc: 'a CSSMathValue of percent type' },
];
for (const {value: x, desc: xDesc} of gValidTestCases) {
for (const {value: y, desc: yDesc} of gValidTestCases) {
test(() => {
const position = new CSSPositionValue(x, y);
assert_equals(position.x, x);
assert_equals(position.y, y);
}, 'CSSPositionValue can be constructed from ' + xDesc + ' and ' + yDesc);
}
}
for (const attr of ['x', 'y']) {
for (const {value, desc} of gValidTestCases) {
test(() => {
const position = new CSSPositionValue(CSS.px(0), CSS.px(0));
position[attr] = value;
assert_style_value_equals(position[attr], value);
}, 'CSSPositionValue.' + attr + ' can be updated to ' + desc);
}
}
</script>
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