tor-browser

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

test_bug1151186.html (2444B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1151186
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1151186</title>
      9  <link rel=stylesheet href="/tests/SimpleTest/test.css">
     10  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     11  <script>
     12  /** Test for Bug 1151186 */
     13  SimpleTest.waitForExplicitFinish();
     14 
     15  // In this test, we want to check the IME enabled state in the `contenteditable`
     16  // editor which is focused by `focus` event listener of the document.
     17  // However, according to the random oranges filed as bug 1176038 and bug 1611360,
     18  // `focus` event are sometimes not fired on the document and the reason is,
     19  // the document sometimes not focused automatically.  Therefore, this test
     20  // will set focus the document when `focus` event is not fired until next
     21  // macro task.
     22  var focusEventFired = false;
     23  function onFocus(event) {
     24    is(event.target.nodeName, "#document", "focus event should be fired on the document node");
     25    if (event.target != document) {
     26      return;
     27    }
     28    focusEventFired = true;
     29    document.getElementById("editor").focus();
     30    SimpleTest.executeSoon(runTests);
     31  }
     32  document.addEventListener("focus", onFocus, {once: true});
     33 
     34  // Register next macro task to check whether `focus` event of the document
     35  // is fired as expected.  If not, let's focus our window manually.  Then,
     36  // the `focus` event listener starts the test anyway.
     37  setTimeout(() => {
     38   if (focusEventFired) {
     39     return; // We've gotten `focus` event as expected.
     40   }
     41   ok(!document.hasFocus(), "The document should not have focus yet");
     42   info("Setting focus to the window forcibly...");
     43   window.focus();
     44  }, 0);
     45 
     46  function runTests() {
     47    let description = focusEventFired ?
     48        "document got focused normally" :
     49        "document got focused forcibly";
     50    is(document.activeElement, document.getElementById("editor"),
     51       `The div element should be focused (${description})`);
     52    var utils = SpecialPowers.getDOMWindowUtils(window);
     53    is(utils.IMEStatus, utils.IME_STATUS_ENABLED,
     54       `IME should be enabled (${description})`);
     55    SimpleTest.finish();
     56  }
     57  </script>
     58 </head>
     59 <body>
     60 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1151186">Mozilla Bug 1151186</a>
     61 <p id="display"></p>
     62 <div id="content" style="display: none">
     63 
     64 </div>
     65 <div id="editor" contenteditable="true"></div>
     66 <pre id="test">
     67 </pre>
     68 </body>
     69 </html>