diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/Tests/DOM')
11 files changed, 218 insertions, 181 deletions
diff --git a/Userland/Libraries/LibWeb/Tests/DOM/Comment.js b/Userland/Libraries/LibWeb/Tests/DOM/Comment.js index 0dab522e9c..354be07dad 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/Comment.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/Comment.js @@ -1,15 +1,17 @@ -loadPage("file:///home/anon/web-tests/Pages/Comment.html"); +describe("Comments", () => { + loadLocalPage("Comment.html"); + afterInitialPageLoad(page => { + test("Basic functionality", () => { + const comment = page.document.body.firstChild.nextSibling; + expect(comment).not.toBeNull(); -afterInitialPageLoad(() => { - test("Basic functionality", () => { - const comment = document.body.firstChild.nextSibling; - expect(comment).not.toBeNull(); + // FIXME: Add this in once Comment's constructor is implemented. + //expect(comment).toBeInstanceOf(Comment); - // FIXME: Add this in once Comment's constructor is implemented. - //expect(comment).toBeInstanceOf(Comment); - - expect(comment.nodeName).toBe("#comment"); - expect(comment.data).toBe("This is a comment"); - expect(comment).toHaveLength(17); + expect(comment.nodeName).toBe("#comment"); + expect(comment.data).toBe("This is a comment"); + expect(comment).toHaveLength(17); + }); }); + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/Element.js b/Userland/Libraries/LibWeb/Tests/DOM/Element.js index 16606829aa..d92fbae200 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/Element.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/Element.js @@ -1,39 +1,42 @@ -loadPage("file:///res/html/misc/innertext_textcontent.html"); +describe("Element", () => { + loadLocalPage("/res/html/misc/innertext_textcontent.html"); -afterInitialPageLoad(() => { - test("Element.innerText", () => { - var p = document.getElementsByTagName("p")[0]; - expect(p.innerText).toBe("This is a very small test page :^)"); + afterInitialPageLoad(page => { + test("Element.innerText", () => { + var p = page.document.getElementsByTagName("p")[0]; + expect(p.innerText).toBe("This is a very small test page :^)"); - // FIXME: Call this on p once that's supported. - var b = document.getElementsByTagName("b")[0]; - b.innerText = "foo"; - expect(b.innerText).toBe("foo"); - expect(p.innerText).toBe("This is a foo test page :^)"); + // FIXME: Call this on p once that's supported. + var b = page.document.getElementsByTagName("b")[0]; + b.innerText = "foo"; + expect(b.innerText).toBe("foo"); + expect(p.innerText).toBe("This is a foo test page :^)"); - p.innerText = "bar"; - expect(p.innerText).toBe("bar"); + p.innerText = "bar"; + expect(p.innerText).toBe("bar"); - var p = document.getElementById("source"); - // FIXME: The leading and trailing two spaces each are wrong. - // FIXME: The text should be affected by the text-transform:uppercase. - expect(p.innerText).toBe(` Take a look at + var p = page.document.getElementById("source"); + // FIXME: The leading and trailing two spaces each are wrong. + // FIXME: The text should be affected by the text-transform:uppercase. + expect(p.innerText).toBe(` Take a look at how this text is interpreted below. `); - }); + }); - test("Element.namespaceURI basics", () => { - const htmlNamespace = "http://www.w3.org/1999/xhtml"; - const p = document.getElementsByTagName("p")[0]; - expect(p.namespaceURI).toBe(htmlNamespace); + test("Element.namespaceURI basics", () => { + const htmlNamespace = "http://www.w3.org/1999/xhtml"; + const p = page.document.getElementsByTagName("p")[0]; + expect(p.namespaceURI).toBe(htmlNamespace); - // createElement always sets the namespace to the HTML namespace in HTML documents. - const svgElement = document.createElement("svg"); - expect(svgElement.namespaceURI).toBe(htmlNamespace); + // createElement always sets the namespace to the HTML namespace in HTML page.documents. + const svgElement = page.document.createElement("svg"); + expect(svgElement.namespaceURI).toBe(htmlNamespace); - const svgNamespace = "http://www.w3.org/2000/svg"; - p.innerHTML = "<svg></svg>"; - const domSVGElement = p.getElementsByTagName("svg")[0]; - expect(domSVGElement.namespaceURI).toBe(svgNamespace); + const svgNamespace = "http://www.w3.org/2000/svg"; + p.innerHTML = "<svg></svg>"; + const domSVGElement = p.getElementsByTagName("svg")[0]; + expect(domSVGElement.namespaceURI).toBe(svgNamespace); + }); }); + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/Node.js b/Userland/Libraries/LibWeb/Tests/DOM/Node.js index ddb02d19d0..12f8e12a57 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/Node.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/Node.js @@ -1,62 +1,68 @@ -loadPage("file:///res/html/misc/innertext_textcontent.html"); - -afterInitialPageLoad(() => { - test("Node.textContent", () => { - var p = document.getElementsByTagName("p")[0]; - expect(p.textContent).toBe("This is a very small test page :^)"); - expect(p.firstChild.textContent).toBe("This is a "); - expect(p.firstChild.firstChild).toBe(null); - - p.firstChild.textContent = "foo"; - expect(p.firstChild.textContent).toBe("foo"); - expect(p.firstChild.firstChild).toBe(null); - expect(p.textContent).toBe("foovery small test page :^)"); - - p.textContent = "bar"; - expect(p.textContent).toBe("bar"); - expect(p.firstChild.textContent).toBe("bar"); - expect(p.firstChild.firstChild).toBe(null); - - var p = document.getElementById("source"); - expect(p.textContent).toBe(` +describe("Node", () => { + loadLocalPage("/res/html/misc/innertext_textcontent.html"); + + afterInitialPageLoad(page => { + test("Node.textContent", () => { + var p = page.document.getElementsByTagName("p")[0]; + expect(p.textContent).toBe("This is a very small test page :^)"); + expect(p.firstChild.textContent).toBe("This is a "); + expect(p.firstChild.firstChild).toBe(null); + + p.firstChild.textContent = "foo"; + expect(p.firstChild.textContent).toBe("foo"); + expect(p.firstChild.firstChild).toBe(null); + expect(p.textContent).toBe("foovery small test page :^)"); + + p.textContent = "bar"; + expect(p.textContent).toBe("bar"); + expect(p.firstChild.textContent).toBe("bar"); + expect(p.firstChild.firstChild).toBe(null); + + var p = page.document.getElementById("source"); + expect(p.textContent).toBe(` #source { color: red; } #text { text-transform: uppercase; } Take a look athow this textis interpreted below. HIDDEN TEXT `); - }); + }); - test("Node.isConnected", () => { - var element = document.createElement("p"); - expect(element.isConnected).toBeFalse(); + test("Node.isConnected", () => { + var element = page.document.createElement("p"); + expect(element.isConnected).toBeFalse(); - document.body.appendChild(element); - expect(element.isConnected).toBeTrue(); + page.document.body.appendChild(element); + expect(element.isConnected).toBeTrue(); - document.body.removeChild(element); - expect(element.isConnected).toBeFalse(); - }); + page.document.body.removeChild(element); + expect(element.isConnected).toBeFalse(); + }); - test("Node.compareDocumentPosition()", () => { - const head = document.head; - const body = document.body; + test("Node.compareDocumentPosition()", () => { + const head = page.document.head; + const body = page.document.body; - expect(head.compareDocumentPosition(head)).toBe(0); + expect(head.compareDocumentPosition(head)).toBe(0); - // FIXME: Can be uncommented once the IDL parser correctly implements nullable parameters. - // expect(head.compareDocumentPosition(null) & Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC). - // toBe(Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC); + // FIXME: Can be uncommented once the IDL parser correctly implements nullable parameters. + // 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); + expect(head.compareDocumentPosition(body)).toBe(page.Node.DOCUMENT_POSITION_FOLLOWING); + expect(body.compareDocumentPosition(head)).toBe(page.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); + const source = page.document.getElementById("source"); + expect(source.compareDocumentPosition(body)).toBe( + page.Node.DOCUMENT_POSITION_CONTAINS | page.Node.DOCUMENT_POSITION_PRECEDING + ); + expect(body.compareDocumentPosition(source)).toBe( + page.Node.DOCUMENT_POSITION_CONTAINED_BY | page.Node.DOCUMENT_POSITION_FOLLOWING + ); + expect(source.compareDocumentPosition(head)).toBe( + page.Node.DOCUMENT_POSITION_PRECEDING + ); + }); }); + + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/Text.js b/Userland/Libraries/LibWeb/Tests/DOM/Text.js index 1557a59d3f..d2bb6b63e3 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/Text.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/Text.js @@ -1,15 +1,18 @@ -loadPage("file:///res/html/misc/blank.html"); +describe("Text", () => { + loadLocalPage("/res/html/misc/blank.html"); -afterInitialPageLoad(() => { - test("Basic functionality", () => { - const title = document.getElementsByTagName("title")[0]; - expect(title).toBeDefined(); + afterInitialPageLoad(page => { + test("Basic functionality", () => { + const title = page.document.getElementsByTagName("title")[0]; + expect(title).toBeDefined(); - // FIXME: Add this in once Text's constructor is implemented. - //expect(title.firstChild).toBeInstanceOf(Text); + // FIXME: Add this in once Text's constructor is implemented. + //expect(title.firstChild).toBeInstanceOf(Text); - expect(title.firstChild.nodeName).toBe("#text"); - expect(title.firstChild.data).toBe("Blank"); - expect(title.firstChild.length).toBe(5); + expect(title.firstChild.nodeName).toBe("#text"); + expect(title.firstChild.data).toBe("Blank"); + expect(title.firstChild.length).toBe(5); + }); }); + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/document.createComment.js b/Userland/Libraries/LibWeb/Tests/DOM/document.createComment.js index a60d6bfcd5..1b67103110 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/document.createComment.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/document.createComment.js @@ -1,13 +1,16 @@ -loadPage("file:///res/html/misc/blank.html"); +describe("createComment", () => { + loadLocalPage("/res/html/misc/blank.html"); -afterInitialPageLoad(() => { - test("Basic functionality", () => { - const comment = document.createComment("Create Comment Test"); + afterInitialPageLoad(page => { + test("Basic functionality", () => { + const comment = page.document.createComment("Create Comment Test"); - // FIXME: Add this in once Comment's constructor is implemented. - //expect(comment).toBeInstanceOf(Comment); - expect(comment.nodeName).toBe("#comment"); - expect(comment.data).toBe("Create Comment Test"); - expect(comment.length).toBe(19); + // FIXME: Add this in once Comment's constructor is implemented. + //expect(comment).toBeInstanceOf(Comment); + expect(comment.nodeName).toBe("#comment"); + expect(comment.data).toBe("Create Comment Test"); + expect(comment.length).toBe(19); + }); }); + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/document.createDocumentFragment.js b/Userland/Libraries/LibWeb/Tests/DOM/document.createDocumentFragment.js index bebc137313..ee3dc1843d 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/document.createDocumentFragment.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/document.createDocumentFragment.js @@ -1,11 +1,15 @@ -loadPage("file:///res/html/misc/blank.html"); +describe("createDocumentFragment", () => { + loadLocalPage("/res/html/misc/blank.html"); -afterInitialPageLoad(() => { - test("Basic functionality", () => { - const fragment = document.createDocumentFragment(); + afterInitialPageLoad(page => { + test("Basic functionality", () => { + const fragment = page.document.createDocumentFragment(); - // FIXME: Add this in once DocumentFragment's constructor is implemented. - //expect(fragment).toBeInstanceOf(DocumentFragment); - expect(fragment.nodeName).toBe("#document-fragment"); + // FIXME: Add this in once DocumentFragment's constructor is implemented. + //expect(fragment).toBeInstanceOf(DocumentFragment); + expect(fragment.nodeName).toBe("#document-fragment"); + }); }); + + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/document.createTextNode.js b/Userland/Libraries/LibWeb/Tests/DOM/document.createTextNode.js index bef06a81c7..37c7b6808e 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/document.createTextNode.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/document.createTextNode.js @@ -1,13 +1,15 @@ -loadPage("file:///res/html/misc/blank.html"); +describe("createTextNode", () => { + loadLocalPage("/res/html/misc/blank.html"); + afterInitialPageLoad(page => { + test("Basic functionality", () => { + const text = page.document.createTextNode("Create Text Test"); -afterInitialPageLoad(() => { - test("Basic functionality", () => { - const text = document.createTextNode("Create Text Test"); - - // FIXME: Add this in once Text's constructor is implemented. - //expect(text).toBeInstanceOf(Text); - expect(text.nodeName).toBe("#text"); - expect(text.data).toBe("Create Text Test"); - expect(text.length).toBe(16); + // FIXME: Add this in once Text's constructor is implemented. + //expect(text).toBeInstanceOf(Text); + expect(text.nodeName).toBe("#text"); + expect(text.data).toBe("Create Text Test"); + expect(text.length).toBe(16); + }); }); + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/document.doctype.js b/Userland/Libraries/LibWeb/Tests/DOM/document.doctype.js index 5da52014d1..32634aa551 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/document.doctype.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/document.doctype.js @@ -1,18 +1,22 @@ -loadPage("file:///res/html/misc/blank.html"); - -afterInitialPageLoad(() => { - test("Basic functionality", () => { - expect(document.compatMode).toBe("CSS1Compat"); - expect(document.doctype).not.toBeNull(); - expect(document.doctype.name).toBe("html"); - expect(document.doctype.publicId).toBe(""); - expect(document.doctype.systemId).toBe(""); +describe("doctype", () => { + loadLocalPage("/res/html/misc/blank.html"); + afterInitialPageLoad(page => { + test("Basic functionality", () => { + expect(page.document.compatMode).toBe("CSS1Compat"); + expect(page.document.doctype).not.toBeNull(); + expect(page.document.doctype.name).toBe("html"); + expect(page.document.doctype.publicId).toBe(""); + expect(page.document.doctype.systemId).toBe(""); + }); }); + waitForPageToLoad(); - libweb_tester.changePage("file:///res/html/misc/blank-no-doctype.html"); - - test("Quirks mode", () => { - expect(document.compatMode).toBe("BackCompat"); - expect(document.doctype).toBeNull(); + loadLocalPage("/res/html/misc/blank-no-doctype.html"); + afterInitialPageLoad(page => { + test("Quirks mode", () => { + expect(page.document.compatMode).toBe("BackCompat"); + expect(page.document.doctype).toBeNull(); + }); }); + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/document.documentElement.js b/Userland/Libraries/LibWeb/Tests/DOM/document.documentElement.js index 9ce06282de..3b4591e66e 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/document.documentElement.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/document.documentElement.js @@ -1,16 +1,20 @@ -loadPage("file:///res/html/misc/blank.html"); +describe("documentElement", () => { + loadLocalPage("/res/html/misc/blank.html"); -afterInitialPageLoad(() => { - test("Basic functionality", () => { - expect(document.documentElement).not.toBeNull(); - // FIXME: Add this in once HTMLHtmlElement's constructor is implemented. - //expect(document.documentElement).toBeInstanceOf(HTMLHtmlElement); - expect(document.documentElement.nodeName).toBe("HTML"); - }); + afterInitialPageLoad(page => { + test("Basic functionality", () => { + expect(page.document.documentElement).not.toBeNull(); + // FIXME: Add this in once HTMLHtmlElement's constructor is implemented. + //expect(document.documentElement).toBeInstanceOf(HTMLHtmlElement); + expect(page.document.documentElement.nodeName).toBe("HTML"); + }); - // FIXME: Add this in once removeChild is implemented. - test.skip("Nullable", () => { - document.removeChild(document.documentElement); - expect(document.documentElement).toBeNull(); + // FIXME: Add this in once removeChild is implemented. + test.skip("Nullable", () => { + page.document.removeChild(page.document.documentElement); + expect(page.document.documentElement).toBeNull(); + }); }); + + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/mixins/NonElementParentNode.js b/Userland/Libraries/LibWeb/Tests/DOM/mixins/NonElementParentNode.js index c567c7b96a..23bcb84d2d 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/mixins/NonElementParentNode.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/mixins/NonElementParentNode.js @@ -1,19 +1,22 @@ -loadPage("file:///home/anon/web-tests/Pages/ParentNode.html"); +describe("NonElementParentNode", () => { + loadLocalPage("ParentNode.html"); -afterInitialPageLoad(() => { - test("getElementById basics", () => { - const unique = document.getElementById("unique"); - expect(unique).not.toBeNull(); - expect(unique.nodeName).toBe("DIV"); - expect(unique.id).toBe("unique"); + afterInitialPageLoad(page => { + test("getElementById basics", () => { + const unique = page.document.getElementById("unique"); + expect(unique).not.toBeNull(); + expect(unique.nodeName).toBe("DIV"); + expect(unique.id).toBe("unique"); - const caseSensitive = document.getElementById("Unique"); - expect(caseSensitive).toBeNull(); + const caseSensitive = page.document.getElementById("Unique"); + expect(caseSensitive).toBeNull(); - const firstDuplicate = document.getElementById("dupeId"); - expect(firstDuplicate).not.toBeNull(); - expect(firstDuplicate.nodeName).toBe("DIV"); - expect(firstDuplicate.id).toBe("dupeId"); - expect(firstDuplicate.innerHTML).toBe("First ID"); + const firstDuplicate = page.document.getElementById("dupeId"); + expect(firstDuplicate).not.toBeNull(); + expect(firstDuplicate.nodeName).toBe("DIV"); + expect(firstDuplicate.id).toBe("dupeId"); + expect(firstDuplicate.innerHTML).toBe("First ID"); + }); }); + waitForPageToLoad(); }); diff --git a/Userland/Libraries/LibWeb/Tests/DOM/mixins/ParentNode.js b/Userland/Libraries/LibWeb/Tests/DOM/mixins/ParentNode.js index c1fa39f760..dab3c35111 100644 --- a/Userland/Libraries/LibWeb/Tests/DOM/mixins/ParentNode.js +++ b/Userland/Libraries/LibWeb/Tests/DOM/mixins/ParentNode.js @@ -1,25 +1,28 @@ -loadPage("file:///home/anon/web-tests/Pages/ParentNode.html"); +describe("ParentNode", () => { + loadLocalPage("ParentNode.html"); -afterInitialPageLoad(() => { - test("querySelector basics", () => { - const firstDuplicateElement = document.querySelector(".duplicate"); - expect(firstDuplicateElement).not.toBeNull(); - expect(firstDuplicateElement.nodeName).toBe("DIV"); - expect(firstDuplicateElement.innerHTML).toBe("First"); + afterInitialPageLoad(page => { + test("querySelector basics", () => { + const firstDuplicateElement = page.document.querySelector(".duplicate"); + expect(firstDuplicateElement).not.toBeNull(); + expect(firstDuplicateElement.nodeName).toBe("DIV"); + expect(firstDuplicateElement.innerHTML).toBe("First"); - const noElement = document.querySelector(".nonexistent"); - expect(noElement).toBeNull(); - }); + const noElement = page.document.querySelector(".nonexistent"); + expect(noElement).toBeNull(); + }); - test("querySelectorAll basics", () => { - const allDuplicates = document.querySelectorAll(".duplicate"); - expect(allDuplicates).toHaveLength(2); - expect(allDuplicates[0].nodeName).toBe("DIV"); - expect(allDuplicates[0].innerHTML).toBe("First"); - expect(allDuplicates[1].nodeName).toBe("DIV"); - expect(allDuplicates[1].innerHTML).toBe("Second"); + test("querySelectorAll basics", () => { + const allDuplicates = page.document.querySelectorAll(".duplicate"); + expect(allDuplicates).toHaveLength(2); + expect(allDuplicates[0].nodeName).toBe("DIV"); + expect(allDuplicates[0].innerHTML).toBe("First"); + expect(allDuplicates[1].nodeName).toBe("DIV"); + expect(allDuplicates[1].innerHTML).toBe("Second"); - const noElements = document.querySelectorAll(".nonexistent"); - expect(noElements).toHaveLength(0); + const noElements = page.document.querySelectorAll(".nonexistent"); + expect(noElements).toHaveLength(0); + }); }); + waitForPageToLoad(); }); |