<!DOCTYPE html>
<html>
<!-- Test for WK104972: this test passes if it does not crash. -->
<body id="body" onload="crash()">
  <svg width="100" height="100">
    <rect id="rect1">
      <animateMotion>
        <g id="g1"></g>
        <g id="g2"></g>
        <set id="animate"></set>
      </animateMotion>
    </rect>
  </svg>
<script>
  if (window.testRunner) {
    testRunner.waitUntilDone();
    testRunner.dumpAsText();
  }

  function crash() {
    var notInDocRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
    setTimeout(function() {
      var g2 = document.getElementById('g2');
      g2.parentNode.removeChild(g2);
      document.getElementById('g1').appendChild(document.getElementById('animate'));
      notInDocRect.appendChild(document.getElementById('rect1'));
      document.getElementById('body').innerHTML = "PASS: test did not crash";

      if (window.testRunner)
        testRunner.notifyDone();
    }, 1);
  }
</script>
</body>
</html>