blob: 2de3cd0b7cd689bb37fa398e68ba0695049f3fd1 [file] [log] [blame]
<div id="container">
<p id="description"></p>
<div id="sample">0123<b>45</b>6789</div>
</div>
<div id="console"></div>
<script src="../../../resources/js-test.js"></script>
<script>
description('Range on detached node should not throw exception.');
function $(id) { return document.getElementById(id); }
function invalidNodeMessage(methodName)
{
return '"InvalidNodeTypeError: Failed to execute \'' + methodName + '\' on \'Range\': the given Node has no parent."'
}
var sample = $('sample').cloneNode(true);
var range = document.createRange();
shouldBe('range.selectNode(sample.firstChild); range.startContainer', 'sample');
shouldBe('range.setEndBefore(sample.firstChild); range.startContainer', 'sample');
shouldBe('range.setEndAfter(sample.firstChild); range.startContainer', 'sample');
shouldBe('range.setStartAfter(sample.firstChild); range.startContainer', 'sample');
shouldBe('range.setStartBefore(sample.firstChild); range.startContainer', 'sample');
shouldThrow('range.selectNode(sample); range.startContainer', invalidNodeMessage('selectNode'));
shouldThrow('range.setEndAfter(sample); range.startContainer', invalidNodeMessage('setEndAfter'));
shouldThrow('range.setEndBefore(sample); range.startContainer', invalidNodeMessage('setEndBefore'));
shouldThrow('range.setStartAfter(sample); range.startContainer', invalidNodeMessage('setStartAfter'));
shouldThrow('range.setStartBefore(sample); range.startContainer', invalidNodeMessage('setStartBefore'));
if (window.testRunner)
$('container').outerHTML = '';
</script>