1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +00:00

Libraries: Move to Userland/Libraries/

This commit is contained in:
Andreas Kling 2021-01-12 12:17:30 +01:00
parent dc28c07fa5
commit 13d7c09125
1857 changed files with 266 additions and 274 deletions

View file

@ -0,0 +1,15 @@
loadPage("file:///home/anon/web-tests/Pages/Comment.html");
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);
expect(comment.nodeName).toBe("#comment");
expect(comment.data).toBe("This is a comment");
expect(comment).toHaveLength(17);
});
});

View file

@ -0,0 +1,39 @@
loadPage("file:///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 :^)");
// 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 :^)");
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
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);
// createElement always sets the namespace to the HTML namespace in HTML documents.
const svgElement = 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);
});
});

View file

@ -0,0 +1,28 @@
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(`
#source { color: red; } #text { text-transform: uppercase; }
Take a look athow this textis interpreted
below.
HIDDEN TEXT
`);
});
});

View file

@ -0,0 +1,15 @@
loadPage("file:///res/html/misc/blank.html");
afterInitialPageLoad(() => {
test("Basic functionality", () => {
const title = document.getElementsByTagName("title")[0];
expect(title).toBeDefined();
// 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);
});
});

View file

@ -0,0 +1,13 @@
loadPage("file:///res/html/misc/blank.html");
afterInitialPageLoad(() => {
test("Basic functionality", () => {
const comment = 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);
});
});

View file

@ -0,0 +1,11 @@
loadPage("file:///res/html/misc/blank.html");
afterInitialPageLoad(() => {
test("Basic functionality", () => {
const fragment = document.createDocumentFragment();
// FIXME: Add this in once DocumentFragment's constructor is implemented.
//expect(fragment).toBeInstanceOf(DocumentFragment);
expect(fragment.nodeName).toBe("#document-fragment");
});
});

View file

@ -0,0 +1,13 @@
loadPage("file:///res/html/misc/blank.html");
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);
});
});

View file

@ -0,0 +1,18 @@
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("");
});
libweb_tester.changePage("file:///res/html/misc/blank-no-doctype.html");
test("Quirks mode", () => {
expect(document.compatMode).toBe("BackCompat");
expect(document.doctype).toBeNull();
});
});

View file

@ -0,0 +1,16 @@
loadPage("file:///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");
});
// FIXME: Add this in once removeChild is implemented.
test.skip("Nullable", () => {
document.removeChild(document.documentElement);
expect(document.documentElement).toBeNull();
});
});

View file

@ -0,0 +1,19 @@
loadPage("file:///home/anon/web-tests/Pages/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");
const caseSensitive = 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");
});
});

View file

@ -0,0 +1,25 @@
loadPage("file:///home/anon/web-tests/Pages/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");
const noElement = 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");
const noElements = document.querySelectorAll(".nonexistent");
expect(noElements).toHaveLength(0);
});
});

View file

@ -0,0 +1,9 @@
loadPage("file:///res/html/misc/welcome.html");
afterInitialPageLoad(() => {
test("contentEditable attribute", () => {
expect(document.body.contentEditable).toBe("inherit");
expect(document.firstChild.nextSibling.nodeName).toBe("html");
expect(document.firstChild.nextSibling.contentEditable).toBe("true");
});
});

View file

@ -0,0 +1,27 @@
loadPage("file:///home/anon/web-tests/Pages/Template.html");
afterInitialPageLoad(() => {
test("Basic functionality", () => {
const template = document.getElementById("template");
expect(template).not.toBeNull();
// The contents of a template element are not children of the actual element.
// The document fragment is not a child of the element either.
expect(template.firstChild).toBeNull();
// FIXME: Add this in once DocumentFragment's constructor is implemented.
//expect(template.content).toBeInstanceOf(DocumentFragment);
expect(template.content.nodeName).toBe("#document-fragment");
const templateDiv = template.content.getElementById("templatediv");
expect(templateDiv.nodeName).toBe("div");
expect(templateDiv.textContent).toBe("Hello template!");
});
test("Templates are inert (e.g. scripts won't run)", () => {
// The page has a template element with a script element in it.
// Templates are inert, for example, they won't run scripts.
// That script will set "templateScriptRan" to true if it ran.
expect(window.templateScriptRan).toBeUndefined();
});
});

View file

@ -0,0 +1,55 @@
loadPage("file:///res/html/misc/blank.html");
afterInitialPageLoad(() => {
test("Basic functionality", () => {
expect(document.body).not.toBeNull();
// FIXME: Add this in once HTMLBodyElement's constructor is implemented.
//expect(document.body).toBeInstanceOf(HTMLBodyElement);
expect(document.body.nodeName).toBe("body");
});
// FIXME: Add this in once set_body is fully implemented.
test.skip("Setting body to a new body element", () => {
// Add something to body to see if it's gone afterwards
const p = document.createElement("p");
document.body.appendChild(p);
expect(document.body.firstChild).toBe(p);
const newBody = document.createElement("body");
document.body = newBody;
expect(document.body).not.toBeNull();
expect(document.body.nodeName).toBe("body");
// FIXME: Add this in once HTMLBodyElement's constructor is implemented.
//expect(document.body).toBeInstanceOf(HTMLBodyElement);
expect(document.body.firstChild).toBeNull();
});
// FIXME: Add this in once set_body is fully implemented.
test.skip("Setting body to a new frameset element", () => {
const newFrameSet = document.createElement("frameset");
document.body = newFrameSet;
expect(document.body).not.toBeNull();
expect(document.body.nodeName).toBe("frameset");
// FIXME: Add this in once HTMLFrameSetElement's constructor is implemented.
//expect(document.body).toBeInstanceOf(HTMLFrameSetElement);
});
// FIXME: Add this in once set_body is fully implemented.
test.skip("Setting body to an element that isn't body/frameset", () => {
expect(() => {
document.body = document.createElement("div");
}).toThrow(DOMException);
});
// FIXME: Add this in once removeChild is implemented.
test.skip("Nullable", () => {
document.documentElement.removeChild(document.body);
expect(document.body).toBeNull();
});
});

View file

@ -0,0 +1,16 @@
loadPage("file:///res/html/misc/blank.html");
afterInitialPageLoad(() => {
test("Basic functionality", () => {
expect(document.head).not.toBeNull();
// FIXME: Add this in once HTMLHeadElement's constructor is implemented.
//expect(document.head).toBeInstanceOf(HTMLHeadElement);
expect(document.head.nodeName).toBe("head");
});
// FIXME: Add this in once removeChild is implemented.
test.skip("Nullable", () => {
document.documentElement.removeChild(document.head);
expect(document.head).toBeNull();
});
});

View file

@ -0,0 +1,31 @@
loadPage("file:///res/html/misc/blank.html");
beforeInitialPageLoad(() => {
window.events = [];
document.addEventListener("readystatechange", () => {
window.events.push(document.readyState);
});
document.addEventListener("DOMContentLoaded", () => {
test("Ready state should be 'interactive' when 'DOMContentLoaded' fires", () => {
expect(document.readyState).toBe("interactive");
});
});
test("Ready state should be 'loading' initially", () => {
expect(document.readyState).toBe("loading");
});
});
afterInitialPageLoad(() => {
test("'interactive' should come before 'complete' and both should have happened", () => {
expect(window.events).toHaveLength(2);
expect(window.events[0]).toBe("interactive");
expect(window.events[1]).toBe("complete");
});
test("Ready state should be 'complete' after loading", () => {
expect(document.readyState).toBe("complete");
});
});

View file

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!--This is a comment-->
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="duplicate">First</div>
<div class="duplicate">Second</div>
<div id="unique"></div>
<div id="dupeId">First ID</div>
<div id="dupeId">Second ID</div>
</body>
</html>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<template id="template">
<div id="templatediv">Hello template!</div>
<script>
// I shouldn't be run.
window.templateScriptRan = true;
</script>
</template>
</body>
</html>

View file

@ -0,0 +1,19 @@
loadPage("file:///res/html/misc/blank.html");
afterInitialPageLoad(() => {
test("atob", () => {
expect(atob("YQ==")).toBe("a");
expect(atob("YWE=")).toBe("aa");
expect(atob("YWFh")).toBe("aaa");
expect(atob("YWFhYQ==")).toBe("aaaa");
expect(atob("/w==")).toBe("\xff");
});
test("btoa", () => {
expect(btoa("a")).toBe("YQ==");
expect(btoa("aa")).toBe("YWE=");
expect(btoa("aaa")).toBe("YWFh");
expect(btoa("aaaa")).toBe("YWFhYQ==");
expect(btoa("\xff")).toBe("/w==");
});
});

View file

@ -0,0 +1,8 @@
loadPage("file:///res/html/misc/blank.html");
afterInitialPageLoad(() => {
test("window.{window,frames,self} all return the Window object", () => {
expect(window.window).toBe(window.frames);
expect(window.window).toBe(window.self);
});
});

View file

@ -0,0 +1,16 @@
// NOTE: This file is only for syntax highlighting, documentation, etc.
interface LibwebTester {
/**
* Changes the page to the specified URL. Everything afterwards will refer to the new page.
* @param url Page to load.
*/
changePage(url: string): void;
}
interface Window {
/**
* Special test object used to ease test development for LibWeb.
*/
readonly libweb_tester: LibwebTester;
}

View file

@ -0,0 +1,31 @@
// NOTE: The tester loads in LibJS's test-common to prevent duplication.
// NOTE: "window.libweb_tester" is set to a special tester object.
// See libweb_tester.d.ts for definitions.
let __PageToLoad__;
// This tells the tester which page to load.
// This will only be checked when we look at which page the test wants to use.
// Subsequent calls to loadPage in before/after initial load will be ignored.
let loadPage;
let __BeforeInitialPageLoad__ = () => {};
// This function will be called just before loading the initial page.
// This is useful for injecting event listeners.
// Defaults to an empty function.
let beforeInitialPageLoad;
let __AfterInitialPageLoad__ = () => {};
// This function will be called just after loading the initial page.
// This is where the main bulk of the tests should be.
// Defaults to an empty function.
let afterInitialPageLoad;
(() => {
loadPage = page => (__PageToLoad__ = page);
beforeInitialPageLoad = callback => (__BeforeInitialPageLoad__ = callback);
afterInitialPageLoad = callback => (__AfterInitialPageLoad__ = callback);
})();