summaryrefslogtreecommitdiffstats
path: root/dom/base/test/chrome/test_range_getClientRectsAndTexts.html
blob: 10eddaf5226fc4d2971e988253ba90ad4f1b1903 (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
<html>
<head>
<meta charset="utf-8">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script>
"use strict";

SimpleTest.waitForExplicitFinish();

function runTests() {
  let range = document.createRange();

  let attempts = [
    {startNode: "one", start: 0, endNode: "one", end: 0, textList: [], message: "Empty rect"},
    {startNode: "one", start: 2, endNode: "one", end: 6, textList: ["l on"], message: "Single line"},
    {startNode: "implicit", start: 6, endNode: "implicit", end: 12, textList: ["it bre"], message: "Implicit break"},
    {startNode: "two.a", start: 1, endNode: "two.b", end: 2, textList: ["wo", "", "li"], message: "Two lines"},
    {startNode: "embed.a", start: 7, endNode: "embed.b", end: 2, textList: ["th ", "simple nested", " ", "te"], message: "Simple nested"},
    {startNode: "deep.a", start: 2, endNode: "deep.b", end: 2, textList: ["ne with ", "complex, more deeply nested", " ", "te"], message: "Complex nested"},
    {startNode: "image.a", start: 7, endNode: "image.b", end: 2, textList: ["th inline ", "", " ", "im"], message: "Inline image"},
    {startNode: "hyphen1", start: 0, endNode: "hyphen1", end: 3, textList: ["a\u00AD", "b"], message: "Shy hyphen (active)"},
    {startNode: "hyphen2", start: 0, endNode: "hyphen2", end: 3, textList: ["c\u00ADd"], message: "Shy hyphen (inactive)"},
    {startNode: "hyphen2", start: 0, endNode: "hyphen2", end: 2, textList: ["c\u00AD"], message: "Shy hyphen (inactive, trailing)"},
    {startNode: "hyphen2", start: 1, endNode: "hyphen2", end: 3, textList: ["\u00ADd"], message: "Shy hyphen (inactive, leading)"},
    {startNode: "uc", start: 0, endNode: "uc", end: 2, textList: ["EF"], message: "UC transform"},
    {startNode: "pre", start: 0, endNode: "pre", end: 3, textList: ["g\n", "h"], message: "pre with break"},
  ];

  for (let attempt of attempts) {
    range.setStart(document.getElementById(attempt.startNode).childNodes[0], attempt.start);
    range.setEnd(document.getElementById(attempt.endNode).childNodes[0], attempt.end);

    let result = range.getClientRectsAndTexts();

    is(result.textList.length, attempt.textList.length, attempt.message + " range has expected number of texts.");
    let i = 0;
    for (let text of result.textList) {
      is(text, attempt.textList[i], attempt.message + " matched text index " + i + ".");
      i++;
    }
  }

  SimpleTest.finish();
}
</script>
</head>
<body onLoad="runTests()">

<div id="one">All on one line</div>

<div id="implicit">Implicit
break in one line</div>

<div id="two.a">Two<br/
><span id="two.b">lines</span></div>

<div id="embed.a">Line with <span>simple nested</span> <span id="embed.b">text</span></div>

<div id="deep.a">Line with <span>complex, <span>more <span>deeply <span>nested</span></span></span></span> <span id="deep.b">text</span></div>

<div id="image.a">Line with inline <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAG0lEQVR42mP8z0A%2BYKJA76jmUc2jmkc1U0EzACKcASfOgGoMAAAAAElFTkSuQmCC" width="20" height="20"/> <span id="image.b">image</span></div>

<div id="hyphen1" style="width:0">a&shy;b</div>

<div id="hyphen2" style="width:100px">c&shy;d</div>

<div id="uc" style="text-transform:uppercase">ef</div>

<pre id="pre">g
h</pre>

</body>
</html>