1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
<!doctype html>
<html>
<head>
<title>Pointer Events predicted events count and properties<</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- Additional helper script for common checks across event types -->
<script type="text/javascript" src="pointerevent_support.js"></script>
<script>
var eventList = All_Pointer_Events;
PhaseEnum = {
WaitingForCancel: 0,
WaitingForOver: 1,
WaitingForEnter: 2,
WaitingForDown: 3,
WaitingForMove: 4,
WaitingForUp: 5,
WaitingForOut: 6,
WaitingForLeave: 7,
Done: 8,
};
var phase = PhaseEnum.WaitingForCancel;
var move_event_count = 0;
function resetTestState() {
phase = PhaseEnum.WaitingForCancel;
}
function expect_no_predicted_events(event, eventName) {
test(function () {
assert_equals(event.getPredictedEvents().length, 0, eventName + ' should not have any predicted events');
}, expectedPointerType + ' ' + eventName + ' should not have any predicted events');
}
function run() {
var test_pointerEvent = setup_pointerevent_test("predicted events attributes in pointerevents", ['touch']);
var target0 = document.getElementById("target0");
var target1 = document.getElementById("target1");
on_event(target0, 'pointercancel', function (event) {
if (phase == PhaseEnum.WaitingForCancel) {
expect_no_predicted_events(event, 'pointercancel');
phase++;
}
});
eventList.forEach(function(eventName) {
on_event(target1, eventName, function (event) {
switch (phase) {
case PhaseEnum.WaitingForOver:
if (eventName == 'pointerover') {
expect_no_predicted_events(event, eventName);
phase++;
}
break;
case PhaseEnum.WaitingForEnter:
if (eventName == 'pointerenter') {
expect_no_predicted_events(event, eventName);
phase++;
}
break;
case PhaseEnum.WaitingForDown:
if (eventName == 'pointerdown') {
expect_no_predicted_events(event, eventName);
phase++;
setTimeout(function(){
// This is just a way to block the main thread.
var current = new Date().getTime();
for (; new Date().getTime() - current < 500;);
}, 0);
}
break;
case PhaseEnum.WaitingForMove:
if (eventName == 'pointermove') {
if (event.getPredictedEvents().length > 0) {
var predictedEvents = event.getPredictedEvents();
test (function() {
for (var i=0; i<predictedEvents.length; i++) {
assert_equals(predictedEvents[i].isTrusted, true, 'isTrusted flag should be true for predicted events.');
if (i > 0)
assert_greater_than_equal(predictedEvents[i].timeStamp, predictedEvents[i-1].timeStamp, 'Time stamps of predicted events must be ascending.');
}
}, expectedPointerType + ' pointermove predicted events should all be marked as trusted.');
test (function() {
for (var i=1; i<predictedEvents.length; i++)
assert_greater_than_equal(predictedEvents[i].timeStamp, predictedEvents[i-1].timeStamp, 'Time stamps of predicted events must be ascending.');
}, expectedPointerType + ' time stamps of predicted events must be ascending.');
test (function() {
for (var i=0; i<predictedEvents.length; i++) {
assert_equals(predictedEvents[i].bubbles, false, 'Bubbles attribute should be false for predicted events.');
assert_equals(predictedEvents[i].cancelable, false, 'Cancelable attribute should be false for predicted events.');
}
}, expectedPointerType + ' pointermove predicted events should all bubbles and cancelable as false.');
phase++;
} else {
assert_less_than(move_event_count++, 20, "pointermove have no predicted event in 20 moves")
}
}
break;
case PhaseEnum.WaitingForUp:
if (eventName == 'pointerup') {
expect_no_predicted_events(event, eventName);
phase++;
}
break;
case PhaseEnum.WaitingForOut:
if (eventName == 'pointerout') {
expect_no_predicted_events(event, eventName);
phase++;
}
break;
case PhaseEnum.WaitingForLeave:
if (eventName == 'pointerleave') {
expect_no_predicted_events(event, eventName);
phase++;
test (function() {
assert_true(false);
})
test_pointerEvent.done();
}
break;
}
});
});
}
</script>
</head>
<body onload="run()">
<h1>Pointer Events predicted events count and properties</h1>
<h2 id="pointerTypeDescription"></h2>
<h4>
Test Description: This test checks the predicted events of all types of pointer events.
<ol>
<li>Pointer down in the black square and drag inside the black square immediately</li>
<li>Release the pointer.</li>
<li>Pointer down in the purple square and drag inside the purple square immediately</li>
<li>Release the pointer and move out of the purple square</li>
</ol>
Test passes if the proper behavior of the events is observed.
</h4>
<div id="target0"></div>
<div id="target1" class="touchActionNone"></div>
<div id="complete-notice">
<p>The following pointer types were detected: <span id="pointertype-log"></span>.</p>
<p>Refresh the page to run the tests again with a different pointer type.</p>
</div>
</body>
</html>
|