tor-browser

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

formatblock-preserving-selection.tentative.html (4379B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4 <meta chareset="utf-8">
      5 <meta name="timeout" content="long">
      6 <meta name="variant" content="?styleWithCSS=false&block=address">
      7 <meta name="variant" content="?styleWithCSS=false&block=article">
      8 <meta name="variant" content="?styleWithCSS=false&block=blockquote">
      9 <meta name="variant" content="?styleWithCSS=false&block=dd">
     10 <meta name="variant" content="?styleWithCSS=false&block=div">
     11 <meta name="variant" content="?styleWithCSS=false&block=dt">
     12 <meta name="variant" content="?styleWithCSS=false&block=h1">
     13 <meta name="variant" content="?styleWithCSS=false&block=li">
     14 <meta name="variant" content="?styleWithCSS=false&block=pre">
     15 <meta name="variant" content="?styleWithCSS=true&block=address">
     16 <meta name="variant" content="?styleWithCSS=true&block=article">
     17 <meta name="variant" content="?styleWithCSS=true&block=blockquote">
     18 <meta name="variant" content="?styleWithCSS=true&block=dd">
     19 <meta name="variant" content="?styleWithCSS=true&block=div">
     20 <meta name="variant" content="?styleWithCSS=true&block=dt">
     21 <meta name="variant" content="?styleWithCSS=true&block=h1">
     22 <meta name="variant" content="?styleWithCSS=true&block=li">
     23 <meta name="variant" content="?styleWithCSS=true&block=pre">
     24 <title>Test preserving selection after formatBlock</title>
     25 <script src="/resources/testharness.js"></script>
     26 <script src="/resources/testharnessreport.js"></script>
     27 <script src="/resources/testdriver.js"></script>
     28 <script src="/resources/testdriver-vendor.js"></script>
     29 <script src="/resources/testdriver-actions.js"></script>
     30 <script src="../include/editor-test-utils.js"></script>
     31 </head>
     32 <body>
     33 <div contenteditable></div>
     34 <script>
     35 "use strict";
     36 
     37 const editor = document.querySelector("div[contenteditable]");
     38 const utils = new EditorTestUtils(editor);
     39 const searchParams = new URLSearchParams(document.location.search);
     40 const styleWithCSS = searchParams.get("styleWithCSS");
     41 const block = searchParams.get("block");
     42 document.execCommand("styleWithCSS", false, styleWithCSS);
     43 
     44 // Note that it's not scope of this test how browsers to convert the selected
     45 // content to a block.
     46 
     47 // html: Initial HTML which will be set editor.innerHTML, it should contain
     48 //       selection range with a pair of "[" or "{" and "]" or "}".
     49 // expectedSelectedString: After executing "outdent", compared with
     50 //                         getSelection().toString().replace(/[ \n\r\t]+/g, "")
     51 const tests = [
     52  {
     53    html: "a[b]c",
     54    expectedSelectedString: "b",
     55  },
     56  {
     57    html: "a[bc<br>de]f",
     58    expectedSelectedString: "bcde",
     59  },
     60  {
     61    html: "<div>a[b]c</div>",
     62    expectedSelectedString: "b",
     63  },
     64  {
     65    html: "<div>a[bc</div><div>de]f</div>",
     66    expectedSelectedString: "bcde",
     67  },
     68  {
     69    html: "<div>a[bc<br>de]f</div>",
     70    expectedSelectedString: "bcde",
     71  },
     72  {
     73    html: "<ul><li>a[b]c</li></ul>",
     74    expectedSelectedString: "b",
     75  },
     76  {
     77    html: "<ul><li>a[bc</li><li>de]f</li></ul>",
     78    expectedSelectedString: "bcde",
     79  },
     80  {
     81    html: "<ul><li>a[bc</li><li>de]f</li><li>ghi</li></ul>",
     82    expectedSelectedString: "bcde",
     83  },
     84  {
     85    html: "<ul><li>abc</li><li>d[ef</li><li>gh]i</li></ul>",
     86    expectedSelectedString: "efgh",
     87  },
     88  {
     89    html: "<ul><li>abc</li><li>d[ef</li></ul>" +
     90          "<div>gh]i</div>",
     91    expectedSelectedString: "efgh",
     92  },
     93  {
     94    html: "<div>a[bc</div>" +
     95          "<ul><li>de]f</li><li>ghi</li></ul>",
     96    expectedSelectedString: "bcde",
     97  },
     98  {
     99    html: "<table><tr><td>a[b]c</td></tr></table>",
    100    expectedSelectedString: "b",
    101  },
    102  {
    103    html: "<table><tr><td>a[bc</td><td>de]f</td></tr></table>",
    104    expectedSelectedString: "bcde",
    105  },
    106  {
    107    html: "<table><tr><td>a[bc</td></tr><tr><td>de]f</td></tr></table>",
    108    expectedSelectedString: "bcde",
    109  },
    110  {
    111    html: "<div>a[bc</div>" +
    112          "<table><tr><td>de]f</td></tr></table>",
    113    expectedSelectedString: "bcde",
    114  },
    115  {
    116    html: "<table><tr><td>a[bc</td></tr></table>" +
    117          "<div>de]f</div>",
    118    expectedSelectedString: "bcde",
    119  },
    120 ];
    121 
    122 for (const t of tests) {
    123  test(() => {
    124    utils.setupEditingHost(t.html);
    125    document.execCommand("formatblock", false, block);
    126    assert_equals(
    127      getSelection().toString().replace(/[ \n\r\t]+/g, ""),
    128      t.expectedSelectedString,
    129      `Result: ${editor.innerHTML}`
    130    );
    131  }, `Preserve selection after formatBlock with ${block} at ${t.html}`);
    132 }
    133 
    134 </script>
    135 </body>
    136 </html>