layout/reftests/selection/splitText-normalize.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/reftests/selection/splitText-normalize.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +/** Test for Bug 191864 **/
     1.5 +var tests_done = 0;
     1.6 +var tests = [
     1.7 + [ {}, [0,4], "012345678" ],
     1.8 + [ {}, [0,0], "012345678" ],
     1.9 + [ {}, [0,9], "012345678" ],
    1.10 + [ {startOffset:4}, [0,4], "012345678" ],
    1.11 + [ {startOffset:5}, [0,4], "012345678" ],
    1.12 + [ {startOffset:5,endOffset:6}, [0,4], "012345678" ],
    1.13 + [ {endOffset:5}, [0,4], "012345678" ],
    1.14 + [ {endOffset:4}, [0,4], "012345678" ],
    1.15 + [ {endOffset:3}, [0,4], "012345678" ],
    1.16 + [ {startOffset:1,endOffset:3}, [0,4], "012345678" ],
    1.17 + [ {startOffset:7,endOffset:7}, [0,4], "012345678" ],
    1.18 + [ {startOffset:4,endOffset:4}, [0,4], "012345678" ],
    1.19 + [ {endNode:1}, [0,4], "012345678", "" ],
    1.20 + [ {endNode:1}, [0,4], "01234567", "8" ],
    1.21 + [ {endNode:1}, [1,4], "0", "12345678" ],
    1.22 + [ {startOffset:1,endNode:1}, [0,0], "0", "12345678" ],
    1.23 + [ {endNode:2}, [1,4], "0", "12345", "678" ],
    1.24 +]
    1.25 +
    1.26 +function runtest(f,t,nosplit) {
    1.27 +  // create content
    1.28 +  let doc = f.contentDocument;
    1.29 +  for (let i = 2; i < t.length; ++i) {
    1.30 +    c = doc.createTextNode(t[i]);
    1.31 +    doc.body.appendChild(c);
    1.32 +  }
    1.33 +
    1.34 +  // setup selection
    1.35 +  let sel = t[0]
    1.36 +  let startNode = sel.startNode === undefined ? doc.body.firstChild : doc.body.childNodes[sel.startNode];
    1.37 +  let startOffset = sel.startOffset === undefined ? 0 : sel.startOffset;
    1.38 +  let endNode = sel.endNode === undefined ? startNode : doc.body.childNodes[sel.endNode];
    1.39 +  let endOffset = sel.endOffset === undefined ? endNode.length : sel.endOffset;
    1.40 +  let selection = f.contentWindow.getSelection();
    1.41 +  let r = doc.createRange();
    1.42 +  r.setStart(startNode, startOffset);
    1.43 +  r.setEnd(endNode, endOffset);
    1.44 +  selection.addRange(r);
    1.45 +
    1.46 +  // splitText
    1.47 +  let split = t[1]
    1.48 +  if (!nosplit)
    1.49 +    doc.body.childNodes[split[0]].splitText(split[1])
    1.50 +}
    1.51 +function test_ref(f,t,nosplit) {
    1.52 +  runtest(f,t,true);
    1.53 +}
    1.54 +function test_split(f,t) {
    1.55 +  runtest(f,t);
    1.56 +}
    1.57 +function test_split_insert(f,t) {
    1.58 +  runtest(f,t);
    1.59 +  let doc = f.contentDocument;
    1.60 +  doc.body.firstChild;
    1.61 +  let split = t[1]
    1.62 +  let text1 = doc.body.childNodes[split[0]]
    1.63 +  let text2 = doc.body.childNodes[split[0]+1]
    1.64 +  if (text2.textContent.length==0) return;
    1.65 +  let c = doc.createTextNode(text2.textContent[0]);
    1.66 +  doc.body.insertBefore(c,text2);
    1.67 +  let r = doc.createRange();
    1.68 +  r.setStart(text2, 0);
    1.69 +  r.setEnd(text2, 1);
    1.70 +  r.deleteContents();
    1.71 +}
    1.72 +function test_split_merge(f,t) {
    1.73 +  runtest(f,t);
    1.74 +  f.contentDocument.body.normalize();
    1.75 +}
    1.76 +function test_merge(f,t) {
    1.77 +  runtest(f,t,true);
    1.78 +  f.contentDocument.body.normalize();
    1.79 +}
    1.80 +
    1.81 +function createFrame(run,t) {
    1.82 +  let f = document.createElement('iframe');
    1.83 +  f.setAttribute('height','22');
    1.84 +  f.setAttribute('frameborder','0');
    1.85 +  f.setAttribute('width','200');
    1.86 +  f.src = 'data:text/html,<body style="margin:0;padding:0">';
    1.87 +  f.onload = function () { try { run(f, t); } finally { ++tests_done; } }
    1.88 +  return f;
    1.89 +}

mercurial