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

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

Issue 2961493002: [DevTools] Migrate inspector-protocol/{input,network} tests to new harness (Closed)
Patch Set: Created 3 years, 6 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 (async function(testRunner) {
2 let {page, session, dp} = await testRunner.startBlank(``);
3
4 await session.evaluate(`
5 var logs = [];
6 function log(text) {
7 logs.push(text);
8 }
9
10 var receivedTimestamps = [];
11 function logEvent(event) {
12 log('-----Event-----');
13 log('type: ' + event.type);
14 receivedTimestamps.push(event.timeStamp);
15 }
16
17 function verifyTimestamps() {
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) {
allada 2017/06/26 22:02:53 Lets arrow function this since we are here.
dgozman 2017/06/26 23:22:08 Done.
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 return logs.join('\\n');
39 }
40
41 window.addEventListener('keydown', logEvent);
42 window.addEventListener('mousedown', logEvent);
43 window.addEventListener('touchstart', logEvent);
44 `);
45
46 // We send epoch timestamp but expect to receive high-res timestamps
47 var baseEpochTimestamp = Date.now() / 1000; // in seconds
48 var sentTimestamps = [0, 5, 10, 15, 20, 25].map(function(offset) {
allada 2017/06/26 22:02:53 Lets arrow function this.
dgozman 2017/06/26 23:22:08 Done.
49 return baseEpochTimestamp + offset;
50 });
51
52 var commands = [{
53 method: dp.Input.dispatchKeyEvent,
allada 2017/06/26 22:02:54 lets bind these to dq.Input and move event into th
dgozman 2017/06/26 23:22:08 Done.
54 event: {
55 'type': 'rawKeyDown',
56 'timestamp': sentTimestamps[0]
57 }
58 }, {
59 method: dp.Input.dispatchKeyEvent,
60 event: {
61 'type': 'rawKeyDown',
62 'timestamp': sentTimestamps[1]
63 }
64 }, {
65 method: dp.Input.dispatchMouseEvent,
66 event: {
67 'type': 'mousePressed',
68 'timestamp': sentTimestamps[2],
69 'button': 'left',
70 'clickCount': 1,
71 'x': 100,
72 'y': 200
73 }
74 }, {
75 method: dp.Input.dispatchMouseEvent,
76 event: {
77 'type': 'mousePressed',
78 'timestamp': sentTimestamps[3],
79 'button': 'left',
80 'clickCount': 1,
81 'x': 100,
82 'y': 200
83 }
84 }, {
85 method: dp.Input.dispatchTouchEvent,
86 event: {
87 'type': 'touchStart',
88 'timestamp': sentTimestamps[4],
89 'touchPoints': [{
90 'state': 'touchPressed',
91 'x': 100,
92 'y': 200
93 }]
94 }
95 }, {
96 method: dp.Input.dispatchTouchEvent,
97 event: {
98 'type': 'touchStart',
99 'timestamp': sentTimestamps[5],
100 'touchPoints': [{
101 'state': 'touchPressed',
102 'x': 100,
103 'y': 100
104 }]
105
106 }
107 }];
108
109 for (var command of commands) {
110 var msg = await command.method.call(dp.Input, command.event);
allada 2017/06/26 22:02:53 And just call the method by itself.
dgozman 2017/06/26 23:22:08 Done.
111 if (msg.error)
112 testRunner.log('Error: ' + msg.error.message);
113 }
114 testRunner.log(await session.evaluate('verifyTimestamps()'));
allada 2017/06/26 22:02:53 It looks like the other tests do a check here to c
dgozman 2017/06/26 23:22:08 Well, we know that commands are coming in the same
allada 2017/06/27 19:08:16 Yes, but we do not know if the event listeners wer
dgozman 2017/06/27 20:01:54 Done.
115 testRunner.completeTest();
116 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698