drag-selection-over-target-text.html (1619B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Drag Selection over a text directive</title> 5 <meta charset="utf-8"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-actions.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 12 </head> 13 <body> 14 <p>This is a sample text.</p> 15 <script> 16 async function rAF() { 17 return new Promise((resolve) => { 18 window.requestAnimationFrame(resolve); 19 }); 20 } 21 22 document.addEventListener('DOMContentLoaded', () => { 23 24 const textElement = document.querySelector('p'); 25 26 const rect = textElement.getBoundingClientRect(); 27 const startX = rect.left + 5; 28 const startY = rect.top + 5; 29 const endX = rect.right - 5; 30 const endY = rect.top + 5; 31 32 promise_test(async t => { 33 const hashChange = new Promise(r => window.addEventListener('hashchange', r, { once: true })); 34 35 location.hash = ':~:text=This is a sample text'; 36 await hashChange; 37 38 await new test_driver.Actions() 39 .pointerMove(startX, startY, { origin: 'viewport' }) 40 .pointerDown({ button: 0 }) 41 .pointerMove(endX, endY, { origin: 'viewport' }) 42 .pointerUp({ button: 0 }) 43 .send(); 44 45 await rAF(); 46 47 const selection = window.getSelection().toString(); 48 assert_true(selection.endsWith("sample text."), "A Selection should be created."); 49 }, "Test drag and drop selection over a text directive"); 50 }); 51 </script> 52 </body> 53 </html>