content/base/test/test_bug890580.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug890580.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=890580
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 883129</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 +    const de = SpecialPowers.Ci.nsIDocumentEncoder;
    1.17 +    const Cc = SpecialPowers.Cc;
    1.18 +
    1.19 +    // Create a plaintext encoder with the flag OutputNonTextContentAsPlaceholder.
    1.20 +    var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
    1.21 +                  .createInstance(de);
    1.22 +    var flags = de.OutputRaw |
    1.23 +                de.OutputNonTextContentAsPlaceholder;
    1.24 +    encoder.init(document, "text/plain", flags);
    1.25 +
    1.26 +    function toPlaintext(id) {
    1.27 +      var element = document.getElementById(id);
    1.28 +      var range = document.createRange();
    1.29 +      range.selectNodeContents(element);
    1.30 +      encoder.setRange(range);
    1.31 +      return encoder.encodeToString();
    1.32 +    }
    1.33 +
    1.34 +    // The follows are test cases.
    1.35 +    is(toPlaintext("case1"), "This is a button. Hello!", "test with <button>");
    1.36 +    is(toPlaintext("case2"), "There is an\uFFFCimage.", "test with <img>");
    1.37 +    is(toPlaintext("case3"), "\uFFFC with text.", "test with <input>");
    1.38 +    is(toPlaintext("case4"), "There is an\uFFFCimage and a \uFFFC.",
    1.39 +       "test with <img> and <input>");
    1.40 +
    1.41 +    SimpleTest.finish();
    1.42 +  }
    1.43 +
    1.44 +  addLoadEvent(testPaintextSerializerWithPlaceHolder);
    1.45 +  SimpleTest.waitForExplicitFinish();
    1.46 +  </script>
    1.47 +</head>
    1.48 +<body>
    1.49 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=890580">Mozilla Bug 890580</a>
    1.50 +<p id="display"></p>
    1.51 +<div id="content" style="display: none">
    1.52 +  <span id="case1"><button id="b">This is a button.</button> Hello!</span>
    1.53 +  <span id="case2">There is an<img>image.</span>
    1.54 +  <span id="case3"><input type="button" value="Input button"> with text.</span>
    1.55 +  <span id="case4" contenteditable="true">There is an<img>image and
    1.56 +  a <input type="button" value="button">.</span>
    1.57 +</div>
    1.58 +<pre id="test">
    1.59 +</pre>
    1.60 +</body>
    1.61 +</html>

mercurial