Bug 191864 - Range and Selection broken with splitText() and normalize().

This commit is contained in:
Mats Palmgren 2011-08-16 02:55:22 +02:00
parent 658d79ef70
commit 00f450ae6c
4 changed files with 178 additions and 0 deletions

View File

@ -30,3 +30,4 @@ fails-if(cocoaWidget) == non-themed-widget.html non-themed-widget-ref.html
fails-if(cocoaWidget) == themed-widget.html themed-widget-ref.html
== addrange-1.html addrange-ref.html
== addrange-2.html addrange-ref.html
== splitText-normalize.html splitText-normalize-ref.html

View File

@ -0,0 +1,40 @@
<!DOCTYPE HTML>
<html class="reftest-wait">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=191864
-->
<head>
<title>Test for Bug 191864</title>
<script type="application/javascript;version=1.7" src="splitText-normalize.js"></script>
<script type="application/javascript;version=1.7">
var id;
function checkFinished() {
if (window.frames.length == tests_done) {
clearInterval(id);
document.documentElement.className = "";
}
}
function runTest() {
let col1 = document.getElementById('col1');
let col2 = document.getElementById('col2');
let col3 = document.getElementById('col3');
let col4 = document.getElementById('col4');
for (let i=0; i < tests.length; ++i) {
let t = tests[i];
col1.appendChild(createFrame(test_ref,t));
col2.appendChild(createFrame(test_ref,t));
col3.appendChild(createFrame(test_ref,t));
col4.appendChild(createFrame(test_ref,t));
}
id = setInterval(checkFinished,500);
}
</script>
</head>
<body onload="runTest()">
<span id="col1" style="float:left; height:800px; width:180px;"></span>
<span id="col2" style="float:left; height:800px; width:180px;"></span>
<span id="col3" style="float:left; height:800px; width:180px;"></span>
<span id="col4" style="float:left; height:800px; width:180px;"></span>
</body>
</html>

View File

@ -0,0 +1,40 @@
<!DOCTYPE HTML>
<html class="reftest-wait">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=191864
-->
<head>
<title>Test for Bug 191864</title>
<script type="application/javascript;version=1.7" src="splitText-normalize.js"></script>
<script type="application/javascript;version=1.7">
var id;
function checkFinished() {
if (window.frames.length == tests_done) {
clearInterval(id);
document.documentElement.className = "";
}
}
function runTest() {
let col1 = document.getElementById('col1');
let col2 = document.getElementById('col2');
let col3 = document.getElementById('col3');
let col4 = document.getElementById('col4');
for (let i=0; i < tests.length; ++i) {
let t = tests[i];
col1.appendChild(createFrame(test_split,t));
col2.appendChild(createFrame(test_split_merge,t));
col3.appendChild(createFrame(test_merge,t));
col4.appendChild(createFrame(test_split_insert,t));
}
id = setInterval(checkFinished,500);
}
</script>
</head>
<body onload="runTest()">
<span id="col1" style="float:left; height:800px; width:180px;"></span>
<span id="col2" style="float:left; height:800px; width:180px;"></span>
<span id="col3" style="float:left; height:800px; width:180px;"></span>
<span id="col4" style="float:left; height:800px; width:180px;"></span>
</body>
</html>

View File

@ -0,0 +1,97 @@
/** Test for Bug 191864 **/
var tests_done = 0;
var tests = [
[ {}, [0,4], "012345678" ],
[ {}, [0,0], "012345678" ],
[ {}, [0,9], "012345678" ],
[ {startOffset:4}, [0,4], "012345678" ],
[ {startOffset:5}, [0,4], "012345678" ],
[ {startOffset:5,endOffset:6}, [0,4], "012345678" ],
[ {endOffset:5}, [0,4], "012345678" ],
[ {endOffset:4}, [0,4], "012345678" ],
[ {endOffset:3}, [0,4], "012345678" ],
[ {startOffset:1,endOffset:3}, [0,4], "012345678" ],
[ {startOffset:7,endOffset:7}, [0,4], "012345678" ],
[ {startOffset:4,endOffset:4}, [0,4], "012345678" ],
[ {endNode:1}, [0,4], "012345678", "" ],
[ {endNode:1}, [0,4], "01234567", "8" ],
[ {endNode:1}, [1,4], "0", "12345678" ],
[ {endNode:2}, [1,4], "0", "12345", "678" ],
]
function runtest(f,t,nosplit) {
// create content
let doc = f.contentDocument;
for (let i = 2; i < t.length; ++i) {
c = doc.createTextNode(t[i]);
doc.body.appendChild(c);
}
// setup selection
let sel = t[0]
let startNode = sel.startNode === undefined ? doc.body.firstChild : doc.body.childNodes[sel.startNode];
let startOffset = sel.startOffset === undefined ? 0 : sel.startOffset;
let endNode = sel.endNode === undefined ? startNode : doc.body.childNodes[sel.endNode];
let endOffset = sel.endOffset === undefined ? endNode.length : sel.endOffset;
let selection = f.contentWindow.getSelection();
let r = doc.createRange();
r.setStart(startNode, startOffset);
r.setEnd(endNode, endOffset);
selection.addRange(r);
// splitText
let split = t[1]
if (!nosplit)
doc.body.childNodes[split[0]].splitText(split[1])
}
function test_ref(f,t,nosplit) {
runtest(f,t,true);
}
function test_split(f,t) {
runtest(f,t);
}
function test_split_insert(f,t) {
runtest(f,t);
let doc = f.contentDocument;
doc.body.firstChild;
let split = t[1]
let text1 = doc.body.childNodes[split[0]]
let text2 = doc.body.childNodes[split[0]+1]
if (text2.textContent.length==0) return;
let c = doc.createTextNode(text2.textContent[0]);
doc.body.insertBefore(c,text2);
let r = doc.createRange();
r.setStart(text2, 0);
r.setEnd(text2, 1);
r.deleteContents();
}
function test_split_merge(f,t) {
runtest(f,t);
f.contentDocument.body.normalize();
}
function test_merge(f,t) {
runtest(f,t,true);
f.contentDocument.body.normalize();
}
function repaint_selection(win) {
let a = new Array;
let sel = win.getSelection();
for (let i = 0; i < sel.rangeCount; ++i) {
a[i] = sel.getRangeAt(i);
}
sel.removeAllRanges();
for (let i = 0; i < a.length; ++i) {
sel.addRange(a[i]);
}
}
function createFrame(run,t) {
let f = document.createElement('iframe');
f.setAttribute('height','22');
f.setAttribute('frameborder','0');
f.setAttribute('width','200');
f.src = 'data:text/html,<body style="margin:0;padding:0">';
f.onload = function () { try { run(f, t); repaint_selection(f.contentWindow);} finally { ++tests_done; } }
return f;
}