summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Tests
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2021-04-10 17:21:22 -0700
committerAndreas Kling <kling@serenityos.org>2021-04-11 09:40:06 +0200
commit988c23fff05238dbd1c1899a862bdb4b42b93c73 (patch)
treef3fa248407334abba2b83f5675cfb707b78d8f04 /Userland/Libraries/LibWeb/Tests
parent0f8932d7ab1bdf598011e138377461fe1f731fa5 (diff)
downloadserenity-988c23fff05238dbd1c1899a862bdb4b42b93c73.zip
LibWeb: Add implementation of Node.compareDocumentPosition()
While looking into getting Duck Duck Go loading further in the Browser, I noticed that it was complaining about the missing method Node.compareDocumentPosition. This change implements as much of the DOM spec as possible with the current implementation of the DOM to date. The implementation is validated by new tests in the Node.js.
Diffstat (limited to 'Userland/Libraries/LibWeb/Tests')
-rw-r--r--Userland/Libraries/LibWeb/Tests/DOM/Node.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Tests/DOM/Node.js b/Userland/Libraries/LibWeb/Tests/DOM/Node.js
index 47c3e1c668..38618c0dd9 100644
--- a/Userland/Libraries/LibWeb/Tests/DOM/Node.js
+++ b/Userland/Libraries/LibWeb/Tests/DOM/Node.js
@@ -36,4 +36,27 @@ afterInitialPageLoad(() => {
document.body.removeChild(element);
expect(element.isConnected).toBeFalse();
});
+
+ test("Node.compareDocumentPosition()", () => {
+ const head = document.head;
+ const body = document.body;
+
+ expect(head.compareDocumentPosition(head)).toBe(0);
+
+ // FIXME: Can be uncommented once the IDL parser correctly implements nullable paramaters.
+ // expect(head.compareDocumentPosition(null) & Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC).
+ // toBe(Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
+
+ expect(head.compareDocumentPosition(body)).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
+ expect(body.compareDocumentPosition(head)).toBe(Node.DOCUMENT_POSITION_PRECEDING);
+
+ const source = document.getElementById("source");
+ expect(source.compareDocumentPosition(body)).toBe(
+ Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
+ );
+ expect(body.compareDocumentPosition(source)).toBe(
+ Node.DOCUMENT_POSITION_CONTAINED_BY | Node.DOCUMENT_POSITION_FOLLOWING
+ );
+ expect(source.compareDocumentPosition(head)).toBe(Node.DOCUMENT_POSITION_PRECEDING);
+ });
});