selection-pointer.html (1977B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <meta name="timeout" content="long"> 4 <title>Selecting texts across input element</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-actions.js"></script> 9 <script src="/resources/testdriver-vendor.js"></script> 10 <link rel="stylesheet" href="/fonts/ahem.css" /> 11 12 <style> 13 .test { 14 font: 16px/1 Ahem; 15 padding-bottom: 16px; 16 } 17 </style> 18 <div class="test"> 19 <span id="foo">foo</span><br> 20 <input id="input"><br> 21 <span id="bar">bar</span> 22 </div> 23 <script type="module"> 24 import inputTypes from "./input-types.js"; 25 26 const selection = getSelection(); 27 const inputVisibleTypes = inputTypes.filter(t => t !== "hidden"); 28 29 for (const inputType of inputVisibleTypes) { 30 promise_test(async () => { 31 input.type = inputType; 32 selection.collapse(foo); 33 await new test_driver.Actions() 34 .pointerMove(0, 0, {origin: foo}) 35 .pointerDown() 36 .pointerMove(0, 0, {origin: input}) 37 .pointerMove(0, 0, {origin: bar}) 38 .pointerUp() 39 .send(); 40 const nRanges = selection.rangeCount; 41 assert_true(nRanges > 0); 42 const expectedStart = foo.childNodes[0]; 43 const expectedEnd = bar.childNodes[0]; 44 if (nRanges === 1) { 45 assert_equals(selection.anchorNode, expectedStart, "anchorNode"); 46 assert_equals(selection.focusNode, expectedEnd, "focusNode"); 47 } else { 48 // In case multiple ranges are supported, make sure the set of ranges 49 // spans the full selection, across the input. 50 const ranges = [...Array(nRanges).keys()].map(n => selection.getRangeAt(n)); 51 assert_true(ranges.some(r => r.startContainer === expectedStart),"startContainer"); 52 assert_true(ranges.some(r => r.endContainer === expectedEnd),"endContainer"); 53 } 54 }, `Selecting texts across <input type=${inputType}> should not cancel selection`); 55 } 56 </script>