layout/generic/test/test_selection_splitText-normalize.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=191864
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 191864</title>
michael@0 8 <script type="application/javascript" src="/MochiKit/packed.js"></script>
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=191864">Mozilla Bug 191864</a>
michael@0 14 <p id="display">
michael@0 15 <span id="col1" style="float:left; height:800px; width:180px;"></span>
michael@0 16 <span id="col2" style="float:left; height:800px; width:180px;"></span>
michael@0 17 </p>
michael@0 18 <div id="content" style="display: none">
michael@0 19
michael@0 20 </div>
michael@0 21 <pre id="test">
michael@0 22 <script type="application/javascript;version=1.7">
michael@0 23 var tests = [
michael@0 24 [ {}, [0,4], "012345678" ],
michael@0 25 [ {}, [0,0], "012345678" ],
michael@0 26 [ {}, [0,9], "012345678" ],
michael@0 27 [ {startOffset:4}, [0,4], "012345678" ],
michael@0 28 [ {startOffset:5}, [0,4], "012345678" ],
michael@0 29 [ {startOffset:5,endOffset:6}, [0,4], "012345678" ],
michael@0 30 [ {endOffset:5}, [0,4], "012345678" ],
michael@0 31 [ {endOffset:4}, [0,4], "012345678" ],
michael@0 32 [ {endOffset:3}, [0,4], "012345678" ],
michael@0 33 [ {startOffset:1,endOffset:3}, [0,4], "012345678" ],
michael@0 34 [ {startOffset:7,endOffset:7}, [0,4], "012345678" ],
michael@0 35 [ {startOffset:4,endOffset:4}, [0,4], "012345678" ],
michael@0 36 [ {endNode:1}, [0,4], "012345678", "" ],
michael@0 37 [ {endNode:1}, [0,4], "01234567", "8" ],
michael@0 38 [ {endNode:1}, [1,4], "0", "12345678" ],
michael@0 39 [ {endNode:2}, [1,4], "0", "12345", "678" ],
michael@0 40 ]
michael@0 41
michael@0 42 function runtest(r,p,t) {
michael@0 43 // create content
michael@0 44 document.original_nodes = [];
michael@0 45 for (let i = 2; i < t.length; ++i) {
michael@0 46 c = document.createTextNode(t[i]);
michael@0 47 p.appendChild(c);
michael@0 48 document.original_nodes.push(c);
michael@0 49 }
michael@0 50
michael@0 51 // setup the range
michael@0 52 let sel = t[0]
michael@0 53 let startNode = p.firstChild;
michael@0 54 let startOffset = sel.startOffset === undefined ? 0 : sel.startOffset;
michael@0 55 let endNode = sel.endNode === undefined ? startNode : p.childNodes[sel.endNode];
michael@0 56 let endOffset = sel.endOffset === undefined ? endNode.length : sel.endOffset;
michael@0 57 r.setStart(startNode, startOffset);
michael@0 58 r.setEnd(endNode, endOffset);
michael@0 59
michael@0 60 // splitText
michael@0 61 let split = t[1]
michael@0 62 p.childNodes[split[0]].splitText(split[1])
michael@0 63 }
michael@0 64 function test_split(r,p,t) {
michael@0 65 runtest(r,p,t);
michael@0 66 }
michael@0 67 function test_split_merge(r,p,t) {
michael@0 68 runtest(r,p,t);
michael@0 69 p.normalize();
michael@0 70 }
michael@0 71 </script>
michael@0 72
michael@0 73 <script type="application/javascript;version=1.7">
michael@0 74
michael@0 75 /** Test for Bug 191864 **/
michael@0 76
michael@0 77 var results = [
michael@0 78 /* test_split */
michael@0 79 [ {}, [ [0, "0123"], "45678" ]],
michael@0 80 [ {}, [ [0, ""], "012345678" ]],
michael@0 81 [ {endNode:0, endOffset:9}, [ [0, "012345678"], "" ]],
michael@0 82 [ {startOffset:4}, [ [0, "0123"], "45678" ]],
michael@0 83 [ {startNode:1, startOffset:1}, [ [0, "0123"], "45678" ]],
michael@0 84 [ {startNode:1, startOffset:1, endOffset:2}, [ [0, "0123"], "45678" ]],
michael@0 85 [ {endOffset:1}, [ [0, "0123"], "45678" ]],
michael@0 86 [ {endNode:0}, [ [0, "0123"], "45678" ]],
michael@0 87 [ {endNode:0, endOffset:3}, [ [0, "0123"], "45678" ]],
michael@0 88 [ {startOffset:1, endNode:0, endOffset:3}, [ [0, "0123"], "45678" ]],
michael@0 89 [ {startNode:1, startOffset:3, endOffset:3}, [ [0, "0123"], "45678" ]],
michael@0 90 [ {startOffset:4, endNode:0}, [ [0, "0123"], "45678" ]],
michael@0 91 [ {endNode:2, endOffset:0}, [ [0, "0123"], "45678", [1, ""] ]],
michael@0 92 [ {endNode:2}, [ [0, "0123"], "4567", [1, "8"] ]],
michael@0 93 [ {endNode:2}, [ [0, "0"], [1, "1234"], "5678" ]],
michael@0 94 [ {endNode:3}, [ [0, "0"], [1, "1234"], "5", [2, "678"] ]],
michael@0 95 /* test_split_merge */
michael@0 96 [ {}, [ [0, "012345678" ] ]],
michael@0 97 [ {startParent:true}, [ "012345678" ]], /* splitText() creates an empty first child which is removed by normalize() */
michael@0 98 [ {}, [ [0, "012345678" ] ]],
michael@0 99 [ {startOffset:4}, [ [0, "012345678" ] ]],
michael@0 100 [ {startOffset:5}, [ [0, "012345678" ] ]],
michael@0 101 [ {startOffset:5,endOffset:6}, [ [0, "012345678" ] ]],
michael@0 102 [ {endOffset:5}, [ [0, "012345678" ] ]],
michael@0 103 [ {endOffset:4}, [ [0, "012345678" ] ]],
michael@0 104 [ {endOffset:3}, [ [0, "012345678" ] ]],
michael@0 105 [ {startOffset:1,endOffset:3}, [ [0, "012345678" ] ]],
michael@0 106 [ {startOffset:7,endOffset:7}, [ [0, "012345678" ] ]],
michael@0 107 [ {startOffset:4,endOffset:4}, [ [0, "012345678" ] ]],
michael@0 108 [ {endParent:true}, [ [0, "012345678" ] ]],
michael@0 109 [ {}, [ [0, "012345678" ] ]],
michael@0 110 [ {}, [ [0, "012345678" ] ]],
michael@0 111 [ {}, [ [0, "012345678" ] ]],
michael@0 112 ]
michael@0 113
michael@0 114 function verifyResults(r,p,i) {
michael@0 115 let nodes = results[i][1];
michael@0 116 is(p.childNodes.length, nodes.length, "same number of DOM nodes" + " (test " + i + ")");
michael@0 117 for (let j = 0; j < nodes.length; ++j) {
michael@0 118 let a = nodes[j];
michael@0 119 let b = p.childNodes[j];
michael@0 120 if (a instanceof Array) {
michael@0 121 is(b, document.original_nodes[a[0]], "same node" + " (test " + i + " child " + j + ")");
michael@0 122 is(b.textContent, a[1], "contents2" + " (test " + i + " child " + j + ")");
michael@0 123 } else {
michael@0 124 is(b.nodeType, Node.TEXT_NODE, "text node" + " (test " + i + " child " + j + ")");
michael@0 125 is(b.textContent, a, "contents1" + " (test " + i + " child " + j + ")");
michael@0 126 }
michael@0 127 }
michael@0 128 let sel = results[i][0];
michael@0 129 if (sel.todo) {
michael@0 130 alert(r.startContainer + '\n' + r.startOffset + '\n' + r.endContainer + '\n' + r.endOffset + '\n')
michael@0 131 return;
michael@0 132 }
michael@0 133 let startNode = sel.startNode === undefined ? p.firstChild : p.childNodes[sel.startNode];
michael@0 134 let startOffset = sel.startOffset === undefined ? 0 : sel.startOffset;
michael@0 135 if (sel.startParent) { startNode = p; startOffset = 0; }
michael@0 136 let endNode = sel.endNode === undefined ? p.childNodes[p.childNodes.length>1 ? 1 : 0] : p.childNodes[sel.endNode];
michael@0 137 let endOffset = sel.endOffset === undefined ? endNode.length : sel.endOffset;
michael@0 138 if (sel.endParent) { endNode = p; endOffset = 1; }
michael@0 139 is(r.startContainer, startNode, "range start node" + " (test " + i + ")");
michael@0 140 is(r.startOffset, startOffset, "range start offset" + " (test " + i + ")");
michael@0 141 is(r.endContainer, endNode, "range end node" + " (test " + i + ")");
michael@0 142 is(r.endOffset, endOffset, "range end offset" + " (test " + i + ")");
michael@0 143 }
michael@0 144
michael@0 145 function runTest() {
michael@0 146 let col1 = document.getElementById('col1');
michael@0 147 let col2 = document.getElementById('col2');
michael@0 148 for (let i=0; i < tests.length; ++i) {
michael@0 149 let t = tests[i];
michael@0 150 let p = document.createElement('p')
michael@0 151 col1.appendChild(p);
michael@0 152 let r = document.createRange();
michael@0 153 test_split(r,p,t);
michael@0 154 verifyResults(r,p,i);
michael@0 155 }
michael@0 156 for (let i=0; i < tests.length; ++i) {
michael@0 157 let t = tests[i];
michael@0 158 let p = document.createElement('p')
michael@0 159 col2.appendChild(p);
michael@0 160 let r = document.createRange();
michael@0 161 test_split_merge(r,p,t);
michael@0 162 verifyResults(r,p,i+tests.length);
michael@0 163 }
michael@0 164 SimpleTest.finish();
michael@0 165 }
michael@0 166
michael@0 167 window.onload = function() { setTimeout(runTest, 0); };
michael@0 168 SimpleTest.waitForExplicitFinish();
michael@0 169
michael@0 170 </script>
michael@0 171 </pre>
michael@0 172 </body>
michael@0 173 </html>

mercurial