Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: third_party/WebKit/LayoutTests/typedcssom/cssSkew.html

Issue 2921243002: [CSS Typed OM] Add setters for the CSSNumericValues contained in CSSSkew (Closed)
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script> 2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 4
5 <script> 5 <script>
6 var EPSILON = 1e-6; // float epsilon 6 var EPSILON = 1e-6; // float epsilon
7 7
8 function angle(deg) { return new CSSUnitValue(deg, 'deg'); } 8 function angle(deg) { return new CSSUnitValue(deg, 'deg'); }
9 9
10 function tanDegrees(degrees) { 10 function tanDegrees(degrees) {
11 var radians = degrees * Math.PI / 180; 11 var radians = degrees * Math.PI / 180;
12 return Math.tan(radians); 12 return Math.tan(radians);
13 } 13 }
14 14
15 function assert_array_approx_equals(actual, expected) {
16 for (var i = 0; i < actual.length; i++) {
17 assert_approx_equals(actual[i], expected[i], EPSILON);
18 }
19 }
20
21 function assert_matrix_approx_equals(actual, expected) {
22 assert_array_approx_equals(actual.toFloat64Array(), expected.toFloat64Array()) ;
23 }
24
15 var values = [ 25 var values = [
16 {input: new CSSSkew(angle(0), angle(0)), ax: 0, ay: 0, cssText: "skew(0deg, 0d eg)"}, 26 {input: new CSSSkew(angle(0), angle(0)), ax: 0, ay: 0, cssText: "skew(0deg, 0d eg)"},
17 {input: new CSSSkew(angle(1), angle(2)), ax: 1, ay: 2, cssText: "skew(1deg, 2d eg)"}, 27 {input: new CSSSkew(angle(1), angle(2)), ax: 1, ay: 2, cssText: "skew(1deg, 2d eg)"},
18 {input: new CSSSkew(angle(-2), angle(-4)), ax: -2, ay: -4, cssText: "skew(-2de g, -4deg)"}, 28 {input: new CSSSkew(angle(-2), angle(-4)), ax: -2, ay: -4, cssText: "skew(-2de g, -4deg)"},
19 {input: new CSSSkew(angle(3.4), angle(2.7)), ax: 3.4, ay: 2.7, cssText: "skew( 3.4deg, 2.7deg)"}, 29 {input: new CSSSkew(angle(3.4), angle(2.7)), ax: 3.4, ay: 2.7, cssText: "skew( 3.4deg, 2.7deg)"},
20 {input: new CSSSkew(new CSSUnitValue(1, 'rad'), angle(0)), ax: 57.2957795, ay: 0, cssText: "skew(1rad, 0deg)"}, 30 {input: new CSSSkew(new CSSUnitValue(1, 'rad'), angle(0)), ax: 57.2957795, ay: 0, cssText: "skew(1rad, 0deg)"},
21 {input: new CSSSkew(angle(0), new CSSUnitValue(1, 'rad')), ax: 0, ay: 57.29577 95, cssText: "skew(0deg, 1rad)"} 31 {input: new CSSSkew(angle(0), new CSSUnitValue(1, 'rad')), ax: 0, ay: 57.29577 95, cssText: "skew(0deg, 1rad)"}
22 ]; 32 ];
23 33
24 test(function() { 34 test(function() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 for (var attribute in expectedMatrix) { 69 for (var attribute in expectedMatrix) {
60 if (attribute == "matrix") { 70 if (attribute == "matrix") {
61 assert_matrix_approx_equals(inputAsMatrix[attribute], expectedMatrix[att ribute]); 71 assert_matrix_approx_equals(inputAsMatrix[attribute], expectedMatrix[att ribute]);
62 } else { 72 } else {
63 assert_equals(inputAsMatrix[attribute], expectedMatrix[attribute]); 73 assert_equals(inputAsMatrix[attribute], expectedMatrix[attribute]);
64 } 74 }
65 } 75 }
66 } 76 }
67 }, "asMatrix is constructed correctly for CSSSkew."); 77 }, "asMatrix is constructed correctly for CSSSkew.");
68 78
69 function assert_array_approx_equals(actual, expected) { 79 test(function() {
70 for (var i = 0; i < actual.length; i++) { 80 var skew = new CSSSkew(new CSSUnitValue(1, 'deg'), new CSSUnitValue(2, 'deg')) ;
71 assert_approx_equals(actual[i], expected[i], EPSILON); 81 skew.ax = new CSSUnitValue(3, 'deg');
72 } 82 skew.ay = new CSSUnitValue(3, 'rad');
73 }
74 83
75 function assert_matrix_approx_equals(actual, expected) { 84 assert_equals(skew.ax.value, 3);
76 assert_array_approx_equals(actual.toFloat64Array(), expected.toFloat64Array()) ; 85 assert_equals(skew.ay.value, 3);
86 assert_equals(skew.ax.unit, 'deg');
87 assert_equals(skew.ay.unit, 'rad');
88 }, "Setting ax and ay for CSSSkew with valid CSSUnitValues");
89
90 for (let a of ['ax', 'ay']) {
91 test(() => {
92 var skew = new CSSSkew(
93 new CSSUnitValue(1, 'deg'), new CSSUnitValue(2, 'deg'));
94 assert_throws(new TypeError(), () => {
95 skew[a] = new CSSUnitValue(1, 'px');
96 });
97 assert_throws(new TypeError(), () => {
98 skew[a] = 'bananas';
99 });
100 assert_throws(new TypeError(), () => {
101 skew[a] = null;
102 });
103 }, "Setting " + a + " with invalid values");
77 } 104 }
78 105
79 </script> 106 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698