Skip to content

Commit

Permalink
[css-typed-om] Update CSSScale tests to follow WPT standards.
Browse files Browse the repository at this point in the history
This patch:
- Moves CSSScale tests to a subfolder containing all the other
  CSSStylevalue subclasses.
- Adds the appropriate meta and link tags.
- Clean up the test code a bit.

Note: Following the WPT guidelines, our test structure closely follows
the spec structure. Therefore, serialization and normalization of
scale values will be done in a separate file as it is a separate
section in the spec.

Spec: https://drafts.css-houdini.org/css-typed-om-1/#dom-cssscale-cssscale
WPT Guidelines: http://web-platform-tests.org/writing-tests/general-guidelines.html

Tests are currently failing because:
1) CSSScale should take numberishes
2) CSSScale should also take CSSMathValues

Bug: 774887
Change-Id: If10a27220d2d7b9e6066950513af958cf2c5cd62
Reviewed-on: https://chromium-review.googlesource.com/768190
Commit-Queue: Darren Shen <[email protected]>
Reviewed-by: meade_UTC10 <[email protected]>
Cr-Commit-Position: refs/heads/master@{#516948}
  • Loading branch information
darrnshn authored and Commit Bot committed Nov 16, 2017
1 parent 63f073a commit dfc102e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 31 deletions.
33 changes: 2 additions & 31 deletions third_party/WebKit/LayoutTests/typedcssom/cssScale.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,6 @@
}
];

for (let params of testParams) {
test(() => {
assert_equals(params.input.x, params.x);
assert_equals(params.input.y, params.y);
assert_equals(params.input.z, params.z);
}, "x, y, and z values are correct for " + params.cssText);
}

for (let params of testParams) {
test(() => {
assert_equals(params.input.is2D, params.is2D);
}, "is2D value is correct for " + params.cssText);
}

for (let params of testParams) {
test(() => {
assert_equals(params.input.toString(), params.cssText);
Expand All @@ -75,18 +61,16 @@
assert_throws(new TypeError(), () => { new CSSScale(1); });
}, "Invalid number of arguments to constructor throws an exception.");

/* FIXME: The spec doesn't say these are invalid.
https://drafts.css-houdini.org/css-typed-om-1/#dom-cssscale-cssscale */
test(() => {
assert_throws(new TypeError(), () => { new CSSScale(NaN, 0); });
assert_throws(new TypeError(), () => { new CSSScale(0, NaN); });
assert_throws(new TypeError(), () => { new CSSScale(NaN, NaN); });
assert_throws(new TypeError(), () => { new CSSScale(Infinity, 0); });
assert_throws(new TypeError(), () => { new CSSScale(-Infinity, 0); });
assert_throws(new TypeError(), () => { new CSSScale("hello", 0); });
assert_throws(new TypeError(), () => { new CSSScale(0, "world"); });
assert_throws(new TypeError(), () => { new CSSScale(undefined, 0); });
assert_throws(new TypeError(), () => { new CSSScale({}, {}); });

assert_throws(new TypeError(), () => { new CSSScale("hello", 0, 0); });
assert_throws(new TypeError(), () => { new CSSScale(0, NaN, 0); });
assert_throws(new TypeError(), () => { new CSSScale(0, Infinity, 0); });
assert_throws(new TypeError(), () => { new CSSScale(0, 0, NaN); });
Expand All @@ -98,9 +82,6 @@
});
assert_throws(new TypeError(), () => { new CSSScale(NaN, undefined, 0); });
assert_throws(new TypeError(), () => { new CSSScale(NaN, 0, NaN); });
assert_throws(new TypeError(), () => { new CSSScale(0, "hello", "world"); });
assert_throws(new TypeError(), () => { new CSSScale(0, {}, {}); });
assert_throws(new TypeError(), () => { new CSSScale({}, {}, {}); });
assert_throws(new TypeError(), () => { new CSSScale(NaN, NaN, NaN); });
}, "Invalid input throws an exception.");

Expand All @@ -119,14 +100,4 @@
}, "asMatrix is constructed correctly for " + params.cssText);
}

test(() => {
var actual = new CSSScale(0, 0, 0);
actual.x = 1;
actual.y = 2;
actual.z = 3;
assert_equals(actual.x, 1);
assert_equals(actual.y, 2);
assert_equals(actual.z, 3);
}, "x, y, z are mutable attributes.");

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is a testharness.js-based test.
PASS Constructing a CSSScale with an angle CSSUnitValue for the coordinates throws a TypeError
FAIL Constructing a CSSScale with a CSSMathValue that doesn't match <number> for the coordinates throws a TypeError assert_throws: function "() => new CSSScale(coord, 0)" did not throw
PASS Updating CSSScale.x to an angle CSSUnitValue throws a TypeError
PASS Updating CSSScale.x to a CSSMathValue that doesn't match <number> throws a TypeError
PASS Updating CSSScale.y to an angle CSSUnitValue throws a TypeError
PASS Updating CSSScale.y to a CSSMathValue that doesn't match <number> throws a TypeError
PASS Updating CSSScale.z to an angle CSSUnitValue throws a TypeError
PASS Updating CSSScale.z to a CSSMathValue that doesn't match <number> throws a TypeError
FAIL CSSScale can be constructed from two number coordinates assert_equals: expected "CSSUnitValue" but got "Number"
FAIL CSSScale can be constructed from three number coordinates assert_equals: expected "CSSUnitValue" but got "Number"
FAIL CSSScale can be constructed from CSSMathValue coordinates assert_equals: expected "CSSMathSum" but got "Number"
FAIL CSSScale.x can be updated to a number assert_equals: expected (object) object "3.14" but got (number) 3.14
FAIL CSSScale.x can be updated to a numberish assert_equals: expected "CSSUnitValue" but got "Number"
FAIL CSSScale.x can be updated to a CSSMathValue assert_equals: expected "CSSMathSum" but got "Number"
FAIL CSSScale.y can be updated to a number assert_equals: expected (object) object "3.14" but got (number) 3.14
FAIL CSSScale.y can be updated to a numberish assert_equals: expected "CSSUnitValue" but got "Number"
FAIL CSSScale.y can be updated to a CSSMathValue assert_equals: expected "CSSMathSum" but got "Number"
FAIL CSSScale.z can be updated to a number assert_equals: expected (object) object "3.14" but got (number) 3.14
FAIL CSSScale.z can be updated to a numberish assert_equals: expected "CSSUnitValue" but got "Number"
FAIL CSSScale.z can be updated to a CSSMathValue assert_equals: expected "CSSMathSum" but got "Number"
PASS Modifying CSSScale.is2D can be updated to true or false
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!doctype html>
<meta charset="utf-8">
<title>CSSScale tests</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#cssscale">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../resources/testhelper.js"></script>
<script>
'use strict';

const gInvalidCoordTestCases = [
{ coord: CSS.deg(1), desc: 'an angle CSSUnitValue'},
{ coord: new CSSMathSum(CSS.px(1)), desc: 'a CSSMathValue that doesn\'t match <number>'},
];

for (const {coord, desc} of gInvalidCoordTestCases) {
test(() => {
assert_throws(new TypeError(), () => new CSSScale(coord, 0));
assert_throws(new TypeError(), () => new CSSScale(0, coord));
assert_throws(new TypeError(), () => new CSSScale(coord, 0, 0));
assert_throws(new TypeError(), () => new CSSScale(0, coord, 0));
assert_throws(new TypeError(), () => new CSSScale(0, 0, coord));
}, 'Constructing a CSSScale with ' + desc + ' for the coordinates throws a TypeError');
}

for (const attr of ['x', 'y', 'z']) {
for (const {value, desc} of gInvalidCoordTestCases) {
test(() => {
let result = new CSSScale(0, 0, 0);
assert_throws(new TypeError(), () => result[attr] = value);
assert_equals(result[attr], 0);
}, 'Updating CSSScale.' + attr + ' to ' + desc + ' throws a TypeError');
}
}

test(() => {
const result = new CSSScale(-3.14, CSS.number(3.14));
assert_style_value_equals(result.x, CSS.number(-3.14));
assert_style_value_equals(result.y, CSS.number(3.14));
assert_style_value_equals(result.z, CSS.number(1));
assert_true(result.is2D);
}, 'CSSScale can be constructed from two number coordinates');

test(() => {
const result = new CSSScale(-3.14, CSS.number(3.14), -3.14);
assert_style_value_equals(result.x, CSS.number(-3.14));
assert_style_value_equals(result.y, CSS.number(3.14));
assert_style_value_equals(result.z, CSS.number(-3.14));
assert_false(result.is2D);
}, 'CSSScale can be constructed from three number coordinates');

test(() => {
const result = new CSSScale(new CSSMathSum(-3.14), new CSSMathMax(3.14), new CSSMathNegate(-3.14));
assert_style_value_equals(result.x, new CSSMathSum(-3.14));
assert_style_value_equals(result.y, new CSSMathMax(3.14));
assert_style_value_equals(result.z, new CSSMathNegate(-3.14));
assert_false(result.is2D);
}, 'CSSScale can be constructed from CSSMathValue coordinates');

for (const attr of ['x', 'y', 'z']) {
test(() => {
let result = new CSSScale(0, 0, 0);
result[attr] = 3.14;
assert_equals(result[attr], CSS.number(3.14));
}, 'CSSScale.' + attr + ' can be updated to a number');

test(() => {
let result = new CSSScale(0, 0, 0);
result[attr] = CSS.number(3.14);
assert_style_value_equals(result[attr], CSS.number(3.14));
}, 'CSSScale.' + attr + ' can be updated to a numberish');

test(() => {
let result = new CSSScale(0, 0, 0);
result[attr] = new CSSMathSum(3.14);
assert_style_value_equals(result[attr], new CSSMathSum(3.14));
}, 'CSSScale.' + attr + ' can be updated to a CSSMathValue');
}

test(() => {
let rotation = new CSSScale(0, 0, 0);
rotation.is2D = true;
assert_true(rotation.is2D);
rotation.is2D = false;
assert_false(rotation.is2D);
}, 'Modifying CSSScale.is2D can be updated to true or false');

</script>

0 comments on commit dfc102e

Please sign in to comment.