blob: 1276d3657f8fdbda3ec880ebba07128f65a7876f [file] [log] [blame]
<!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>