content/base/test/test_bug895239.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug895239.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=895239
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 895239</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +  <script type="application/javascript">
    1.15 +  function testPaintextSerializerWithPlaceHolder() {
    1.16 +
    1.17 +    const de = SpecialPowers.Ci.nsIDocumentEncoder;
    1.18 +    const Cc = SpecialPowers.Cc;
    1.19 +
    1.20 +    // Create a plaintext encoder with the flag OutputNonTextContentAsPlaceholder.
    1.21 +    var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
    1.22 +                  .createInstance(de);
    1.23 +    var flags = de.OutputRaw |
    1.24 +                de.OutputNonTextContentAsPlaceholder;
    1.25 +    encoder.init(document, "text/plain", flags);
    1.26 +
    1.27 +    function toPlaintext(id) {
    1.28 +      var element = document.getElementById(id);
    1.29 +      var range = document.createRange();
    1.30 +      range.selectNodeContents(element);
    1.31 +      encoder.setRange(range);
    1.32 +      return encoder.encodeToString();
    1.33 +    }
    1.34 +
    1.35 +    // Test cases to serialize all nodes including invisible nodes.
    1.36 +    is(toPlaintext("case1"), "This is an audio \uFFFC! ", "test with <audio>");
    1.37 +    is(toPlaintext("case2"), "This is a canvas \uFFFC! ", "test with <canvas>");
    1.38 +    is(toPlaintext("case3"), "This is an iframe \uFFFC! ", "test with one <iframe>");
    1.39 +    is(toPlaintext("case4"), "One iframe \uFFFC with another iframe \uFFFC. ", "test with two <iframes>");
    1.40 +    is(toPlaintext("case5"), "This is a meter \uFFFC! ", "test with <meter>");
    1.41 +    is(toPlaintext("case6"), "This is a progress \uFFFC! ", "test with <progress>");
    1.42 +    is(toPlaintext("case7"), "This is an object \uFFFC! ", "test with <object>");
    1.43 +    is(toPlaintext("case8"), "This is a svg \uFFFC! ", "test with <svg>");
    1.44 +    is(toPlaintext("case9"), "This is a video \uFFFC! ", "test with <video>");
    1.45 +    is(toPlaintext("case10"), "This is a video \uFFFC! ", "test with nested tags");
    1.46 +
    1.47 +    // Test cases to serialize visible nodes only.
    1.48 +    encoder.init(document, "text/plain", flags | de.SkipInvisibleContent);
    1.49 +    is(toPlaintext("case1"), "This is an audio \uFFFC! ", "test with <audio> for visible nodes");
    1.50 +    is(toPlaintext("case2"), "This is a canvas \uFFFC! ", "test with <canvas> for visible nodes");
    1.51 +    is(toPlaintext("case3"), "This is an iframe \uFFFC! ", "test with one <iframe> for visible nodes");
    1.52 +    is(toPlaintext("case4"), "One iframe \uFFFC with another iframe . ", "test with two <iframes> for visible nodes");
    1.53 +    is(toPlaintext("case5"), "This is a meter \uFFFC! ", "test with <meter> for visible nodes");
    1.54 +    is(toPlaintext("case6"), "This is a progress \uFFFC! ", "test with <progress> for visible nodes");
    1.55 +    is(toPlaintext("case7"), "This is an object \uFFFC! ", "test with <object> for visible nodes");
    1.56 +    is(toPlaintext("case8"), "This is a svg \uFFFC! ", "test with <svg> for visible nodes");
    1.57 +    is(toPlaintext("case9"), "This is a video \uFFFC! ", "test with <video> for visible nodes");
    1.58 +    is(toPlaintext("case10"), "This is a video \uFFFC! ", "test with nested tags for visible nodes");
    1.59 +    SimpleTest.finish();
    1.60 +  }
    1.61 +
    1.62 +  addLoadEvent(testPaintextSerializerWithPlaceHolder);
    1.63 +  SimpleTest.waitForExplicitFinish();
    1.64 +  </script>
    1.65 +</head>
    1.66 +<body>
    1.67 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=895239">Mozilla Bug 895239</a>
    1.68 +<p id="display"></p>
    1.69 +<div id="content">
    1.70 +  <span id="case1">This is an audio
    1.71 +    <audio controls="controls">
    1.72 +      Your browser does not support <code>audio</code> element.
    1.73 +    </audio>!
    1.74 +  </span>
    1.75 +  <span id="case2">This is a canvas
    1.76 +    <canvas height="100" width="100">
    1.77 +      Your browser does not support canvas element.
    1.78 +    </canvas>!
    1.79 +  </span>
    1.80 +  <span id="case3">This is an iframe
    1.81 +    <iframe src="about:blank">
    1.82 +      Your browser does not support iframes.
    1.83 +    </iframe>!
    1.84 +  </span>
    1.85 +  <span id="case4">One iframe
    1.86 +    <iframe src="about:blank">
    1.87 +      Your browser does not support iframes.
    1.88 +    </iframe> with another iframe
    1.89 +    <iframe src="about:blank" style="display: none"></iframe>.
    1.90 +  </span>
    1.91 +  <span id="case5">This is a meter
    1.92 +    <meter min="0" max="100" value="50">
    1.93 +      50%
    1.94 +    </meter>!
    1.95 +  </span>
    1.96 +  <span id="case6">This is a progress
    1.97 +    <progress max="100" value="70">
    1.98 +      70%
    1.99 +    </progress>!
   1.100 +  </span>
   1.101 +  <span id="case7">This is an object
   1.102 +    <object type="application/x-shockware-flash">
   1.103 +      <a href="#">Download the plugin.</a>
   1.104 +    </object>!
   1.105 +  </span>
   1.106 +  <span id="case8">This is a svg
   1.107 +    <svg height="100" width="100">
   1.108 +      Your browser does not support svg.
   1.109 +      <circle cx="100" cy="100" r="80" fill="green"></circle>
   1.110 +    </svg>!
   1.111 +  </span>
   1.112 +  <span id="case9">This is a video
   1.113 +    <video>
   1.114 +      Your browser does not support videos.
   1.115 +    </video>!
   1.116 +  </span>
   1.117 +  <span id="case10">This is a video
   1.118 +    <video>
   1.119 +      Your browser does not support videos.<iframe src="about:blank"></iframe>
   1.120 +    </video>!
   1.121 +  </span>
   1.122 +</div>
   1.123 +<pre id="test">
   1.124 +</pre>
   1.125 +</body>
   1.126 +</html>

mercurial