Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/inspector-protocol/input/emulateTouchFromMouseEvent.js |
| diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/input/emulateTouchFromMouseEvent.js b/third_party/WebKit/LayoutTests/inspector-protocol/input/emulateTouchFromMouseEvent.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..be2315326dacc3df4fe877d9e50bd2e940122168 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/inspector-protocol/input/emulateTouchFromMouseEvent.js |
| @@ -0,0 +1,109 @@ |
| +(async function(testRunner) { |
| + let {page, session, dp} = await testRunner.startBlank(``); |
| + |
| + await session.evaluate(` |
| + var logs = []; |
| + function log(text) { |
| + logs.push(text); |
| + } |
| + |
| + const expectedEventCount = 5; |
|
allada
2017/06/26 22:02:53
lets un-const this and set it to -1.
dgozman
2017/06/26 23:22:07
Done.
|
| + var eventCount = 0; |
| + var resolve; |
| + var gotEventsPromise = new Promise(f => resolve = f); |
| + |
| + function logEvent(event) { |
| + event.preventDefault(); |
|
allada
2017/06/26 22:02:53
Lets add an assert here like:
console.assert(expe
dgozman
2017/06/26 23:22:07
I am a bit hesitant on this - expecting flakes due
|
| + log('-----Event-----'); |
| + log('type: ' + event.type); |
| + if (event.shiftKey) |
| + log('shiftKey'); |
| + log('----Touches----'); |
| + for (var i = 0; i < event.touches.length; i++) { |
| + var touch = event.touches[i]; |
| + log('id: ' + i); |
| + log('pageX: ' + touch.pageX); |
| + log('pageY: ' + touch.pageY); |
| + log('radiusX: ' + touch.radiusX); |
| + log('radiusY: ' + touch.radiusY); |
| + log('rotationAngle: ' + touch.rotationAngle); |
| + log('force: ' + touch.force); |
| + } |
| + eventCount++; |
| + if (eventCount === expectedEventCount) |
| + resolve(logs.join('\\n')); |
| + } |
| + |
| + window.addEventListener('touchstart', logEvent, {passive: false}); |
| + window.addEventListener('touchmove', logEvent, {passive: false}); |
| + window.addEventListener('touchend', logEvent); |
| + window.addEventListener('touchcancel', logEvent); |
| + `); |
| + |
| + var events = [ |
| + { |
| + 'type': 'mousePressed', |
| + 'button': 'left', |
| + 'clickCount': 1, |
| + 'x': 100, |
| + 'y': 200 |
| + }, |
| + { |
| + 'type': 'mouseMoved', |
| + 'button': 'left', |
| + 'clickCount': 1, |
| + 'x': 100, |
| + 'y': 250 |
| + }, |
| + { |
| + 'type': 'mouseReleased', |
| + 'button': 'left', |
| + 'clickCount': 1, |
| + 'x': 100, |
| + 'y': 250 |
| + }, |
| + { |
| + 'type': 'mouseMoved', |
|
allada
2017/06/26 22:02:53
Add comment here saying something like:
// Should
dgozman
2017/06/26 23:22:07
Done.
|
| + 'button': 'none', |
| + 'modifiers': 8, // shift |
| + 'x': 50, |
| + 'y': 150 |
| + }, |
| + { |
| + 'type': 'mousePressed', |
| + 'button': 'left', |
| + 'clickCount': 1, |
| + 'x': 100, |
| + 'y': 200 |
| + }, |
| + { |
| + 'type': 'mouseMoved', |
| + 'button': 'left', |
| + 'clickCount': 1, |
| + 'x': 100, |
| + 'y': 250 |
| + }, |
| + { |
| + 'type': 'mouseReleased', |
| + 'button': 'left', |
| + 'clickCount': 1, |
| + 'x': 100, |
| + 'y': 250 |
| + } |
| + ]; |
| + |
|
allada
2017/06/26 22:02:53
lets add:
await session.evaluateAsync('expectedEv
dgozman
2017/06/26 23:22:07
Nice idea! Done.
|
| + await dp.Page.enable(); |
| + await dp.Page.setTouchEmulationEnabled({enabled: true}); |
| + |
| + var time = Number(new Date()) / 1000; |
| + for (var index = 0; index < events.length; index++) { |
| + var event = events[index]; |
| + event.timestamp = time + index; |
| + var msg = await dp.Input.emulateTouchFromMouseEvent(event); |
| + if (msg.error) |
| + testRunner.log('Error: ' + msg.error.message); |
| + } |
| + |
| + testRunner.log(await session.evaluateAsync('gotEventsPromise')); |
| + testRunner.completeTest(); |
| +}) |