dom/tests/mochitest/general/test_outerHTML.xhtml

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=92264
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 92264</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body onload="runTest();">
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=92264">Mozilla Bug 92264</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15 <div id="wrap"><dl></dl><p id="thep">foo<span>bar</span></p><ol></ol></div>
michael@0 16 <table id="thetable"><tbody><tr><td>1</td></tr><tr id="thetr"><td>2</td></tr><tr><td>3</td></tr></tbody></table>
michael@0 17 <iframe></iframe>
michael@0 18 <div id="fragmentwrap"></div>
michael@0 19 </div>
michael@0 20 <pre id="test">
michael@0 21 <script type="application/javascript">
michael@0 22 <![CDATA[
michael@0 23
michael@0 24 /** Test for Bug 92264 **/
michael@0 25
michael@0 26 SimpleTest.waitForExplicitFinish();
michael@0 27
michael@0 28 function runTest() {
michael@0 29
michael@0 30 var thep = document.getElementById("thep");
michael@0 31 var wrap = document.getElementById("wrap");
michael@0 32 is(thep.outerHTML, '<p xmlns="http://www.w3.org/1999/xhtml" id="thep">foo<span>bar</span></p>', "Unexpected thep outerHTML");
michael@0 33 thep.outerHTML = "<ul></ul><tr></tr><p></p>";
michael@0 34 is(wrap.innerHTML, '<dl xmlns="http://www.w3.org/1999/xhtml"></dl><ul xmlns="http://www.w3.org/1999/xhtml"></ul><tr xmlns="http://www.w3.org/1999/xhtml"></tr><p xmlns="http://www.w3.org/1999/xhtml"></p><ol xmlns="http://www.w3.org/1999/xhtml"></ol>', "Bad outerHTML parsing inside wrap");
michael@0 35
michael@0 36 var thetr = document.getElementById("thetr");
michael@0 37 thetr.outerHTML = "<tr><td>a</td></tr><div></div><tr><td>b</td></tr>";
michael@0 38 var thetable = document.getElementById("thetable");
michael@0 39 is(thetable.innerHTML, '<tbody xmlns="http://www.w3.org/1999/xhtml"><tr><td>1</td></tr><tr><td>a</td></tr><div></div><tr><td>b</td></tr><tr><td>3</td></tr></tbody>', "Wrong outerHTML parsing inside table");
michael@0 40
michael@0 41 var iframe = document.getElementsByTagName("iframe")[0];
michael@0 42 var oldbody = iframe.contentDocument.body;
michael@0 43 iframe.contentDocument.body.outerHTML = "<body></body>";
michael@0 44 isnot(oldbody, iframe.contentDocument.body, "Failed to replace body");
michael@0 45 is(iframe.contentDocument.getElementsByTagName("body").length, 1, "Should have gotten one body");
michael@0 46 // Yes, two heads per spec. Also Ragnarök and Chrome produce two heads.
michael@0 47 is(iframe.contentDocument.getElementsByTagName("head").length, 2, "Should have gotten two heads");
michael@0 48
michael@0 49 try {
michael@0 50 document.documentElement.outerHTML = "<html></html>";
michael@0 51 ok(false, "Should have thrown an exception");
michael@0 52 } catch(e) {
michael@0 53 is(e.name, "NoModificationAllowedError", "outerHTML should throw NoModificationAllowedError");
michael@0 54 is(e.code, 7, "outerHTML should throw NO_MODIFICATION_ALLOWED_ERR");
michael@0 55 }
michael@0 56
michael@0 57 var f = document.createDocumentFragment();
michael@0 58 var dl = document.createElement("dl");
michael@0 59 var p = document.createElement("p");
michael@0 60 var ol = document.createElement("ol");
michael@0 61 f.appendChild(dl);
michael@0 62 f.appendChild(p);
michael@0 63 f.appendChild(ol);
michael@0 64 p.outerHTML = "<ul></ul><tr></tr><body></body><p></p>";
michael@0 65 var fragmentwrap = document.getElementById("fragmentwrap");
michael@0 66 fragmentwrap.appendChild(f);
michael@0 67 is(fragmentwrap.innerHTML, '<dl xmlns="http://www.w3.org/1999/xhtml"></dl><ul xmlns="http://www.w3.org/1999/xhtml"></ul><tr xmlns="http://www.w3.org/1999/xhtml"></tr><body xmlns="http://www.w3.org/1999/xhtml"></body><p xmlns="http://www.w3.org/1999/xhtml"></p><ol xmlns="http://www.w3.org/1999/xhtml"></ol>', "Bad outerHTML parsing in fragment");
michael@0 68
michael@0 69 SimpleTest.finish();
michael@0 70 }
michael@0 71 ]]>
michael@0 72 </script>
michael@0 73 </pre>
michael@0 74 </body>
michael@0 75 </html>

mercurial