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
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=895239
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 895239</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
function testPaintextSerializerWithPlaceHolder() {
const de = SpecialPowers.Ci.nsIDocumentEncoder;
const Cc = SpecialPowers.Cc;
// Create a plaintext encoder with the flag OutputNonTextContentAsPlaceholder.
var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
.createInstance(de);
var flags = de.OutputRaw |
de.OutputNonTextContentAsPlaceholder;
encoder.init(document, "text/plain", flags);
function toPlaintext(id) {
var element = document.getElementById(id);
var range = document.createRange();
range.selectNodeContents(element);
encoder.setRange(range);
return encoder.encodeToString();
}
// Test cases to serialize all nodes including invisible nodes.
is(toPlaintext("case1"), "This is an audio \uFFFC! ", "test with <audio>");
is(toPlaintext("case2"), "This is a canvas \uFFFC! ", "test with <canvas>");
is(toPlaintext("case3"), "This is an iframe \uFFFC! ", "test with one <iframe>");
is(toPlaintext("case4"), "One iframe \uFFFC with another iframe \uFFFC. ", "test with two <iframes>");
is(toPlaintext("case5"), "This is a meter \uFFFC! ", "test with <meter>");
is(toPlaintext("case6"), "This is a progress \uFFFC! ", "test with <progress>");
is(toPlaintext("case7"), "This is an object \uFFFC! ", "test with <object>");
is(toPlaintext("case8"), "This is a svg \uFFFC! ", "test with <svg>");
is(toPlaintext("case9"), "This is a video \uFFFC! ", "test with <video>");
is(toPlaintext("case10"), "This is a video \uFFFC! ", "test with nested tags");
// Test cases to serialize visible nodes only.
encoder.init(document, "text/plain", flags | de.SkipInvisibleContent);
is(toPlaintext("case1"), "This is an audio \uFFFC! ", "test with <audio> for visible nodes");
is(toPlaintext("case2"), "This is a canvas \uFFFC! ", "test with <canvas> for visible nodes");
is(toPlaintext("case3"), "This is an iframe \uFFFC! ", "test with one <iframe> for visible nodes");
is(toPlaintext("case4"), "One iframe \uFFFC with another iframe . ", "test with two <iframes> for visible nodes");
is(toPlaintext("case5"), "This is a meter \uFFFC! ", "test with <meter> for visible nodes");
is(toPlaintext("case6"), "This is a progress \uFFFC! ", "test with <progress> for visible nodes");
is(toPlaintext("case7"), "This is an object \uFFFC! ", "test with <object> for visible nodes");
is(toPlaintext("case8"), "This is a svg \uFFFC! ", "test with <svg> for visible nodes");
is(toPlaintext("case9"), "This is a video \uFFFC! ", "test with <video> for visible nodes");
is(toPlaintext("case10"), "This is a video \uFFFC! ", "test with nested tags for visible nodes");
SimpleTest.finish();
}
addLoadEvent(testPaintextSerializerWithPlaceHolder);
SimpleTest.waitForExplicitFinish();
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=895239">Mozilla Bug 895239</a>
<p id="display"></p>
<div id="content">
<span id="case1">This is an audio
<audio controls="controls">
Your browser does not support <code>audio</code> element.
</audio>!
</span>
<span id="case2">This is a canvas
<canvas height="100" width="100">
Your browser does not support canvas element.
</canvas>!
</span>
<span id="case3">This is an iframe
<iframe src="about:blank">
Your browser does not support iframes.
</iframe>!
</span>
<span id="case4">One iframe
<iframe src="about:blank">
Your browser does not support iframes.
</iframe> with another iframe
<iframe src="about:blank" style="display: none"></iframe>.
</span>
<span id="case5">This is a meter
<meter min="0" max="100" value="50">
50%
</meter>!
</span>
<span id="case6">This is a progress
<progress max="100" value="70">
70%
</progress>!
</span>
<span id="case7">This is an object
<object type="application/x-shockware-flash">
<a href="#">Download the plugin.</a>
</object>!
</span>
<span id="case8">This is a svg
<svg height="100" width="100">
Your browser does not support svg.
<circle cx="100" cy="100" r="80" fill="green"></circle>
</svg>!
</span>
<span id="case9">This is a video
<video>
Your browser does not support videos.
</video>!
</span>
<span id="case10">This is a video
<video>
Your browser does not support videos.<iframe src="about:blank"></iframe>
</video>!
</span>
</div>
<pre id="test">
</pre>
</body>
</html>
|