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