chromium/third_party/blink/web_tests/fast/dom/Range/surroundContents-for-detached-node.html

<div id="container">
<p id="description"></p>
<div id="sample">0123456789</div>
</div>
<div id="console"></div>
<script src="../../../resources/js-test.js"></script>
<script>
description('Range.surroundContents() should not throw exception for detached node.');
function $(id) { return document.getElementById(id); }

function surroundContents(node) {
    var range = document.createRange();
    range.setStart(node.firstChild, 2);
    range.setEnd(node.firstChild, 6);
    var newNode = document.createElement('b');
    range.surroundContents(newNode);
    return newNode.outerHTML;
}

var sample = $('sample');
var expected = '<b>' + sample.firstChild.textContent.substring(2, 6) + '</b>';
shouldBeEqualToString('surroundContents(sample.cloneNode(true))', expected);
sample.parentNode.removeChild(sample);
shouldBeEqualToString('surroundContents(sample)', expected);

if (window.testRunner)
    $('container').outerHTML = '';
</script>