tor-browser

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

typing-text-in-direct-child-of-editing-host.html (4538B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <meta name="timeout" content="long">
      6 <meta name="variant" content="?white-space=normal">
      7 <meta name="variant" content="?white-space=pre">
      8 <meta name="variant" content="?white-space=pre-line">
      9 <meta name="variant" content="?white-space=pre-wrap">
     10 <title>Typing in `Text` which is direct child of editing host</title>
     11 <script src="/resources/testharness.js"></script>
     12 <script src="/resources/testharnessreport.js"></script>
     13 <script src="/resources/testdriver.js"></script>
     14 <script src="/resources/testdriver-vendor.js"></script>
     15 <script src="/resources/testdriver-actions.js"></script>
     16 <script src="../include/editor-test-utils.js"></script>
     17 <script>
     18 "use strict";
     19 
     20 const searchParams = new URLSearchParams(document.location.search);
     21 const whiteSpace = searchParams.get("white-space");
     22 const mustUseBR = whiteSpace == "normal";
     23 const collapseWhiteSpaces = whiteSpace == "normal" || whiteSpace == "pre-line";
     24 
     25 /**
     26 * Some browsers may use preformatted linefeed only in direct child of the
     27 * editing host.  This is intended to check the basic behavior rather than
     28 * compatibility between browsers.
     29 */
     30 
     31 addEventListener("DOMContentLoaded", () => {
     32  const editingHost = document.querySelector("div[contenteditable]");
     33  editingHost.style.whiteSpace = whiteSpace;
     34  const utils = new EditorTestUtils(editingHost);
     35  editingHost.focus();
     36 
     37  promise_test(async () => {
     38    await utils.sendKey("a");
     39    await utils.sendKey("\uE00D");
     40    if (mustUseBR) {
     41      assert_in_array(editingHost.innerHTML, ["a&nbsp;", "a <br>"], "Typed white-space should be visible");
     42    } else if (collapseWhiteSpaces) {
     43      assert_in_array(editingHost.innerHTML, ["a&nbsp;", "a <br>", "a \n"], "Typed white-space should be visible");
     44    } else {
     45      assert_equals(editingHost.innerHTML, "a ", "Typed white-space should be visible");
     46    }
     47    await utils.sendKey("b");
     48    assert_equals(editingHost.innerHTML, "a b", `Typing "b" after white-space should keep the white-space visible`);
     49  }, `Typing "a b"`);
     50  promise_test(async () => {
     51    utils.setupEditingHost("a b[]");
     52    await utils.sendBackspaceKey();
     53    if (mustUseBR) {
     54      assert_in_array(editingHost.innerHTML, ["a&nbsp;", "a <br>"], "Previous white-space should be visible");
     55    } else if (collapseWhiteSpaces) {
     56      assert_in_array(editingHost.innerHTML, ["a&nbsp;", "a <br>", "a \n"], "Previous white-space should be visible");
     57    } else {
     58      assert_equals(editingHost.innerHTML, "a ", "Previous white-space should be visible");
     59    }
     60  }, `Backspace when "a b[]"`);
     61  promise_test(async () => {
     62    utils.setupEditingHost("a&nbsp;b[]");
     63    await utils.sendBackspaceKey();
     64    if (mustUseBR) {
     65      assert_in_array(editingHost.innerHTML, ["a&nbsp;", "a <br>"], "Previous NBSP should be visible");
     66    } else if (collapseWhiteSpaces) {
     67      assert_in_array(editingHost.innerHTML, ["a&nbsp;", "a <br>", "a \n"], "Previous NBSP should be visible");
     68    } else {
     69      assert_equals(editingHost.innerHTML, "a&nbsp;", "Previous NBSP should be visible and shouldn't be converted to ASCII space");
     70    }
     71  }, `Backspace when "a&nbsp;b[]"`);
     72  promise_test(async () => {
     73    utils.setupEditingHost("X[]");
     74    await utils.sendKey("\uE00D");
     75    await utils.sendKey("\uE00D");
     76    await utils.sendKey("\uE00D");
     77    if (mustUseBR) {
     78      assert_in_array(
     79        editingHost.innerHTML,
     80        ["X&nbsp; &nbsp;", "X &nbsp;&nbsp;", "X&nbsp;&nbsp; <br>", "X &nbsp; <br>"],
     81        "Typed spaces should be visible but must contain one ASCII white-space for line break opportunities"
     82      );
     83    } else if (collapseWhiteSpaces) {
     84      assert_in_array(
     85        editingHost.innerHTML,
     86        ["X&nbsp; &nbsp;", "X &nbsp;&nbsp;", "X&nbsp;&nbsp; <br>", "X &nbsp; <br>", "X&nbsp;&nbsp; \n", "X &nbsp; \n"],
     87        "Typed spaces should be visible but must contain one ASCII white-space for line break opportunities"
     88      );
     89    } else {
     90      assert_equals(editingHost.innerHTML, "X   ", "Typed spaces should be visible");
     91    }
     92    await utils.sendKey("Y");
     93    if (collapseWhiteSpaces) {
     94      assert_in_array(
     95        editingHost.innerHTML,
     96        ["X&nbsp; &nbsp;Y", "X &nbsp; Y", "X &nbsp;&nbsp;Y", "X&nbsp;&nbsp; Y"],
     97        "Previous white-spaces should be visible"
     98      );
     99    } else {
    100      assert_equals(editingHost.innerHTML, "X   Y", "Previous white-spaces should be visible");
    101    }
    102  }, `Typing multiple white-spaces and type "Y"`);
    103 }, {once: true});
    104 </script>
    105 </head>
    106 <body>
    107  <div contenteditable></div>
    108 </body>
    109 </html>