Skip to content

Commit

Permalink
Bug 1784839 [wpt PR 35463] - Add asin() function for CSSTrigonometrcF…
Browse files Browse the repository at this point in the history
…unctions, a=testonly

Automatic update from web-platform-tests
Add asin() function for CSSTrigonometrcFunctions

According to the CSS Values and Units Module Level 4 [1],
the trigonometric function should be parsed and evaluated.

This CL adds asin() function and testcases for asin().

And add parentheses to the test cases in sin-cos-tan-serialized.html.
It does not make test failure due to the consume simple block rule
in the spec [2]. However, the expression that missed closing
parenthesis is not the goal of the test suite
and could make misunderstandings.

Therefore, add the closing parentheses on the test cases.

Feature status: [3]
Intent to prototype: [4]

[1] https://www.w3.org/TR/css-values-4/#trig-funcs
[2] https://www.w3.org/TR/css-syntax-3/#consume-simple-block
[3] https://chromestatus.com/feature/5165381072191488
[4] https://groups.google.com/a/chromium.org/g/blink-dev/c/-c9p-Sq_gWg

Bug: 1190444
Change-Id: Ie000b6a7fd429d9c1bad28c29fc89104342706be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3820863
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Seokho Song <seokho@chromium.org>
Reviewed-by: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1038485}

--

wpt-commits: 4131ef3ac9ca26a310d7a00d4fc8211f1430b810
wpt-pr: 35463
  • Loading branch information
DevSDK authored and moz-wptsync-bot committed Sep 4, 2022
1 parent 50ba420 commit d5673eb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,40 @@
<link rel="help" href="https://drafts.csswg.org/css-values-4/#angles">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-serialize">
<link rel="author" title="Apple Inc">
<link rel="author" title="Seokho Song" href="seokho@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/serialize-testcommon.js"></script>
<div id=target></div>
<script>
function test_serialization(t,s,c,u, {prop="transform"}={}) {
t = `rotate(${t})`;
test_specified_serialization(prop, t, `rotate(${s})`);
test_computed_serialization(prop, t, c);
if(u) test_used_serialization(prop, t, u);
}

// Browsers aren't perfectly interoperable about how a 90deg rotation is serialized,
// but that's not the focus of this test,
// so just capture *whatever* the browser does and expect that.
const rotateMatrix = (()=>{
const el = document.querySelector("#target");
el.style.transform = "rotate(90deg)";
const ret = getComputedStyle(el).transform;
el.removeAttribute('style');
return ret;
})();

test_serialization(
'acos(0)',
'calc(90deg)',
rotateMatrix);
test_serialization(
'asin(1)',
'calc(90deg)',
rotateMatrix);
function test_serialization(specified, expected, {prop="transform"}={}) {

test_serialization(
'calc(acos(pi - pi))',
'calc(90deg)',
rotateMatrix);
test_serialization(
'calc(asin(pi - pi + 1))',
'calc(90deg)',
rotateMatrix);
// We only test the specified serialization,
// and not the computed or used serialization,
// since we'd need to do that by retrieving the rotation matrix,
// and that isn't perfectly interoperable in corner cases.
// Plus the point of this test is to check the trig functions themselves.
test_specified_serialization(prop, `rotate(${specified})`, `rotate(${expected})`)
}
//TEST CASE | EXPECTED
var test_map = {
"acos(0)" :"calc(90deg)",
"asin(1)" :"calc(90deg)",
"asin(-1)" :"calc(-90deg)",
"asin(-1.5)" :"calc(NaN * 1deg)",
"asin(1.5)" :"calc(NaN * 1deg)",
"asin(2)" :"calc(NaN * 1deg)",
"asin(0.5)" :"calc(30deg)",
"asin(1 - 0.5)" :"calc(30deg)",
"asin(0)" :"calc(0deg)",
"acos(pi - pi)" :"calc(90deg)",
"asin(pi - pi + 1)" :"calc(90deg)",
"atan(infinity)" :"calc(90deg)",
};

test_serialization(
'calc(atan(infinity))',
'calc(90deg)',
rotateMatrix);
for (var exp in test_map) {
test_serialization(exp, test_map[exp]);
test_serialization(`calc(${exp})`, test_map[exp]);
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<link rel="help" href="https://drafts.csswg.org/css-values-4/#numbers">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-type-checking">
<link rel="author" title="Apple Inc">
<link rel="author" title="Seokho Song" href="seokho@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/numeric-testcommon.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<link rel="help" href="https://drafts.csswg.org/css-values-4/#angles">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-type-checking">
<link rel="author" title="Apple Inc">
<link rel="author" title="Seokho Song" href="seokho@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/parsing-testcommon.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
<link rel="help" href="https://drafts.csswg.org/css-values-4/#numbers">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-serialize">
<link rel="author" title="Apple Inc">
<link rel="author" title="Seokho Song" href="seokho@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/serialize-testcommon.js"></script>
<div id=target></div>
<script>
function test_serialization(specified, expected, {prop="transform"}={}) {
test_specified_serialization(prop, specified, expected)
test_specified_serialization(prop, `scale(${specified})`, `scale(${expected})`)
}
//TEST CASE | EXPECTED
var test_map = {
"cos(0)" :"calc(1)",
"sin(0)" :"calc(0)",
"tan(0)" :"calc(0)",
"calc(sin(0) + 0.5)" :"calc(0.5)",
"calc(sin(0) + cos(0) + tan(0)" :"calc(1)",
"calc(sin(0) + cos(0) + tan(0))" :"calc(1)",
"calc(cos(0) + 0.5)" :"calc(1.5)",
"calc(tan(0) + 0.5)" :"calc(0.5)",
"cos(0deg)" :"calc(1)",
Expand All @@ -38,7 +39,7 @@
"tan(0.78539816)" :"calc(1)",
"tan(0.78539816rad)" :"calc(1)",
"tan(0.125turn)" :"calc(1)",
"calc(sin(30deg) + cos(60deg) + tan(45deg)" :"calc(2)",
"calc(sin(30deg) + cos(60deg) + tan(45deg))" :"calc(2)",
"calc(sin(infinity))" :"calc(NaN)",
"calc(cos(infinity))" :"calc(NaN)",
"calc(tan(infinity))" :"calc(NaN)",
Expand All @@ -48,8 +49,8 @@
};

for (var exp in test_map) {
test_serialization(`scale(calc(${exp}))`, `scale(${test_map[exp]})`);
test_serialization(`scale(${exp})`, `scale(${test_map[exp]})`);
test_serialization(exp, test_map[exp]);
test_serialization(`calc(${exp})`, test_map[exp]);
}

</script>

0 comments on commit d5673eb

Please sign in to comment.