tor-browser

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

test_bug1418629.html (6282B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <title>Mozilla bug 1418629</title>
      5  <link rel=stylesheet href="/tests/SimpleTest/test.css">
      6  <script src="/tests/SimpleTest/EventUtils.js"></script>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <script src="/tests/editor/spellchecker/tests/spellcheck.js"></script>
      9 </head>
     10 <body>
     11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1418629">Mozilla Bug 1418629</a>
     12 <p id="display"></p>
     13 <div id="content" style="display: none;">
     14 
     15 </div>
     16 
     17 <input id="input1" spellcheck="true">
     18 <textarea id="textarea1"></textarea>
     19 <div id="edit1" contenteditable=true></div>
     20 
     21 <script>
     22 const { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
     23  "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
     24 );
     25 
     26 SimpleTest.waitForExplicitFinish();
     27 
     28 function getEditor(input) {
     29  if (input instanceof HTMLInputElement ||
     30      input instanceof HTMLTextAreaElement) {
     31    return SpecialPowers.wrap(input).editor;
     32  }
     33 
     34  return SpecialPowers.wrap(window).docShell.editor;
     35 }
     36 
     37 function isTextControl(input) {
     38  return input instanceof HTMLInputElement ||
     39         input instanceof HTMLTextAreaElement;
     40 }
     41 
     42 function resetEditableContent(input) {
     43  if (isTextControl(input)) {
     44    input.value = "";
     45    return;
     46  }
     47  input.innerHTML = "";
     48 }
     49 
     50 async function test_with_single_quote(input) {
     51  let misspeltWords = [];
     52 
     53  input.focus();
     54  resetEditableContent(input);
     55 
     56  synthesizeKey("d");
     57  synthesizeKey("o");
     58  synthesizeKey("e");
     59  synthesizeKey("s");
     60 
     61  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
     62  let editor = getEditor(input);
     63  // isSpellingCheckOk is defined in spellcheck.js
     64  ok(isSpellingCheckOk(editor, misspeltWords), "no misspelt words");
     65 
     66  synthesizeKey("n");
     67  synthesizeKey("\'");
     68  is(input.value || input.textContent, "doesn\'", "");
     69 
     70  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
     71  // XXX This won't work since mozInlineSpellWordUtil::SplitDOM removes
     72  // last single quote unfortunately that is during inputting.
     73  // isSpellingCheckOk is defined in spellcheck.js
     74  todo_is(isSpellingCheckOk(editor, misspeltWords, true), true,
     75          "don't run spellchecker during inputting word");
     76 
     77  synthesizeKey(" ");
     78  is(
     79    input.value || input.textContent,
     80    !isTextControl(input) ? "doesn\'\u00A0" : "doesn\' ",
     81    `Typing white-space after "doesn'" should've succeeded`
     82  );
     83 
     84  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
     85  misspeltWords.push("doesn");
     86  // isSpellingCheckOk is defined in spellcheck.js
     87  ok(isSpellingCheckOk(editor, misspeltWords), "should run spellchecker");
     88 }
     89 
     90 async function test_with_twice_characters(input, ch) {
     91  let misspeltWords = [];
     92 
     93  input.focus();
     94  resetEditableContent(input);
     95 
     96  synthesizeKey("d");
     97  synthesizeKey("o");
     98  synthesizeKey("e");
     99  synthesizeKey("s");
    100  synthesizeKey("n");
    101  synthesizeKey(ch);
    102  synthesizeKey(ch);
    103  is(input.value || input.textContent, "doesn" + ch + ch, "");
    104 
    105  // trigger spellchecker
    106  synthesizeKey(" ");
    107 
    108  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
    109  misspeltWords.push("doesn");
    110  let editor = getEditor(input);
    111  // isSpellingCheckOk is defined in spellcheck.js
    112  ok(isSpellingCheckOk(editor, misspeltWords), "should run spellchecker");
    113 }
    114 
    115 async function test_between_single_quote(input) {
    116  let misspeltWords = [];
    117 
    118  input.focus();
    119  resetEditableContent(input);
    120 
    121  synthesizeKey("\'");
    122  synthesizeKey("t");
    123  synthesizeKey("e");
    124  synthesizeKey("s");
    125  synthesizeKey("t");
    126  synthesizeKey("\'");
    127 
    128  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
    129  let editor = getEditor(input);
    130  ok(isSpellingCheckOk(editor, misspeltWords),
    131     "don't run spellchecker between single qoute");
    132 }
    133 
    134 async function test_with_email(input) {
    135  let misspeltWords = [];
    136 
    137  input.focus();
    138  resetEditableContent(input);
    139 
    140  synthesizeKey("t");
    141  synthesizeKey("t");
    142  synthesizeKey("t");
    143  synthesizeKey("t");
    144  synthesizeKey("@");
    145  synthesizeKey("t");
    146  synthesizeKey("t");
    147  synthesizeKey("t");
    148  synthesizeKey("t");
    149  synthesizeKey(".");
    150  synthesizeKey("c");
    151  synthesizeKey("o");
    152  synthesizeKey("m");
    153 
    154  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
    155  let editor = getEditor(input);
    156  ok(isSpellingCheckOk(editor, misspeltWords),
    157     "don't run spellchecker for email address");
    158 
    159  synthesizeKey(" ");
    160 
    161  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
    162  ok(isSpellingCheckOk(editor, misspeltWords),
    163     "no misspelt words due to email address");
    164 }
    165 
    166 async function test_with_url(input) {
    167  let misspeltWords = [];
    168 
    169  input.focus();
    170  resetEditableContent(input);
    171 
    172  synthesizeKey("h");
    173  synthesizeKey("t");
    174  synthesizeKey("t");
    175  synthesizeKey("p");
    176  synthesizeKey(":");
    177  synthesizeKey("/");
    178  synthesizeKey("/");
    179  synthesizeKey("t");
    180  synthesizeKey("t");
    181  synthesizeKey("t");
    182  synthesizeKey("t");
    183  synthesizeKey(".");
    184  synthesizeKey("c");
    185  synthesizeKey("o");
    186  synthesizeKey("m");
    187 
    188  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
    189  let editor = getEditor(input);
    190  ok(isSpellingCheckOk(editor, misspeltWords),
    191     "don't run spellchecker for URL");
    192 
    193  synthesizeKey(" ");
    194 
    195  await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
    196  ok(isSpellingCheckOk(editor, misspeltWords),
    197     "no misspelt words due to URL");
    198 }
    199 
    200 SimpleTest.waitForFocus(() => {
    201  for (let n of ["input1", "textarea1", "edit1"])  {
    202    add_task(test_with_single_quote.bind(null,
    203                                         document.getElementById(n)));
    204    add_task(test_with_twice_characters.bind(null,
    205                                             document.getElementById(n),
    206                                             "\'"));
    207    add_task(test_with_twice_characters.bind(null,
    208                                             document.getElementById(n),
    209                                             String.fromCharCode(0x2019)));
    210    add_task(test_between_single_quote.bind(null,
    211                                            document.getElementById(n)));
    212    add_task(test_with_email.bind(null, document.getElementById(n)));
    213    add_task(test_with_url.bind(null, document.getElementById(n)));
    214  }
    215 });
    216 </script>
    217 </body>
    218 </html>