blob: e91d1b9fbaf3377801490cf4817d1d5f6575d307 [file] [log] [blame]
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script type="text/javascript">
'use strict';
const testCases = {
'mousedown': () => eventSender.mouseDown(),
'keydown': () => eventSender.keyDown('x'),
'touchstart': () => {
eventSender.addTouchPoint(1, 1);
eventSender.touchStart();
},
'click': () => eventSender.gestureTap(1, 1),
'contextmenu': () => eventSender.contextClick(),
'wheel': () => eventSender.mouseScrollBy(0, -50),
};
let receivedEvents = [];
for (let eventName in testCases)
createTest(eventName, testCases[eventName]);
function createTest(eventName, dispatchEventFn) {
async_test(function(t) {
document.addEventListener(eventName, t.step_func(function(e) {
receivedEvents.push(eventName);
// Prevent default to ensure contextmenu is not shown which can
// potentially hijack other events.
e.preventDefault();
const platformTimestamp = eventSender.lastEventTimestamp(); // in seconds
const expectedUnclampedTimestamp = internals.monotonicTimeToZeroBasedDocumentTime(platformTimestamp) * 1000; // in milliseconds
// Time clamping logic in Blink can introduce at most 2*100us of
// difference. Use 0.200001 instead of 0.2 to deal with floating
// point comparison issues.
assert_approx_equals(e.timeStamp, expectedUnclampedTimestamp, 0.200001);
t.done();
}));
dispatchEventFn();
t.step_timeout(function() {
assert_unreached("timeout with received events: " + receivedEvents.join(', '));
}, 5000);
}, "Event timestamp should be equal to the timestamp provided by the platform for " + eventName);
}
</script>