1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:37:34 +00:00

LibWeb: Implement test-web in terms of LibTest/JavaScriptTestRunner

This deduplicates the test-js copy-ism :^)
This commit is contained in:
Ali Mohammad Pur 2021-05-18 18:46:54 +04:30 committed by Linus Groh
parent f137c1bfaa
commit d897abf4c2
26 changed files with 643 additions and 1159 deletions

View file

@ -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();
});

View file

@ -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 = page.document.getElementsByTagName("p")[0];
expect(p.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);
});
});
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);
});
waitForPageToLoad();
});

View file

@ -1,62 +1,68 @@
loadPage("file:///res/html/misc/innertext_textcontent.html");
describe("Node", () => {
loadLocalPage("/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);
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.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);
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(`
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 = page.document.createElement("p");
expect(element.isConnected).toBeFalse();
page.document.body.appendChild(element);
expect(element.isConnected).toBeTrue();
page.document.body.removeChild(element);
expect(element.isConnected).toBeFalse();
});
test("Node.compareDocumentPosition()", () => {
const head = page.document.head;
const body = page.document.body;
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);
expect(head.compareDocumentPosition(body)).toBe(page.Node.DOCUMENT_POSITION_FOLLOWING);
expect(body.compareDocumentPosition(head)).toBe(page.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
);
});
});
test("Node.isConnected", () => {
var element = document.createElement("p");
expect(element.isConnected).toBeFalse();
document.body.appendChild(element);
expect(element.isConnected).toBeTrue();
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 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);
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);
});
waitForPageToLoad();
});

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();
});

View file

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

View file

@ -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();
});

View file

@ -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();
});
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);
const noElement = page.document.querySelector(".nonexistent");
expect(noElement).toBeNull();
});
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 = page.document.querySelectorAll(".nonexistent");
expect(noElements).toHaveLength(0);
});
});
waitForPageToLoad();
});

View file

@ -1,9 +1,12 @@
loadPage("file:///res/html/misc/welcome.html");
describe("HTMLElement", () => {
loadLocalPage("/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");
afterInitialPageLoad(page => {
test("contentEditable attribute", () => {
expect(page.document.body.contentEditable).toBe("inherit");
expect(page.document.firstChild.nextSibling.nodeName).toBe("HTML");
expect(page.document.firstChild.nextSibling.contentEditable).toBe("true");
});
});
waitForPageToLoad();
});

View file

@ -1,118 +1,121 @@
loadPage("file:///home/anon/web-tests/Pages/Table.html");
describe("HTMLTableElement", () => {
loadLocalPage("Table.html");
afterInitialPageLoad(() => {
test("empty table attributes", () => {
let table = document.getElementById("empty-table");
expect(table).not.toBeNull();
afterInitialPageLoad(page => {
test("empty table attributes", () => {
let table = page.document.getElementById("empty-table");
expect(table).not.toBeNull();
expect(table.caption).toBe(null);
expect(table.tHead).toBe(null);
expect(table.tFoot).toBe(null);
expect(table.caption).toBe(null);
expect(table.tHead).toBe(null);
expect(table.tFoot).toBe(null);
expect(table.tBodies).toHaveLength(0);
expect(table.rows).toHaveLength(0);
});
test("full table attributes", () => {
let table = document.getElementById("full-table");
expect(table).not.toBeNull();
expect(table.caption.nodeName).toBe("CAPTION");
expect(table.tHead.nodeName).toBe("THEAD");
expect(table.tFoot.nodeName).toBe("TFOOT");
expect(table.tBodies.length).toBe(1);
expect(table.rows.length).toBe(3);
});
test("create/delete caption", () => {
let table = document.createElement("table");
expect(table).not.toBeNull();
expect(table.caption).toBeNull();
table.createCaption();
expect(table.caption).not.toBeNull();
table.deleteCaption();
expect(table.caption).toBeNull();
});
test("create/delete thead", () => {
let table = document.createElement("table");
expect(table).not.toBeNull();
expect(table.tHead).toBeNull();
table.createTHead();
expect(table.tHead).not.toBeNull();
table.deleteTHead();
expect(table.tHead).toBeNull();
});
test("create/delete tfoot", () => {
let table = document.createElement("table");
expect(table).not.toBeNull();
expect(table.tFoot).toBeNull();
table.createTFoot();
expect(table.tFoot).not.toBeNull();
table.deleteTFoot();
expect(table.tFoot).toBeNull();
});
test("insert rows", () => {
let table = document.createElement("table");
expect(table).not.toBeNull();
// We hardcode the default value in a few places, due to the WrapperGenerator's bug with default values
const defaultValue = -1;
expect(table.rows.length).toBe(0);
// insertRow with an index > number of rows will throw
expect(() => {
table.insertRow(1);
}).toThrow();
// Inserting a row into an empty table will create a <tbody> and <tr>
let rowFirst = table.insertRow(defaultValue);
rowFirst.innerText = "row_first";
expect(table.firstElementChild.nodeName).toBe("TBODY");
expect(table.firstElementChild.firstElementChild.nodeName).toBe("TR");
expect(table.firstElementChild.firstElementChild.innerText).toBe("row_first");
for (let i = 0; i < 10; i++) {
let row = table.insertRow(defaultValue);
row.innerText = "row" + i;
}
expect(table.rows.length).toBe(11);
// insertRow with the default value
let rowDefault = table.insertRow(defaultValue);
rowDefault.innerText = "row_default";
expect(table.rows[table.rows.length - 1].innerText).toBe("row_default");
});
test("delete rows", () => {
let table = document.createElement("table");
expect(table).not.toBeNull();
// We hardcode the default value in a few places, due to the WrapperGenerator's bug with default values
const defaultValue = -1;
// deleteRow with an index > number of rows will throw
expect(table.deleteRow).toThrow();
for (let i = 0; i < 10; i++) {
let row = table.insertRow(defaultValue);
row.innerText = "row" + i;
}
// deleteRow with with no argument will delete the last row
expect(table.rows[table.rows.length - 1].innerText).toBe("row9");
table.deleteRow(defaultValue);
expect(table.rows[table.rows.length - 1].innerText).toBe("row8");
// We can delete a row with a specific index
expect(table.rows[5].innerText).toBe("row5");
table.deleteRow(5);
expect(table.rows[5].innerText).toBe("row6");
expect(table.tBodies).toHaveLength(0);
expect(table.rows).toHaveLength(0);
});
test("full table attributes", () => {
let table = page.document.getElementById("full-table");
expect(table).not.toBeNull();
expect(table.caption.nodeName).toBe("CAPTION");
expect(table.tHead.nodeName).toBe("THEAD");
expect(table.tFoot.nodeName).toBe("TFOOT");
expect(table.tBodies.length).toBe(1);
expect(table.rows.length).toBe(3);
});
test("create/delete caption", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
expect(table.caption).toBeNull();
table.createCaption();
expect(table.caption).not.toBeNull();
table.deleteCaption();
expect(table.caption).toBeNull();
});
test("create/delete thead", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
expect(table.tHead).toBeNull();
table.createTHead();
expect(table.tHead).not.toBeNull();
table.deleteTHead();
expect(table.tHead).toBeNull();
});
test("create/delete tfoot", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
expect(table.tFoot).toBeNull();
table.createTFoot();
expect(table.tFoot).not.toBeNull();
table.deleteTFoot();
expect(table.tFoot).toBeNull();
});
test("insert rows", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
// We hardcode the default value in a few places, due to the WrapperGenerator's bug with default values
const defaultValue = -1;
expect(table.rows.length).toBe(0);
// insertRow with an index > number of rows will throw
expect(() => {
table.insertRow(1);
}).toThrow();
// Inserting a row into an empty table will create a <tbody> and <tr>
let rowFirst = table.insertRow(defaultValue);
rowFirst.innerText = "row_first";
expect(table.firstElementChild.nodeName).toBe("TBODY");
expect(table.firstElementChild.firstElementChild.nodeName).toBe("TR");
expect(table.firstElementChild.firstElementChild.innerText).toBe("row_first");
for (let i = 0; i < 10; i++) {
let row = table.insertRow(defaultValue);
row.innerText = "row" + i;
}
expect(table.rows.length).toBe(11);
// insertRow with the default value
let rowDefault = table.insertRow(defaultValue);
rowDefault.innerText = "row_default";
expect(table.rows[table.rows.length - 1].innerText).toBe("row_default");
});
test("delete rows", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
// We hardcode the default value in a few places, due to the WrapperGenerator's bug with default values
const defaultValue = -1;
// deleteRow with an index > number of rows will throw
expect(table.deleteRow).toThrow();
for (let i = 0; i < 10; i++) {
let row = table.insertRow(defaultValue);
row.innerText = "row" + i;
}
// deleteRow with with no argument will delete the last row
expect(table.rows[table.rows.length - 1].innerText).toBe("row9");
table.deleteRow(defaultValue);
expect(table.rows[table.rows.length - 1].innerText).toBe("row8");
// We can delete a row with a specific index
expect(table.rows[5].innerText).toBe("row5");
table.deleteRow(5);
expect(table.rows[5].innerText).toBe("row6");
});
});
waitForPageToLoad();
});

View file

@ -1,27 +1,30 @@
loadPage("file:///home/anon/web-tests/Pages/Template.html");
describe("HTMLTemplateElement", () => {
loadLocalPage("Template.html");
afterInitialPageLoad(() => {
test("Basic functionality", () => {
const template = document.getElementById("template");
expect(template).not.toBeNull();
afterInitialPageLoad(page => {
test("Basic functionality", () => {
const template = page.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();
// 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");
// FIXME: Add this in once page.DocumentFragment's constructor is implemented.
//expect(template.content).toBeInstanceOf(page.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();
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(page.window.templateScriptRan).toBeUndefined();
});
});
waitForPageToLoad();
});

View file

@ -1,55 +1,58 @@
loadPage("file:///res/html/misc/blank.html");
describe("body", () => {
loadLocalPage("/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();
afterInitialPageLoad(page => {
test("Basic functionality", () => {
expect(page.document.body).not.toBeNull();
// FIXME: Add this in once HTMLBodyElement's constructor is implemented.
//expect(page.document.body).toBeInstanceOf(HTMLBodyElement);
expect(page.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 = page.document.createElement("p");
page.document.body.appendChild(p);
expect(page.document.body.firstChild).toBe(p);
const newBody = page.document.createElement("body");
page.document.body = newBody;
expect(page.document.body).not.toBeNull();
expect(page.document.body.nodeName).toBe("BODY");
// FIXME: Add this in once HTMLBodyElement's constructor is implemented.
//expect(page.document.body).toBeInstanceOf(HTMLBodyElement);
expect(page.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 = page.document.createElement("frameset");
page.document.body = newFrameSet;
expect(page.document.body).not.toBeNull();
expect(page.document.body.nodeName).toBe("FRAMESET");
// FIXME: Add this in once HTMLFrameSetElement's constructor is implemented.
//expect(page.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(() => {
page.document.body = page.document.createElement("div");
}).toThrow(DOMException);
});
// FIXME: Add this in once removeChild is implemented.
test.skip("Nullable", () => {
page.document.page.documentElement.removeChild(page.document.body);
expect(page.document.body).toBeNull();
});
});
waitForPageToLoad();
});

View file

@ -1,16 +1,19 @@
loadPage("file:///res/html/misc/blank.html");
describe("head", () => {
loadLocalPage("/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");
});
afterInitialPageLoad(page => {
test("Basic functionality", () => {
expect(page.document.head).not.toBeNull();
// FIXME: Add this in once HTMLHeadElement's constructor is implemented.
//expect(page.document.head).toBeInstanceOf(HTMLHeadElement);
expect(page.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();
// FIXME: Add this in once removeChild is implemented.
test.skip("Nullable", () => {
page.document.documentElement.removeChild(page.document.head);
expect(page.document.head).toBeNull();
});
});
waitForPageToLoad();
});

View file

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

View file

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

View file

@ -1,12 +1,11 @@
<!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>
<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

@ -1,28 +1,25 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table id="empty-table"></table>
<table id="full-table">
<caption>A Caption</caption>
<thead>
<th>Head Cell</th>
</thead>
<tbody>
<tr>
<td>
Body Cell
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
Footer Cell
</td>
</tr>
</tfoot>
</table>
</body>
<head> </head>
<body>
<table id="empty-table"></table>
<table id="full-table">
<caption>
A Caption
</caption>
<thead>
<th>Head Cell</th>
</thead>
<tbody>
<tr>
<td>Body Cell</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Footer Cell</td>
</tr>
</tfoot>
</table>
</body>
</html>

View file

@ -1,14 +1,13 @@
<!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>
<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

@ -1,19 +1,22 @@
loadPage("file:///res/html/misc/blank.html");
describe("Base64", () => {
loadLocalPage("/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");
});
afterInitialPageLoad(page => {
test("atob", () => {
expect(page.atob("YQ==")).toBe("a");
expect(page.atob("YWE=")).toBe("aa");
expect(page.atob("YWFh")).toBe("aaa");
expect(page.atob("YWFhYQ==")).toBe("aaaa");
expect(page.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==");
test("btoa", () => {
expect(page.btoa("a")).toBe("YQ==");
expect(page.btoa("aa")).toBe("YWE=");
expect(page.btoa("aaa")).toBe("YWFh");
expect(page.btoa("aaaa")).toBe("YWFhYQ==");
expect(page.btoa("\xff")).toBe("/w==");
});
});
waitForPageToLoad();
});

View file

@ -1,8 +1,11 @@
loadPage("file:///res/html/misc/blank.html");
describe("window_frames_self", () => {
loadLocalPage("/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);
afterInitialPageLoad(page => {
test("window.{window,frames,self} all return the Window object", () => {
expect(page.window.window).toBe(page.window.frames);
expect(page.window.window).toBe(page.window.self);
});
});
waitForPageToLoad();
});

View file

@ -1,31 +0,0 @@
// 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);
})();