OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 TODO(chongz): Remove this file and import from w3c tests after approved. |
| 3 crbug.com/552530 |
| 4 --> |
| 5 <!DOCTYPE HTML> |
| 6 <html> |
| 7 <!-- |
| 8 Test cases for Touch Events v2 Recommendation |
| 9 https://w3c.github.io/touch-events/ |
| 10 |
| 11 These tests are based on Mozilla-Nokia-Google's single-touch tests. |
| 12 |
| 13 The primary purpose of the tests in this document is checking that the creat
eTouch and |
| 14 createTouchList interfaces of the Touch Events APIs are correctly implemente
d. |
| 15 Other interactions are covered in other test files. |
| 16 |
| 17 This document references Test Assertions (abbrev TA below) written by Cathy
Chan |
| 18 http://www.w3.org/2010/webevents/wiki/TestAssertions |
| 19 --> |
| 20 |
| 21 <head> |
| 22 <title>Touch Events Touch and TouchEvent Constructor Tests</title> |
| 23 <meta name="viewport" content="width=device-width"> |
| 24 <script src="../../../resources/testharness.js"></script> |
| 25 <script src="../../../resources/testharnessreport.js"></script> |
| 26 <script src="touch-support.js"></script> |
| 27 <script> |
| 28 setup({ |
| 29 explicit_done: true |
| 30 }); |
| 31 |
| 32 function run() { |
| 33 var target0 = document.getElementById("target0"); |
| 34 var touch1, touch2; |
| 35 var touchEvent1; |
| 36 |
| 37 var testPageX = 15; |
| 38 var testPageY = 20.2; |
| 39 var testScreenX = 35.34; |
| 40 var testScreenY = 40.56; |
| 41 var testClientX = 10.175; |
| 42 var testClientY = 5; |
| 43 var approxEpsilon = 0.00001; |
| 44 |
| 45 test(function() { |
| 46 touch1 = new Touch({ |
| 47 identifier: 42, |
| 48 target: target0, |
| 49 pageX: testPageX, |
| 50 pageY: testPageY, |
| 51 screenX: testScreenX, |
| 52 screenY: testScreenY, |
| 53 clientX: testClientX, |
| 54 clientY: testClientY, |
| 55 }); |
| 56 check_Touch_object(touch1); |
| 57 assert_equals(touch1.target, target0, "touch.target is target0"); |
| 58 assert_equals(touch1.identifier, 42, "touch.identifier is requested valu
e"); |
| 59 assert_approx_equals(touch1.pageX, testPageX, approxEpsilon, "touch.page
X is requested value"); |
| 60 assert_approx_equals(touch1.pageY, testPageY, approxEpsilon, "touch.page
Y is requested value"); |
| 61 assert_approx_equals(touch1.screenX, testScreenX, approxEpsilon, "touch.
screenX is requested value"); |
| 62 assert_approx_equals(touch1.screenY, testScreenY, approxEpsilon, "touch.
screenY is requested value"); |
| 63 // Constructor does not calculate clientX/Y in v2 |
| 64 assert_approx_equals(touch1.clientX, testClientX, approxEpsilon, "touch.
clientX is requested value."); |
| 65 assert_approx_equals(touch1.clientY, testClientY, approxEpsilon, "touch.
clientY is requested value."); |
| 66 }, "Touch constructor exists and creates a Touch object with requested prope
rties"); |
| 67 |
| 68 test(function() { |
| 69 assert_throws(new TypeError(), function() {touch1 = new Touch();}, "Touc
h constructor requires initialize dictionary"); |
| 70 assert_throws(new TypeError(), function() {touch1 = new Touch({});}, "To
uch constructor requires identifier and target"); |
| 71 }, "Create a Touch object with insufficient properties"); |
| 72 |
| 73 test(function() { |
| 74 touch2 = new Touch({ |
| 75 identifier: 74, |
| 76 target: target0, |
| 77 }); |
| 78 check_Touch_object(touch2); |
| 79 assert_equals(touch2.target, target0, "touch.target is target0"); |
| 80 assert_equals(touch2.identifier, 74, "touch.identifier is requested valu
e"); |
| 81 assert_approx_equals(touch2.pageX, 0, approxEpsilon, "touch.pageX is def
ault value"); |
| 82 assert_approx_equals(touch2.pageY, 0, approxEpsilon, "touch.pageY is def
ault value"); |
| 83 assert_approx_equals(touch2.screenX, 0, approxEpsilon, "touch.screenX is
default value"); |
| 84 assert_approx_equals(touch2.screenY, 0, approxEpsilon, "touch.screenY is
default value"); |
| 85 assert_approx_equals(touch2.clientX, 0, approxEpsilon, "touch.clientX is
default value."); |
| 86 assert_approx_equals(touch2.clientY, 0, approxEpsilon, "touch.clientY is
default value."); |
| 87 }, "Touch constructor exists and creates a Touch object with minimum propert
ies"); |
| 88 |
| 89 test(function() { |
| 90 touch1 = new Touch({ |
| 91 identifier: 45, |
| 92 target: target0, |
| 93 pageX: 45, |
| 94 pageY: 50, |
| 95 screenX: 65, |
| 96 screenY: 60, |
| 97 clientX: 70, |
| 98 clientY: 75, |
| 99 }); |
| 100 touch2 = new Touch({ |
| 101 identifier: 52, |
| 102 target: target0, |
| 103 pageX: 15, |
| 104 pageY: 20, |
| 105 screenX: 15, |
| 106 screenY: 20, |
| 107 clientX: 15, |
| 108 clientY: 20, |
| 109 }); |
| 110 |
| 111 touchEvent1 = new TouchEvent("ontouchstart", { |
| 112 touches: [touch1, touch2], |
| 113 targetTouches: [touch1], |
| 114 altKey: true, |
| 115 metaKey: false, |
| 116 }); |
| 117 |
| 118 check_TouchEvent(touchEvent1); |
| 119 assert_equals(touchEvent1.type, "ontouchstart", "touchEvent.type is requ
ested value"); |
| 120 assert_equals(touchEvent1.touches.length, 2, "touchEvent.touches.length
is requested value"); |
| 121 assert_equals(touchEvent1.touches[0], touch1, "touchEvent.touches[0] is
requested value"); |
| 122 assert_equals(touchEvent1.touches[1], touch2, "touchEvent.touches[1] is
requested value"); |
| 123 assert_equals(touchEvent1.targetTouches.length, 1, "touchEvent.targetTou
ches.length is requested value"); |
| 124 assert_equals(touchEvent1.targetTouches[0], touch1, "touchEvent.targetTo
uches[0] is requested value"); |
| 125 assert_equals(touchEvent1.changedTouches.length, 0, "touchEvent.changedT
ouches.length is requested value"); |
| 126 assert_equals(touchEvent1.altKey, true, "touchEvent.altKey is requested
value"); |
| 127 assert_equals(touchEvent1.metaKey, false, "touchEvent.metaKey is request
ed value"); |
| 128 assert_equals(touchEvent1.ctrlKey, false, "touchEvent.ctrlKey is request
ed value"); |
| 129 assert_equals(touchEvent1.shiftKey, false, "touchEvent.shiftKey is reque
sted value."); |
| 130 }, "TouchEvent constructor exists and creates a TouchEvent object with reque
sted properties"); |
| 131 |
| 132 target0.innerHTML = "Test complete." |
| 133 done(); |
| 134 } |
| 135 </script> |
| 136 <style> |
| 137 div { |
| 138 margin: 0em; |
| 139 padding: 2em; |
| 140 } |
| 141 |
| 142 #target0 { |
| 143 background: yellow; |
| 144 border: 1px solid orange; |
| 145 } |
| 146 </style> |
| 147 </head> |
| 148 |
| 149 <body onload="run()"> |
| 150 <h1>Touch Events: Touch and TouchEvent constructor tests</h1> |
| 151 <div id="target0">Please wait for test to complete...</div> |
| 152 <div id="log"></div> |
| 153 </body> |
| 154 |
| 155 </html> |
OLD | NEW |