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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/geometry-interfaces-dom-matrix-readonly.html

Issue 2283363003: GeometryInterface: Add DOMMatrixInit and fromMatrix(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 3 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 <html> 2 <html>
3 <head> 3 <head>
4 <title>Geometry Interfaces: DOMMatrixReadOnly</title> 4 <title>Geometry Interfaces: DOMMatrixReadOnly</title>
5 <script src="../../resources/testharness.js"></script> 5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharnessreport.js"></script> 6 <script src="../../resources/testharnessreport.js"></script>
7 <script src="./resources/geometry-interfaces-test-helpers.js"></script>
7 </head> 8 </head>
8 <body> 9 <body>
9 <script> 10 <script>
10 test(function() { 11 test(() => {
11 var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 3.1, 2, 1]); 12 var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 3.1, 2, 1]);
12 assert_true(matrix2d.is2D); 13 assert_2d_matrix_equals(matrix2d, {
13 assert_equals(matrix2d.a, 1); 14 m11: 1, m12: 2,
14 assert_equals(matrix2d.b, 2); 15 m21: 3, m22: 3.1,
15 assert_equals(matrix2d.c, 3); 16 m41: 2, m42: 1,
16 assert_equals(matrix2d.d, 3.1); 17 isIdentity: false
17 assert_equals(matrix2d.e, 2); 18 });
18 assert_equals(matrix2d.f, 1);
19 }, "DOMMatrixReadOnly constructor - 2D matrix"); 19 }, "DOMMatrixReadOnly constructor - 2D matrix");
20 20
21 test(function() { 21 test(() => {
22 var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 1 2, 13, 14, 15, 16.6]); 22 var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 1 2, 13, 14, 15, 16.6]);
23 assert_false(matrix3d.is2D); 23 assert_3d_matrix_equals(matrix3d, {
24 assert_equals(matrix3d.m11, 1); 24 m11: 1, m12: 2, m13: 3, m14: 4,
25 assert_equals(matrix3d.m12, 2); 25 m21: 5, m22: 6, m23: 7, m24: 8,
26 assert_equals(matrix3d.m13, 3); 26 m31: 9, m32: 10.1, m33: 11, m34: 12,
27 assert_equals(matrix3d.m14, 4); 27 m41: 13, m42: 14, m43: 15, m44: 16.6,
28 assert_equals(matrix3d.m21, 5); 28 isIdentity: false
29 assert_equals(matrix3d.m22, 6); 29 });
30 assert_equals(matrix3d.m23, 7);
31 assert_equals(matrix3d.m24, 8);
32 assert_equals(matrix3d.m31, 9);
33 assert_equals(matrix3d.m32, 10.1);
34 assert_equals(matrix3d.m33, 11);
35 assert_equals(matrix3d.m34, 12);
36 assert_equals(matrix3d.m41, 13);
37 assert_equals(matrix3d.m42, 14);
38 assert_equals(matrix3d.m43, 15);
39 assert_equals(matrix3d.m44, 16.6);
40 }, "DOMMatrixReadOnly constructor - 3D matrix"); 30 }, "DOMMatrixReadOnly constructor - 3D matrix");
41 31
42 test(function() { 32 test(() => {
43 var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 3.1, 2, 1]); 33 var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 3.1, 2, 1]);
44 assert_true(matrix2d.is2D); 34 assert_true(matrix2d.is2D);
45 assert_equals(matrix2d.toString(), "matrix(1, 2, 3, 3.1, 2, 1)"); 35 assert_equals(matrix2d.toString(), "matrix(1, 2, 3, 3.1, 2, 1)");
46 }, "DOMMatrixReadOnly toString() - 2D matrix"); 36 }, "DOMMatrixReadOnly toString() - 2D matrix");
47 37
48 test(function() { 38 test(() => {
49 var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 1 2, 13, 14, 15, 16.6]); 39 var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 1 2, 13, 14, 15, 16.6]);
50 assert_false(matrix3d.is2D); 40 assert_false(matrix3d.is2D);
51 assert_equals(matrix3d.toString(), "matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1 , 11, 12, 13, 14, 15, 16.6)"); 41 assert_equals(matrix3d.toString(), "matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1 , 11, 12, 13, 14, 15, 16.6)");
52 }, "DOMMatrixReadOnly toString() - 3D matrix"); 42 }, "DOMMatrixReadOnly toString() - 3D matrix");
53 43
54 test(function() { 44 test(() => {
55 assert_throws(new TypeError(), function() { new DOMMatrixReadOnly(1, 2, 3, 4 , 5, 6); }, 45 assert_throws(new TypeError(), () => { new DOMMatrixReadOnly(1, 2, 3, 4, 5, 6); },
56 "DOMMatrixReadOnly constructor only accepts 1 argument"); 46 "DOMMatrixReadOnly constructor only accepts 1 argument");
57 assert_throws(new TypeError(), function() { new DOMMatrixReadOnly("myString" ); }, 47 assert_throws(new TypeError(), () => { new DOMMatrixReadOnly("myString"); },
58 "DOMMatrixReadOnly constructor only accepts 1 number sequence"); 48 "DOMMatrixReadOnly constructor only accepts 1 number sequence");
59 assert_throws(new TypeError(), function() { new DOMMatrixReadOnly([1, 2, 3]) ; }, 49 assert_throws(new TypeError(), () => { new DOMMatrixReadOnly([1, 2, 3]); },
60 "DOMMatrixReadOnly constructor only accepts 1 number sequence with 6 or 16 elements."); 50 "DOMMatrixReadOnly constructor only accepts 1 number sequence with 6 or 16 elements.");
61 }, "DOMMatrixReadOnly constructor - invalid arguments"); 51 }, "DOMMatrixReadOnly constructor - invalid arguments");
52
53 test(() => {
54 var matrix = DOMMatrixReadOnly.fromMatrix();
55 assert_identity_2d_matrix(matrix);
56 }, "DOMMatrixReadOnly.fromMatrix() with no parameter.");
57
58 test(() => {
59 var matrix = DOMMatrixReadOnly.fromMatrix(null);
60 assert_identity_2d_matrix(matrix);
61 }, "DOMMatrixReadOnly.fromMatrix() with null.");
62
63 test(() => {
64 var matrix = DOMMatrixReadOnly.fromMatrix(undefined);
65 assert_identity_2d_matrix(matrix);
66 }, "DOMMatrixReadOnly.fromMatrix() with undefined.");
67
68 test(() => {
69 var matrix = DOMMatrixReadOnly.fromMatrix({});
70 assert_identity_2d_matrix(matrix);
71 }, "DOMMatrixReadOnly.fromMatrix() with empty object.");
72
73 test(() => {
74 var matrix = DOMMatrixReadOnly.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6} );
75 assert_2d_matrix_equals(matrix, {
76 m11: 1, m12: 2,
77 m21: 3, m22: 4,
78 m41: 5, m42: 6,
79 isIdentity: false
80 });
81 }, "DOMMatrixReadOnly.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}) should cr eate a 2D DOMMatrixReadOnly.");
82
83 test(() => {
84 var matrix = DOMMatrixReadOnly.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23 : 5, m43: 6});
85 assert_3d_matrix_equals(matrix, {
86 m11: 1, m12: 0, m13: 0, m14: 0,
87 m21: 0, m22: 2, m23: 5, m24: 0,
88 m31: 0, m32: 0, m33: 3, m34: 0,
89 m41: 0, m42: 0, m43: 6, m44: 4,
90 isIdentity: false
91 });
92 }, "DOMMatrixReadOnly.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43: 6 }) should create a 3D DOMMatrixReadOnly.");
93
94 test(() => {
95 var matrix = DOMMatrixReadOnly.fromMatrix({a: 7, c: 9});
96 assert_2d_matrix_equals(matrix, {
97 m11: 7, m12: 0,
98 m21: 9, m22: 1,
99 m41: 0, m42: 0,
100 isIdentity: false
101 });
102 }, "If 2d related properties don't be set, should set to fallback.");
103
104 test(function() {
105 var matrix = DOMMatrixReadOnly.fromMatrix({
106 m11: NaN, m12: NaN, m13: NaN, m14: NaN,
107 m21: NaN, m22: NaN, m23: NaN, m24: NaN,
108 m31: NaN, m32: NaN, m33: NaN, m34: NaN,
109 m41: NaN, m42: NaN, m43: NaN, m44: NaN,
110 is2D: false
111 });
112 assert_equals(matrix.a, matrix.m11);
113 assert_equals(matrix.b, matrix.m12);
114 assert_equals(matrix.c, matrix.m21);
115 assert_equals(matrix.d, matrix.m22);
116 assert_equals(matrix.e, matrix.m41);
117 assert_equals(matrix.f, matrix.m42);
118 assert_3d_matrix_equals(matrix, {
119 m11: NaN, m12: NaN, m13: NaN, m14: NaN,
120 m21: NaN, m22: NaN, m23: NaN, m24: NaN,
121 m31: NaN, m32: NaN, m33: NaN, m34: NaN,
122 m41: NaN, m42: NaN, m43: NaN, m44: NaN,
123 isIdentity: false, is2D: false
124 });
125 }, "DOMMatrixReadOnly.fromMatrix(): NaN test");
126
127 test(() => {
128 assert_throws(new TypeError(), () => {
129 DOMMatrixReadOnly.fromMatrix({a: 1, b: 2, m33: 3, m44: 4, is2D: true});
130 }, "The 'is2D' property is set to true but the input matrix is 3d matrix." );
131 assert_throws(new TypeError(), () => {
132 DOMMatrixReadOnly.fromMatrix({a: 1, b: 2, m11: 3});
133 }, "The 'a' property should equal the 'm11' property.");
134 }, "DOMMatrixReadOnly.fromMatrix(): Exception test.");
135
62 </script> 136 </script>
63 </body> 137 </body>
64 </html> 138 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698