2 <script src=
"../../../resources/js-test.js"></script>
15 <div id=
"grey" style=
"background-color:grey">
16 <div id=
"lightgreen" style=
"background-color:lightgreen">
17 <div id=
"green" style=
"background-color:green;">
22 <div id=
"console"></div>
25 description("Verifies that tapping on an element fires appropriate pointer events.");
29 var receivedPEsAtTarget
= [];
31 function getPhaseString(event
) {
32 return event
.eventPhase
== Event
.NONE
? "none" :
33 event
.eventPhase
== Event
.CAPTURING_PHASE
? "capturing" :
34 event
.eventPhase
== Event
.AT_TARGET
? "target" :
35 event
.eventPhase
== Event
.BUBBLING_PHASE
? "bubbling" :
40 ["grey", "lightgreen", "green"].forEach(function(id
) {
41 var targetDiv
= document
.getElementById(id
);
43 ["touchstart", "touchend", "touchmove"].forEach(function(eventName
) {
44 targetDiv
.addEventListener(eventName
, function(event
) {
46 debug(id
+ " received " + event
.type
+ " at phase=" + getPhaseString(event
));
50 ["pointerdown", "pointerup", "pointermove", "pointercancel"].forEach(function(eventName
) {
51 targetDiv
.addEventListener(eventName
, function(event
) {
52 if (event
.eventPhase
== Event
.AT_TARGET
)
53 receivedPEsAtTarget
.push(event
);
54 if (logAllEvents
|| event
.eventPhase
== Event
.AT_TARGET
)
55 debug(id
+ " received " + event
.type
+ " at phase=" + getPhaseString(event
));
57 event
.preventDefault();
64 function testEventSequences(x
, y
) {
65 eventSender
.addTouchPoint(x
, y
);
66 eventSender
.touchStart();
68 eventSender
.updateTouchPoint(0, x
+20, y
+20);
69 eventSender
.touchMove();
71 eventSender
.releaseTouchPoint(0);
72 eventSender
.touchEnd();
75 function testPEParamsSingleTouch(x
, y
) {
76 receivedPEsAtTarget
= [];
78 eventSender
.addTouchPoint(x
, y
);
79 eventSender
.touchStart();
80 shouldBeTrue("receivedPEsAtTarget[0].isPrimary");
81 shouldBeEqualToNumber("receivedPEsAtTarget[0].button", 0);
82 shouldBeEqualToNumber("receivedPEsAtTarget[0].buttons", 1);
83 shouldBeEqualToNumber("receivedPEsAtTarget[0].clientX", x
);
84 shouldBeEqualToNumber("receivedPEsAtTarget[0].clientY", y
);
86 eventSender
.updateTouchPoint(0, x
+20, y
+20);
87 eventSender
.touchMove();
88 shouldBeTrue("receivedPEsAtTarget[1].isPrimary");
89 shouldBeEqualToNumber("receivedPEsAtTarget[1].button", 0);
90 shouldBeEqualToNumber("receivedPEsAtTarget[1].buttons", 1);
91 shouldBeEqualToNumber("receivedPEsAtTarget[1].clientX", x
+20);
92 shouldBeEqualToNumber("receivedPEsAtTarget[1].clientY", y
+20);
94 eventSender
.releaseTouchPoint(0);
95 eventSender
.touchEnd();
96 shouldBeTrue("receivedPEsAtTarget[2].isPrimary");
97 shouldBeEqualToNumber("receivedPEsAtTarget[2].button", 0);
98 shouldBeEqualToNumber("receivedPEsAtTarget[2].buttons", 0);
100 shouldBeEqualToNumber("receivedPEsAtTarget.length", 3);
103 function testPEParamsMultiTouch(x
, y
) {
104 receivedPEsAtTarget
= [];
106 eventSender
.addTouchPoint(x
, y
);
107 eventSender
.touchStart();
108 shouldBeTrue("receivedPEsAtTarget[0].isPrimary");
109 var idFirst
= receivedPEsAtTarget
[0].pointerId
;
110 debug("receivedPEsAtTarget[0].pointerId=" + idFirst
)
112 eventSender
.addTouchPoint(x
+10, y
+10);
113 eventSender
.touchStart();
114 shouldBeFalse("receivedPEsAtTarget[1].isPrimary");
115 var idSecond
= receivedPEsAtTarget
[1].pointerId
;
116 debug("receivedPEsAtTarget[1].pointerId=" + idSecond
)
118 eventSender
.updateTouchPoint(1, x
+20, y
+20);
119 eventSender
.touchMove();
120 shouldBeFalse("receivedPEsAtTarget[2].isPrimary");
121 shouldBeEqualToNumber("receivedPEsAtTarget[2].pointerId", idSecond
);
123 eventSender
.releaseTouchPoint(0);
124 eventSender
.touchEnd();
125 shouldBeTrue("receivedPEsAtTarget[3].isPrimary");
126 shouldBeEqualToNumber("receivedPEsAtTarget[3].pointerId", idFirst
);
128 eventSender
.updateTouchPoint(0, x
+10, y
+10);
129 eventSender
.touchMove();
130 shouldBeFalse("receivedPEsAtTarget[4].isPrimary");
131 shouldBeEqualToNumber("receivedPEsAtTarget[4].pointerId", idSecond
);
133 eventSender
.addTouchPoint(x
, y
);
134 eventSender
.touchStart();
135 shouldBeFalse("receivedPEsAtTarget[5].isPrimary");
136 var idThird
= receivedPEsAtTarget
[5].pointerId
;
137 debug("receivedPEsAtTarget[5].pointerId=" + idThird
)
139 eventSender
.releaseTouchPoint(0);
140 eventSender
.touchEnd();
141 shouldBeFalse("receivedPEsAtTarget[6].isPrimary");
142 shouldBeEqualToNumber("receivedPEsAtTarget[6].pointerId", idSecond
);
144 eventSender
.releaseTouchPoint(0);
145 eventSender
.touchEnd();
146 shouldBeFalse("receivedPEsAtTarget[7].isPrimary");
147 shouldBeEqualToNumber("receivedPEsAtTarget[7].pointerId", idThird
);
149 eventSender
.addTouchPoint(x
, y
);
150 eventSender
.touchStart();
151 shouldBeTrue("receivedPEsAtTarget[8].isPrimary");
153 shouldBeEqualToNumber("receivedPEsAtTarget.length", 9);
156 function runTests() {
157 var rect
= document
.getElementById("green").getBoundingClientRect();
158 var x
= rect
.left
+ 10;
159 var y
= rect
.top
+ 10;
162 preventDefault
= false;
164 debug("--- test PE+TE event sequences without preventDefault ---");
165 testEventSequences(x
, y
);
168 preventDefault
= true;
170 debug("--- test PE+TE event sequences with PE preventDefault ---");
171 testEventSequences(x
, y
);
174 logAllEvents
= false;
176 debug("--- test PE params for single-touch ---");
177 testPEParamsSingleTouch(x
, y
);
180 debug("--- test PE isPrimary values ---");
181 testPEParamsMultiTouch(x
, y
);
186 if (window
.eventSender
)
189 debug("This test requires eventSender");