Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto r-protocol-test.js"></script> | |
| 2 <script> | |
| 3 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.
| |
| 4 window.addEventListener("mousedown", logEvent); | |
| 5 window.addEventListener("touchstart", logEvent); | |
| 6 | |
| 7 var receivedTimestamps = []; | |
| 8 | |
| 9 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.
| |
| 10 log("-----Event-----"); | |
| 11 log("type: " + event.type); | |
| 12 receivedTimestamps.push(event.timeStamp); | |
| 13 } | |
| 14 | |
| 15 function verifyTimestamps() { | |
| 16 log("-----Verify-----"); | |
| 17 log("Received " + receivedTimestamps.length + " timestamps"); | |
| 18 | |
| 19 // Event.timeStamp values are in milliseconds | |
| 20 var expectedOffsets = [0, 5000, 10000, 15000, 20000, 25000]; | |
| 21 var receivedOffsets = receivedTimestamps.map(function(timestamp) { | |
| 22 return timestamp - receivedTimestamps[0]; | |
| 23 }); | |
| 24 for (var i = 0; i < receivedOffsets.length; ++i) { | |
| 25 if (isNear(receivedOffsets[i], expectedOffsets[i])) | |
| 26 log("timeStamps offsets is as expected."); | |
| 27 else | |
| 28 log("timeStamp offset is expected " + expectedOffsets[i] + " but it is:" + receivedOffsets[i]); | |
| 29 } | |
| 30 | |
| 31 function isNear(a, b) { | |
| 32 var epsilon = 0.01; | |
| 33 return Math.abs(b - a) < epsilon; | |
| 34 } | |
| 35 | |
| 36 } | |
| 37 | |
| 38 function test() { | |
| 39 // We send epoch timestamp but expect to receive high-res timestamps | |
| 40 var baseEpochTimestamp = Date.now() / 1000; // in seconds | |
| 41 var sentTimestamps = [0, 5, 10, 15, 20, 25].map(function(offset) { | |
| 42 return baseEpochTimestamp + offset; | |
| 43 }); | |
| 44 | |
| 45 var commands = [{ | |
| 46 value: "Input.dispatchKeyEvent", | |
| 47 event: { | |
| 48 "type": "rawKeyDown", | |
| 49 "timestamp": sentTimestamps[0] | |
| 50 } | |
| 51 }, { | |
| 52 value: "Input.dispatchKeyEvent", | |
| 53 event: { | |
| 54 "type": "rawKeyDown", | |
| 55 "timestamp": sentTimestamps[1] | |
| 56 } | |
| 57 }, { | |
| 58 value: "Input.dispatchMouseEvent", | |
| 59 event: { | |
| 60 "type": "mousePressed", | |
| 61 "timestamp": sentTimestamps[2], | |
| 62 "button": "left", | |
| 63 "clickCount": 1, | |
| 64 "x": 100, | |
| 65 "y": 200 | |
| 66 } | |
| 67 }, { | |
| 68 value: "Input.dispatchMouseEvent", | |
| 69 event: { | |
| 70 "type": "mousePressed", | |
| 71 "timestamp": sentTimestamps[3], | |
| 72 "button": "left", | |
| 73 "clickCount": 1, | |
| 74 "x": 100, | |
| 75 "y": 200 | |
| 76 } | |
| 77 }, { | |
| 78 value: "Input.dispatchTouchEvent", | |
| 79 event: { | |
| 80 "type": "touchStart", | |
| 81 "timestamp": sentTimestamps[4], | |
| 82 "touchPoints": [{ | |
| 83 "state": "touchPressed", | |
| 84 "x": 100, | |
| 85 "y": 200 | |
| 86 }] | |
| 87 } | |
| 88 }, { | |
| 89 value: "Input.dispatchTouchEvent", | |
| 90 event: { | |
| 91 "type": "touchStart", | |
| 92 "timestamp": sentTimestamps[5], | |
| 93 "touchPoints": [{ | |
| 94 "state": "touchPressed", | |
| 95 "x": 100, | |
| 96 "y": 100 | |
| 97 }] | |
| 98 | |
| 99 } | |
| 100 }]; | |
| 101 | |
| 102 for (var i = 0; i < commands.length; i++) | |
| 103 InspectorTest.sendCommand(commands[i].value, commands[i].event, chec kResponse.bind(undefined, i == commands.length - 1)); | |
| 104 | |
| 105 function checkResponse(isLastCommand, msg) { | |
| 106 if (msg.error) | |
| 107 InspectorTest.log("Error: " + msg.error.message); | |
| 108 if (isLastCommand) { | |
| 109 InspectorTest.sendCommandOrDie("Runtime.evaluate", { | |
| 110 expression: 'verifyTimestamps()' | |
| 111 }); | |
| 112 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.
| |
| 113 } | |
| 114 } | |
| 115 } | |
| 116 </script> | |
| 117 | |
| 118 <body onload="runTest()"> | |
| 119 </body> | |
| OLD | NEW |