summaryrefslogtreecommitdiffstats
path: root/toolkit/modules/tests/browser/browser_InlineSpellChecker.js
blob: c9316150913c67f27e6788a508589e0f74de55dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var InlineSpellChecker;
var SpellCheckHelper;

function test() {
  let tempScope = ChromeUtils.importESModule(
    "resource://gre/modules/InlineSpellChecker.sys.mjs"
  );
  InlineSpellChecker = tempScope.InlineSpellChecker;
  SpellCheckHelper = tempScope.SpellCheckHelper;

  ok(InlineSpellChecker, "InlineSpellChecker class exists");
  for (var fname in tests) {
    tests[fname]();
  }
}

var tests = {
  testFlagsForInputs() {
    const HTML_NS = "http://www.w3.org/1999/xhtml";
    const { INPUT, EDITABLE, TEXTINPUT, NUMERIC, PASSWORD, SPELLCHECKABLE } =
      SpellCheckHelper;
    const kExpectedResults = {
      text: INPUT | EDITABLE | TEXTINPUT | SPELLCHECKABLE,
      password: INPUT | EDITABLE | TEXTINPUT | PASSWORD,
      search: INPUT | EDITABLE | TEXTINPUT | SPELLCHECKABLE,
      url: INPUT | EDITABLE | TEXTINPUT,
      tel: INPUT | EDITABLE | TEXTINPUT,
      email: INPUT | EDITABLE | TEXTINPUT,
      number: INPUT | EDITABLE | TEXTINPUT | NUMERIC,
      checkbox: INPUT,
      radio: INPUT,
    };

    for (let [type, expectedFlags] of Object.entries(kExpectedResults)) {
      let input = document.createElementNS(HTML_NS, "input");
      input.type = type;
      let actualFlags = SpellCheckHelper.isEditable(input, window);
      is(
        actualFlags,
        expectedFlags,
        `For input type "${type}" expected flags ${
          "0x" + expectedFlags.toString(16)
        }; got ${"0x" + actualFlags.toString(16)}`
      );
    }
  },
};