content/base/test/test_bug422403-2.xhtml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 3 <!--
michael@0 4 -->
michael@0 5 <head>
michael@0 6 <title>Test XHTML serializer with entities and selection</title>
michael@0 7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=422043">Mozilla Bug </a>
michael@0 12 <p id="display"></p>
michael@0 13 <div id="content" style="display: none">
michael@0 14 <iframe id="testframe" src="file_xhtmlserializer_2.xhtml">
michael@0 15 </iframe>
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script class="testbody" type="text/javascript">
michael@0 19 //<![CDATA[
michael@0 20
michael@0 21 function loadFileContent(aFile, aCharset) {
michael@0 22 //if(aAsIso == undefined) aAsIso = false;
michael@0 23 if(aCharset == undefined)
michael@0 24 aCharset = 'UTF-8';
michael@0 25
michael@0 26 var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
michael@0 27 .createInstance(SpecialPowers.Ci.nsIURI);
michael@0 28 baseUri.spec = window.location.href;
michael@0 29
michael@0 30 var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
michael@0 31 .getService(SpecialPowers.Ci.nsIIOService);
michael@0 32 var chann = ios.newChannel(aFile, aCharset, baseUri);
michael@0 33
michael@0 34 var cis = SpecialPowers.Ci.nsIConverterInputStream;
michael@0 35
michael@0 36 var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"]
michael@0 37 .createInstance(cis);
michael@0 38 inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER);
michael@0 39 var str = {}, content = '';
michael@0 40 while (inputStream.readString(4096, str) != 0) {
michael@0 41 content += str.value;
michael@0 42 }
michael@0 43 return content;
michael@0 44 }
michael@0 45
michael@0 46
michael@0 47 function testHtmlSerializer_1 () {
michael@0 48 const de = SpecialPowers.Ci.nsIDocumentEncoder
michael@0 49 var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
michael@0 50 .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
michael@0 51
michael@0 52 var doc = $("testframe").contentDocument;
michael@0 53 var out, expected;
michael@0 54
michael@0 55 // in the following tests, we must use the OutputLFLineBreak flag, to avoid
michael@0 56 // to have the default line break of the platform in the result, so the test
michael@0 57 // can pass on all platform
michael@0 58
michael@0 59 //------------ OutputEncodeW3CEntities
michael@0 60 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputEncodeW3CEntities);
michael@0 61 out = encoder.encodeToString();
michael@0 62 expected = loadFileContent("file_xhtmlserializer_2_basic.xhtml");
michael@0 63 is(out, expected, "test OutputEncodeW3CEntities");
michael@0 64
michael@0 65 //------------ OutputEncodeBasicEntities
michael@0 66 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputEncodeBasicEntities);
michael@0 67 out = encoder.encodeToString();
michael@0 68 expected = loadFileContent("file_xhtmlserializer_2_basic.xhtml");
michael@0 69 is(out, expected, "test OutputEncodeBasicEntities");
michael@0 70
michael@0 71 //------------ OutputEncodeLatin1Entities
michael@0 72 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputEncodeLatin1Entities);
michael@0 73 out = encoder.encodeToString();
michael@0 74 expected = loadFileContent("file_xhtmlserializer_2_basic.xhtml");
michael@0 75 is(out, expected, "test OutputEncodeLatin1Entities");
michael@0 76
michael@0 77 //------------ OutputEncodeHTMLEntities
michael@0 78 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputEncodeHTMLEntities);
michael@0 79 out = encoder.encodeToString();
michael@0 80 expected = loadFileContent("file_xhtmlserializer_2_basic.xhtml");
michael@0 81 is(out, expected, "test OutputEncodeHTMLEntities");
michael@0 82
michael@0 83 // tests on the serialization of selections
michael@0 84
michael@0 85 var node = document.getElementById('draggable');
michael@0 86
michael@0 87 var select = window.getSelection();
michael@0 88 select.selectAllChildren(node);
michael@0 89
michael@0 90 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 91 encoder.setSelection(select);
michael@0 92 out = encoder.encodeToString();
michael@0 93 expected = 'This is a <em xmlns=\"http://www.w3.org/1999/xhtml\">draggable</em> bit of text.';
michael@0 94 is(out, expected, "test selection");
michael@0 95
michael@0 96 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 97 encoder.setSelection(null);
michael@0 98 encoder.setContainerNode(node);
michael@0 99 out = encoder.encodeToString();
michael@0 100 expected = 'This is a <em xmlns=\"http://www.w3.org/1999/xhtml\">draggable</em> bit of text.';
michael@0 101 is(out, expected, "test container node");
michael@0 102
michael@0 103 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 104 encoder.setNode(node);
michael@0 105 out = encoder.encodeToString();
michael@0 106 expected = "<div xmlns=\"http://www.w3.org/1999/xhtml\" id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>";
michael@0 107 is(out, expected, "test node");
michael@0 108
michael@0 109 node = document.getElementById('aList');
michael@0 110
michael@0 111 var select = window.getSelection();
michael@0 112 select.selectAllChildren(node);
michael@0 113
michael@0 114 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 115 encoder.setSelection(select);
michael@0 116 out = encoder.encodeToString();
michael@0 117 expected = '\n <li xmlns=\"http://www.w3.org/1999/xhtml\">Lorem ipsum dolor</li>\n <li xmlns=\"http://www.w3.org/1999/xhtml\">sit amet, <strong>consectetuer</strong> </li>\n <li xmlns=\"http://www.w3.org/1999/xhtml\">adipiscing elit</li>\n <li xmlns=\"http://www.w3.org/1999/xhtml\">Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li xmlns=\"http://www.w3.org/1999/xhtml\">aptent taciti</li>\n';
michael@0 118 is(out, expected, "test list selection");
michael@0 119
michael@0 120 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 121 encoder.setSelection(null);
michael@0 122 encoder.setContainerNode(node);
michael@0 123 out = encoder.encodeToString();
michael@0 124 expected = '\n <li xmlns=\"http://www.w3.org/1999/xhtml\">Lorem ipsum dolor</li>\n <li xmlns=\"http://www.w3.org/1999/xhtml\">sit amet, <strong>consectetuer</strong> </li>\n <li xmlns=\"http://www.w3.org/1999/xhtml\">adipiscing elit</li>\n <li xmlns=\"http://www.w3.org/1999/xhtml\">Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li xmlns=\"http://www.w3.org/1999/xhtml\">aptent taciti</li>\n';
michael@0 125 is(out, expected, "test list container node");
michael@0 126
michael@0 127 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 128 encoder.setNode(node);
michael@0 129 out = encoder.encodeToString();
michael@0 130 expected = "<ol xmlns=\"http://www.w3.org/1999/xhtml\" id=\"aList\">\n <li>Lorem ipsum dolor</li>\n <li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>";
michael@0 131 is(out, expected, "test list node");
michael@0 132
michael@0 133 var liList = node.getElementsByTagName("li");
michael@0 134 var range = document.createRange();
michael@0 135
michael@0 136 // selection start at the first child of the ol, and end after the element ol
michael@0 137 range.setStart(node, 1);
michael@0 138 range.setEnd(node.parentNode, 2);
michael@0 139 select.removeAllRanges();
michael@0 140 select.addRange(range);
michael@0 141 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 142 encoder.setSelection(select);
michael@0 143 out = encoder.encodeToString();
michael@0 144 expected = '<ol xmlns=\"http://www.w3.org/1999/xhtml\" id="aList"><li>Lorem ipsum dolor</li>\n <li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>';
michael@0 145 is(out, expected, "test list selection with range: selection start at the first child of the ol, and end after the element ol");
michael@0 146
michael@0 147 // selection start at the third child of the ol, and end after the element ol
michael@0 148 range.setStart(node, 3);
michael@0 149 range.setEnd(node.parentNode, 2);
michael@0 150 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 151 encoder.setSelection(select);
michael@0 152 out = encoder.encodeToString();
michael@0 153 expected = '<ol xmlns=\"http://www.w3.org/1999/xhtml\" id="aList"><li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>';
michael@0 154 is(out, expected, "test list selection with range: selection start at the third child of the ol, and end after the element ol");
michael@0 155
michael@0 156
michael@0 157 // selection start at the third child of the ol, and end after the element ol + ol start at the value 5
michael@0 158 range.setStart(node, 3);
michael@0 159 range.setEnd(node.parentNode, 2);
michael@0 160 node.setAttribute("start","5");
michael@0 161 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 162 encoder.setSelection(select);
michael@0 163 out = encoder.encodeToString();
michael@0 164 expected = '<ol xmlns=\"http://www.w3.org/1999/xhtml\" id="aList" start="5"><li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>';
michael@0 165 is(out, expected, "test list selection with range: selection start at the third child of the ol, and end after the element ol + ol start at the value 5");
michael@0 166
michael@0 167
michael@0 168 // selection contains only some child of the ol
michael@0 169 node.removeAttribute("start");
michael@0 170 range.setStart(node, 3);
michael@0 171 range.setEnd(node, 5);
michael@0 172 encoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputSelectionOnly);
michael@0 173 encoder.setSelection(select);
michael@0 174 out = encoder.encodeToString();
michael@0 175 expected = '<li xmlns=\"http://www.w3.org/1999/xhtml\">sit amet, <strong>consectetuer</strong> </li>\n ';
michael@0 176 is(out, expected, "test list selection with range: selection contains only some child of the ol");
michael@0 177
michael@0 178
michael@0 179 // test on short attributes
michael@0 180
michael@0 181 node = document.getElementById('shortattr1');
michael@0 182 encoder.init(document, "application/xhtml+xml",de.OutputSelectionOnly | de.OutputRaw);
michael@0 183 encoder.setNode(node);
michael@0 184 out = encoder.encodeToString();
michael@0 185 expected = '<input xmlns="http://www.w3.org/1999/xhtml" id="shortattr1" checked="checked" value="" disabled="disabled" ismap="ismap" readonly="readonly" foo:checked="" xmlns:foo="http://mozilla.org/ns/any" foo:disabled="" />';
michael@0 186 is(out, expected, "test short attr #1");
michael@0 187
michael@0 188 node = document.getElementById('shortattr2');
michael@0 189 encoder.init(document, "application/xhtml+xml",de.OutputSelectionOnly | de.OutputRaw);
michael@0 190 encoder.setNode(node);
michael@0 191 out = encoder.encodeToString();
michael@0 192 expected = '<ol xmlns="http://www.w3.org/1999/xhtml" id="shortattr2" compact="compact"><li></li></ol>';
michael@0 193 is(out, expected, "test short attr #2");
michael@0 194
michael@0 195 node = document.getElementById('shortattr3');
michael@0 196 encoder.init(document, "application/xhtml+xml",de.OutputSelectionOnly | de.OutputRaw);
michael@0 197 encoder.setNode(node);
michael@0 198 out = encoder.encodeToString();
michael@0 199 expected = '<object xmlns="http://www.w3.org/1999/xhtml" id="shortattr3" declare="declare"></object>';
michael@0 200 is(out, expected, "test short attr #3");
michael@0 201
michael@0 202 node = document.getElementById('shortattr4');
michael@0 203 encoder.init(document, "application/xhtml+xml",de.OutputSelectionOnly | de.OutputRaw);
michael@0 204 encoder.setNode(node);
michael@0 205 out = encoder.encodeToString();
michael@0 206 expected = '<script xmlns="http://www.w3.org/1999/xhtml" id="shortattr4" defer="defer"></script>';
michael@0 207 is(out, expected, "test short attr #4");
michael@0 208
michael@0 209 node = document.getElementById('shortattr5');
michael@0 210 encoder.init(document, "application/xhtml+xml",de.OutputSelectionOnly | de.OutputRaw);
michael@0 211 encoder.setNode(node);
michael@0 212 out = encoder.encodeToString();
michael@0 213 expected = '<select xmlns="http://www.w3.org/1999/xhtml" id="shortattr5" multiple="multiple"><option selected="selected">aaa</option></select>';
michael@0 214 is(out, expected, "test short attr #5");
michael@0 215
michael@0 216 node = document.getElementById('shortattr6');
michael@0 217 encoder.init(document, "application/xhtml+xml",de.OutputSelectionOnly | de.OutputRaw);
michael@0 218 encoder.setNode(node);
michael@0 219 out = encoder.encodeToString();
michael@0 220 expected = '<hr xmlns="http://www.w3.org/1999/xhtml" noshade="noshade" id="shortattr6" />';
michael@0 221 is(out, expected, "test short attr #6");
michael@0 222
michael@0 223 node = document.getElementById('shortattr7');
michael@0 224 encoder.init(document, "application/xhtml+xml",de.OutputSelectionOnly | de.OutputRaw);
michael@0 225 encoder.setNode(node);
michael@0 226 out = encoder.encodeToString();
michael@0 227 expected = '<div xmlns="http://www.w3.org/1999/xhtml" id="shortattr7"><foo:bar xmlns:foo="http://mozilla.org/ns/any" checked="" value="" disabled="" ismap="" readonly=""/></div>';
michael@0 228 is(out, expected, "test short attr #7");
michael@0 229
michael@0 230 // test on _moz and -moz attr
michael@0 231 node = document.getElementById('mozattr');
michael@0 232 encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly | de.OutputRaw);
michael@0 233 encoder.setNode(node);
michael@0 234 out = encoder.encodeToString();
michael@0 235 expected = '<div __moz_b="b" id="mozattr"> lorem ipsum</div>';
michael@0 236 is(out, expected, "test -moz/_moz attr");
michael@0 237
michael@0 238 node.setAttribute('_moz_c','barc');
michael@0 239 node.setAttribute('_-moz_d','bard');
michael@0 240 node.setAttribute('__moz_e','bare');
michael@0 241
michael@0 242 encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly | de.OutputRaw);
michael@0 243 encoder.setNode(node);
michael@0 244 out = encoder.encodeToString();
michael@0 245 expected = '<div __moz_e="bare" _-moz_d="bard" __moz_b="b" id="mozattr"> lorem ipsum</div>';
michael@0 246 is(out, expected, "test -moz/_moz attr #2");
michael@0 247
michael@0 248 SimpleTest.finish();
michael@0 249 }
michael@0 250
michael@0 251
michael@0 252 SimpleTest.waitForExplicitFinish();
michael@0 253
michael@0 254 addLoadEvent(testHtmlSerializer_1);
michael@0 255 //]]>
michael@0 256 </script>
michael@0 257 </pre>
michael@0 258 <div style="display: none">
michael@0 259
michael@0 260 <div id="draggable" ondragstart="doDragStartSelection(event)">This is a <em>draggable</em> bit of text.</div>
michael@0 261
michael@0 262 </div>
michael@0 263 <div style="display: none">
michael@0 264
michael@0 265 <ol id="aList">
michael@0 266 <li>Lorem ipsum dolor</li>
michael@0 267 <li>sit amet, <strong>consectetuer</strong> </li>
michael@0 268 <li>adipiscing elit</li>
michael@0 269 <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>
michael@0 270 <li>aptent taciti</li>
michael@0 271 </ol>
michael@0 272
michael@0 273 <!-- test for some short attr -->
michael@0 274 <div id="shortattr" xmlns:foo="http://mozilla.org/ns/any">
michael@0 275 <input id="shortattr1" checked="" value="" disabled="" ismap="" readonly="" foo:checked="" foo:disabled=""/>
michael@0 276 <ol id="shortattr2" compact=""><li></li></ol>
michael@0 277 <object id="shortattr3" declare="" />
michael@0 278 <script id="shortattr4" defer="" />
michael@0 279 <select id="shortattr5" multiple=""><option selected="">aaa</option></select>
michael@0 280 <hr noshade="" id="shortattr6"/>
michael@0 281 <div id="shortattr7"><foo:bar checked="" value="" disabled="" ismap="" readonly="" /></div>
michael@0 282 <div id="mozattr" _moz_a="a" __moz_b="b"> lorem ipsum</div>
michael@0 283 </div>
michael@0 284
michael@0 285 </div>
michael@0 286 </body>
michael@0 287 </html>
michael@0 288
michael@0 289

mercurial