tor-browser

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

modal-dialog-selection.html (1954B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <title>Content selection in modal dialog</title>
      4 <link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
      5 <link rel="help" href="https://drafts.csswg.org/css-ui-4/#content-selection">
      6 <meta name="assert" content="Checks that text can be selected in a modal dialog, except with 'user-select: none'.">
      7 
      8 <link rel="stylesheet" href="/fonts/ahem.css">
      9 <style>
     10 dialog {
     11  font: 10px/1 Ahem;
     12  text-align: center;
     13 }
     14 </style>
     15 
     16 <dialog>123456789A</dialog>
     17 
     18 <script src="/resources/testharness.js"></script>
     19 <script src="/resources/testharnessreport.js"></script>
     20 <script src="/resources/testdriver.js"></script>
     21 <script src="/resources/testdriver-vendor.js"></script>
     22 <script src="/resources/testdriver-actions.js"></script>
     23 <script>
     24 const dialog = document.querySelector("dialog");
     25 dialog.showModal();
     26 
     27 function selectSomeText() {
     28  // Clear existing selection.
     29  getSelection().removeAllRanges();
     30 
     31  // The dialog contains 10 characters. Select the 6 ones at the center.
     32  return new test_driver.Actions()
     33    .pointerMove(-3e1, 0, {origin: dialog})
     34    .pointerDown()
     35    .pointerMove(+3e1, 0, {origin: dialog})
     36    .pointerUp()
     37    .send();
     38 }
     39 
     40 function clickOnBackdrop() {
     41  getSelection().removeAllRanges();
     42 
     43  return new test_driver.Actions()
     44    .pointerMove(10, 10)
     45    .pointerDown()
     46    .pointerUp()
     47    .send();
     48 }
     49 
     50 promise_test(async function() {
     51  await selectSomeText();
     52  assert_equals(getSelection().toString(), "345678");
     53 }, "By default, text inside a modal dialog can be selected");
     54 
     55 promise_test(async function() {
     56  await clickOnBackdrop();
     57  assert_equals(getSelection().toString(), "");
     58 }, "Clicking on backdrop doesn't select text");
     59 
     60 promise_test(async function() {
     61  dialog.style.userSelect = "none";
     62 
     63  await selectSomeText();
     64  assert_equals(getSelection().toString(), "");
     65 
     66  dialog.style.userSelect = "";
     67 }, "'user-select: none' prevents text from being selected");
     68 </script>