summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/textrange/test_general.html
blob: b7da4ee8aa29c10743dddefe489add7a9f0bd96e (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
<!DOCTYPE html>
<html>
<head>
  <title>Text Range tests</title>
  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

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

    function doTest() {
      // enclosingRange
      var input = getAccessible("input", [ nsIAccessibleText ]);
      testTextRange(input.enclosingRange, "enclosing range for 'input'",
                    input, 0, input, 5, "hello", input);

      var ta = getAccessible("textarea", [ nsIAccessibleText ]);
      testTextRange(ta.enclosingRange, "enclosing range for 'textarea'",
                    ta, 0, ta, 5, "hello", ta);

      var iframeDocNode = getNode("iframe").contentDocument;
      var iframeDoc = getAccessible(iframeDocNode, [ nsIAccessibleText ]);
      testTextRange(iframeDoc.enclosingRange, "enclosing range for iframe doc",
                    iframeDoc, 0, iframeDoc, 1, "hello",
                    iframeDoc, [ getNode("p", iframeDocNode) ]);

      // getRangeByChild
      var docacc = getAccessible(document, [ nsIAccessibleText ]);
      var p1 = getAccessible("p1");
      var p1Range = docacc.getRangeByChild(p1);
      testTextRange(p1Range, "range by 'p1' child",
                    p1, 0, "p1", 11, "text  text",
                    p1, ["p1_img"]);

      testTextRange(docacc.getRangeByChild(getAccessible("p1_img")),
                    "range by 'p1_img' child",
                    "p1", 5, "p1", 5, "",
                    "p1", ["p1_img"]);

      var p2 = getAccessible("p2");
      var p2Range = docacc.getRangeByChild(p2);
      testTextRange(p2Range, "range by 'p2' child",
                    p2, 0, "p2", 11, "text link text",
                    p2, ["p2_a"]);

      testTextRange(docacc.getRangeByChild(getAccessible("p2_a")),
                    "range by 'p2_a' child",
                    "p2_a", 0, "p2_a", 5, "link",
                    "p2_a", ["p2_img"]);

      // getRangeAtPoint
      getNode("p2_a").scrollIntoView(true);
      var [x, y] = getPos("p2_a");
      testTextRange(docacc.getRangeAtPoint(x + 1, y + 1),
                    "range at 'p2_a' top-left edge",
                    "p2_a", 0, "p2_a", 0, "",
                    "p2_a");

      // TextRange::compare
      ok(input.enclosingRange.compare(input.enclosingRange),
         "input enclosing ranges should be equal");

      ok(!input.enclosingRange.compare(ta.enclosingRange),
         "input and textarea enclosing ranges can't be equal");

      // TextRange::compareEndPoints
      var res = p1Range.compareEndPoints(EndPoint_End, p2Range, EndPoint_Start);
      is(res, -1, "p1 range must be lesser with p2 range");

      res = p2Range.compareEndPoints(EndPoint_Start, p1Range, EndPoint_End);
      is(res, 1, "p2 range must be greater with p1 range");

      res = p1Range.compareEndPoints(EndPoint_Start, p1Range, EndPoint_Start);
      is(res, 0, "p1 range must be equal with p1 range");

      SimpleTest.finish();
    }

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

  <a target="_blank"
     title="Implement Text accessible text range methods"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=975065">Bug 975065</a>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>

  <input id="input" value="hello">
  <textarea id="textarea">hello</textarea>
  <iframe id="iframe" src="data:text/html,<html><body><p id='p'>hello</p></body></html>"></iframe>
  <p id="p1">text <img id="p1_img", src="../moz.png"> text</p>
  <p id="p2">text <a id="p2_a" href="www">link<img id="p2_img", src="../moz.png"></a> text</p>

</body>
</html>