mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
Merge pull request #1009 from lightpanda-io/migrate_some_tests_4
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
migrate to htmlRunner
This commit is contained in:
@@ -104,23 +104,6 @@ pub fn _reverse(self: *const Animation) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const testing = @import("../../testing.zig");
|
const testing = @import("../../testing.zig");
|
||||||
test "Browser.Animation" {
|
test "Browser: DOM.Animation" {
|
||||||
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "" });
|
try testing.htmlRunner("dom/animation.html");
|
||||||
defer runner.deinit();
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let a1 = document.createElement('div').animate(null, null)", null },
|
|
||||||
.{ "a1.playState", "finished" },
|
|
||||||
.{ "let cb = [];", null },
|
|
||||||
.{ "a1.ready.then(() => { cb.push('ready') })", null },
|
|
||||||
.{
|
|
||||||
\\ a1.finished.then((x) => {
|
|
||||||
\\ cb.push('finished');
|
|
||||||
\\ cb.push(x == a1);
|
|
||||||
\\ })
|
|
||||||
,
|
|
||||||
null,
|
|
||||||
},
|
|
||||||
.{ "cb", "finished,true" },
|
|
||||||
}, .{});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,32 +70,6 @@ pub const Attr = struct {
|
|||||||
// -----
|
// -----
|
||||||
|
|
||||||
const testing = @import("../../testing.zig");
|
const testing = @import("../../testing.zig");
|
||||||
test "Browser.DOM.Attribute" {
|
test "Browser: DOM.Attribute" {
|
||||||
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
|
try testing.htmlRunner("dom/attribute.html");
|
||||||
defer runner.deinit();
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let a = document.createAttributeNS('foo', 'bar')", "undefined" },
|
|
||||||
.{ "a.namespaceURI", "foo" },
|
|
||||||
.{ "a.prefix", "null" },
|
|
||||||
.{ "a.localName", "bar" },
|
|
||||||
.{ "a.name", "bar" },
|
|
||||||
.{ "a.value", "" },
|
|
||||||
// TODO: libdom has a bug here: the created attr has no parent, it
|
|
||||||
// causes a panic w/ libdom when setting the value.
|
|
||||||
//.{ "a.value = 'nok'", "nok" },
|
|
||||||
.{ "a.ownerElement", "null" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let b = document.getElementById('link').getAttributeNode('class')", "undefined" },
|
|
||||||
.{ "b.name", "class" },
|
|
||||||
.{ "b.value", "ok" },
|
|
||||||
.{ "b.value = 'nok'", "nok" },
|
|
||||||
.{ "b.value", "nok" },
|
|
||||||
.{ "b.value = null", "null" },
|
|
||||||
.{ "b.value", "null" },
|
|
||||||
.{ "b.value = 'ok'", "ok" },
|
|
||||||
.{ "b.ownerElement.id", "link" },
|
|
||||||
}, .{});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,69 +129,6 @@ pub const CharacterData = struct {
|
|||||||
// -----
|
// -----
|
||||||
|
|
||||||
const testing = @import("../../testing.zig");
|
const testing = @import("../../testing.zig");
|
||||||
test "Browser.DOM.CharacterData" {
|
test "Browser: DOM.CharacterData" {
|
||||||
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
|
try testing.htmlRunner("dom/character_data.html");
|
||||||
defer runner.deinit();
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let link = document.getElementById('link')", "undefined" },
|
|
||||||
.{ "let cdata = link.firstChild", "undefined" },
|
|
||||||
.{ "cdata.data", "OK" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.data = 'OK modified'", "OK modified" },
|
|
||||||
.{ "cdata.data === 'OK modified'", "true" },
|
|
||||||
.{ "cdata.data = 'OK'", "OK" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.length === 2", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.nextElementSibling === null", "true" },
|
|
||||||
// create a next element
|
|
||||||
.{ "let next = document.createElement('a')", "undefined" },
|
|
||||||
.{ "link.appendChild(next, cdata) !== undefined", "true" },
|
|
||||||
.{ "cdata.nextElementSibling.localName === 'a' ", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.previousElementSibling === null", "true" },
|
|
||||||
// create a prev element
|
|
||||||
.{ "let prev = document.createElement('div')", "undefined" },
|
|
||||||
.{ "link.insertBefore(prev, cdata) !== undefined", "true" },
|
|
||||||
.{ "cdata.previousElementSibling.localName === 'div' ", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.appendData(' modified')", "undefined" },
|
|
||||||
.{ "cdata.data === 'OK modified' ", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.deleteData('OK'.length, ' modified'.length)", "undefined" },
|
|
||||||
.{ "cdata.data == 'OK'", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.insertData('OK'.length-1, 'modified')", "undefined" },
|
|
||||||
.{ "cdata.data == 'OmodifiedK'", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.replaceData('OK'.length-1, 'modified'.length, 'replaced')", "undefined" },
|
|
||||||
.{ "cdata.data == 'OreplacedK'", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.substringData('OK'.length-1, 'replaced'.length) == 'replaced'", "true" },
|
|
||||||
.{ "cdata.substringData('OK'.length-1, 0) == ''", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "cdata.substringData('OK'.length-1, 'replaced'.length) == 'replaced'", "true" },
|
|
||||||
.{ "cdata.substringData('OK'.length-1, 0) == ''", "true" },
|
|
||||||
}, .{});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,15 +40,6 @@ pub const Comment = struct {
|
|||||||
// -----
|
// -----
|
||||||
|
|
||||||
const testing = @import("../../testing.zig");
|
const testing = @import("../../testing.zig");
|
||||||
test "Browser.DOM.Comment" {
|
test "Browser: DOM.Comment" {
|
||||||
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
|
try testing.htmlRunner("dom/comment.html");
|
||||||
defer runner.deinit();
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let comment = new Comment('foo')", "undefined" },
|
|
||||||
.{ "comment.data", "foo" },
|
|
||||||
|
|
||||||
.{ "let emptycomment = new Comment()", "undefined" },
|
|
||||||
.{ "emptycomment.data", "" },
|
|
||||||
}, .{});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -314,214 +314,22 @@ pub const Document = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const testing = @import("../../testing.zig");
|
const testing = @import("../../testing.zig");
|
||||||
test "Browser.DOM.Document" {
|
test "Browser: DOM.Document" {
|
||||||
var runner = try testing.jsRunner(testing.tracking_allocator, .{
|
try testing.htmlRunner("dom/document.html");
|
||||||
.url = "about:blank",
|
|
||||||
});
|
|
||||||
defer runner.deinit();
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
// const Case = testing.JsRunner.Case;
|
||||||
.{ "document.__proto__.__proto__.constructor.name", "Document" },
|
// const tags = comptime parser.Tag.all();
|
||||||
.{ "document.__proto__.__proto__.__proto__.constructor.name", "Node" },
|
// var createElements: [(tags.len) * 2]Case = undefined;
|
||||||
.{ "document.__proto__.__proto__.__proto__.__proto__.constructor.name", "EventTarget" },
|
// inline for (tags, 0..) |tag, i| {
|
||||||
|
// const tag_name = @tagName(tag);
|
||||||
.{ "let newdoc = new Document()", "undefined" },
|
// createElements[i * 2] = Case{
|
||||||
.{ "newdoc.documentElement", "null" },
|
// "var " ++ tag_name ++ "Elem = document.createElement('" ++ tag_name ++ "')",
|
||||||
.{ "newdoc.children.length", "0" },
|
// "undefined",
|
||||||
.{ "newdoc.getElementsByTagName('*').length", "0" },
|
// };
|
||||||
.{ "newdoc.getElementsByTagName('*').item(0)", "null" },
|
// createElements[(i * 2) + 1] = Case{
|
||||||
.{ "newdoc.inputEncoding === document.inputEncoding", "true" },
|
// tag_name ++ "Elem.localName",
|
||||||
.{ "newdoc.documentURI === document.documentURI", "true" },
|
// tag_name,
|
||||||
.{ "newdoc.URL === document.URL", "true" },
|
// };
|
||||||
.{ "newdoc.compatMode === document.compatMode", "true" },
|
// }
|
||||||
.{ "newdoc.characterSet === document.characterSet", "true" },
|
// try runner.testCases(&createElements, .{});
|
||||||
.{ "newdoc.charset === document.charset", "true" },
|
|
||||||
.{ "newdoc.contentType === document.contentType", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let getElementById = document.getElementById('content')", "undefined" },
|
|
||||||
.{ "getElementById.constructor.name", "HTMLDivElement" },
|
|
||||||
.{ "getElementById.localName", "div" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let getElementsByTagName = document.getElementsByTagName('p')", "undefined" },
|
|
||||||
.{ "getElementsByTagName.length", "2" },
|
|
||||||
.{ "getElementsByTagName.item(0).localName", "p" },
|
|
||||||
.{ "getElementsByTagName.item(1).localName", "p" },
|
|
||||||
.{ "let getElementsByTagNameAll = document.getElementsByTagName('*')", "undefined" },
|
|
||||||
.{ "getElementsByTagNameAll.length", "8" },
|
|
||||||
.{ "getElementsByTagNameAll.item(0).localName", "html" },
|
|
||||||
.{ "getElementsByTagNameAll.item(7).localName", "p" },
|
|
||||||
.{ "getElementsByTagNameAll.namedItem('para-empty-child').localName", "span" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let ok = document.getElementsByClassName('ok')", "undefined" },
|
|
||||||
.{ "ok.length", "2" },
|
|
||||||
.{ "let empty = document.getElementsByClassName('empty')", "undefined" },
|
|
||||||
.{ "empty.length", "1" },
|
|
||||||
.{ "let emptyok = document.getElementsByClassName('empty ok')", "undefined" },
|
|
||||||
.{ "emptyok.length", "1" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let e = document.documentElement", "undefined" },
|
|
||||||
.{ "e.localName", "html" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "document.characterSet", "UTF-8" },
|
|
||||||
.{ "document.charset", "UTF-8" },
|
|
||||||
.{ "document.inputEncoding", "UTF-8" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "document.compatMode", "CSS1Compat" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "document.contentType", "text/html" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "document.documentURI", "about:blank" },
|
|
||||||
.{ "document.URL", "about:blank" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let impl = document.implementation", "undefined" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let d = new Document()", "undefined" },
|
|
||||||
.{ "d.characterSet", "UTF-8" },
|
|
||||||
.{ "d.URL", "about:blank" },
|
|
||||||
.{ "d.documentURI", "about:blank" },
|
|
||||||
.{ "d.compatMode", "CSS1Compat" },
|
|
||||||
.{ "d.contentType", "text/html" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "var v = document.createDocumentFragment()", "undefined" },
|
|
||||||
.{ "v.nodeName", "#document-fragment" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "var v = document.createTextNode('foo')", "undefined" },
|
|
||||||
.{ "v.nodeName", "#text" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "var v = document.createCDATASection('foo')", "undefined" },
|
|
||||||
.{ "v.nodeName", "#cdata-section" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "var v = document.createComment('foo')", "undefined" },
|
|
||||||
.{ "v.nodeName", "#comment" },
|
|
||||||
.{ "let v2 = v.cloneNode()", "undefined" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let pi = document.createProcessingInstruction('foo', 'bar')", "undefined" },
|
|
||||||
.{ "pi.target", "foo" },
|
|
||||||
.{ "let pi2 = pi.cloneNode()", "undefined" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let nimp = document.getElementById('content')", "undefined" },
|
|
||||||
.{ "var v = document.importNode(nimp)", "undefined" },
|
|
||||||
.{ "v.nodeName", "DIV" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "var v = document.createAttribute('foo')", "undefined" },
|
|
||||||
.{ "v.nodeName", "foo" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "document.children.length", "1" },
|
|
||||||
.{ "document.children.item(0).nodeName", "HTML" },
|
|
||||||
.{ "document.firstElementChild.nodeName", "HTML" },
|
|
||||||
.{ "document.lastElementChild.nodeName", "HTML" },
|
|
||||||
.{ "document.childElementCount", "1" },
|
|
||||||
|
|
||||||
.{ "let nd = new Document()", "undefined" },
|
|
||||||
.{ "nd.children.length", "0" },
|
|
||||||
.{ "nd.children.item(0)", "null" },
|
|
||||||
.{ "nd.firstElementChild", "null" },
|
|
||||||
.{ "nd.lastElementChild", "null" },
|
|
||||||
.{ "nd.childElementCount", "0" },
|
|
||||||
|
|
||||||
.{ "let emptydoc = document.createElement('html')", "undefined" },
|
|
||||||
.{ "emptydoc.prepend(document.createElement('html'))", "undefined" },
|
|
||||||
|
|
||||||
.{ "let emptydoc2 = document.createElement('html')", "undefined" },
|
|
||||||
.{ "emptydoc2.append(document.createElement('html'))", "undefined" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "document.querySelector('')", "null" },
|
|
||||||
.{ "document.querySelector('*').nodeName", "HTML" },
|
|
||||||
.{ "document.querySelector('#content').id", "content" },
|
|
||||||
.{ "document.querySelector('#para').id", "para" },
|
|
||||||
.{ "document.querySelector('.ok').id", "link" },
|
|
||||||
.{ "document.querySelector('a ~ p').id", "para-empty" },
|
|
||||||
.{ "document.querySelector(':root').nodeName", "HTML" },
|
|
||||||
|
|
||||||
.{ "document.querySelectorAll('p').length", "2" },
|
|
||||||
.{
|
|
||||||
\\ Array.from(document.querySelectorAll('#content > p#para-empty'))
|
|
||||||
\\ .map(row => row.querySelector('span').textContent)
|
|
||||||
\\ .length;
|
|
||||||
,
|
|
||||||
"1",
|
|
||||||
},
|
|
||||||
|
|
||||||
.{ "document.querySelectorAll('.\\\\:popover-open').length", "0" },
|
|
||||||
.{ "document.querySelectorAll('.foo\\\\:bar').length", "0" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "document.activeElement === document.body", "true" },
|
|
||||||
.{ "document.getElementById('link').focus()", "undefined" },
|
|
||||||
.{ "document.activeElement === document.getElementById('link')", "true" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "document.styleSheets.length", "0" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
// this test breaks the doc structure, keep it at the end of the test
|
|
||||||
// suite.
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "let nadop = document.getElementById('content')", "undefined" },
|
|
||||||
.{ "var v = document.adoptNode(nadop)", "undefined" },
|
|
||||||
.{ "v.nodeName", "DIV" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
try runner.testCases(&.{
|
|
||||||
.{ "const acss = document.adoptedStyleSheets", null },
|
|
||||||
.{ "acss.length", "0" },
|
|
||||||
.{ "acss.push(new CSSStyleSheet())", null },
|
|
||||||
.{ "document.adoptedStyleSheets.length", "1" },
|
|
||||||
}, .{});
|
|
||||||
|
|
||||||
const Case = testing.JsRunner.Case;
|
|
||||||
const tags = comptime parser.Tag.all();
|
|
||||||
var createElements: [(tags.len) * 2]Case = undefined;
|
|
||||||
inline for (tags, 0..) |tag, i| {
|
|
||||||
const tag_name = @tagName(tag);
|
|
||||||
createElements[i * 2] = Case{
|
|
||||||
"var " ++ tag_name ++ "Elem = document.createElement('" ++ tag_name ++ "')",
|
|
||||||
"undefined",
|
|
||||||
};
|
|
||||||
createElements[(i * 2) + 1] = Case{
|
|
||||||
tag_name ++ "Elem.localName",
|
|
||||||
tag_name,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
try runner.testCases(&createElements, .{});
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/tests/dom/animation.html
Normal file
14
src/tests/dom/animation.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<script src="../testing.js"></script>
|
||||||
|
|
||||||
|
<script id=animation>
|
||||||
|
let a1 = document.createElement('div').animate(null, null);
|
||||||
|
testing.expectEqual('finished', a1.playState);
|
||||||
|
|
||||||
|
let cb = [];
|
||||||
|
a1.ready.then(() => { cb.push('ready') });
|
||||||
|
a1.finished.then((x) => {
|
||||||
|
cb.push('finished');
|
||||||
|
cb.push(x == a1);
|
||||||
|
});
|
||||||
|
testing.eventually(() => testing.expectEqual(['finished', true], cb));
|
||||||
|
</script>
|
||||||
32
src/tests/dom/attribute.html
Normal file
32
src/tests/dom/attribute.html
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<script src="../testing.js"></script>
|
||||||
|
|
||||||
|
<a id="link" href="foo" class="ok">OK</a>
|
||||||
|
|
||||||
|
<script id=attribute>
|
||||||
|
let a = document.createAttributeNS('foo', 'bar');
|
||||||
|
testing.expectEqual('foo', a.namespaceURI);
|
||||||
|
testing.expectEqual(null, a.prefix);
|
||||||
|
testing.expectEqual('bar', a.localName);
|
||||||
|
testing.expectEqual('bar', a.name);
|
||||||
|
testing.expectEqual('', a.value);
|
||||||
|
|
||||||
|
// TODO: libdom has a bug here: the created attr has no parent, it
|
||||||
|
// causes a panic w/ libdom when setting the value.
|
||||||
|
//.{ "a.value = 'nok'", "nok" },
|
||||||
|
testing.expectEqual(null, a.ownerElement);
|
||||||
|
|
||||||
|
let b = document.getElementById('link').getAttributeNode('class');
|
||||||
|
testing.expectEqual('class', b.name);
|
||||||
|
testing.expectEqual('ok', b.value);
|
||||||
|
|
||||||
|
b.value = 'nok';
|
||||||
|
testing.expectEqual('nok', b.value)
|
||||||
|
|
||||||
|
b.value = null;
|
||||||
|
testing.expectEqual('null', b.value);
|
||||||
|
|
||||||
|
b.value = 'ok';
|
||||||
|
testing.expectEqual('ok', b.value);
|
||||||
|
|
||||||
|
testing.expectEqual('link', b.ownerElement.id);
|
||||||
|
</script>
|
||||||
47
src/tests/dom/character_data.html
Normal file
47
src/tests/dom/character_data.html
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<script src="../testing.js"></script>
|
||||||
|
|
||||||
|
<a id="link" href="foo" class="ok">OK</a>
|
||||||
|
|
||||||
|
<script id=character_data>
|
||||||
|
let link = document.getElementById('link');
|
||||||
|
let cdata = link.firstChild;
|
||||||
|
testing.expectEqual('OK', cdata.data);
|
||||||
|
|
||||||
|
cdata.data = 'OK modified';
|
||||||
|
testing.expectEqual('OK modified', cdata.data);
|
||||||
|
cdata.data = 'OK';
|
||||||
|
|
||||||
|
testing.expectEqual(2, cdata.length);
|
||||||
|
|
||||||
|
testing.expectEqual(true, cdata.nextElementSibling === null);
|
||||||
|
|
||||||
|
// create a next element
|
||||||
|
let next = document.createElement('a');
|
||||||
|
testing.expectEqual(true, link.appendChild(next, cdata) !== undefined);
|
||||||
|
testing.expectEqual(true, cdata.nextElementSibling.localName === 'a');
|
||||||
|
|
||||||
|
testing.expectEqual(true, cdata.previousElementSibling === null);
|
||||||
|
|
||||||
|
// create a prev element
|
||||||
|
let prev = document.createElement('div');
|
||||||
|
testing.expectEqual(true, link.insertBefore(prev, cdata) !== undefined);
|
||||||
|
testing.expectEqual('div', cdata.previousElementSibling.localName);
|
||||||
|
|
||||||
|
cdata.appendData(' modified');
|
||||||
|
testing.expectEqual('OK modified', cdata.data);
|
||||||
|
|
||||||
|
cdata.deleteData('OK'.length, ' modified'.length);
|
||||||
|
testing.expectEqual('OK', cdata.data)
|
||||||
|
|
||||||
|
cdata.insertData('OK'.length-1, 'modified');
|
||||||
|
testing.expectEqual('OmodifiedK', cdata.data);
|
||||||
|
|
||||||
|
cdata.replaceData('OK'.length-1, 'modified'.length, 'replaced');
|
||||||
|
testing.expectEqual('OreplacedK', cdata.data);
|
||||||
|
|
||||||
|
testing.expectEqual('replaced', cdata.substringData('OK'.length-1, 'replaced'.length));
|
||||||
|
testing.expectEqual('', cdata.substringData('OK'.length-1, 0));
|
||||||
|
|
||||||
|
testing.expectEqual('replaced', cdata.substringData('OK'.length-1, 'replaced'.length));
|
||||||
|
testing.expectEqual('', cdata.substringData('OK'.length-1, 0));
|
||||||
|
</script>
|
||||||
8
src/tests/dom/comment.html
Normal file
8
src/tests/dom/comment.html
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<script src="../testing.js"></script>
|
||||||
|
<script id=comment>
|
||||||
|
let comment = new Comment('foo');
|
||||||
|
testing.expectEqual('foo', comment.data);
|
||||||
|
|
||||||
|
let empty = new Comment()
|
||||||
|
testing.expectEqual('', empty.data);
|
||||||
|
</script>
|
||||||
169
src/tests/dom/document.html
Normal file
169
src/tests/dom/document.html
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
<script src="../testing.js"></script>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
<a id="a1" href="foo" class="ok">OK</a>
|
||||||
|
<p id="p1" class="ok empty">
|
||||||
|
<span id="s1"></span>
|
||||||
|
</p>
|
||||||
|
<p id="p2"> And</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script id=document>
|
||||||
|
testing.expectEqual('Document', document.__proto__.__proto__.constructor.name);
|
||||||
|
testing.expectEqual('Node', document.__proto__.__proto__.__proto__.constructor.name);
|
||||||
|
testing.expectEqual('EventTarget', document.__proto__.__proto__.__proto__.__proto__.constructor.name);
|
||||||
|
|
||||||
|
let newdoc = new Document();
|
||||||
|
testing.expectEqual(null, newdoc.documentElement);
|
||||||
|
testing.expectEqual(0, newdoc.children.length);
|
||||||
|
testing.expectEqual(0, newdoc.getElementsByTagName('*').length);
|
||||||
|
testing.expectEqual(null, newdoc.getElementsByTagName('*').item(0));
|
||||||
|
testing.expectEqual(true, newdoc.inputEncoding === document.inputEncoding);
|
||||||
|
testing.expectEqual(true, newdoc.documentURI === document.documentURI);
|
||||||
|
testing.expectEqual(true, newdoc.URL === document.URL);
|
||||||
|
testing.expectEqual(true, newdoc.compatMode === document.compatMode);
|
||||||
|
testing.expectEqual(true, newdoc.characterSet === document.characterSet);
|
||||||
|
testing.expectEqual(true, newdoc.charset === document.charset);
|
||||||
|
testing.expectEqual(true, newdoc.contentType === document.contentType);
|
||||||
|
|
||||||
|
testing.expectEqual('HTML', document.documentElement.tagName);
|
||||||
|
|
||||||
|
testing.expectEqual('UTF-8', document.characterSet);
|
||||||
|
testing.expectEqual('UTF-8', document.charset);
|
||||||
|
testing.expectEqual('UTF-8', document.inputEncoding);
|
||||||
|
testing.expectEqual('CSS1Compat', document.compatMode);
|
||||||
|
testing.expectEqual('text/html', document.contentType);
|
||||||
|
|
||||||
|
testing.expectEqual('http://localhost:9582/src/tests/dom/document.html', document.documentURI);
|
||||||
|
testing.expectEqual('http://localhost:9582/src/tests/dom/document.html', document.URL);
|
||||||
|
|
||||||
|
testing.expectEqual(document.body, document.activeElement);
|
||||||
|
|
||||||
|
$('#a1').focus();
|
||||||
|
testing.expectEqual($('#a1'), document.activeElement);
|
||||||
|
|
||||||
|
testing.expectEqual(0, document.styleSheets.length);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=getElementById>
|
||||||
|
let divById = document.getElementById('content');
|
||||||
|
testing.expectEqual('HTMLDivElement', divById.constructor.name);
|
||||||
|
testing.expectEqual('div', divById.localName);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=getElementsByTagName>
|
||||||
|
let byTagName = document.getElementsByTagName('p');
|
||||||
|
testing.expectEqual(2, byTagName.length)
|
||||||
|
testing.expectEqual('p1', byTagName.item(0).id);
|
||||||
|
testing.expectEqual('p2', byTagName.item(1).id);
|
||||||
|
|
||||||
|
let byTagNameAll = document.getElementsByTagName('*');
|
||||||
|
// If you add a script block (or change the HTML in any other way on this
|
||||||
|
// page), this test will break. Adjust it accordingly.
|
||||||
|
testing.expectEqual(20, byTagNameAll.length);
|
||||||
|
testing.expectEqual('html', byTagNameAll.item(0).localName);
|
||||||
|
testing.expectEqual('SCRIPT', byTagNameAll.item(11).tagName);
|
||||||
|
|
||||||
|
testing.expectEqual('s1', byTagNameAll.namedItem('s1').id);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=getElementByClassName>
|
||||||
|
let ok = document.getElementsByClassName('ok');
|
||||||
|
testing.expectEqual(2, ok.length);
|
||||||
|
|
||||||
|
let empty = document.getElementsByClassName('empty');
|
||||||
|
testing.expectEqual(1, empty.length);
|
||||||
|
|
||||||
|
let emptyok = document.getElementsByClassName('empty ok');
|
||||||
|
testing.expectEqual(1, emptyok.length);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=createXYZ>
|
||||||
|
var v = document.createDocumentFragment();
|
||||||
|
testing.expectEqual('#document-fragment', v.nodeName);
|
||||||
|
|
||||||
|
v = document.createTextNode('foo');
|
||||||
|
testing.expectEqual('#text', v.nodeName);
|
||||||
|
|
||||||
|
v = document.createCDATASection('foo');
|
||||||
|
testing.expectEqual('#cdata-section', v.nodeName);
|
||||||
|
|
||||||
|
v = document.createAttribute('foo');
|
||||||
|
testing.expectEqual('foo', v.nodeName);
|
||||||
|
|
||||||
|
v = document.createComment('foo');
|
||||||
|
testing.expectEqual('#comment', v.nodeName);
|
||||||
|
v.cloneNode(); // doesn't crash, (I guess that's the point??)
|
||||||
|
|
||||||
|
let pi = document.createProcessingInstruction('foo', 'bar')
|
||||||
|
testing.expectEqual('foo', pi.target);
|
||||||
|
pi.cloneNode(); // doesn't crash (I guess that's the point??)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=importNode>
|
||||||
|
let nimp = document.getElementById('content');
|
||||||
|
var v = document.importNode(nimp);
|
||||||
|
testing.expectEqual('DIV', v.nodeName);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=children>
|
||||||
|
testing.expectEqual(1, document.children.length);
|
||||||
|
testing.expectEqual('HTML', document.children.item(0).nodeName);
|
||||||
|
testing.expectEqual('HTML', document.firstElementChild.nodeName);
|
||||||
|
testing.expectEqual('HTML', document.lastElementChild.nodeName);
|
||||||
|
testing.expectEqual(1, document.childElementCount);
|
||||||
|
|
||||||
|
let nd = new Document();
|
||||||
|
testing.expectEqual(0, nd.children.length);
|
||||||
|
testing.expectEqual(null, nd.children.item(0));
|
||||||
|
testing.expectEqual(null, nd.firstElementChild);
|
||||||
|
testing.expectEqual(null, nd.lastElementChild);
|
||||||
|
testing.expectEqual(0, nd.childElementCount);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=createElement>
|
||||||
|
let emptydoc = document.createElement('html');
|
||||||
|
emptydoc.prepend(document.createElement('html'));
|
||||||
|
|
||||||
|
let emptydoc2 = document.createElement('html');
|
||||||
|
emptydoc2.append(document.createElement('html'));
|
||||||
|
|
||||||
|
// Not sure what the above are testing, I just copied and pasted them.
|
||||||
|
// Maybe that something doesn't crash?
|
||||||
|
// Adding this so that the test runner doesn't complain;
|
||||||
|
testing.skip();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=querySelector>
|
||||||
|
testing.expectEqual(null, document.querySelector(''));
|
||||||
|
testing.expectEqual('HTML', document.querySelector('*').nodeName);
|
||||||
|
testing.expectEqual('content', document.querySelector('#content').id);
|
||||||
|
testing.expectEqual('p1', document.querySelector('#p1').id);
|
||||||
|
testing.expectEqual('a1', document.querySelector('.ok').id);
|
||||||
|
testing.expectEqual('p1', document.querySelector('a ~ p').id);
|
||||||
|
testing.expectEqual('HTML', document.querySelector(':root').nodeName);
|
||||||
|
|
||||||
|
testing.expectEqual(2, document.querySelectorAll('p').length);
|
||||||
|
|
||||||
|
testing.expectEqual([''],
|
||||||
|
Array.from(document.querySelectorAll('#content > p#p1'))
|
||||||
|
.map(row => row.querySelector('span').textContent)
|
||||||
|
);
|
||||||
|
|
||||||
|
testing.expectEqual(0, document.querySelectorAll('.\\:popover-open').length);
|
||||||
|
testing.expectEqual(0, document.querySelectorAll('.foo\\:bar').length);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=adoptNode>
|
||||||
|
// this test breaks the doc structure, keep it at the end
|
||||||
|
let nadop = document.getElementById('content')
|
||||||
|
var v = document.adoptNode(nadop);
|
||||||
|
testing.expectEqual('DIV', v.nodeName);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=adoptedStyleSheets>
|
||||||
|
const acss = document.adoptedStyleSheets;
|
||||||
|
testing.expectEqual(0, acss.length);
|
||||||
|
acss.push(new CSSStyleSheet());
|
||||||
|
testing.expectEqual(1, acss.length);
|
||||||
|
</script>
|
||||||
@@ -42,6 +42,10 @@
|
|||||||
expectEqual('an error', null);
|
expectEqual('an error', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function skip() {
|
||||||
|
_recordExecution();
|
||||||
|
}
|
||||||
|
|
||||||
// Should only be called by the test runner
|
// Should only be called by the test runner
|
||||||
function getStatus() {
|
function getStatus() {
|
||||||
// if we're already in a fail state, return fail, nothing can recover this
|
// if we're already in a fail state, return fail, nothing can recover this
|
||||||
@@ -156,6 +160,7 @@
|
|||||||
_eventually: [],
|
_eventually: [],
|
||||||
_executed_scripts: {},
|
_executed_scripts: {},
|
||||||
_captured: null,
|
_captured: null,
|
||||||
|
skip: skip,
|
||||||
getStatus: getStatus,
|
getStatus: getStatus,
|
||||||
eventually: eventually,
|
eventually: eventually,
|
||||||
expectEqual: expectEqual,
|
expectEqual: expectEqual,
|
||||||
|
|||||||
Reference in New Issue
Block a user