Bug 619273 - regression tests for DOM mutations inside selection.
authorMats Palmgren <matspal@gmail.com>
Tue, 20 Dec 2011 10:15:41 +0100
changeset 83116 0aa9c3a5b7e1f4a359a4f7af3b51806fb8765cc7
parent 83115 a08580f18cb72e6bba342a5caaf1eb30119ef812
child 83117 e945a4b34a8a746cc494d1f9e912a90e93a02664
push id21732
push userbmo@edmorley.co.uk
push dateTue, 20 Dec 2011 16:54:34 +0000
treeherdermozilla-central@a8506ab2c654 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs619273
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 619273 - regression tests for DOM mutations inside selection.
layout/reftests/selection/dom-mutations-ref.html
layout/reftests/selection/dom-mutations.html
layout/reftests/selection/reftest.list
new file mode 100644
--- /dev/null
+++ b/layout/reftests/selection/dom-mutations-ref.html
@@ -0,0 +1,200 @@
+<!DOCTYPE HTML>
+<html class="reftest-wait">
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=619273
+-->
+<head>
+  <title>Test for Bug 619273</title>
+<script type="application/javascript;version=1.7">
+/** Test DOM mutations inside selection **/
+function createDOM(doc) {
+  let s = doc.createElement('span');
+  s.appendChild(doc.createTextNode('|'))
+  let s2 = doc.createElement('span');
+  s2.appendChild(doc.createTextNode('z'))
+  s.appendChild(s2)
+  return s;
+}
+
+var tests_done = 0;
+var tests = [
+  function(win,doc,sel) {
+    doc.body.innerHTML = '.I<br>B<br>C|z'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(a, 1);
+    r.setEnd(a, 2);
+    sel.addRange(r);
+  },
+   function(win,doc,sel) {
+    doc.body.innerHTML = '.I<br>B<br>C|z'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(doc.firstChild, 0);
+    r.setEnd(a, 2);
+    sel.addRange(r);
+  },
+ function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>.B<br>C|z'
+    let a = doc.body.firstChild;
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>.B<br>C|z'
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(doc.body, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>.B<br>C|z'
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(doc, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>.C|z'
+    let a = doc.body.firstChild;
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 2);
+    sel.addRange(r);
+  },
+
+  function(win,doc,sel) {
+    doc.body.innerHTML = '|z|zI<br>B<br>C'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(a, 4);
+    r.setEnd(a, 5);
+    sel.addRange(r);
+  },
+   function(win,doc,sel) {
+    doc.body.innerHTML = '|z|zI<br>B<br>C'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(doc.firstChild, 0);
+    r.setEnd(a, 5);
+    sel.addRange(r);
+  },
+ function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>|z|zB<br>C'
+    let a = doc.body.firstChild;
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>|z|zB<br>C'
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(doc.body, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>|z|zB<br>C'
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(doc, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>|z|zC'
+    let a = doc.body.firstChild;
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 5);
+    sel.addRange(r);
+  },
+
+  function(win,doc,sel) {
+    doc.body.innerHTML = '<br>B<br>CI'
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = '<br>B<br>C'
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+  },
+
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I|z'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(a, 1);
+    r.setEnd(a, 2);
+    sel.addRange(r);
+  },
+
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'Iz|'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(a, 1);
+    r.setEnd(a, 2);
+    sel.addRange(r);
+
+    document.body.appendChild(document.createTextNode('I'));
+    document.body.appendChild(document.createTextNode(' '));
+    document.body.appendChild(createDOM(document));
+  },
+]
+
+function runTestInIframe(run,t) {
+  let f = document.createElement('iframe');
+  f.setAttribute('frameborder','0');
+  f.setAttribute('height','100');
+  f.setAttribute('width','200');
+  f.src = 'data:text/html,<body style="margin:0;padding:0;font-family:monospace">';
+  f.onload = function () {
+    try {
+      run(f.contentWindow, f.contentDocument, f.contentWindow.getSelection());
+    } finally { ++tests_done; }
+  }
+  return f;
+}
+
+var id;
+function checkFinished() {
+  if (window.frames.length == tests_done) {
+    clearInterval(id);
+    document.documentElement.className = "";
+  }
+}
+
+function runTest() {
+  for (let i=0; i < tests.length; ++i) {
+    let t = tests[i];
+    document.body.appendChild(runTestInIframe(t));
+  }
+  id = setInterval(checkFinished,500);
+}
+</script>
+</head>
+<body onload="runTest()"></body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/selection/dom-mutations.html
@@ -0,0 +1,250 @@
+<!DOCTYPE HTML>
+<html class="reftest-wait">
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=619273
+-->
+<head>
+  <title>Test for Bug 619273</title>
+<script type="application/javascript;version=1.7">
+/** Test DOM mutations inside selection **/
+function createDOM(doc) {
+  let s = doc.createElement('span');
+  s.appendChild(doc.createTextNode('|'))
+  let s2 = doc.createElement('span');
+  s2.appendChild(doc.createTextNode('z'))
+  s.appendChild(s2)
+  return s;
+}
+
+var tests_done = 0;
+var tests = [
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(a, 1);
+    sel.addRange(r);
+    doc.body.insertBefore(doc.createTextNode('.'), a);
+    doc.body.appendChild(createDOM(doc));
+  },
+   function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(doc.firstChild, 0);
+    r.setEnd(a, 1);
+    sel.addRange(r);
+    doc.body.insertBefore(doc.createTextNode('.'), a);
+    doc.body.appendChild(createDOM(doc));
+  },
+ function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    doc.body.insertBefore(doc.createTextNode('.'), b);
+    doc.body.appendChild(createDOM(doc));
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(doc.body, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    doc.body.insertBefore(doc.createTextNode('.'), b);
+    doc.body.appendChild(createDOM(doc));
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(doc, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    doc.body.insertBefore(doc.createTextNode('.'), b);
+    doc.body.appendChild(createDOM(doc));
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    doc.body.insertBefore(doc.createTextNode('.'), c);
+    doc.body.appendChild(createDOM(doc));
+  },
+
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(a, 1);
+    sel.addRange(r);
+    let span = createDOM(doc);
+    doc.body.insertBefore(span, a);
+    span.appendChild(createDOM(doc));
+  },
+   function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(doc.firstChild, 0);
+    r.setEnd(a, 1);
+    sel.addRange(r);
+    let span = createDOM(doc);
+    doc.body.insertBefore(span, a);
+    span.appendChild(createDOM(doc));
+  },
+ function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    let span = createDOM(doc);
+    doc.body.insertBefore(span, b);
+    span.appendChild(createDOM(doc));
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(doc.body, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    let span = createDOM(doc);
+    doc.body.insertBefore(span, b);
+    span.appendChild(createDOM(doc));
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let b = doc.body.childNodes[2];
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(doc, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    let span = createDOM(doc);
+    doc.body.insertBefore(span, b);
+    span.appendChild(createDOM(doc));
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    let span = createDOM(doc);
+    doc.body.insertBefore(span, c);
+    span.appendChild(createDOM(doc));
+  },
+
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(a, 1);
+    sel.addRange(r);
+    doc.body.appendChild(a);
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(a, 1);
+    sel.addRange(r);
+    document.adoptNode(a);
+    document.body.appendChild(a);
+    document.body.appendChild(document.createTextNode(' '));
+  },
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I<br>B<br>C'
+    let a = doc.body.firstChild;
+    let c = doc.body.childNodes[4];
+    let r = doc.createRange();
+    r.setStart(a, 0);
+    r.setEnd(c, 1);
+    sel.addRange(r);
+    let span = createDOM(doc);
+    doc.body.insertBefore(span, c);
+    document.adoptNode(span);
+    document.body.appendChild(span);
+  },
+
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I'
+    let a = doc.body.firstChild;
+    let span = createDOM(doc);
+    let r = doc.createRange();
+    r.setStart(span, 0);
+    r.setEnd(span, 1);
+    sel.addRange(r);
+    doc.body.appendChild(span);
+  },
+
+  function(win,doc,sel) {
+    doc.body.innerHTML = 'I'
+    let a = doc.body.firstChild;
+    let span = createDOM(doc);
+    let r = doc.createRange();
+    r.setStart(span.firstChild, 0);
+    r.setEnd(span.firstChild, 1);
+    sel.addRange(r);
+    doc.body.appendChild(span);
+    doc.body.appendChild(span.firstChild);
+    r.setEnd(span.firstChild, 1);
+  },
+]
+
+function runTestInIframe(run,t) {
+  let f = document.createElement('iframe');
+  f.setAttribute('frameborder','0');
+  f.setAttribute('height','100');
+  f.setAttribute('width','200');
+  f.src = 'data:text/html,<body style="margin:0;padding:0;font-family:monospace">';
+  f.onload = function () {
+    try {
+      run(f.contentWindow, f.contentDocument, f.contentWindow.getSelection());
+    } finally { ++tests_done; }
+  }
+  return f;
+}
+
+var id;
+function checkFinished() {
+  if (window.frames.length == tests_done) {
+    clearInterval(id);
+    document.documentElement.className = "";
+  }
+}
+
+function runTest() {
+  for (let i=0; i < tests.length; ++i) {
+    let t = tests[i];
+    document.body.appendChild(runTestInIframe(t));
+  }
+  id = setInterval(checkFinished,500);
+}
+</script>
+</head>
+<body onload="runTest()"></body>
+</html>
--- a/layout/reftests/selection/reftest.list
+++ b/layout/reftests/selection/reftest.list
@@ -26,8 +26,9 @@
 == extend-4b.html extend-4-ref.html
 fails-if(Android) != pseudo-element-of-native-anonymous.html pseudo-element-of-native-anonymous-ref.html # bug 676641
 # These tests uses Highlight and HighlightText color keywords, they are not same as text selection color on Mac.
 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
+== dom-mutations.html dom-mutations-ref.html