mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:37:46 +00:00
LibWeb: Implement test-web in terms of LibTest/JavaScriptTestRunner
This deduplicates the test-js copy-ism :^)
This commit is contained in:
parent
f137c1bfaa
commit
d897abf4c2
26 changed files with 643 additions and 1159 deletions
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue