blob: b5492daba7017d65576683e39639de36d10206bd [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script>
var a, b;
function testElements(_a, _b) {
a = _a;
b = _b;
shouldBe('a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_DISCONNECTED', 'Node.DOCUMENT_POSITION_DISCONNECTED');
shouldBe('b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_DISCONNECTED', 'Node.DOCUMENT_POSITION_DISCONNECTED');
shouldBe('a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC', 'Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC');
shouldBe('b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC', 'Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC');
shouldNotBe('a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_PRECEDING', 'b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING');
shouldNotBe('a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING', 'b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_FOLLOWING');
shouldBeNonZero('a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_PRECEDING || a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING');
shouldBeNonZero('b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING || b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_FOLLOWING');
// Make sure the returned result is consistent.
shouldBe('a.compareDocumentPosition(b)', 'a.compareDocumentPosition(b)');
shouldBe('b.compareDocumentPosition(a)', 'b.compareDocumentPosition(a)');
}
debug("* Test with 2 disconnected elements");
testElements(document.createElement('a'), document.createElement('b'));
debug("* Test with document and a disconnected element");
testElements(document, document.createElement('b'));
debug("* Test with document and a disconnected attribute");
testElements(document, document.createAttribute('b'));
debug("* Test with 2 disconnected attributes");
testElements(document.createAttribute("a"), document.createAttribute("b"));
debug("* Test with disconnected attribute and element");
testElements(document.createAttribute("a"), document.createElement("b"));
</script>
<script src="../../resources/js-test-post.js"></script>
</head>
<body>
<p>Comparing the positions of two disconnected nodes should result in DOCUMENT_POSITION_DISCONNECTED.</p>
</body>
</html>