content/base/test/test_bug895239.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:d6df92319c5c
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=895239
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 895239</title>
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 <script type="application/javascript">
12 function testPaintextSerializerWithPlaceHolder() {
13
14 const de = SpecialPowers.Ci.nsIDocumentEncoder;
15 const Cc = SpecialPowers.Cc;
16
17 // Create a plaintext encoder with the flag OutputNonTextContentAsPlaceholder.
18 var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
19 .createInstance(de);
20 var flags = de.OutputRaw |
21 de.OutputNonTextContentAsPlaceholder;
22 encoder.init(document, "text/plain", flags);
23
24 function toPlaintext(id) {
25 var element = document.getElementById(id);
26 var range = document.createRange();
27 range.selectNodeContents(element);
28 encoder.setRange(range);
29 return encoder.encodeToString();
30 }
31
32 // Test cases to serialize all nodes including invisible nodes.
33 is(toPlaintext("case1"), "This is an audio \uFFFC! ", "test with <audio>");
34 is(toPlaintext("case2"), "This is a canvas \uFFFC! ", "test with <canvas>");
35 is(toPlaintext("case3"), "This is an iframe \uFFFC! ", "test with one <iframe>");
36 is(toPlaintext("case4"), "One iframe \uFFFC with another iframe \uFFFC. ", "test with two <iframes>");
37 is(toPlaintext("case5"), "This is a meter \uFFFC! ", "test with <meter>");
38 is(toPlaintext("case6"), "This is a progress \uFFFC! ", "test with <progress>");
39 is(toPlaintext("case7"), "This is an object \uFFFC! ", "test with <object>");
40 is(toPlaintext("case8"), "This is a svg \uFFFC! ", "test with <svg>");
41 is(toPlaintext("case9"), "This is a video \uFFFC! ", "test with <video>");
42 is(toPlaintext("case10"), "This is a video \uFFFC! ", "test with nested tags");
43
44 // Test cases to serialize visible nodes only.
45 encoder.init(document, "text/plain", flags | de.SkipInvisibleContent);
46 is(toPlaintext("case1"), "This is an audio \uFFFC! ", "test with <audio> for visible nodes");
47 is(toPlaintext("case2"), "This is a canvas \uFFFC! ", "test with <canvas> for visible nodes");
48 is(toPlaintext("case3"), "This is an iframe \uFFFC! ", "test with one <iframe> for visible nodes");
49 is(toPlaintext("case4"), "One iframe \uFFFC with another iframe . ", "test with two <iframes> for visible nodes");
50 is(toPlaintext("case5"), "This is a meter \uFFFC! ", "test with <meter> for visible nodes");
51 is(toPlaintext("case6"), "This is a progress \uFFFC! ", "test with <progress> for visible nodes");
52 is(toPlaintext("case7"), "This is an object \uFFFC! ", "test with <object> for visible nodes");
53 is(toPlaintext("case8"), "This is a svg \uFFFC! ", "test with <svg> for visible nodes");
54 is(toPlaintext("case9"), "This is a video \uFFFC! ", "test with <video> for visible nodes");
55 is(toPlaintext("case10"), "This is a video \uFFFC! ", "test with nested tags for visible nodes");
56 SimpleTest.finish();
57 }
58
59 addLoadEvent(testPaintextSerializerWithPlaceHolder);
60 SimpleTest.waitForExplicitFinish();
61 </script>
62 </head>
63 <body>
64 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=895239">Mozilla Bug 895239</a>
65 <p id="display"></p>
66 <div id="content">
67 <span id="case1">This is an audio
68 <audio controls="controls">
69 Your browser does not support <code>audio</code> element.
70 </audio>!
71 </span>
72 <span id="case2">This is a canvas
73 <canvas height="100" width="100">
74 Your browser does not support canvas element.
75 </canvas>!
76 </span>
77 <span id="case3">This is an iframe
78 <iframe src="about:blank">
79 Your browser does not support iframes.
80 </iframe>!
81 </span>
82 <span id="case4">One iframe
83 <iframe src="about:blank">
84 Your browser does not support iframes.
85 </iframe> with another iframe
86 <iframe src="about:blank" style="display: none"></iframe>.
87 </span>
88 <span id="case5">This is a meter
89 <meter min="0" max="100" value="50">
90 50%
91 </meter>!
92 </span>
93 <span id="case6">This is a progress
94 <progress max="100" value="70">
95 70%
96 </progress>!
97 </span>
98 <span id="case7">This is an object
99 <object type="application/x-shockware-flash">
100 <a href="#">Download the plugin.</a>
101 </object>!
102 </span>
103 <span id="case8">This is a svg
104 <svg height="100" width="100">
105 Your browser does not support svg.
106 <circle cx="100" cy="100" r="80" fill="green"></circle>
107 </svg>!
108 </span>
109 <span id="case9">This is a video
110 <video>
111 Your browser does not support videos.
112 </video>!
113 </span>
114 <span id="case10">This is a video
115 <video>
116 Your browser does not support videos.<iframe src="about:blank"></iframe>
117 </video>!
118 </span>
119 </div>
120 <pre id="test">
121 </pre>
122 </body>
123 </html>

mercurial