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

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

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

Powered by Google App Engine
This is Rietveld 408576698