content/base/test/test_bug469020.html

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>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=469020
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 469020</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>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=469020">Mozilla Bug 469020</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script type="application/javascript">
michael@0 19
michael@0 20 /** Test for Bug 469020 **/
michael@0 21
michael@0 22 var range = null;
michael@0 23 var anchor = null;
michael@0 24
michael@0 25 function doRangeAnchor(elem, start, end) {
michael@0 26 range = document.createRange();
michael@0 27 range.setStart(elem.firstChild, start);
michael@0 28 end = end < elem.lastChild.length ? end : elem.lastChild.length
michael@0 29 range.setEnd(elem.lastChild, end);
michael@0 30 anchor = document.createElement('a');
michael@0 31 anchor.href = "javascript: void(0);";
michael@0 32 range.surroundContents(anchor);
michael@0 33 }
michael@0 34
michael@0 35 function undoRangeAnchor() {
michael@0 36 var pnode = anchor.parentNode;
michael@0 37 var range2 = document.createRange();
michael@0 38 range2.selectNodeContents(anchor);
michael@0 39 var contents = range2.extractContents();
michael@0 40 pnode.replaceChild(contents,anchor);
michael@0 41 }
michael@0 42
michael@0 43 function serializeNode(node) {
michael@0 44 var s;
michael@0 45 var isElem = false;
michael@0 46 if (node.nodeName == "#text") {
michael@0 47 if (node.nodeValue) {
michael@0 48 s = node.nodeValue
michael@0 49 } else {
michael@0 50 s = "<#empty>"
michael@0 51 }
michael@0 52 } else {
michael@0 53 isElem = true;
michael@0 54 s = "<" + node.nodeName + ">";
michael@0 55 }
michael@0 56 for (var j = 0; j < node.childNodes.length; ++j) {
michael@0 57 s += serializeNode(node.childNodes[j]);
michael@0 58 }
michael@0 59 if (isElem) {
michael@0 60 s += "</" + node.nodeName + ">";
michael@0 61 }
michael@0 62 return s;
michael@0 63 }
michael@0 64
michael@0 65 function runTest(elementID, start, end, expected1, expected2, expected3) {
michael@0 66 var e = document.getElementById(elementID);
michael@0 67 doRangeAnchor(e, start, end);
michael@0 68 is(serializeNode(e), expected1, "Wrong range behavior!");
michael@0 69 document.getElementById('log').textContent += serializeNode(e) + "\n";
michael@0 70 undoRangeAnchor();
michael@0 71 is(serializeNode(e), expected2, "Wrong range behavior!");
michael@0 72 document.getElementById('log').textContent += serializeNode(e) + "\n";
michael@0 73 doRangeAnchor(e, start, end);
michael@0 74 is(serializeNode(e), expected3, "Wrong range behavior!");
michael@0 75 document.getElementById('log').textContent += serializeNode(e) + "\n";
michael@0 76 }
michael@0 77
michael@0 78 function runTests() {
michael@0 79 runTest("test1", 0, 3,
michael@0 80 "<P><#empty><A>http://www.<SPAN>mozilla.</SPAN>org</A><#empty></P>",
michael@0 81 "<P><#empty>http://www.<SPAN>mozilla.</SPAN>org<#empty></P>",
michael@0 82 "<P><#empty><A><#empty>http://www.<SPAN>mozilla.</SPAN>org<#empty></A><#empty></P>");
michael@0 83
michael@0 84 runTest("test2", 1, 3,
michael@0 85 "<P>h<A>ttp://www.<SPAN>mozilla.</SPAN>org</A><#empty></P>",
michael@0 86 "<P>http://www.<SPAN>mozilla.</SPAN>org<#empty></P>",
michael@0 87 "<P>h<A><#empty>ttp://www.<SPAN>mozilla.</SPAN>org<#empty></A><#empty></P>");
michael@0 88
michael@0 89 runTest("test3", 0, 2,
michael@0 90 "<P><#empty><A>http://www.<SPAN>mozilla.</SPAN>or</A>g</P>",
michael@0 91 "<P><#empty>http://www.<SPAN>mozilla.</SPAN>org</P>",
michael@0 92 "<P><#empty><A><#empty>http://www.<SPAN>mozilla.</SPAN>org</A><#empty></P>");
michael@0 93
michael@0 94 runTest("test4", 1, 2,
michael@0 95 "<P>h<A>ttp://www.<SPAN>mozilla.</SPAN>or</A>g</P>",
michael@0 96 "<P>http://www.<SPAN>mozilla.</SPAN>org</P>",
michael@0 97 "<P>h<A><#empty>ttp://www.<SPAN>mozilla.</SPAN>org</A><#empty></P>");
michael@0 98
michael@0 99 runTest("test5", 11, 0,
michael@0 100 "<P>http://www.<A><#empty><SPAN>mozilla.</SPAN><#empty></A>org</P>",
michael@0 101 "<P>http://www.<#empty><SPAN>mozilla.</SPAN><#empty>org</P>",
michael@0 102 "<P>http://www.<A><#empty><#empty><SPAN>mozilla.</SPAN><#empty><#empty></A>org</P>");
michael@0 103
michael@0 104 runTest("test6", 10, 1,
michael@0 105 "<P>http://www<A>.<SPAN>mozilla.</SPAN>o</A>rg</P>",
michael@0 106 "<P>http://www.<SPAN>mozilla.</SPAN>org</P>",
michael@0 107 "<P>http://www<A><#empty>.<SPAN>mozilla.</SPAN>or</A>g</P>");
michael@0 108
michael@0 109 SimpleTest.finish();
michael@0 110 }
michael@0 111
michael@0 112 SimpleTest.waitForExplicitFinish();
michael@0 113 addLoadEvent(runTests);
michael@0 114
michael@0 115
michael@0 116
michael@0 117 </script>
michael@0 118 </pre>
michael@0 119 <p id="test1">http://www.<span>mozilla.</span>org</p>
michael@0 120 <p id="test2">http://www.<span>mozilla.</span>org</p>
michael@0 121 <p id="test3">http://www.<span>mozilla.</span>org</p>
michael@0 122 <p id="test4">http://www.<span>mozilla.</span>org</p>
michael@0 123 <p id="test5">http://www.<span>mozilla.</span>org</p>
michael@0 124 <p id="test6">http://www.<span>mozilla.</span>org</p>
michael@0 125 <pre id="log">
michael@0 126 </pre>
michael@0 127 </body>
michael@0 128 </html>

mercurial