1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"target" style=
"padding: 10px; background-color: blue;"></div>
9 <div id=
"console"></div>
11 description("Tests that events are received properly even when we never saw the touchstart for the first finger (eg. was skipped by cc touch hit testing) - crbug.com/363321");
14 var expectingStart
= false;
15 var expectingEnd
= false;
17 var target
= document
.getElementById('target');
18 var rect
= target
.getBoundingClientRect();
19 var targetX
= rect
.left
+ rect
.width
/ 2;
20 var targetY
= rect
.top
+ rect
.height
/ 2;
22 window
.addEventListener('touchstart', function(e
) {
23 if (!expectingStart
) {
24 testFailed('Got unexpected touchstart event');
27 expectingStart
= false;
30 shouldBe('event.target', 'target');
32 // Touch ID 0 is the one we never got a touchstart for, so it should
33 // be targetted at the document.
34 shouldBe('event.touches.length', '2');
35 shouldBe('event.touches[0].identifier', '0');
36 shouldBe('event.touches[0].pageX', '12');
37 shouldBe('event.touches[0].pageY', '0');
38 shouldBe('event.touches[0].target', 'document');
40 // Touch ID 1 should be the new touch.
41 shouldBe('event.touches[1].identifier', '1');
42 shouldBe('event.touches[1].pageX', 'targetX');
43 shouldBe('event.touches[1].pageY', 'targetY');
44 shouldBe('event.touches[1].target', 'target');
46 shouldBe('event.changedTouches.length', '1');
47 shouldBe('event.changedTouches[0].identifier', '1');
49 shouldBe('event.targetTouches.length', '1');
50 shouldBe('event.targetTouches[0].identifier', '1');
53 window
.addEventListener('touchmove', function(e
) {
54 testFailed('Got unexpected touchmove event');
57 window
.addEventListener('touchend', function(e
) {
59 testFailed('Got unexpected touchstart event');
65 shouldBe('event.target', 'target');
67 shouldBe('event.touches.length', '0');
69 shouldBe('event.changedTouches.length', '1');
70 shouldBe('event.changedTouches[0].identifier', '1');
71 shouldBe('event.changedTouches[0].pageX', 'targetX');
72 shouldBe('event.changedTouches[0].pageY', 'targetY');
73 shouldBe('event.changedTouches[0].target', 'target');
75 shouldBe('event.targetTouches.length', '0');
78 if (document
.elementFromPoint(targetX
, targetY
) != target
) {
79 testFailed('Failed to hit expected target at ' + targetX
+ ',' + targetY
);
80 } else if (!window
.eventSender
) {
81 testFailed('This test requires eventSender');
83 eventSender
.clearTouchPoints();
85 // First touch point is outside our target, but we never actually
86 // get a touchstart event sent to the renderer for it.
87 eventSender
.addTouchPoint(10, 0);
88 eventSender
.updateTouchPoint(0, 12, 0);
90 // Second point is on our target and we expect touchstart
91 eventSender
.addTouchPoint(targetX
, targetY
);
92 debug('Sending touchstart event.');
93 expectingStart
= true;
94 eventSender
.touchStart();
96 testFailed("Didn't receive expected touchstart event");
99 // Make sure we don't get any events (or crash) if we receive a move or
100 // end for just the first touch point.
101 debug('Sending touchmove and touchend for unrelated touch point.');
102 eventSender
.updateTouchPoint(0, 13, 0);
103 eventSender
.touchMove();
104 eventSender
.releaseTouchPoint(0);
105 eventSender
.touchEnd();
108 // If the 2nd touch point lifts, we get an event showing just that change.
109 debug('Sending touchend.');
110 eventSender
.releaseTouchPoint(0);
112 eventSender
.touchEnd();
114 testFailed("Didn't receive expected touchend event");