summaryrefslogtreecommitdiff
path: root/dom/base/test/test_bug682592.html
blob: c2dc8ed3a4845e19c9d12cadc501f804d052b0b9 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=682592
-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
    <title>Test for bug 682592</title>
    <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
<iframe id="iframe-ref"></iframe>
<iframe id="iframe-test"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript;version=1.7">
/** Test for Bug 682592 **/

/* 
   We want to check that bidi is detected correctly. So, we have a reference
   document where ltr is set explicitely with <bdo> element. Then, we compare
   it with test document.

   In mozilla, once bidi has been detected in a document, document always
   consider it's in bidi mode. So, if one fragment enables bidi correctly, and
   we create or update a fragment in the same document, that operation may not
   enable bidi by itself, but it will not be detected. So, we need to have new
   document for each test.

   So, instead of many diferent reftests, this mochitest implements a
   reftest-like. It creates reference text fragments in reference iframe, test
   text fragments in test iframe, and compare the documents. Then, it reloads
   test iframe. Reference iframe does not need to be reloaded between tests.
   It's ok (and maybe, desired) to keep bidi always enabled in that document. 
*/

SimpleTest.waitForExplicitFinish();
SimpleTest.requestLongerTimeout(3);
if (navigator.platform.startsWith("Linux arm")) { /* bugs 982875, 999429 */
  SimpleTest.expectAssertions(0, 4);
}

var page = `data:text/html;charset=UTF-8,<!DOCTYPE html>
<html><body><p id="content"></p></body></html>`;
var refFrame = document.getElementById("iframe-ref")
var testFrame = document.getElementById("iframe-test");

refFrame.addEventListener("load", function() {
  testFrame.addEventListener("load", function() {
    try {
      tests.next();
      ok(compareSnapshots(snapshotWindow(testFrame.contentWindow), 
                          snapshotWindow(refFrame.contentWindow), true)[0], 
         "bidi is not detected correctly");

      testFrame.contentWindow.location.reload();
    } catch (err if err instanceof StopIteration) {
      SimpleTest.finish();
    }
  }, false);
  testFrame.src = page;
}, false);
refFrame.src = page;

var rtl = "עִבְרִית";
var non8bit =  "ʃ";
var is8bit = "a";

// concats aStr aNumber of times
function strMult(aStr, aNumber) {
  if (aNumber === 0) {
    return "";
  }
  return strMult(aStr, aNumber - 1) + aStr;
}

function runTests () {
  var ltr = "", prefix = null;
  var refContainer = refFrame.contentDocument.getElementById('content');
  var testContainer, textNode;
  var i = 0;

  // 8bit chars + bidi
  for (i = 0; i <= 16; i++) {
    ltr = strMult(is8bit, i);
    refContainer.innerHTML = ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    testContainer.innerHTML = ltr + rtl;
    yield undefined;
  }

  // non-8bit char + 8bit chars + bidi
  for (i = 0; i <= 16; i++) {
    ltr = non8bit + strMult(is8bit, i);
    refContainer.innerHTML = ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    testContainer.innerHTML = ltr + rtl;
    yield undefined;
  }

  // appendData
  for (i = 0; i <= 16; i++) {
    ltr = strMult(is8bit, i);
    refContainer.innerHTML = ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode("");
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  for (i = 0; i <= 16; i++) {
    ltr = non8bit + strMult(is8bit, i);
    refContainer.innerHTML = ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode("");
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  // appendData with 8bit prefix
  for (i = 0; i <= 16; i++) {
    prefix = is8bit;
    ltr = strMult(is8bit, i);
    refContainer.innerHTML = prefix + ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode(prefix);
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  for (i = 0; i <= 16; i++) {
    prefix = is8bit;
    ltr = non8bit + strMult(is8bit, i);
    refContainer.innerHTML = prefix + ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode(prefix);
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  // appendData with non-8bit prefix
  for (i = 0; i <= 16; i++) {
    prefix = non8bit;
    ltr = strMult(is8bit, i);
    refContainer.innerHTML = prefix + ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode(prefix);
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  for (i = 0; i <= 16; i++) {
    prefix = non8bit;
    ltr = non8bit + strMult(is8bit, i);
    refContainer.innerHTML = prefix + ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode(prefix);
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }
};

var tests = runTests();

</script>
</pre>
</body>
</html>