Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.html

Issue 1747383002: Convert Devtools protocol Input timestamp to monotonic clock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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>

Powered by Google App Engine
This is Rietveld 408576698