summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/events/test_textattrchange.html
blob: a69a8df15e08d9e5d93252e4a6766e0f913d214a (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<html>

<head>
  <title>Text attribute changed event for misspelled text</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../states.js"></script>
  <script type="application/javascript"
          src="../events.js"></script>
  <script type="application/javascript"
          src="../attributes.js"></script>

  <script type="application/javascript">

    const nsIDOMNSEditableElement =
      Components.interfaces.nsIDOMNSEditableElement;

    Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");

    function spelledTextInvoker(aID)
    {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new invokerChecker(EVENT_TEXT_ATTRIBUTE_CHANGED, this.DOMNode)
      ];

      this.invoke = function spelledTextInvoker_invoke()
      {
        var editor = this.DOMNode.QueryInterface(nsIDOMNSEditableElement).editor;
        var spellChecker = new InlineSpellChecker(editor);
        spellChecker.enabled = true;

        //var spellchecker = editor.getInlineSpellChecker(true);
        //spellchecker.enableRealTimeSpell = true;

        this.DOMNode.value = "valid text inalid tixt";
      }

      this.finalCheck = function spelledTextInvoker_finalCheck()
      {
        var defAttrs = buildDefaultTextAttrs(this.DOMNode, kInputFontSize,
                                             kNormalFontWeight,
                                             kInputFontFamily);
        testDefaultTextAttrs(aID, defAttrs);

        var attrs = { };
        var misspelledAttrs = {
          "invalid": "spelling"
        };

        testTextAttrs(aID, 0, attrs, defAttrs, 0, 11);
        testTextAttrs(aID, 11, misspelledAttrs, defAttrs, 11, 17);
        testTextAttrs(aID, 17, attrs, defAttrs, 17, 18);
        testTextAttrs(aID, 18, misspelledAttrs, defAttrs, 18, 22);
      }

      this.getID = function spelledTextInvoker_getID()
      {
        return "text attribute change for misspelled text";
      }
    }

    /**
     * Do tests.
     */
    //gA11yEventDumpID = "eventdump"; // debug stuff
    //gA11yEventDumpToConsole = true;

    var gQueue = null;
    function doTests()
    {
      // Synth focus before spellchecking turning on to make sure editor
      // gets a time for initialization.

      gQueue = new eventQueue();
      gQueue.push(new synthFocus("input"));
      gQueue.push(new spelledTextInvoker("input"));
      gQueue.invoke(); // Will call SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTests);
  </script>
</head>

<body>

  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=345759"
     title="Implement text attributes">
    Mozilla Bug 345759
  </a>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>

  <input id="input"/>

  <div id="eventdump"></div>
</body>
</html>