tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bug1448730.html (3852B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <script src="/tests/SimpleTest/EventUtils.js"></script>
      5 </head>
      6 <body>
      7 <p id="display">
      8  <input id="input" inputmode="none">
      9  <textarea id="textarea" cols="10" rows="2" inputmode="none"></textarea>
     10  <div id="editable" contenteditable style="width: 200px;" inputmode="none"></div>
     11 </p>
     12 <div id="content" style="display: none;"></div>
     13 <pre id="test">
     14 </pre>
     15 <script>
     16 const SimpleTest = parent.SimpleTest;
     17 const is = parent.is;
     18 const isnot = parent.isnot;
     19 const ok = parent.ok;
     20 
     21 window.addEventListener("load", runTest);
     22 
     23 function runTest() {
     24  let target = document.getElementById("input");
     25  target.focus();
     26 
     27  // <input>
     28  target.value = "  ";
     29  synthesizeTouchAtCenter(target, { type: "touchstart" });
     30  synthesizeMouseAtCenter(target, { type: "mouselongtap" });
     31  synthesizeTouchAtCenter(target, { type: "touchend" });
     32  is(target.selectionStart, target.value.length, "Don't select whitespace");
     33  is(target.selectionEnd, target.value.length, "Don't select whitespace");
     34 
     35  target.value = "abc";
     36  synthesizeTouchAtCenter(target, { type: "touchstart" });
     37  synthesizeMouseAtCenter(target, { type: "mouselongtap" });
     38  synthesizeTouchAtCenter(target, { type: "touchend" });
     39  is(target.selectionStart, target.value.length, "Don't select word");
     40  is(target.selectionEnd, target.value.length, "Don't select word");
     41 
     42  target.value = " ".repeat(100);
     43  synthesizeTouchAtCenter(target, { type: "touchstart" });
     44  synthesizeMouseAtCenter(target, { type: "mouselongtap" });
     45  synthesizeTouchAtCenter(target, { type: "touchend" });
     46  is(target.selectionStart, 0, "Select whitespace");
     47 
     48  // <textarea>
     49  target = document.getElementById("textarea");
     50  target.value = "  ";
     51  synthesizeTouchAtCenter(target, { type: "touchstart" });
     52  synthesizeMouseAtCenter(target, { type: "mouselongtap" });
     53  synthesizeTouchAtCenter(target, { type: "touchend" });
     54  is(target.selectionStart, 2, "Don't select whitespace");
     55  is(target.selectionEnd, 2, "Don't select whitespace");
     56 
     57  target.value = "abc";
     58  synthesizeTouchAtCenter(target, { type: "touchstart" });
     59  synthesizeMouseAtCenter(target, { type: "mouselongtap" });
     60  synthesizeTouchAtCenter(target, { type: "touchend" });
     61  is(target.selectionStart, target.value.length, "Don't select word");
     62  is(target.selectionEnd, target.value.length, "Don't select word");
     63 
     64  target.value = " ".repeat(10) + "\n" + " ".repeat(10) + "\n" + " ".repeat(10);
     65  synthesizeTouchAtCenter(target, { type: "touchstart" });
     66  synthesizeMouseAtCenter(target, { type: "mouselongtap" });
     67  synthesizeTouchAtCenter(target, { type: "touchend" });
     68  isnot(target.selectionStart, target.selectionEnd, "Select whitespace");
     69 
     70  // contenteditable
     71  target = document.getElementById("editable");
     72  target.innerHTML = "test";
     73  target.focus();
     74  let range = document.createRange();
     75  range.setStart(target.firstChild, target.firstChild.length);
     76  range.setEnd(target.firstChild, target.firstChild.length);
     77  let selection = window.getSelection();
     78  selection.removeAllRanges();
     79  selection.addRange(range);
     80 
     81  synthesizeTouchAtCenter(target, { type: "touchstart" });
     82  synthesizeMouseAtCenter(target, { type: "mouselongtap" });
     83  synthesizeTouchAtCenter(target, { type: "touchend" });
     84  ok(selection.getRangeAt(0).collapsed, "Don't select word");
     85 
     86  target.innerHTML = "t".repeat(50);
     87  target.focus();
     88  range = document.createRange();
     89  range.setStart(target.firstChild, target.firstChild.length);
     90  range.setEnd(target.firstChild, target.firstChild.length);
     91  selection.removeAllRanges();
     92  selection.addRange(range);
     93 
     94  synthesizeTouchAtCenter(target, { type: "touchstart" });
     95  synthesizeMouseAtCenter(target, { type: "mouselongtap" });
     96  synthesizeTouchAtCenter(target, { type: "touchend" });
     97  ok(!selection.getRangeAt(0).collapsed, "Select word");
     98 
     99  SimpleTest.finish();
    100 }
    101 </script>
    102 </body>
    103 </html>