gecko/content/base/test/test_bug895239.html

124 lines
4.8 KiB
HTML
Raw Normal View History

<!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>