Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /** Test for Bug 191864 **/ |
michael@0 | 2 | var tests_done = 0; |
michael@0 | 3 | var tests = [ |
michael@0 | 4 | [ {}, [0,4], "012345678" ], |
michael@0 | 5 | [ {}, [0,0], "012345678" ], |
michael@0 | 6 | [ {}, [0,9], "012345678" ], |
michael@0 | 7 | [ {startOffset:4}, [0,4], "012345678" ], |
michael@0 | 8 | [ {startOffset:5}, [0,4], "012345678" ], |
michael@0 | 9 | [ {startOffset:5,endOffset:6}, [0,4], "012345678" ], |
michael@0 | 10 | [ {endOffset:5}, [0,4], "012345678" ], |
michael@0 | 11 | [ {endOffset:4}, [0,4], "012345678" ], |
michael@0 | 12 | [ {endOffset:3}, [0,4], "012345678" ], |
michael@0 | 13 | [ {startOffset:1,endOffset:3}, [0,4], "012345678" ], |
michael@0 | 14 | [ {startOffset:7,endOffset:7}, [0,4], "012345678" ], |
michael@0 | 15 | [ {startOffset:4,endOffset:4}, [0,4], "012345678" ], |
michael@0 | 16 | [ {endNode:1}, [0,4], "012345678", "" ], |
michael@0 | 17 | [ {endNode:1}, [0,4], "01234567", "8" ], |
michael@0 | 18 | [ {endNode:1}, [1,4], "0", "12345678" ], |
michael@0 | 19 | [ {startOffset:1,endNode:1}, [0,0], "0", "12345678" ], |
michael@0 | 20 | [ {endNode:2}, [1,4], "0", "12345", "678" ], |
michael@0 | 21 | ] |
michael@0 | 22 | |
michael@0 | 23 | function runtest(f,t,nosplit) { |
michael@0 | 24 | // create content |
michael@0 | 25 | let doc = f.contentDocument; |
michael@0 | 26 | for (let i = 2; i < t.length; ++i) { |
michael@0 | 27 | c = doc.createTextNode(t[i]); |
michael@0 | 28 | doc.body.appendChild(c); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | // setup selection |
michael@0 | 32 | let sel = t[0] |
michael@0 | 33 | let startNode = sel.startNode === undefined ? doc.body.firstChild : doc.body.childNodes[sel.startNode]; |
michael@0 | 34 | let startOffset = sel.startOffset === undefined ? 0 : sel.startOffset; |
michael@0 | 35 | let endNode = sel.endNode === undefined ? startNode : doc.body.childNodes[sel.endNode]; |
michael@0 | 36 | let endOffset = sel.endOffset === undefined ? endNode.length : sel.endOffset; |
michael@0 | 37 | let selection = f.contentWindow.getSelection(); |
michael@0 | 38 | let r = doc.createRange(); |
michael@0 | 39 | r.setStart(startNode, startOffset); |
michael@0 | 40 | r.setEnd(endNode, endOffset); |
michael@0 | 41 | selection.addRange(r); |
michael@0 | 42 | |
michael@0 | 43 | // splitText |
michael@0 | 44 | let split = t[1] |
michael@0 | 45 | if (!nosplit) |
michael@0 | 46 | doc.body.childNodes[split[0]].splitText(split[1]) |
michael@0 | 47 | } |
michael@0 | 48 | function test_ref(f,t,nosplit) { |
michael@0 | 49 | runtest(f,t,true); |
michael@0 | 50 | } |
michael@0 | 51 | function test_split(f,t) { |
michael@0 | 52 | runtest(f,t); |
michael@0 | 53 | } |
michael@0 | 54 | function test_split_insert(f,t) { |
michael@0 | 55 | runtest(f,t); |
michael@0 | 56 | let doc = f.contentDocument; |
michael@0 | 57 | doc.body.firstChild; |
michael@0 | 58 | let split = t[1] |
michael@0 | 59 | let text1 = doc.body.childNodes[split[0]] |
michael@0 | 60 | let text2 = doc.body.childNodes[split[0]+1] |
michael@0 | 61 | if (text2.textContent.length==0) return; |
michael@0 | 62 | let c = doc.createTextNode(text2.textContent[0]); |
michael@0 | 63 | doc.body.insertBefore(c,text2); |
michael@0 | 64 | let r = doc.createRange(); |
michael@0 | 65 | r.setStart(text2, 0); |
michael@0 | 66 | r.setEnd(text2, 1); |
michael@0 | 67 | r.deleteContents(); |
michael@0 | 68 | } |
michael@0 | 69 | function test_split_merge(f,t) { |
michael@0 | 70 | runtest(f,t); |
michael@0 | 71 | f.contentDocument.body.normalize(); |
michael@0 | 72 | } |
michael@0 | 73 | function test_merge(f,t) { |
michael@0 | 74 | runtest(f,t,true); |
michael@0 | 75 | f.contentDocument.body.normalize(); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function createFrame(run,t) { |
michael@0 | 79 | let f = document.createElement('iframe'); |
michael@0 | 80 | f.setAttribute('height','22'); |
michael@0 | 81 | f.setAttribute('frameborder','0'); |
michael@0 | 82 | f.setAttribute('width','200'); |
michael@0 | 83 | f.src = 'data:text/html,<body style="margin:0;padding:0">'; |
michael@0 | 84 | f.onload = function () { try { run(f, t); } finally { ++tests_done; } } |
michael@0 | 85 | return f; |
michael@0 | 86 | } |