tor-browser

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

test_focused_document_element_becoming_editable.html (6393B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4 <meta chareset="utf-8">
      5 <title>Testing non-editable root becomes editable after getting focus</title>
      6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
      8 </head>
      9 <body>
     10 <script>
     11 SimpleTest.waitForExplicitFinish();
     12 addEventListener("load", async () => {
     13  await SimpleTest.promiseFocus(window);
     14 
     15  await (async () => {
     16    const iframe = document.createElement("iframe");
     17    document.body.appendChild(iframe);
     18    await new Promise(resolve => {
     19      iframe.addEventListener("load", async () => {
     20        const doc = iframe.contentDocument;
     21        const win = iframe.contentWindow;
     22        win.focus();
     23        doc.documentElement.focus();
     24        doc.designMode = "on";
     25        await new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r)));
     26        is(
     27          SpecialPowers.getDOMWindowUtils(win).IMEStatus,
     28          SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_ENABLED,
     29          "IME should be enabled in the design mode document"
     30        );
     31        is(
     32          SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
     33          doc.body,
     34          "The <body> should be observed by IMEContentObserver in design mode"
     35        );
     36        doc.designMode = "off";
     37        iframe.remove();
     38        resolve();
     39      }, {once: true});
     40      info("Waiting for load of sub-document for testing design mode");
     41      iframe.srcdoc = "<!doctype html><html><meta charset=\"utf-8\"></head><body></body></html>";
     42    });
     43  })();
     44 
     45  await (async () => {
     46    const iframe = document.createElement("iframe");
     47    document.body.appendChild(iframe);
     48    await new Promise(resolve => {
     49      iframe.addEventListener("load", async () => {
     50        const doc = iframe.contentDocument;
     51        const win = iframe.contentWindow;
     52        win.focus()
     53        doc.documentElement.focus();
     54        doc.documentElement.contentEditable = "true";
     55        await new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r)));
     56        is(
     57          SpecialPowers.getDOMWindowUtils(win).IMEStatus,
     58          SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_ENABLED,
     59          "IME should be enabled when the <html> element whose contenteditable is set to true"
     60        );
     61        is(
     62          SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
     63          doc.documentElement,
     64          "The <html> should be observed by IMEContentObserver when <html contenteditable=\"true\">"
     65        );
     66        iframe.remove();
     67        resolve();
     68      }, {once: true});
     69      info("Waiting for load of sub-document for testing <html> element becomes editable");
     70      iframe.srcdoc = "<!doctype html><html><meta charset=\"utf-8\"></head><body></body></html>";
     71    });
     72  })();
     73 
     74  await (async () => {
     75    const iframe = document.createElement("iframe");
     76    document.body.appendChild(iframe);
     77    await new Promise(resolve => {
     78      iframe.addEventListener("load", async () => {
     79        const doc = iframe.contentDocument;
     80        const win = iframe.contentWindow;
     81        win.focus();
     82        doc.body.focus();
     83        doc.body.contentEditable = "true";
     84        await new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r)));
     85        if (doc.activeElement === doc.body && doc.hasFocus()) {
     86          todo_is(
     87            SpecialPowers.getDOMWindowUtils(win).IMEStatus,
     88            SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_ENABLED,
     89            "IME should be enabled when the <body> element whose contenteditable is set to true and it has focus"
     90          );
     91          todo_is(
     92            SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
     93            doc.body,
     94            "The <body> should be observed by IMEContentObserver when <body contenteditable=\"true\"> and it has focus"
     95          );
     96        } else {
     97          is(
     98            SpecialPowers.getDOMWindowUtils(win).IMEStatus,
     99            SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_DISABLED,
    100            "IME should be disabled when the <body> element whose contenteditable is set to true but it does not have focus"
    101          );
    102          is(
    103            SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
    104            null,
    105            "Nobody should be observed by IMEContentObserver when <body contenteditable=\"true\"> but it does not have focus"
    106          );
    107        }
    108        iframe.remove();
    109        resolve();
    110      }, {once: true});
    111      info("Waiting for load of sub-document for testing <body> element becomes editable");
    112      iframe.srcdoc = "<!doctype html><html><meta charset=\"utf-8\"></head><body></body></html>";
    113    });
    114  })();
    115 
    116  await (async () => {
    117    const iframe = document.createElement("iframe");
    118    document.body.appendChild(iframe);
    119    await new Promise(resolve => {
    120      iframe.addEventListener("load", async () => {
    121        const doc = iframe.contentDocument;
    122        const win = iframe.contentWindow;
    123        win.focus();
    124        const editingHost = doc.createElement("div");
    125        doc.documentElement.remove();
    126        doc.appendChild(editingHost);
    127        editingHost.focus();
    128        is(
    129          SpecialPowers.unwrap(SpecialPowers.focusManager.focusedElement),
    130          editingHost,
    131          "The <div contenteditable> should have focus because of only child of the Document node"
    132        );
    133        editingHost.contentEditable = "true";
    134        await new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r)));
    135        is(
    136          SpecialPowers.getDOMWindowUtils(win).IMEStatus,
    137          SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_ENABLED,
    138          "IME should be enabled in the root element"
    139        );
    140        is(
    141          SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
    142          editingHost,
    143          "The <div contenteditable> should be observed by IMEContentObserver"
    144        );
    145        iframe.srcdoc = "";
    146        resolve();
    147      }, {once: true});
    148      info("Waiting for load of sub-document for testing root <div> element becomes editable");
    149      iframe.srcdoc = "<!doctype html><html><meta charset=\"utf-8\"></head><body></body></html>";
    150    });
    151  })();
    152 
    153  SimpleTest.finish();
    154 }, false);
    155 </script>
    156 </body>
    157 </html>