Wed, 31 Dec 2014 06:09:35 +0100
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=803924 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test for Bug 803924</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 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=803924">Mozilla Bug 803924</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script type="application/javascript"> |
michael@0 | 20 | |
michael@0 | 21 | /** Test for Bug 803924 **/ |
michael@0 | 22 | |
michael@0 | 23 | var sel = document.getSelection(); |
michael@0 | 24 | var flush = true; |
michael@0 | 25 | var dry = true; |
michael@0 | 26 | var run = ""; |
michael@0 | 27 | var empty_range; |
michael@0 | 28 | var empty_first_text_range; |
michael@0 | 29 | var empty_last_text_range; |
michael@0 | 30 | var full_range; |
michael@0 | 31 | |
michael@0 | 32 | function check(range, expected, test) |
michael@0 | 33 | { |
michael@0 | 34 | is(""+range, expected, test); |
michael@0 | 35 | is(""+empty_range, "", "empty range test after: "+test); |
michael@0 | 36 | is(""+empty_first_text_range, "", "empty first text range test after: "+test); |
michael@0 | 37 | if (empty_last_text_range) is(""+empty_last_text_range, "", "empty last text range test after: "+test); |
michael@0 | 38 | is(""+full_range, full_range.startContainer.textContent, "full range test after: "+test); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function newDiv() |
michael@0 | 42 | { |
michael@0 | 43 | var div = document.createElement('div'); |
michael@0 | 44 | for (var i = 0; i < arguments.length; ++i) { |
michael@0 | 45 | div.appendChild(document.createTextNode(arguments[i])); |
michael@0 | 46 | } |
michael@0 | 47 | document.body.appendChild(div) |
michael@0 | 48 | empty_range = document.createRange(); |
michael@0 | 49 | empty_range.setStart(div,0); |
michael@0 | 50 | empty_range.setEnd(div,0); |
michael@0 | 51 | var firstTextNode = div.childNodes[0]; |
michael@0 | 52 | var lastTextNode = div.childNodes[div.childNodes.length - 1]; |
michael@0 | 53 | empty_first_text_range = document.createRange(); |
michael@0 | 54 | empty_first_text_range.setStart(firstTextNode,0); |
michael@0 | 55 | empty_first_text_range.setEnd(firstTextNode,0); |
michael@0 | 56 | empty_last_text_range = null; |
michael@0 | 57 | if (firstTextNode != lastTextNode) { |
michael@0 | 58 | empty_last_text_range = document.createRange(); |
michael@0 | 59 | empty_last_text_range.setStart(lastTextNode,0); |
michael@0 | 60 | empty_last_text_range.setEnd(lastTextNode,0); |
michael@0 | 61 | } |
michael@0 | 62 | full_range = document.createRange(); |
michael@0 | 63 | full_range.setStart(div,0); |
michael@0 | 64 | full_range.setEnd(div,div.childNodes.length); |
michael@0 | 65 | return div; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function selEnd(div,child,index,split,s) |
michael@0 | 69 | { |
michael@0 | 70 | var start = div.childNodes[child]; |
michael@0 | 71 | var r = document.createRange(); |
michael@0 | 72 | sel.addRange(r); |
michael@0 | 73 | r.setStart(start, index); |
michael@0 | 74 | r.setEnd(div, div.childNodes.length); |
michael@0 | 75 | if (!dry) start.splitText(split); |
michael@0 | 76 | check(r,s,run+" selEnd "+child+","+index+","+split); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function selStart(div,child,index,split,s) |
michael@0 | 80 | { |
michael@0 | 81 | if (flush) document.body.getClientRects(); |
michael@0 | 82 | var start = div.childNodes[child]; |
michael@0 | 83 | var r = document.createRange(); |
michael@0 | 84 | sel.addRange(r); |
michael@0 | 85 | r.setStart(div, 0); |
michael@0 | 86 | r.setEnd(start, index); |
michael@0 | 87 | if (!dry) start.splitText(split); |
michael@0 | 88 | check(r,s,run+" selStart "+child+","+index+","+split); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function selMiddleStart(div,child,index,split,s) |
michael@0 | 92 | { |
michael@0 | 93 | if (flush) document.body.getClientRects(); |
michael@0 | 94 | var start = div.childNodes[child]; |
michael@0 | 95 | var r = document.createRange(); |
michael@0 | 96 | sel.addRange(r); |
michael@0 | 97 | r.setStart(div, 1); |
michael@0 | 98 | r.setEnd(start, index); |
michael@0 | 99 | if (!dry) start.splitText(split); |
michael@0 | 100 | check(r,s,run+" selMiddleStart "+child+","+index+","+split); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function selMiddleEnd(div,child,index,split,s) |
michael@0 | 104 | { |
michael@0 | 105 | if (flush) document.body.getClientRects(); |
michael@0 | 106 | var start = div.childNodes[child]; |
michael@0 | 107 | var r = document.createRange(); |
michael@0 | 108 | sel.addRange(r); |
michael@0 | 109 | r.setStart(start, index); |
michael@0 | 110 | r.setEnd(div, 2); |
michael@0 | 111 | if (!dry) start.splitText(split); |
michael@0 | 112 | check(r,s,run+" selMiddleEnd "+child+","+index+","+split); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function splitBefore(div,child,index,split,s) |
michael@0 | 116 | { |
michael@0 | 117 | if (flush) document.body.getClientRects(); |
michael@0 | 118 | var start = div.childNodes[child]; |
michael@0 | 119 | var r = document.createRange(); |
michael@0 | 120 | sel.addRange(r); |
michael@0 | 121 | r.setStart(div, 1); |
michael@0 | 122 | r.setEnd(start, index); |
michael@0 | 123 | if (!dry) div.childNodes[0].splitText(split); |
michael@0 | 124 | check(r,s,run+" splitBefore "+child+","+index+","+split); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | function runTests(s) |
michael@0 | 128 | { |
michael@0 | 129 | run = s+":"; |
michael@0 | 130 | selEnd(newDiv('111'), 0,0,0,'111'); |
michael@0 | 131 | selEnd(newDiv('111'), 0,0,1,'111'); |
michael@0 | 132 | selEnd(newDiv('111'), 0,0,3,'111'); |
michael@0 | 133 | selEnd(newDiv(''), 0,0,0,''); |
michael@0 | 134 | selEnd(newDiv('111'), 0,1,0,'11'); |
michael@0 | 135 | selEnd(newDiv('111'), 0,2,1,'1'); |
michael@0 | 136 | selEnd(newDiv('111'), 0,1,3,'11'); |
michael@0 | 137 | selEnd(newDiv('111','222'), 0,1,0,'11222'); |
michael@0 | 138 | selEnd(newDiv('111','222'), 0,2,1,'1222'); |
michael@0 | 139 | selEnd(newDiv('111','222'), 0,1,3,'11222'); |
michael@0 | 140 | selEnd(newDiv('111','222'), 1,1,0,'22'); |
michael@0 | 141 | selEnd(newDiv('111','222'), 1,2,1,'2'); |
michael@0 | 142 | selEnd(newDiv('','222'), 1,1,1,'22'); |
michael@0 | 143 | selEnd(newDiv('','222'), 0,0,0,'222'); |
michael@0 | 144 | selEnd(newDiv('111',''), 0,1,0,'11'); |
michael@0 | 145 | selEnd(newDiv('111','222'), 1,1,3,'22'); |
michael@0 | 146 | selEnd(newDiv('111','222','333'), 1,1,0,'22333'); |
michael@0 | 147 | selEnd(newDiv('111','222','333'), 1,2,1,'2333'); |
michael@0 | 148 | selEnd(newDiv('111','222','333'), 1,1,3,'22333'); |
michael@0 | 149 | selEnd(newDiv('111','222',''), 1,1,3,'22'); |
michael@0 | 150 | selEnd(newDiv('111','','333'), 0,1,3,'11333'); |
michael@0 | 151 | |
michael@0 | 152 | selStart(newDiv('111'), 0,0,0,''); |
michael@0 | 153 | selStart(newDiv('111'), 0,0,1,''); |
michael@0 | 154 | selStart(newDiv('111'), 0,0,3,''); |
michael@0 | 155 | selStart(newDiv('111'), 0,1,0,'1'); |
michael@0 | 156 | selStart(newDiv('111'), 0,2,1,'11'); |
michael@0 | 157 | selStart(newDiv('111'), 0,1,3,'1'); |
michael@0 | 158 | selStart(newDiv(''), 0,0,0,''); |
michael@0 | 159 | selStart(newDiv('111','222'), 0,1,0,'1'); |
michael@0 | 160 | selStart(newDiv('111','222'), 0,2,1,'11'); |
michael@0 | 161 | selStart(newDiv('111','222'), 0,1,3,'1'); |
michael@0 | 162 | selStart(newDiv('111','222'), 1,1,0,'1112'); |
michael@0 | 163 | selStart(newDiv('111','222'), 1,2,1,'11122'); |
michael@0 | 164 | selStart(newDiv('111','222'), 1,1,3,'1112'); |
michael@0 | 165 | selStart(newDiv('','222'), 1,1,2,'2'); |
michael@0 | 166 | selStart(newDiv('','222'), 0,0,0,''); |
michael@0 | 167 | selStart(newDiv('111',''), 1,0,0,'111'); |
michael@0 | 168 | selStart(newDiv('111','222','333'), 1,1,0,'1112'); |
michael@0 | 169 | selStart(newDiv('111','222','333'), 1,2,1,'11122'); |
michael@0 | 170 | selStart(newDiv('111','222','333'), 1,1,3,'1112'); |
michael@0 | 171 | selStart(newDiv('111','','333'), 1,0,0,'111'); |
michael@0 | 172 | selStart(newDiv('111','222',''), 1,1,3,'1112'); |
michael@0 | 173 | |
michael@0 | 174 | selMiddleStart(newDiv('111','222','333'), 1,1,0,'2'); |
michael@0 | 175 | selMiddleStart(newDiv('111','222','333'), 1,2,1,'22'); |
michael@0 | 176 | selMiddleStart(newDiv('111','222','333'), 1,1,3,'2'); |
michael@0 | 177 | selMiddleStart(newDiv('111','222','333'), 2,1,0,'2223'); |
michael@0 | 178 | selMiddleStart(newDiv('111','222','333'), 2,2,1,'22233'); |
michael@0 | 179 | selMiddleStart(newDiv('111','222','333'), 2,1,3,'2223'); |
michael@0 | 180 | selMiddleStart(newDiv('111','','333'), 2,1,2,'3'); |
michael@0 | 181 | selMiddleStart(newDiv('111','','333'), 1,0,0,''); |
michael@0 | 182 | |
michael@0 | 183 | selMiddleEnd(newDiv('111','222','333'), 0,1,0,'11222'); |
michael@0 | 184 | selMiddleEnd(newDiv('111','222','333'), 0,2,1,'1222'); |
michael@0 | 185 | selMiddleEnd(newDiv('111','222','333'), 0,1,3,'11222'); |
michael@0 | 186 | selMiddleEnd(newDiv('111','222','333'), 1,1,0,'22'); |
michael@0 | 187 | selMiddleEnd(newDiv('111','222','333'), 1,2,1,'2'); |
michael@0 | 188 | selMiddleEnd(newDiv('111','222','333'), 1,1,3,'22'); |
michael@0 | 189 | selMiddleEnd(newDiv('111','','333'), 0,1,2,'11'); |
michael@0 | 190 | selMiddleEnd(newDiv('111','','333'), 0,1,3,'11'); |
michael@0 | 191 | selMiddleEnd(newDiv('111','','333'), 1,0,0,''); |
michael@0 | 192 | |
michael@0 | 193 | splitBefore(newDiv('111','222','333'), 1,1,0,'2'); |
michael@0 | 194 | splitBefore(newDiv('111','222','333'), 1,2,1,'22'); |
michael@0 | 195 | splitBefore(newDiv('111','222','333'), 1,1,3,'2'); |
michael@0 | 196 | splitBefore(newDiv('111','222','333'), 2,1,0,'2223'); |
michael@0 | 197 | splitBefore(newDiv('111','222','333'), 2,2,1,'22233'); |
michael@0 | 198 | splitBefore(newDiv('111','222','333'), 2,1,3,'2223'); |
michael@0 | 199 | splitBefore(newDiv('','222','333'), 1,1,0,'2'); |
michael@0 | 200 | splitBefore(newDiv('','','333'), 1,0,0,''); |
michael@0 | 201 | splitBefore(newDiv('','222',''), 2,0,0,'222'); |
michael@0 | 202 | splitBefore(newDiv('111','','333'), 2,1,2,'3'); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | function boom() |
michael@0 | 206 | { |
michael@0 | 207 | runTests("dry run"); // this is to verify the result strings without splitText() |
michael@0 | 208 | dry = false; |
michael@0 | 209 | flush = false; |
michael@0 | 210 | runTests("no flush"); |
michael@0 | 211 | flush = true; |
michael@0 | 212 | runTests("flush"); |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | boom(); |
michael@0 | 216 | |
michael@0 | 217 | |
michael@0 | 218 | </script> |
michael@0 | 219 | </pre> |
michael@0 | 220 | </body> |
michael@0 | 221 | </html> |