<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<div>
  <div id="child"></div>
  <div id="newparent"><span id="beforeChild"></div>
</div>
<script>
description("Ensures that insertBefore() throws an exception if mutation even handler does something wrong");

var listener = function() {
    document.removeEventListener("DOMNodeRemoved", listener, false);
    child.appendChild(newparent);
};
document.addEventListener("DOMNodeRemoved", listener, false);
shouldThrowErrorName("newparent.insertBefore(child, beforeChild);",  "HierarchyRequestError");
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
