| Index: third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.html
|
| diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.html b/third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fe385b95113090b578ed18232a659f6f7564246b
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.html
|
| @@ -0,0 +1,124 @@
|
| +<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
|
| +<script>
|
| +window.addEventListener("keydown", logEvent);
|
| +window.addEventListener("mousedown", logEvent);
|
| +window.addEventListener("touchstart", logEvent);
|
| +
|
| +var receivedTimestamps = [];
|
| +
|
| +function logEvent(event)
|
| +{
|
| + log("-----Event-----");
|
| + log("type: " + event.type);
|
| + receivedTimestamps.push(event.timeStamp);
|
| +}
|
| +
|
| +function verifyTimestamps()
|
| +{
|
| + log("-----Verify-----");
|
| + log("Received " + receivedTimestamps.length + " timestamps");
|
| +
|
| + // Event.timeStamp values are in milliseconds
|
| + var expectedOffsets = [0, 5000, 10000, 15000, 20000, 25000];
|
| + var receivedOffsets = receivedTimestamps.map(function(timestamp) {
|
| + return timestamp - receivedTimestamps[0];
|
| + });
|
| + for (var i = 0; i < receivedOffsets.length; ++i) {
|
| + if (isNear(receivedOffsets[i], expectedOffsets[i]))
|
| + log("timeStamps offsets is as expected.");
|
| + else
|
| + log("timeStamp offset is expected " + expectedOffsets[i] + " but it is:" + receivedOffsets[i]);
|
| + }
|
| +
|
| + function isNear(a, b) {
|
| + var epsilon = 0.5;
|
| + return Math.abs(b - a) < epsilon;
|
| + }
|
| +
|
| +}
|
| +
|
| +function test()
|
| +{
|
| + // We send epoch timestamp but expect to receive high-res timestamps
|
| + var baseEpochTimestamp = Date.now() / 1000; // in seconds
|
| + var sentTimestamps = [0, 5, 10, 15, 20, 25].map(function(offset) {
|
| + return baseEpochTimestamp + offset;
|
| + });
|
| +
|
| + var commands = [{
|
| + value: "Input.dispatchKeyEvent",
|
| + event: {
|
| + "type": "rawKeyDown",
|
| + "timestamp": sentTimestamps[0]
|
| + }
|
| + }, {
|
| + value: "Input.dispatchKeyEvent",
|
| + event: {
|
| + "type": "rawKeyDown",
|
| + "timestamp": sentTimestamps[1]
|
| + }
|
| + }, {
|
| + value: "Input.dispatchMouseEvent",
|
| + event: {
|
| + "type": "mousePressed",
|
| + "timestamp": sentTimestamps[2],
|
| + "button": "left",
|
| + "clickCount": 1,
|
| + "x": 100,
|
| + "y": 200
|
| + }
|
| + }, {
|
| + value: "Input.dispatchMouseEvent",
|
| + event: {
|
| + "type": "mousePressed",
|
| + "timestamp": sentTimestamps[3],
|
| + "button": "left",
|
| + "clickCount": 1,
|
| + "x": 100,
|
| + "y": 200
|
| + }
|
| + }, {
|
| + value: "Input.dispatchTouchEvent",
|
| + event: {
|
| + "type": "touchStart",
|
| + "timestamp": sentTimestamps[4],
|
| + "touchPoints": [{
|
| + "state": "touchPressed",
|
| + "x": 100,
|
| + "y": 200
|
| + }]
|
| + }
|
| + }, {
|
| + value: "Input.dispatchTouchEvent",
|
| + event: {
|
| + "type": "touchStart",
|
| + "timestamp": sentTimestamps[5],
|
| + "touchPoints": [{
|
| + "state": "touchPressed",
|
| + "x": 100,
|
| + "y": 100
|
| + }]
|
| +
|
| + }
|
| + }];
|
| +
|
| + for (var i = 0; i < commands.length; i++)
|
| + InspectorTest.sendCommand(commands[i].value, commands[i].event, checkResponse.bind(undefined, i == commands.length - 1));
|
| +
|
| + function checkResponse(isLastCommand, msg)
|
| + {
|
| + if (msg.error)
|
| + InspectorTest.log("Error: " + msg.error.message);
|
| + if (isLastCommand) {
|
| + InspectorTest.sendCommandOrDie("Runtime.evaluate", {
|
| + expression: 'verifyTimestamps()'
|
| + }, function() {
|
| + InspectorTest.completeTest();
|
| + });
|
| + }
|
| + }
|
| +}
|
| +</script>
|
| +
|
| +<body onload="runTest()">
|
| +</body>
|
|
|