| OLD | NEW |
| 1 // This file contains the commonly used functions in pointerevent tests. | 1 // This file contains the commonly used functions in pointerevent tests. |
| 2 | 2 |
| 3 const scrollOffset = 20; | 3 const scrollOffset = 20; |
| 4 const boundaryOffset = 2; | 4 const boundaryOffset = 2; |
| 5 | 5 |
| 6 function delayPromise(delay) { | 6 function delayPromise(delay) { |
| 7 return new Promise(function(resolve, reject) { | 7 return new Promise(function(resolve, reject) { |
| 8 window.setTimeout(resolve, delay); | 8 window.setTimeout(resolve, delay); |
| 9 }); | 9 }); |
| 10 } | 10 } |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 for (var step=1; step<=maxStep; step++) | 468 for (var step=1; step<=maxStep; step++) |
| 469 action += '{ "name": "pointerMove", "x":' + (xPosition1 + Math.floor((st
ep/maxStep)*(xPosition2 - xPosition1))) +', "y":' + (yPosition1 + Math.floor((st
ep/maxStep)*(yPosition2 - yPosition1))) +' },'; | 469 action += '{ "name": "pointerMove", "x":' + (xPosition1 + Math.floor((st
ep/maxStep)*(xPosition2 - xPosition1))) +', "y":' + (yPosition1 + Math.floor((st
ep/maxStep)*(yPosition2 - yPosition1))) +' },'; |
| 470 action += '{ "name": "pointerUp" }]}]'; | 470 action += '{ "name": "pointerUp" }]}]'; |
| 471 chrome.gpuBenchmarking.pointerActionSequence(JSON.parse(action), resolve); | 471 chrome.gpuBenchmarking.pointerActionSequence(JSON.parse(action), resolve); |
| 472 } else { | 472 } else { |
| 473 reject(); | 473 reject(); |
| 474 } | 474 } |
| 475 }); | 475 }); |
| 476 } | 476 } |
| 477 | 477 |
| 478 function selectAndDrag(dragSelector, dropSelector) { |
| 479 return new Promise(function(resolve, reject) { |
| 480 if (window.eventSender) { |
| 481 const dragElement = document.querySelector(dragSelector); |
| 482 const dropElement = document.querySelector(dropSelector); |
| 483 if (dragElement.select) { |
| 484 dragElement.select(); |
| 485 } else { |
| 486 const selection = window.getSelection(); |
| 487 selection.collapse(dragElement, 0); |
| 488 selection.extend(dragElement, 1); |
| 489 } |
| 490 |
| 491 const xPosition1 = dragElement.offsetLeft + dragElement.offsetWidth
/ 2; |
| 492 const yPosition1 = dragElement.offsetTop + dragElement.offsetHeight
/ 2; |
| 493 const xPosition2 = dropElement.offsetLeft + dropElement.offsetWidth
/ 2; |
| 494 const yPosition2 = dropElement.offsetTop + dropElement.offsetHeight
/ 2; |
| 495 |
| 496 // --- Snippet 1 |
| 497 chrome.gpuBenchmarking.pointerActionSequence( [ |
| 498 {source: 'mouse', |
| 499 actions: [ |
| 500 { name: 'pointerMove', x: xPosition1, y: yPosition1 }, |
| 501 { name: 'pointerDown', x: xPosition1, y: yPosition1 }, |
| 502 { name: 'pause', duration: 0.6 }, |
| 503 { name: 'pointerMove', x: xPosition2, y: yPosition2 }, |
| 504 { name: 'pointerUp'}, |
| 505 ]}], resolve); |
| 506 // --- |
| 507 |
| 508 // --- Snippet 2 |
| 509 // eventSender.mouseMoveTo(xPosition1, yPosition1); |
| 510 // eventSender.mouseDown(); |
| 511 // eventSender.leapForward(600); |
| 512 // eventSender.mouseMoveTo(xPosition2, yPosition2); |
| 513 // eventSender.mouseUp(); |
| 514 // resolve(); |
| 515 // --- |
| 516 } else { |
| 517 reject(); |
| 518 } |
| 519 }); |
| 520 } |
| 521 |
| 478 { | 522 { |
| 479 var pointerevent_automation = async_test("PointerEvent Automation"); | 523 var pointerevent_automation = async_test("PointerEvent Automation"); |
| 480 // Defined in every test and should return a promise that gets resolved when i
nput is finished. | 524 // Defined in every test and should return a promise that gets resolved when i
nput is finished. |
| 481 inject_input().then(function() { | 525 inject_input().then(function() { |
| 482 pointerevent_automation.done(); | 526 pointerevent_automation.done(); |
| 483 }); | 527 }); |
| 484 } | 528 } |
| OLD | NEW |