WebKit export of https://bugs.webkit.org/show_bug.cgi?id=230129 (#30493)

Export of tests for calc functions sin, cos, tan
diff --git a/css/css-values/sin-cos-tan-computed.html b/css/css-values/sin-cos-tan-computed.html
new file mode 100644
index 0000000..7f85727
--- /dev/null
+++ b/css/css-values/sin-cos-tan-computed.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-values-4/#comp-func">
+<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">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../support/numeric-testcommon.js"></script>
+<div id="target"></div>
+<script>
+// Simple tests
+test_math_used('cos(0)', '1', {type:'number'});
+test_math_used('sin(0)', '0', {type:'number'});
+test_math_used('tan(0)', '0', {type:'number'});
+
+// Test pi
+test_math_used('calc(sin(pi/2 - pi/2) )', '0', {type:'number', approx:0.1});
+test_math_used('calc(cos(pi - 3.14159265358979323846) )', '1', {type:'number', approx:0.1});
+
+//Test e
+test_math_used('calc(cos(e - 2.7182818284590452354) )', '1', {type:'number', approx:0.1});
+
+//Test units
+test_math_used('calc(sin(30deg + 1.0471967rad ) )', '1', {type:'number', approx:0.1});
+test_math_used('calc(cos(30deg - 0.523599rad ) )', '1'), {type:'number', approx:0.1};
+test_math_used('calc(sin(3.14159 / 2 + 1 - 1) )', '1', {type:'number', approx:0.1});
+test_math_used('calc(sin(100grad) )', '1', {type:'number', approx:0.1});
+test_math_used('calc(cos(0 / 2 + 1 - 1) )', '1', {type:'number', approx:0.1});
+test_math_used('calc(tan(30deg + 0.261799rad ) )', '1', {type:'number', approx:0.1});
+test_math_used('calc(tan(0.7853975rad ) )', '1', {type:'number', approx:0.1});
+test_math_used('calc(tan(3.14159 / 4 + 1 - 1) )', '1', {type:'number', approx:0.1});
+test_math_used('calc(sin(0.25turn) )', '1', {type:'number', approx:0.1});
+
+//Test nesting
+test_math_used('calc(cos(sin(cos(pi) + 1)))', '1', {type:'number', approx:0.1});
+test_math_used('calc(sin(tan(pi/4)*pi/2) )', '1', {type:'number', approx:0.1});
+</script>
diff --git a/css/css-values/sin-cos-tan-invalid.html b/css/css-values/sin-cos-tan-invalid.html
new file mode 100644
index 0000000..b504e6d
--- /dev/null
+++ b/css/css-values/sin-cos-tan-invalid.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-values-4/#comp-func">
+<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">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../support/parsing-testcommon.js"></script>
+<script>
+function test_invalid_angle(value) {
+  test_invalid_value('transform', `rotate(${value})`);
+}
+
+// Syntax checking
+test_invalid_angle('sin()');
+test_invalid_angle('sin( )');
+test_invalid_angle('sin(,)');
+test_invalid_angle('sin(1dag)');
+test_invalid_angle('sin(1deg, )');
+test_invalid_angle('sin(, 1deg)');
+test_invalid_angle('sin(1deg + )');
+test_invalid_angle('sin(1deg - )');
+test_invalid_angle('sin(1deg * )');
+test_invalid_angle('sin(1deg / )');
+test_invalid_angle('sin(1deg 2deg)');
+test_invalid_angle('sin(1deg, , 2deg)');
+test_invalid_angle('cos()');
+test_invalid_angle('cos( )');
+test_invalid_angle('cos(,)');
+test_invalid_angle('cos(1dag)');
+test_invalid_angle('cos(1deg, )');
+test_invalid_angle('cos(, 1deg)');
+test_invalid_angle('cos(1deg + )');
+test_invalid_angle('cos(1deg - )');
+test_invalid_angle('cos(1deg * )');
+test_invalid_angle('cos(1deg / )');
+test_invalid_angle('cos(1deg 2deg)');
+test_invalid_angle('cos(1deg, , 2deg)');
+test_invalid_angle('tan()');
+test_invalid_angle('tan( )');
+test_invalid_angle('tan(,)');
+test_invalid_angle('tan(1dag)');
+test_invalid_angle('tan(1deg, )');
+test_invalid_angle('tan(, 1deg)');
+test_invalid_angle('tan(1deg + )');
+test_invalid_angle('tan(1deg - )');
+test_invalid_angle('tan(1deg * )');
+test_invalid_angle('tan(1deg / )');
+test_invalid_angle('tan(1deg 2deg)');
+test_invalid_angle('tan(1deg, , 2deg)');
+test_invalid_angle('sin(90px)');
+test_invalid_angle('sin(30deg + 1.0471967rad, 0)');
+test_invalid_angle('cos( 0 ,)');
+test_invalid_angle('cos( () 30deg - 0.523599rad )');
+test_invalid_angle('tan(45deg )');
+test_invalid_angle('tan(30deg, + 0.261799rad)');
+</script>
diff --git a/css/css-values/sin-cos-tan-serialize.html b/css/css-values/sin-cos-tan-serialize.html
new file mode 100644
index 0000000..f7d3083
--- /dev/null
+++ b/css/css-values/sin-cos-tan-serialize.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-values-4/#comp-func">
+<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">
+<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) {
+    test_specified_serialization('opacity', t, s);
+    test_specified_serialization('transform', `scale(${t})`, `scale(calc(${c}))`);
+    test_computed_serialization('opacity', t, c);
+    test_computed_serialization('transform', `scale(${t})`, `matrix(${c}, 0, 0, ${c}, 0, 0)`);
+}
+
+test_serialization(
+    'cos(0)',
+    'calc(1)',
+    '1');
+test_serialization(
+    'sin(0)',
+    'calc(0)',
+    '0');
+test_serialization(
+    'tan(0)',
+    'calc(0)',
+    '0');
+
+test_serialization(
+    'calc(sin(0) + cos(0) + tan(0))',
+    'calc(1)',
+    '1');
+
+test_serialization(
+    'calc(sin(0) + 0.5)',
+    'calc(0.5)',
+    '0.5');
+test_serialization(
+    'calc(cos(0) + 0.5)',
+    'calc(1.5)',
+    '1.5');
+test_serialization(
+    'calc(tan(0) + 0.5)',
+    'calc(0.5)',
+    '0.5');
+</script>
diff --git a/css/support/numeric-testcommon.js b/css/support/numeric-testcommon.js
index e0569fe..f5ba088 100644
--- a/css/support/numeric-testcommon.js
+++ b/css/support/numeric-testcommon.js
@@ -42,7 +42,7 @@
 
 
 
-function test_math_used(testString, expectedString, {msg, msgExtra, type, prop, prefix, suffix, extraStyle={}}={}) {
+function test_math_used(testString, expectedString, {approx, msg, msgExtra, type, prop, prefix, suffix, extraStyle={}}={}) {
     if(type === undefined) type = "length";
     if(!prop) {
         switch(type) {
@@ -57,10 +57,10 @@
         }
 
     }
-    _test_math({stage:'used', testString, expectedString, type, msg, msgExtra, prop, prefix, suffix, extraStyle});
+    _test_math({stage:'used', testString, expectedString, type, approx, msg, msgExtra, prop, prefix, suffix, extraStyle});
 }
 
-function test_math_computed(testString, expectedString, {msg, msgExtra, type, prop, prefix, suffix, extraStyle={}}={}) {
+function test_math_computed(testString, expectedString, {approx, msg, msgExtra, type, prop, prefix, suffix, extraStyle={}}={}) {
     if(type === undefined) type = "length";
     if(!prop) {
         switch(type) {
@@ -75,10 +75,10 @@
         }
 
     }
-    _test_math({stage:'computed', testString, expectedString, type, msg, msgExtra, prop, prefix, suffix, extraStyle});
+    _test_math({stage:'computed', testString, expectedString, type, approx, msg, msgExtra, prop, prefix, suffix, extraStyle});
 }
 
-function test_math_specified(testString, expectedString, {msg, msgExtra, type, prop, prefix, suffix, extraStyle={}}={}) {
+function test_math_specified(testString, expectedString, {approx, msg, msgExtra, type, prop, prefix, suffix, extraStyle={}}={}) {
     if(type === undefined) type = "length";
     const stage = "specified";
     if(!prop) {
@@ -152,7 +152,7 @@
 }
 
 
-function _test_math({stage, testEl, testString, expectedString, type, msg, msgExtra, prop, prefix, suffix, extraStyle}={}) {
+function _test_math({stage, testEl, testString, expectedString, type, approx, msg, msgExtra, prop, prefix, suffix, extraStyle}={}) {
     // Find the test element
     if(!testEl) testEl = document.getElementById('target');
     if(testEl == null) throw "Couldn't find #target element to run tests on.";
@@ -184,6 +184,12 @@
         testEl.style[prop] = e;
         const expectedValue = getComputedStyle(testEl)[prop];
         assert_not_equals(expectedValue, '', `${expectedString} isn't valid in '${prop}'; got the default value instead.`)
-        assert_equals(usedValue, expectedValue, `${testString} and ${expectedString} serialize to the same thing in ${stage} values.`);
+        if(approx && type == "number"){
+            let parsedUsed = usedValue.split('(')[1].split(')')[0].split(',').map(parseFloat);
+            let parsedExpected = expectedValue.split('(')[1].split(')')[0].split(',').map(parseFloat);
+            assert_array_approx_equals(parsedUsed, parsedExpected, approx, `${testString} and ${expectedString} ${approx} serialize to the same thing in ${stage} values.`);
+        } else {
+            assert_equals(usedValue, expectedValue, `${testString} and ${expectedString} serialize to the same thing in ${stage} values.`);
+        }
     }, msg || `${testString} should be ${stage}-value-equivalent to ${expectedString}`);
-}
\ No newline at end of file
+}