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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.js
diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.js b/third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.js
new file mode 100644
index 0000000000000000000000000000000000000000..b8ef1a99662b5e25c9351cf813df94e993ee3a0e
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/inspector-protocol/input/eventTimestamp.js
@@ -0,0 +1,116 @@
+(async function(testRunner) {
+ let {page, session, dp} = await testRunner.startBlank(``);
+
+ await session.evaluate(`
+ var logs = [];
+ function log(text) {
+ logs.push(text);
+ }
+
+ 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) {
allada 2017/06/26 22:02:53 Lets arrow function this since we are here.
dgozman 2017/06/26 23:22:08 Done.
+ 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;
+ }
+
+ return logs.join('\\n');
+ }
+
+ window.addEventListener('keydown', logEvent);
+ window.addEventListener('mousedown', logEvent);
+ window.addEventListener('touchstart', logEvent);
+ `);
+
+ // 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) {
allada 2017/06/26 22:02:53 Lets arrow function this.
dgozman 2017/06/26 23:22:08 Done.
+ return baseEpochTimestamp + offset;
+ });
+
+ var commands = [{
+ 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.
+ event: {
+ 'type': 'rawKeyDown',
+ 'timestamp': sentTimestamps[0]
+ }
+ }, {
+ method: dp.Input.dispatchKeyEvent,
+ event: {
+ 'type': 'rawKeyDown',
+ 'timestamp': sentTimestamps[1]
+ }
+ }, {
+ method: dp.Input.dispatchMouseEvent,
+ event: {
+ 'type': 'mousePressed',
+ 'timestamp': sentTimestamps[2],
+ 'button': 'left',
+ 'clickCount': 1,
+ 'x': 100,
+ 'y': 200
+ }
+ }, {
+ method: dp.Input.dispatchMouseEvent,
+ event: {
+ 'type': 'mousePressed',
+ 'timestamp': sentTimestamps[3],
+ 'button': 'left',
+ 'clickCount': 1,
+ 'x': 100,
+ 'y': 200
+ }
+ }, {
+ method: dp.Input.dispatchTouchEvent,
+ event: {
+ 'type': 'touchStart',
+ 'timestamp': sentTimestamps[4],
+ 'touchPoints': [{
+ 'state': 'touchPressed',
+ 'x': 100,
+ 'y': 200
+ }]
+ }
+ }, {
+ method: dp.Input.dispatchTouchEvent,
+ event: {
+ 'type': 'touchStart',
+ 'timestamp': sentTimestamps[5],
+ 'touchPoints': [{
+ 'state': 'touchPressed',
+ 'x': 100,
+ 'y': 100
+ }]
+
+ }
+ }];
+
+ for (var command of commands) {
+ 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.
+ if (msg.error)
+ testRunner.log('Error: ' + msg.error.message);
+ }
+ 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.
+ testRunner.completeTest();
+})

Powered by Google App Engine
This is Rietveld 408576698