layout/reftests/selection/splitText-normalize.js

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

mercurial