Chromium Code Reviews| 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..37ff7bc2e6d10033fd6f6de436d1aad0af2c7e86 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.html |
| @@ -0,0 +1,119 @@ |
| +<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script> |
| +<script> |
| + window.addEventListener("keydown", logEvent); |
|
dgozman
2016/03/09 17:08:21
style: no indentation in <script> tag
majidvp
2016/03/09 20:09:08
Done.
|
| + window.addEventListener("mousedown", logEvent); |
| + window.addEventListener("touchstart", logEvent); |
| + |
| + var receivedTimestamps = []; |
| + |
| + function logEvent(event) { |
|
dgozman
2016/03/09 17:08:21
style: { on next line for function body
majidvp
2016/03/09 20:09:08
Done.
|
| + 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.01; |
| + 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()' |
| + }); |
| + InspectorTest.completeTest(); |
|
dgozman
2016/03/09 17:08:21
You have to wait for Runtime.evaluate to finish be
majidvp
2016/03/09 20:09:08
Done.
|
| + } |
| + } |
| + } |
| +</script> |
| + |
| +<body onload="runTest()"> |
| +</body> |