basic-multi-touch-events.js revision dcc8cf2e65d1aa555cce12431a16547e66b469ee
1var div = document.createElement("div"); 2div.id = "touchtarget"; 3div.style.width = "100px"; 4div.style.height = "100px"; 5div.style.backgroundColor = "blue"; 6 7var lastEvent = null; 8var touchEventsReceived = 0; 9var EXPECTED_TOUCH_EVENTS_TOTAL = 4; 10 11function touchEventCallback() { 12 if (window.eventSender) { 13 lastEvent = event; 14 verifyTouch(touchEventsReceived++); 15 } else { 16 debug(event.type); 17 } 18 19 if (window.layoutTestController && touchEventsReceived == EXPECTED_TOUCH_EVENTS_TOTAL) { 20 // If we've got here, we can safely say we were successfully parsed :) We need to 21 // call the isSucccessfullyParsed function to output the correct TEST COMPLETE 22 // footer message. 23 successfullyParsed = true; 24 isSuccessfullyParsed(); 25 layoutTestController.notifyDone(); 26 } 27} 28 29div.addEventListener("touchstart", touchEventCallback, false); 30div.addEventListener("touchmove", touchEventCallback, false); 31div.addEventListener("touchend", touchEventCallback, false); 32document.body.insertBefore(div, document.body.firstChild); 33 34function verifyTouchEvent(type, totalTouchCount, changedTouchCount, targetTouchCount) 35{ 36 shouldBeEqualToString("lastEvent.type", type); 37 shouldBe("lastEvent.touches.length", totalTouchCount.toString()); 38 shouldBe("lastEvent.changedTouches.length", changedTouchCount.toString()); 39 shouldBe("lastEvent.targetTouches.length", targetTouchCount.toString()); 40 shouldBe("lastEvent.pageX", "0"); 41 shouldBe("lastEvent.pageY", "0"); 42} 43 44function verifyTouchPoint(list, point, x, y, id) 45{ 46 shouldBe("lastEvent." + list + "[" + point + "].pageX", x.toString()); 47 shouldBe("lastEvent." + list + "[" + point + "].pageY", y.toString()); 48 shouldBe("lastEvent." + list + "[" + point + "].clientX", x.toString()); 49 shouldBe("lastEvent." + list + "[" + point + "].clientY", y.toString()); 50 shouldBe("lastEvent." + list + "[" + point + "].identifier", id.toString()); 51} 52 53function verifyTouch(which) { 54 switch (which) { 55 case 0: 56 verifyTouchEvent("touchstart", 2, 2, 2); 57 verifyTouchPoint("touches", 0, 10, 10, 0); 58 verifyTouchPoint("touches", 1, 20, 30, 1); 59 verifyTouchPoint("changedTouches", 0, 10, 10, 0); 60 verifyTouchPoint("changedTouches", 1, 20, 30, 1); 61 verifyTouchPoint("targetTouches", 0, 10, 10, 0); 62 verifyTouchPoint("targetTouches", 1, 20, 30, 1); 63 break; 64 case 1: 65 verifyTouchEvent("touchmove", 2, 1, 2); 66 verifyTouchPoint("touches", 0, 15, 15, 0); 67 verifyTouchPoint("changedTouches", 0, 15, 15, 0); 68 verifyTouchPoint("touches", 1, 20, 30, 1); 69 break; 70 case 2: 71 verifyTouchEvent("touchend", 1, 1, 1); 72 verifyTouchPoint("touches", 0, 20, 30, 1); 73 verifyTouchPoint("changedTouches", 0, 15, 15, 0); 74 verifyTouchPoint("targetTouches", 0, 20, 30, 1); 75 break; 76 case 3: 77 verifyTouchEvent("touchend", 0, 1, 0); 78 verifyTouchPoint("changedTouches", 0, 20, 30, 1); 79 break; 80 81 default: testFailed("Wrong number of touch events! (" + which + ")"); 82 } 83} 84 85function multiTouchSequence() 86{ 87 debug("multi touch sequence"); 88 89 debug("Two touchpoints pressed"); 90 eventSender.addTouchPoint(10, 10); 91 eventSender.addTouchPoint(20, 30); 92 eventSender.touchStart(); 93 94 debug("First touchpoint moved"); 95 eventSender.updateTouchPoint(0, 15, 15); 96 eventSender.touchMove(); 97 98 debug("First touchpoint is released"); 99 eventSender.releaseTouchPoint(0); 100 eventSender.touchEnd(); 101 102 debug("Last remaining touchpoint is released"); 103 eventSender.releaseTouchPoint(0); 104 eventSender.touchEnd(); 105} 106 107if (window.eventSender) { 108 description("This tests basic multi touch event support."); 109 110 lastEvent = null; 111 eventSender.clearTouchPoints(); 112 multiTouchSequence(); 113} else { 114 debug("This test requires DumpRenderTree. Tap on the blue rect to log.") 115} 116 117var successfullyParsed = true; 118