OLD | NEW |
(Empty) | |
| 1 // TODO(chongz): Remove this file and import from w3c tests after approved. |
| 2 // crbug.com/552530 |
| 3 |
| 4 // Check a Touch object's atttributes for existence and correct type |
| 5 // TA: 1.1.2, 1.1.3 |
| 6 function check_Touch_object(t) { |
| 7 test(function() { |
| 8 assert_equals(Object.prototype.toString.call(t), "[object Touch]", "touc
h is of type Touch"); |
| 9 }, "touch point is a Touch object"); |
| 10 [ |
| 11 ["long", "identifier"], |
| 12 ["EventTarget", "target"], |
| 13 ["long", "screenX"], |
| 14 ["long", "screenY"], |
| 15 ["long", "clientX"], |
| 16 ["long", "clientY"], |
| 17 ["long", "pageX"], |
| 18 ["long", "pageY"], |
| 19 ["long", "radiusX"], |
| 20 ["long", "radiusY"], |
| 21 ["long", "rotationAngle"], |
| 22 ["long", "force"], |
| 23 ].forEach(function(attr) { |
| 24 var type = attr[0]; |
| 25 var name = attr[1]; |
| 26 |
| 27 // existence check |
| 28 test(function() { |
| 29 assert_true(name in t, name + " attribute in Touch object"); |
| 30 }, "Touch." + name + " attribute exists"); |
| 31 |
| 32 // type check |
| 33 switch (type) { |
| 34 case "long": |
| 35 test(function() { |
| 36 assert_equals(typeof t[name], "number", name + " attribute o
f type long"); |
| 37 }, "Touch." + name + " attribute is of type number (long)"); |
| 38 break; |
| 39 case "EventTarget": |
| 40 // An event target is some type of Element |
| 41 test(function() { |
| 42 assert_true(t[name] instanceof Element, "EventTarget must be
an Element."); |
| 43 }, "Touch." + name + " attribute is of type Element"); |
| 44 break; |
| 45 default: |
| 46 break; |
| 47 } |
| 48 }); |
| 49 } |
| 50 |
| 51 // Check a TouchList object's attributes and methods for existence and proper ty
pe |
| 52 // Also make sure all of the members of the list are Touch objects |
| 53 // TA: 1.2.1, 1.2.2, 1.2.5, 1.2.6 |
| 54 function check_TouchList_object(tl) { |
| 55 test(function() { |
| 56 assert_equals(Object.prototype.toString.call(tl), "[object TouchList]",
"touch list is of type TouchList"); |
| 57 }, "touch list is a TouchList object"); |
| 58 [ |
| 59 ["unsigned long", "length"], |
| 60 ["function", "item"], |
| 61 ].forEach(function(attr) { |
| 62 var type = attr[0]; |
| 63 var name = attr[1]; |
| 64 |
| 65 // existence check |
| 66 test(function() { |
| 67 assert_true(name in tl, name + " attribute in TouchList"); |
| 68 }, "TouchList." + name + " attribute exists"); |
| 69 |
| 70 // type check |
| 71 switch (type) { |
| 72 case "unsigned long": |
| 73 test(function() { |
| 74 assert_equals(typeof tl[name], "number", name + " attribute
of type long"); |
| 75 }, "TouchList." + name + " attribute is of type number (unsigned
long)"); |
| 76 break; |
| 77 case "function": |
| 78 test(function() { |
| 79 assert_equals(typeof tl[name], "function", name + " attribut
e of type function"); |
| 80 }, "TouchList." + name + " attribute is of type function"); |
| 81 break; |
| 82 default: |
| 83 break; |
| 84 } |
| 85 }); |
| 86 // Each member of tl should be a proper Touch object |
| 87 for (var i = 0; i < tl.length; i++) { |
| 88 check_Touch_object(tl.item(i)); |
| 89 } |
| 90 // TouchList.item(x) should return null if x is >= TouchList.length |
| 91 test(function() { |
| 92 var t = tl.item(tl.length); |
| 93 assert_equals(t, null, "TouchList.item(TouchList.length) must return nul
l"); |
| 94 }, "TouchList.item returns null if the index is >= the length of the list"); |
| 95 } |
| 96 |
| 97 // Check a TouchEvent event's attributes for existence and proper type |
| 98 // Also check that each of the event's TouchList objects are valid |
| 99 // TA: 1.{3,4,5}.1.1, 1.{3,4,5}.1.2 |
| 100 function check_TouchEvent(ev) { |
| 101 test(function() { |
| 102 assert_true(ev instanceof TouchEvent, "event is a TouchEvent event"); |
| 103 }, ev.type + " event is a TouchEvent event"); |
| 104 [ |
| 105 ["TouchList", "touches"], |
| 106 ["TouchList", "targetTouches"], |
| 107 ["TouchList", "changedTouches"], |
| 108 ["boolean", "altKey"], |
| 109 ["boolean", "metaKey"], |
| 110 ["boolean", "ctrlKey"], |
| 111 ["boolean", "shiftKey"], |
| 112 ].forEach(function(attr) { |
| 113 var type = attr[0]; |
| 114 var name = attr[1]; |
| 115 // existence check |
| 116 test(function() { |
| 117 assert_true(name in ev, name + " attribute in " + ev.type + " event"
); |
| 118 }, ev.type + "." + name + " attribute exists"); |
| 119 // type check |
| 120 switch (type) { |
| 121 case "boolean": |
| 122 test(function() { |
| 123 assert_equals(typeof ev[name], "boolean", name + " attribute
of type boolean"); |
| 124 }, ev.type + "." + name + " attribute is of type boolean"); |
| 125 break; |
| 126 case "TouchList": |
| 127 test(function() { |
| 128 assert_equals(Object.prototype.toString.call(ev[name]), "[ob
ject TouchList]", name + " attribute of type TouchList"); |
| 129 }, ev.type + "." + name + " attribute is of type TouchList"); |
| 130 break; |
| 131 default: |
| 132 break; |
| 133 } |
| 134 }); |
| 135 } |
OLD | NEW |