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

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

Issue 1709003002: Geometry: Reimplement DOMPoint using V8 extras. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 <title>Geometry Interfaces: DOMPoint tests</title>
3 <head> 3 <script src="../../resources/testharness.js"></script>
4 <title>Geometry Interfaces: DOMPoint</title> 4 <script src="../../resources/testharnessreport.js"></script>
5 <script src="../../resources/js-test.js"></script>
6 </head>
7 <body>
8 <script> 5 <script>
9 6
10 debug("# DOMPoint(2, 3)"); 7 function assert_dom_point_equals(dom_point, expected) {
11 var point = new DOMPoint(2, 3); 8 assert_equals(dom_point.x, expected.x, 'x');
12 shouldBe("point.x", "2"); 9 assert_equals(dom_point.y, expected.y, 'y');
13 shouldBe("point.y", "3"); 10 assert_equals(dom_point.z, expected.z, 'z');
14 shouldBe("point.z", "0"); 11 assert_equals(dom_point.w, expected.w, 'w');
15 shouldBe("point.w", "1"); 12 }
16 debug("");
17 13
18 debug("# DOMPoint(5, 7, 9)"); 14 test(() => {
19 point = new DOMPoint(5, 7, 9); 15 var dom_point_read_only = new DOMPointReadOnly();
20 shouldBe("point.x", "5"); 16 assert_dom_point_equals(dom_point_read_only, { x: 0, y: 0, z: 0, w: 1 });
21 shouldBe("point.y", "7"); 17 var dom_point = new DOMPoint();
22 shouldBe("point.z", "9"); 18 assert_dom_point_equals(dom_point, { x: 0, y: 0, z: 0, w: 1 });
23 shouldBe("point.w", "1"); 19 }, 'new DOMPoint/DOMPointReadOnly()');
24 debug("");
25 20
26 debug("# DOMPoint(8, 2, 1, 6)"); 21 test(() => {
27 point = new DOMPoint(5, 7, 9); 22 var dom_point_read_only = new DOMPointReadOnly(1);
28 point = new DOMPoint(8, 2, 1, 6); 23 assert_dom_point_equals(dom_point_read_only, { x: 1, y: 0, z: 0, w: 1 });
29 shouldBe("point.x", "8"); 24 var dom_point = new DOMPoint(1);
30 shouldBe("point.y", "2"); 25 assert_dom_point_equals(dom_point, { x: 1, y: 0, z: 0, w: 1 });
31 shouldBe("point.z", "1"); 26 }, 'new DOMPoint/DOMPointReadOnly(1)');
32 shouldBe("point.w", "6");
33 debug("");
34 27
35 debug("# DOMPoint({ x : 2 })"); 28 test(() => {
36 point = new DOMPoint({ x : 2 }); 29 var dom_point_read_only = new DOMPointReadOnly(1, 2);
37 shouldBe("point.x", "2"); 30 assert_dom_point_equals(dom_point_read_only, { x: 1, y: 2, z: 0, w: 1 });
38 shouldBe("point.y", "0"); 31 var dom_point = new DOMPoint(1, 2);
39 shouldBe("point.z", "0"); 32 assert_dom_point_equals(dom_point, { x: 1, y: 2, z: 0, w: 1 });
40 shouldBe("point.w", "1"); 33 }, 'new DOMPoint/DOMPointReadOnly(1, 2)');
41 debug("");
42 34
43 debug("# DOMPoint({ y : 2 })"); 35 test(() => {
44 point = new DOMPoint({ y : 2 }); 36 var dom_point_read_only = new DOMPointReadOnly(1, 2, 3);
45 shouldBe("point.x", "0"); 37 assert_dom_point_equals(dom_point_read_only, { x: 1, y: 2, z: 3, w: 1 });
46 shouldBe("point.y", "2"); 38 var dom_point = new DOMPoint(1, 2, 3);
47 shouldBe("point.z", "0"); 39 assert_dom_point_equals(dom_point, { x: 1, y: 2, z: 3, w: 1 });
48 shouldBe("point.w", "1"); 40 }, 'new DOMPoint/DOMPointReadOnly(1, 2, 3)');
49 debug("");
50 41
51 debug("# DOMPoint({ z : 2 })"); 42 test(() => {
52 point = new DOMPoint({ z : 2 }); 43 var dom_point_read_only = new DOMPointReadOnly(1, 2, 3, 4);
53 shouldBe("point.x", "0"); 44 assert_dom_point_equals(dom_point_read_only, { x: 1, y: 2, z: 3, w: 4 });
54 shouldBe("point.y", "0"); 45 var dom_point = new DOMPoint(1, 2, 3, 4);
55 shouldBe("point.z", "2"); 46 assert_dom_point_equals(dom_point, { x: 1, y: 2, z: 3, w: 4 });
56 shouldBe("point.w", "1"); 47 }, 'new DOMPoint/DOMPointReadOnly(1, 2, 3, 4)');
57 debug("");
58 48
59 debug("# DOMPoint({ w : 2 })"); 49 test(() => {
60 point = new DOMPoint({ w : 2 }); 50 var dom_point_read_only =
61 shouldBe("point.x", "0"); 51 new DOMPointReadOnly(undefined, undefined, undefined, undefined);
62 shouldBe("point.y", "0"); 52 assert_dom_point_equals(dom_point_read_only, { x: 0, y: 0, z: 0, w: 1 });
63 shouldBe("point.z", "0"); 53 var dom_point = new DOMPoint(undefined, undefined, undefined, undefined);
64 shouldBe("point.w", "2"); 54 assert_dom_point_equals(dom_point, { x: 0, y: 0, z: 0, w: 1 });
65 debug(""); 55 }, 'If constructor takes undefined as parameter, should set default value.');
66 56
67 debug("# DOMPoint({ x : 2, y : 3, z : 4, w : 5 })"); 57 test(() => {
68 point = new DOMPoint({ x : 2, y : 3, z : 4, w : 5 }); 58 var dom_point_read_only = new DOMPointReadOnly(null, null, null, null);
69 shouldBe("point.x", "2"); 59 assert_dom_point_equals(dom_point_read_only, { x: 0, y: 0, z: 0, w: 0 });
70 shouldBe("point.y", "3"); 60 var dom_point = new DOMPoint(null, null, null, null);
71 shouldBe("point.z", "4"); 61 assert_dom_point_equals(dom_point, { x: 0, y: 0, z: 0, w: 0 });
72 shouldBe("point.w", "5"); 62 }, 'The "null" is the same to 0.');
73 debug("");
74 63
75 debug("# DOMPoint()"); 64 test(() => {
76 point = new DOMPoint(); 65 var dom_point_read_only =
77 shouldBe("point.x", "0"); 66 new DOMPointReadOnly(function() {}, {}, new Object(), 'string');
78 shouldBe("point.y", "0"); 67 assert_dom_point_equals(dom_point_read_only, { x: NaN, y: NaN, z: NaN, w: NaN });
79 shouldBe("point.z", "0"); 68 var dom_point = new DOMPoint(function() {}, {}, new Object(), 'string');
80 shouldBe("point.w", "1"); 69 assert_dom_point_equals(dom_point, { x: NaN, y: NaN, z: NaN, w: NaN });
81 debug(""); 70 }, 'If constructor takes function/object as parameter, should set "NaN".');
82 71
83 debug("# DOMPoint setter"); 72 test(() => {
84 point.x = 10; 73 var dom_point_read_only =
85 shouldBe("point.x", "10"); 74 new DOMPointReadOnly(function() {}, {}, new Object(), 'string');
86 point.y = 20; 75 assert_dom_point_equals(
87 shouldBe("point.y", "20"); 76 dom_point_read_only, { x: NaN, y: NaN, z: NaN, w: NaN });
88 point.z = 30; 77 var dom_point = new DOMPoint(function() {}, {}, new Object(), 'string');
89 shouldBe("point.z", "30"); 78 assert_dom_point_equals(dom_point, { x: NaN, y: NaN, z: NaN, w: NaN });
90 point.w = 40; 79 }, 'new DOMPoint/DOMPointReadOnly([], [10], ["string"], [10, 20])');
91 shouldBe("point.w", "40");
92 debug("");
93 80
94 debug("# DOMPointReadOnly(10, 20, 30, 40)"); 81 test(() => {
95 point = new DOMPointReadOnly(10, 20, 30, 40); 82 var dom_point_read_only = new DOMPointReadOnly(1, 2, 3, 4);
96 shouldBe("point.x", "10"); 83 dom_point_read_only.x = 4;
97 shouldBe("point.y", "20"); 84 dom_point_read_only.y = 3;
98 shouldBe("point.z", "30"); 85 dom_point_read_only.z = 2;
99 shouldBe("point.w", "40"); 86 dom_point_read_only.w = 1;
100 debug(""); 87 assert_dom_point_equals(dom_point_read_only, { x: 1, y: 2, z: 3, w: 4 });
88 }, 'DOMPointReadOnly does not have setter');
101 89
102 debug("# DOMPointReadOnly readonly test"); 90 test(() => {
103 point.x = 100; 91 var dom_point = new DOMPoint(1, 2, 3, 4);
104 shouldBe("point.x", "10"); 92 dom_point.x = 10.5;
105 point.y = 100; 93 dom_point.y = 20.7;
106 shouldBe("point.y", "20"); 94 dom_point.z = 30;
107 point.z = 100; 95 dom_point.w = 40;
108 shouldBe("point.z", "30"); 96 assert_dom_point_equals(dom_point, { x: 10.5, y: 20.7, z: 30, w: 40 });
109 point.w = 100; 97 }, 'DOMPoint setter test (number)');
110 shouldBe("point.w", "40"); 98
99 test(() => {
100 var dom_point = new DOMPoint(1, 2, 3, 4);
101 dom_point.x = undefined;
102 dom_point.y = null;
103 dom_point.z = undefined;
104 dom_point.w = null;
105 assert_dom_point_equals(dom_point, { x: NaN, y: 0, z: NaN, w: 0 });
106 }, 'DOMPoint setter test (undefined/null)');
107
108 test(() => {
109 var dom_point = new DOMPoint(1, 2, 3, 4);
110 dom_point.x = function() {};
111 dom_point.y = {};
112 dom_point.z = 'string';
113 dom_point.w = new Object();
114 assert_dom_point_equals(dom_point, { x: NaN, y: NaN, z: NaN, w: NaN });
115 }, 'DOMPoint setter test (function/object)');
116
117 test(() => {
118 var dom_point = new DOMPoint(1, 2, 3, 4);
119 dom_point.x = [];
120 dom_point.y = [10];
121 dom_point.z = ['string'];
122 dom_point.w = [10, 20];
123 assert_dom_point_equals(dom_point, { x: 0, y: 10, z: NaN, w: NaN });
124 }, 'DOMPoint setter test (array)');
125
126 test(() => {
127 const dom_point_read_only_getter =
128 Object.getOwnPropertyDescriptor(DOMPointReadOnly.prototype, 'x').get;
129 dom_point_read_only_getter.call(new DOMPoint());
130 dom_point_read_only_getter.call(new DOMPointReadOnly());
131 assert_throws(null, () => dom_point_read_only_getter.call({}));
132 assert_throws(null, () => dom_point_read_only_getter.call({ x: 10 }));
133
134 const dom_point_setter =
135 Object.getOwnPropertyDescriptor(DOMPoint.prototype, 'y').set;
136 var dom_point = new DOMPoint();
137 dom_point_setter.call(dom_point, 10);
138 assert_dom_point_equals(dom_point, { x: 0, y: 10, z: 0, w: 1 });
139 assert_throws(null, () => dom_point_setter.call({}, 10));
140 assert_throws(null, () => dom_point_setter.call({ y: 10 }, 20));
141 }, 'Test for exception when binding object is not DOMPoint/DOMPointReadOnly');
111 142
112 </script> 143 </script>
113 </body>
114 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698