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=804784 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test for Bug 804784</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=804784">Mozilla Bug 804784</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 804784 **/ |
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,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) div.normalize(); |
michael@0 | 76 | check(r,s,run+" selEnd "+child+","+index); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function selStart(div,child,index,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) div.normalize(); |
michael@0 | 88 | check(r,s,run+" selStart "+child+","+index); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function selMiddleStart(div,child,index,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 | div.normalize(); |
michael@0 | 100 | check(r,s,run+" selMiddleStart "+child+","+index); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function selMiddleEnd(div,child,index,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) div.normalize(); |
michael@0 | 112 | check(r,s,run+" selMiddleEnd "+child+","+index); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function mergeBefore(div,child,index,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.normalize(); |
michael@0 | 124 | check(r,s,run+" mergeBefore "+child+","+index); |
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,'111'); |
michael@0 | 131 | selEnd(newDiv('111'), 0,1,'11'); |
michael@0 | 132 | selEnd(newDiv('111'), 0,2,'1'); |
michael@0 | 133 | selEnd(newDiv(''), 0,0,''); |
michael@0 | 134 | selEnd(newDiv('',''), 1,0,''); |
michael@0 | 135 | selEnd(newDiv('','',''), 1,0,''); |
michael@0 | 136 | selEnd(newDiv('111','222'), 0,1,'11222'); |
michael@0 | 137 | selEnd(newDiv('111','222'), 0,2,'1222'); |
michael@0 | 138 | selEnd(newDiv('111','222'), 1,1,'22'); |
michael@0 | 139 | selEnd(newDiv('','222'), 1,2,'2'); |
michael@0 | 140 | selEnd(newDiv('111',''), 0,1,'11'); |
michael@0 | 141 | selEnd(newDiv('111','222'), 1,2,'2'); |
michael@0 | 142 | selEnd(newDiv('111','222','333'), 1,1,'22333'); |
michael@0 | 143 | selEnd(newDiv('111','222','333'), 1,2,'2333'); |
michael@0 | 144 | selEnd(newDiv('111','','333'), 0,2,'1333'); |
michael@0 | 145 | selEnd(newDiv('111','','333'), 1,0,'333'); |
michael@0 | 146 | selEnd(newDiv('111','','333'), 2,0,'333'); |
michael@0 | 147 | |
michael@0 | 148 | selStart(newDiv('111'), 0,0,''); |
michael@0 | 149 | selStart(newDiv('111'), 0,1,'1'); |
michael@0 | 150 | selStart(newDiv('111'), 0,2,'11'); |
michael@0 | 151 | selStart(newDiv(''), 0,0,''); |
michael@0 | 152 | selStart(newDiv('111','222'), 0,1,'1'); |
michael@0 | 153 | selStart(newDiv('111','222'), 0,2,'11'); |
michael@0 | 154 | selStart(newDiv('111','222'), 1,1,'1112'); |
michael@0 | 155 | selStart(newDiv('111','222'), 1,2,'11122'); |
michael@0 | 156 | selStart(newDiv('111',''), 1,0,'111'); |
michael@0 | 157 | selStart(newDiv('111',''), 0,2,'11'); |
michael@0 | 158 | selStart(newDiv('111','222','333'), 1,1,'1112'); |
michael@0 | 159 | selStart(newDiv('111','222','333'), 1,2,'11122'); |
michael@0 | 160 | selStart(newDiv('111','222','333'), 1,2,'11122'); |
michael@0 | 161 | selStart(newDiv('111','','333'), 1,0,'111'); |
michael@0 | 162 | |
michael@0 | 163 | selMiddleStart(newDiv('111','222','333'), 1,1,'2'); |
michael@0 | 164 | selMiddleStart(newDiv('111','222','333'), 1,2,'22'); |
michael@0 | 165 | selMiddleStart(newDiv('111','222','333'), 2,1,'2223'); |
michael@0 | 166 | selMiddleStart(newDiv('111','222','333'), 2,2,'22233'); |
michael@0 | 167 | selMiddleStart(newDiv('111','','333'), 2,2,'33'); |
michael@0 | 168 | selMiddleStart(newDiv('111','222',''), 2,0,'222'); |
michael@0 | 169 | |
michael@0 | 170 | selMiddleEnd(newDiv('111','222','333'), 0,1,'11222'); |
michael@0 | 171 | selMiddleEnd(newDiv('111','222','333'), 0,2,'1222'); |
michael@0 | 172 | selMiddleEnd(newDiv('111','222','333'), 1,1,'22'); |
michael@0 | 173 | selMiddleEnd(newDiv('111','222','333'), 1,2,'2'); |
michael@0 | 174 | selMiddleEnd(newDiv('111','','333'), 1,0,''); |
michael@0 | 175 | selMiddleEnd(newDiv('','222','333'), 0,0,'222'); |
michael@0 | 176 | |
michael@0 | 177 | mergeBefore(newDiv('111','222'), 1,1,'2'); |
michael@0 | 178 | mergeBefore(newDiv('111','222','333'), 1,2,'22'); |
michael@0 | 179 | mergeBefore(newDiv('111','222','333'), 2,1,'2223'); |
michael@0 | 180 | mergeBefore(newDiv('111','222','333'), 2,2,'22233'); |
michael@0 | 181 | mergeBefore(newDiv('111','','333'), 2,0,''); |
michael@0 | 182 | mergeBefore(newDiv('111','','333'), 2,2,'33'); |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | function boom() |
michael@0 | 186 | { |
michael@0 | 187 | runTests("dry run"); // this is to verify the result strings without normalize() |
michael@0 | 188 | dry = false; |
michael@0 | 189 | flush = false; |
michael@0 | 190 | runTests("no flush"); |
michael@0 | 191 | flush = true; |
michael@0 | 192 | runTests("flush"); |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | boom(); |
michael@0 | 196 | |
michael@0 | 197 | |
michael@0 | 198 | </script> |
michael@0 | 199 | </pre> |
michael@0 | 200 | </body> |
michael@0 | 201 | </html> |