tor-browser

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

test_bug1497480.html (2895B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1497480
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1497480</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <script src="/tests/SimpleTest/EventUtils.js"></script>
     11  <script src="spellcheck.js"></script>
     12  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     13 
     14 </head>
     15 <body>
     16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1497480">Mozilla Bug 1497480</a>
     17 <p id="display"></p>
     18 
     19 <div id="outOfTarget" contenteditable>Bug 1497480</div>
     20 <div id="light"></div>
     21 
     22 <script>
     23 
     24 /** Test for Bug 1497480 */
     25 let gMisspeltWords = [];
     26 let { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     27  "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     28 );
     29 
     30 const template = document.createElement("template");
     31 template.innerHTML = `<div id="target" contenteditable>Test</div>`;
     32 
     33 let shadow = document.getElementById("light").attachShadow({mode: "closed"});
     34 shadow.appendChild(template.content.cloneNode(true));
     35 
     36 let target = shadow.getElementById("target");
     37 let outOfTarget = document.getElementById("outOfTarget");
     38 
     39 function getEditor() {
     40  var win = window;
     41  var editingSession = SpecialPowers.wrap(win).docShell.editingSession;
     42  return editingSession.getEditorForWindow(win);
     43 }
     44 
     45 // Wait for the page to be ready for testing
     46 add_task(async function() {
     47  await new Promise((resolve) => {
     48    SimpleTest.waitForFocus(() => {
     49      SimpleTest.executeSoon(resolve);
     50    }, window);
     51  });
     52 
     53  // Wait for first full spell-checking.
     54  synthesizeMouseAtCenter(outOfTarget, {}, window);
     55  await new Promise((resolve) => {
     56    maybeOnSpellCheck(outOfTarget, function() {
     57      resolve();
     58    });
     59  });
     60 });
     61 
     62 // Should perform spell-checking when anchor navigates away from ShadowDOM.
     63 add_task(async function() {
     64  synthesizeMouseAtCenter(target, {}, window);
     65  sendString(" spellechek");
     66  gMisspeltWords.push("spellechek");
     67  synthesizeMouseAtCenter(outOfTarget, {}, window);
     68  await new Promise((resolve) => {
     69    maybeOnSpellCheck(target, function() {
     70      ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
     71         "Spell-checking should be performed when anchor navigates away from ShadowDOM");
     72      SimpleTest.executeSoon(resolve);
     73    });
     74  });
     75 });
     76 
     77 // Should perform spell-checking when pressing enter in contenteditable in ShadowDOM.
     78 add_task(async function() {
     79  synthesizeMouseAtCenter(target, {}, window);
     80  sendString(" spellechck");
     81  gMisspeltWords.push("spellechck");
     82  synthesizeKey("KEY_Enter", {}, window);
     83  await new Promise((resolve) => {
     84    maybeOnSpellCheck(target, function() {
     85      ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
     86         "Spell-checking should be performed when pressing enter in contenteditable in ShadowDOM");
     87      SimpleTest.executeSoon(resolve);
     88    });
     89  });
     90 });
     91 
     92 </script>
     93 </body>
     94 </html>