From ede35718ae437c8b321df5c1a8dce3f72517e73b Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 11 Sep 2025 12:07:17 +0800 Subject: [PATCH] migrate more tests to htmlRunner --- src/browser/html/AbortController.zig | 42 +-- src/browser/html/DataSet.zig | 20 +- src/browser/html/document.zig | 113 +----- src/browser/html/elements.zig | 333 +----------------- src/browser/html/history.zig | 31 +- src/browser/html/location.zig | 18 +- src/browser/html/navigator.zig | 14 +- src/browser/html/select.zig | 78 +--- src/browser/html/svg_elements.zig | 9 +- src/tests/html/abort_controller.html | 40 +++ src/tests/html/dataset.html | 29 ++ src/tests/html/document.html | 84 +++++ src/tests/html/element.html | 52 +++ src/tests/html/error_event.html | 5 - src/tests/html/history.html | 23 ++ src/tests/html/image.html | 31 ++ src/tests/html/input.html | 110 ++++++ src/tests/html/link.html | 59 ++++ src/tests/html/location.html | 14 + src/tests/html/navigator.html | 7 + src/tests/html/script/script.html | 14 + src/tests/html/select.html | 74 ++++ .../{html_slot_element.html => slot.html} | 0 src/tests/html/style.html | 7 + src/tests/html/svg.html | 5 + src/tests/html/template.html | 21 ++ 26 files changed, 602 insertions(+), 631 deletions(-) create mode 100644 src/tests/html/abort_controller.html create mode 100644 src/tests/html/dataset.html create mode 100644 src/tests/html/document.html create mode 100644 src/tests/html/element.html create mode 100644 src/tests/html/history.html create mode 100644 src/tests/html/image.html create mode 100644 src/tests/html/input.html create mode 100644 src/tests/html/link.html create mode 100644 src/tests/html/location.html create mode 100644 src/tests/html/navigator.html create mode 100644 src/tests/html/script/script.html create mode 100644 src/tests/html/select.html rename src/tests/html/{html_slot_element.html => slot.html} (100%) create mode 100644 src/tests/html/style.html create mode 100644 src/tests/html/svg.html create mode 100644 src/tests/html/template.html diff --git a/src/browser/html/AbortController.zig b/src/browser/html/AbortController.zig index aa1dbaea..ff1a3cbd 100644 --- a/src/browser/html/AbortController.zig +++ b/src/browser/html/AbortController.zig @@ -138,44 +138,6 @@ const TimeoutCallback = struct { }; const testing = @import("../../testing.zig"); -test "Browser.HTML.AbortController" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "var called = 0", null }, - .{ "var a1 = new AbortController()", null }, - .{ "var s1 = a1.signal", null }, - .{ "s1.throwIfAborted()", "undefined" }, - .{ "s1.reason", "undefined" }, - .{ "var target;", null }, - .{ - \\ s1.addEventListener('abort', (e) => { - \\ called += 1; - \\ target = e.target; - \\ - \\ }); - , - null, - }, - .{ "a1.abort()", null }, - .{ "s1.aborted", "true" }, - .{ "target == s1", "true" }, - .{ "s1.reason", "AbortError" }, - .{ "called", "1" }, - }, .{}); - - try runner.testCases(&.{ - .{ "var s2 = AbortSignal.abort('over 9000')", null }, - .{ "s2.aborted", "true" }, - .{ "s2.reason", "over 9000" }, - .{ "AbortSignal.abort().reason", "AbortError" }, - }, .{}); - - try runner.testCases(&.{ - .{ "var s3 = AbortSignal.timeout(10)", null }, - .{ "s3.aborted", "true" }, - .{ "s3.reason", "TimeoutError" }, - .{ "try { s3.throwIfAborted() } catch (e) { e }", "Error: TimeoutError" }, - }, .{}); +test "Browser: HTML.AbortController" { + try testing.htmlRunner("html/abort_controller.html"); } diff --git a/src/browser/html/DataSet.zig b/src/browser/html/DataSet.zig index 3c5a24e4..e5365733 100644 --- a/src/browser/html/DataSet.zig +++ b/src/browser/html/DataSet.zig @@ -76,22 +76,6 @@ fn normalize(allocator: Allocator, name: []const u8) ![]const u8 { } const testing = @import("../../testing.zig"); -test "Browser.HTML.DataSet" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "" }); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "let el1 = document.createElement('div')", null }, - .{ "el1.dataset.x", "undefined" }, - .{ "el1.dataset.x = '123'", "123" }, - .{ "delete el1.dataset.x", "true" }, - .{ "el1.dataset.x", "undefined" }, - .{ "delete el1.dataset.other", "true" }, // yes, this is right - - .{ "let ds1 = el1.dataset", null }, - .{ "ds1.helloWorld = 'yes'", null }, - .{ "el1.getAttribute('data-hello-world')", "yes" }, - .{ "el1.setAttribute('data-this-will-work', 'positive')", null }, - .{ "ds1.thisWillWork", "positive" }, - }, .{}); +test "Browser: HTML.DataSet" { + try testing.htmlRunner("html/dataset.html"); } diff --git a/src/browser/html/document.zig b/src/browser/html/document.zig index 2920d09c..55b94ed6 100644 --- a/src/browser/html/document.zig +++ b/src/browser/html/document.zig @@ -314,116 +314,7 @@ pub const HTMLDocument = struct { } }; -// Tests -// ----- - const testing = @import("../../testing.zig"); - -test "Browser.HTML.Document" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "document.__proto__.constructor.name", "HTMLDocument" }, - .{ "document.__proto__.__proto__.constructor.name", "Document" }, - .{ "document.body.localName == 'body'", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.domain", "lightpanda.io" }, - .{ "document.referrer", "" }, - .{ "document.title", "" }, - .{ "document.body.localName", "body" }, - .{ "document.head.localName", "head" }, - .{ "document.images.length", "0" }, - .{ "document.embeds.length", "0" }, - .{ "document.plugins.length", "0" }, - .{ "document.scripts.length", "0" }, - .{ "document.forms.length", "0" }, - .{ "document.links.length", "1" }, - .{ "document.applets.length", "0" }, - .{ "document.anchors.length", "0" }, - .{ "document.all.length", "8" }, - .{ "document.currentScript", "null" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.title = 'foo'", "foo" }, - .{ "document.title", "foo" }, - .{ "document.title = ''", "" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.getElementById('link').setAttribute('name', 'foo')", "undefined" }, - .{ "let list = document.getElementsByName('foo')", "undefined" }, - .{ "list.length", "1" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.cookie", "" }, - .{ "document.cookie = 'name=Oeschger; SameSite=None; Secure'", "name=Oeschger; SameSite=None; Secure" }, - .{ "document.cookie = 'favorite_food=tripe; SameSite=None; Secure'", "favorite_food=tripe; SameSite=None; Secure" }, - .{ "document.cookie", "name=Oeschger; favorite_food=tripe" }, - .{ "document.cookie = 'IgnoreMy=Ghost; HttpOnly'", null }, // "" should be returned, but the framework overrules it atm - .{ "document.cookie", "name=Oeschger; favorite_food=tripe" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.elementFromPoint(0.5, 0.5)", "null" }, // Return null since we only return element s when they have previously been localized - .{ "document.elementsFromPoint(0.5, 0.5)", "" }, - .{ - \\ let div1 = document.createElement('div'); - \\ document.body.appendChild(div1); - \\ div1.getClientRects(); - , - null, - }, - .{ "document.elementFromPoint(0.5, 0.5)", "[object HTMLDivElement]" }, - .{ "let elems = document.elementsFromPoint(0.5, 0.5)", null }, - .{ "elems.length", "3" }, - .{ "elems[0]", "[object HTMLDivElement]" }, - .{ "elems[1]", "[object HTMLBodyElement]" }, - .{ "elems[2]", "[object HTMLHtmlElement]" }, - }, .{}); - - try runner.testCases(&.{ - .{ - \\ let a = document.createElement('a'); - \\ a.href = "https://lightpanda.io"; - \\ document.body.appendChild(a); - \\ a.getClientRects(); - , // Note this will be placed after the div of previous test - null, - }, - .{ "let a_again = document.elementFromPoint(1.5, 0.5)", null }, - .{ "a_again", "[object HTMLAnchorElement]" }, - .{ "a_again.href", "https://lightpanda.io" }, - .{ "let a_agains = document.elementsFromPoint(1.5, 0.5)", null }, - .{ "a_agains[0].href", "https://lightpanda.io" }, - }, .{}); - - try runner.testCases(&.{ - .{ "!document.all", "true" }, - .{ "!!document.all", "false" }, - .{ "document.all(5)", "[object HTMLParagraphElement]" }, - .{ "document.all('content')", "[object HTMLDivElement]" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.defaultView.document == document", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.readyState", "loading" }, - }, .{}); - - try HTMLDocument.documentIsLoaded(runner.page.window.document, runner.page); - try runner.testCases(&.{ - .{ "document.readyState", "interactive" }, - }, .{}); - - try HTMLDocument.documentIsComplete(runner.page.window.document, runner.page); - try runner.testCases(&.{ - .{ "document.readyState", "complete" }, - }, .{}); +test "Browser: HTML.Document" { + try testing.htmlRunner("html/document.html"); } diff --git a/src/browser/html/elements.zig b/src/browser/html/elements.zig index e1820571..c8c98c31 100644 --- a/src/browser/html/elements.zig +++ b/src/browser/html/elements.zig @@ -1285,336 +1285,35 @@ pub fn toInterfaceFromTag(comptime T: type, e: *parser.Element, tag: parser.Tag) } const testing = @import("../../testing.zig"); -test "Browser.HTML.Element" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "let link = document.getElementById('link')", "undefined" }, - .{ "link.target", "" }, - .{ "link.target = '_blank'", "_blank" }, - .{ "link.target", "_blank" }, - .{ "link.target = ''", "" }, - - .{ "link.href", "foo" }, - .{ "link.href = 'https://lightpanda.io/'", "https://lightpanda.io/" }, - .{ "link.href", "https://lightpanda.io/" }, - - .{ "link.origin", "https://lightpanda.io" }, - - .{ "link.host = 'lightpanda.io:443'", "lightpanda.io:443" }, - .{ "link.host", "lightpanda.io:443" }, - .{ "link.port", "443" }, - .{ "link.hostname", "lightpanda.io" }, - - .{ "link.host = 'lightpanda.io'", "lightpanda.io" }, - .{ "link.host", "lightpanda.io" }, - .{ "link.port", "" }, - .{ "link.hostname", "lightpanda.io" }, - - .{ "link.host", "lightpanda.io" }, - .{ "link.hostname", "lightpanda.io" }, - .{ "link.hostname = 'foo.bar'", "foo.bar" }, - .{ "link.href", "https://foo.bar/" }, - - .{ "link.search", "" }, - .{ "link.search = 'q=bar'", "q=bar" }, - .{ "link.search", "?q=bar" }, - .{ "link.href", "https://foo.bar/?q=bar" }, - - .{ "link.hash", "" }, - .{ "link.hash = 'frag'", "frag" }, - .{ "link.hash", "#frag" }, - .{ "link.href", "https://foo.bar/?q=bar#frag" }, - - .{ "link.port", "" }, - .{ "link.port = '443'", "443" }, - .{ "link.host", "foo.bar:443" }, - .{ "link.hostname", "foo.bar" }, - .{ "link.href", "https://foo.bar:443/?q=bar#frag" }, - .{ "link.port = null", "null" }, - .{ "link.href", "https://foo.bar/?q=bar#frag" }, - - .{ "link.href = 'foo'", "foo" }, - - .{ "link.type", "" }, - .{ "link.type = 'text/html'", "text/html" }, - .{ "link.type", "text/html" }, - .{ "link.type = ''", "" }, - - .{ "link.text", "OK" }, - .{ "link.text = 'foo'", "foo" }, - .{ "link.text", "foo" }, - .{ "link.text = 'OK'", "OK" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let script = document.createElement('script')", "undefined" }, - .{ "script.src = 'foo.bar'", "foo.bar" }, - - .{ "script.async = true", "true" }, - .{ "script.async", "true" }, - .{ "script.async = false", "false" }, - .{ "script.async", "false" }, - }, .{}); - - try runner.testCases(&.{ - .{ "const backup = document.getElementById('content')", "undefined" }, - .{ "document.getElementById('content').innerText = 'foo';", "foo" }, - .{ "document.getElementById('content').innerText", "foo" }, - .{ "document.getElementById('content').innerHTML = backup; true;", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let click_count = 0;", "undefined" }, - .{ "let clickCbk = function() { click_count++ }", "undefined" }, - .{ "document.getElementById('content').addEventListener('click', clickCbk);", "undefined" }, - .{ "document.getElementById('content').click()", "undefined" }, - .{ "click_count", "1" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let style = document.getElementById('content').style", "undefined" }, - .{ "style.cssText = 'color: red; font-size: 12px; margin: 5px !important;'", "color: red; font-size: 12px; margin: 5px !important;" }, - .{ "style.length", "3" }, - .{ "style.setProperty('background-color', 'blue')", "undefined" }, - .{ "style.getPropertyValue('background-color')", "blue" }, - .{ "style.length", "4" }, - }, .{}); - - // Image - try runner.testCases(&.{ - // Testing constructors - .{ "(new Image).width", "0" }, - .{ "(new Image).height", "0" }, - .{ "(new Image(4)).width", "4" }, - .{ "(new Image(4, 6)).height", "6" }, - - // Testing ulong property - .{ "let fruit = new Image", null }, - .{ "fruit.width", "0" }, - .{ "fruit.width = 5", "5" }, - .{ "fruit.width", "5" }, - .{ "fruit.width = '15'", "15" }, - .{ "fruit.width", "15" }, - .{ "fruit.width = 'apple'", "apple" }, - .{ "fruit.width;", "0" }, - - // Testing string property - .{ "let lyric = new Image", null }, - .{ "lyric.src", "" }, - .{ "lyric.src = 'okay'", "okay" }, - .{ "lyric.src", "okay" }, - .{ "lyric.src = 15", "15" }, - .{ "lyric.src", "15" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let a = document.createElement('a');", null }, - .{ "a.href", "" }, - .{ "a.host", "" }, - .{ "a.href = 'about'", null }, - .{ "a.href", "https://lightpanda.io/opensource-browser/about" }, - }, .{}); - - // detached node cannot be focused - try runner.testCases(&.{ - .{ "const focused = document.activeElement", null }, - .{ "document.createElement('a').focus()", null }, - .{ "document.activeElement === focused", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let l2 = document.createElement('link');", null }, - .{ "l2.href", "" }, - .{ "l2.href = 'https://lightpanda.io/opensource-browser/15'", null }, - .{ "l2.href", "https://lightpanda.io/opensource-browser/15" }, - - .{ "l2.href = '/over/9000'", null }, - .{ "l2.href", "https://lightpanda.io/over/9000" }, - }, .{}); +test "Browser: HTML.Element" { + try testing.htmlRunner("html/element.html"); } -test "Browser.HTML.Element.DataSet" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "
" }); - defer runner.deinit(); - - try runner.testCases(&.{ .{ "let div = document.getElementById('x')", null }, .{ "div.dataset.nope", "undefined" }, .{ "div.dataset.power", "over 9000" }, .{ "div.dataset.empty", "" }, .{ "div.dataset.someLongKey", "ok" }, .{ "delete div.dataset.power", "true" }, .{ "div.dataset.power", "undefined" } }, .{}); +test "Browser: HTML.HtmlLinkElement" { + try testing.htmlRunner("html/link.html"); } -test "Browser.HTML.HtmlInputElement.properties" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .url = "https://lightpanda.io/noslashattheend" }); - defer runner.deinit(); - var alloc = std.heap.ArenaAllocator.init(runner.allocator); - defer alloc.deinit(); - const arena = alloc.allocator(); - - try runner.testCases(&.{.{ "let elem_input = document.createElement('input')", null }}, .{}); - - try runner.testCases(&.{.{ "elem_input.form", "null" }}, .{}); // Initial value - // Valid input.form is tested separately :Browser.HTML.HtmlInputElement.propeties.form - try testProperty(arena, &runner, "elem_input.form", "null", &.{.{ .input = "'foo'" }}); // Invalid - - try runner.testCases(&.{.{ "elem_input.accept", "" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.accept", null, &str_valids); // Valid - - try runner.testCases(&.{.{ "elem_input.alt", "" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.alt", null, &str_valids); // Valid - - try runner.testCases(&.{.{ "elem_input.disabled", "false" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.disabled", null, &bool_valids); // Valid - - try runner.testCases(&.{.{ "elem_input.maxLength", "-1" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.maxLength", null, &.{.{ .input = "5" }}); // Valid - try testProperty(arena, &runner, "elem_input.maxLength", "0", &.{.{ .input = "'banana'" }}); // Invalid - try runner.testCases(&.{.{ "try { elem_input.maxLength = -45 } catch(e) {e}", "Error: NegativeValueNotAllowed" }}, .{}); // Error - - try runner.testCases(&.{.{ "elem_input.name", "" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.name", null, &str_valids); // Valid - - try runner.testCases(&.{.{ "elem_input.readOnly", "false" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.readOnly", null, &bool_valids); // Valid - - try runner.testCases(&.{.{ "elem_input.size", "20" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.size", null, &.{.{ .input = "5" }}); // Valid - try testProperty(arena, &runner, "elem_input.size", "20", &.{.{ .input = "-26" }}); // Invalid - try runner.testCases(&.{.{ "try { elem_input.size = 0 } catch(e) {e}", "Error: ZeroNotAllowed" }}, .{}); // Error - try runner.testCases(&.{.{ "try { elem_input.size = 'banana' } catch(e) {e}", "Error: ZeroNotAllowed" }}, .{}); // Error - - try runner.testCases(&.{.{ "elem_input.src", "" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.src", null, &.{ - .{ .input = "'foo'", .expected = "https://lightpanda.io/foo" }, // TODO stitch should work with spaces -> %20 - .{ .input = "-3", .expected = "https://lightpanda.io/-3" }, - .{ .input = "''", .expected = "https://lightpanda.io/noslashattheend" }, - }); - - try runner.testCases(&.{.{ "elem_input.type", "text" }}, .{}); // Initial value - try testProperty(arena, &runner, "elem_input.type", null, &.{.{ .input = "'checkbox'", .expected = "checkbox" }}); // Valid - try testProperty(arena, &runner, "elem_input.type", "text", &.{.{ .input = "'5'" }}); // Invalid - - // Properties that are related - try runner.testCases(&.{ - .{ "let input_checked = document.createElement('input')", null }, - .{ "input_checked.defaultChecked", "false" }, - .{ "input_checked.checked", "false" }, - - .{ "input_checked.defaultChecked = true", "true" }, - .{ "input_checked.defaultChecked", "true" }, - .{ "input_checked.checked", "true" }, // Also perceived as true - - .{ "input_checked.checked = false", "false" }, - .{ "input_checked.defaultChecked", "true" }, - .{ "input_checked.checked", "false" }, - - .{ "input_checked.defaultChecked = true", "true" }, - .{ "input_checked.checked", "false" }, // Still false - }, .{}); - try runner.testCases(&.{ - .{ "let input_value = document.createElement('input')", null }, - .{ "input_value.defaultValue", "" }, - .{ "input_value.value", "" }, - - .{ "input_value.defaultValue = 3.1", "3.1" }, - .{ "input_value.defaultValue", "3.1" }, - .{ "input_value.value", "3.1" }, // Also perceived as 3.1 - - .{ "input_value.value = 'mango'", "mango" }, - .{ "input_value.defaultValue", "3.1" }, - .{ "input_value.value", "mango" }, - - .{ "input_value.defaultValue = true", "true" }, - .{ "input_value.value", "mango" }, // Still mango - }, .{}); +test "Browser: HTML.HtmlImageElement" { + try testing.htmlRunner("html/image.html"); } -test "Browser.HTML.HtmlInputElement.properties.form" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = - \\
- \\

- \\ - \\

- \\
- }); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "let elem_input = document.querySelector('input')", null }, - .{ "elem_input.form", "[object HTMLFormElement]" }, // Initial value - .{ "elem_input.form = 'foo'", null }, - .{ "elem_input.form", "[object HTMLFormElement]" }, // Invalid - }, .{}); +test "Browser: HTML.HtmlInputElement" { + try testing.htmlRunner("html/input.html"); } -test "Browser.HTML.HTMLTemplateElement" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "
" }); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "let t = document.createElement('template')", null }, - .{ "let d = document.createElement('div')", null }, - .{ "d.id = 'abc'", null }, - .{ "t.content.append(d)", null }, - .{ "document.getElementById('abc')", "null" }, - .{ "document.getElementById('c').appendChild(t.content.cloneNode(true))", null }, - .{ "document.getElementById('abc').id", "abc" }, - .{ "t.innerHTML = 'over

9000!

';", null }, - .{ "t.content.childNodes.length", "2" }, - .{ "t.content.childNodes[0].tagName", "SPAN" }, - .{ "t.content.childNodes[0].innerHTML", "over" }, - .{ "t.content.childNodes[1].tagName", "P" }, - .{ "t.content.childNodes[1].innerHTML", "9000!" }, - }, .{}); +test "Browser: HTML.HtmlTemplateElement" { + try testing.htmlRunner("html/template.html"); } -test "Browser.HTML.HTMLStyleElement" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "" }); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "let s = document.createElement('style')", null }, - .{ "s.sheet.type", "text/css" }, - .{ "s.sheet == s.sheet", "true" }, - .{ "document.createElement('style').sheet == s.sheet", "false" }, - }, .{}); +test "Browser: HTML.HtmlStyleElement" { + try testing.htmlRunner("html/style.html"); } -test "Browser: HTML.HTMLScriptElement" { +test "Browser: HTML.HtmlScriptElement" { + try testing.htmlRunner("html/script/script.html"); try testing.htmlRunner("html/script/inline_defer.html"); } -test "Browser: HTML.HTMLSlotElement" { - try testing.htmlRunner("html/html_slot_element.html"); -} - -const Check = struct { - input: []const u8, - expected: ?[]const u8 = null, // Needed when input != expected -}; -const bool_valids = [_]Check{ - .{ .input = "true" }, - .{ .input = "''", .expected = "false" }, - .{ .input = "13.5", .expected = "true" }, -}; -const str_valids = [_]Check{ - .{ .input = "'foo'", .expected = "foo" }, - .{ .input = "5", .expected = "5" }, - .{ .input = "''", .expected = "" }, - .{ .input = "document", .expected = "[object HTMLDocument]" }, -}; - -// .{ "elem.type = '5'", "5" }, -// .{ "elem.type", "text" }, -fn testProperty( - arena: std.mem.Allocator, - runner: *testing.JsRunner, - elem_dot_prop: []const u8, - always: ?[]const u8, // Ignores checks' expected if set - checks: []const Check, -) !void { - for (checks) |check| { - try runner.testCases(&.{ - .{ try std.mem.concat(arena, u8, &.{ elem_dot_prop, " = ", check.input }), null }, - .{ elem_dot_prop, always orelse check.expected orelse check.input }, - }, .{}); - } +test "Browser: HTML.HtmlSlotElement" { + try testing.htmlRunner("html/slot.html"); } diff --git a/src/browser/html/history.zig b/src/browser/html/history.zig index 592d26fd..e7d6726b 100644 --- a/src/browser/html/history.zig +++ b/src/browser/html/history.zig @@ -87,34 +87,7 @@ pub const History = struct { } }; -// Tests -// ----- - const testing = @import("../../testing.zig"); -test "Browser.HTML.History" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "history.scrollRestoration", "auto" }, - .{ "history.scrollRestoration = 'manual'", "manual" }, - .{ "history.scrollRestoration = 'foo'", "foo" }, - .{ "history.scrollRestoration", "manual" }, - .{ "history.scrollRestoration = 'auto'", "auto" }, - .{ "history.scrollRestoration", "auto" }, - - .{ "history.state", "null" }, - - .{ "history.pushState({}, null, '')", "undefined" }, - - .{ "history.replaceState({}, null, '')", "undefined" }, - - .{ "history.go()", "undefined" }, - .{ "history.go(1)", "undefined" }, - .{ "history.go(-1)", "undefined" }, - - .{ "history.forward()", "undefined" }, - - .{ "history.back()", "undefined" }, - }, .{}); +test "Browser: HTML.History" { + try testing.htmlRunner("html/history.html"); } diff --git a/src/browser/html/location.zig b/src/browser/html/location.zig index 31904db6..99b1e93c 100644 --- a/src/browser/html/location.zig +++ b/src/browser/html/location.zig @@ -87,20 +87,6 @@ pub const Location = struct { }; const testing = @import("../../testing.zig"); -test "Browser.HTML.Location" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "location.href", "https://lightpanda.io/opensource-browser/" }, - .{ "document.location.href", "https://lightpanda.io/opensource-browser/" }, - - .{ "location.host", "lightpanda.io" }, - .{ "location.hostname", "lightpanda.io" }, - .{ "location.origin", "https://lightpanda.io" }, - .{ "location.pathname", "/opensource-browser/" }, - .{ "location.hash", "" }, - .{ "location.port", "" }, - .{ "location.search", "" }, - }, .{}); +test "Browser: HTML.Location" { + try testing.htmlRunner("html/location.html"); } diff --git a/src/browser/html/navigator.zig b/src/browser/html/navigator.zig index e09f6f1a..448db057 100644 --- a/src/browser/html/navigator.zig +++ b/src/browser/html/navigator.zig @@ -80,17 +80,7 @@ pub const Navigator = struct { } }; -// Tests -// ----- - const testing = @import("../../testing.zig"); -test "Browser.HTML.Navigator" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "navigator.userAgent", "Lightpanda/1.0" }, - .{ "navigator.appVersion", "1.0" }, - .{ "navigator.language", "en-US" }, - }, .{}); +test "Browser: HTML.Navigator" { + try testing.htmlRunner("html/navigator.html"); } diff --git a/src/browser/html/select.zig b/src/browser/html/select.zig index aaf90caa..ddca9e22 100644 --- a/src/browser/html/select.zig +++ b/src/browser/html/select.zig @@ -199,80 +199,6 @@ pub const HTMLOptionsCollection = struct { }; const testing = @import("../../testing.zig"); -test "Browser.HTML.Select" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = - \\
- \\ - \\
- \\ - }); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "const s = document.getElementById('s1');", null }, - .{ "s.form", "[object HTMLFormElement]" }, - - .{ "document.getElementById('s2').form", "null" }, - - .{ "s.disabled", "false" }, - .{ "s.disabled = true", null }, - .{ "s.disabled", "true" }, - .{ "s.disabled = false", null }, - .{ "s.disabled", "false" }, - - .{ "s.multiple", "false" }, - .{ "s.multiple = true", null }, - .{ "s.multiple", "true" }, - .{ "s.multiple = false", null }, - .{ "s.multiple", "false" }, - - .{ "s.name;", "s1" }, - .{ "s.name = 'sel1';", null }, - .{ "s.name", "sel1" }, - - .{ "s.length;", "2" }, - - .{ "s.selectedIndex", "0" }, - .{ "s.selectedIndex = 2", null }, // out of range - .{ "s.selectedIndex", "-1" }, - - .{ "s.selectedIndex = -1", null }, - .{ "s.selectedIndex", "-1" }, - - .{ "s.selectedIndex = 0", null }, - .{ "s.selectedIndex", "0" }, - - .{ "s.selectedIndex = 1", null }, - .{ "s.selectedIndex", "1" }, - - .{ "s.selectedIndex = -323", null }, - .{ "s.selectedIndex", "-1" }, - - .{ "let options = s.options", null }, - .{ "options.length", "2" }, - .{ "options.item(1).value", "o2" }, - .{ "options.selectedIndex", "-1" }, - - .{ "let o3 = document.createElement('option');", null }, - .{ "o3.value = 'o3';", null }, - .{ "options.add(o3)", null }, - .{ "options.length", "3" }, - .{ "options.item(2).value", "o3" }, - - .{ "let o4 = document.createElement('option');", null }, - .{ "o4.value = 'o4';", null }, - .{ "options.add(o4, 1)", null }, - .{ "options.length", "4" }, - .{ "options.item(1).value", "o4" }, - - .{ "let o5 = document.createElement('option');", null }, - .{ "o5.value = 'o5';", null }, - .{ "options.add(o5, o3)", null }, - .{ "options.length", "5" }, - .{ "options.item(3).value", "o5" }, - - .{ "options.remove(3)", null }, - .{ "options.length", "4" }, - .{ "options.item(3).value", "o3" }, - }, .{}); +test "Browser: HTML.Select" { + try testing.htmlRunner("html/select.html"); } diff --git a/src/browser/html/svg_elements.zig b/src/browser/html/svg_elements.zig index 867256d0..7c2d1964 100644 --- a/src/browser/html/svg_elements.zig +++ b/src/browser/html/svg_elements.zig @@ -31,11 +31,6 @@ pub const SVGElement = struct { }; const testing = @import("../../testing.zig"); -test "Browser.HTML.SVGElement" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "'AString' instanceof SVGElement", "false" }, - }, .{}); +test "Browser: HTML.SVGElement" { + try testing.htmlRunner("html/svg.html"); } diff --git a/src/tests/html/abort_controller.html b/src/tests/html/abort_controller.html new file mode 100644 index 00000000..81e0655f --- /dev/null +++ b/src/tests/html/abort_controller.html @@ -0,0 +1,40 @@ + + + + + + + diff --git a/src/tests/html/dataset.html b/src/tests/html/dataset.html new file mode 100644 index 00000000..e972da70 --- /dev/null +++ b/src/tests/html/dataset.html @@ -0,0 +1,29 @@ + +
+ + + + diff --git a/src/tests/html/document.html b/src/tests/html/document.html new file mode 100644 index 00000000..f453579c --- /dev/null +++ b/src/tests/html/document.html @@ -0,0 +1,84 @@ + + +
+ + + + + + diff --git a/src/tests/html/element.html b/src/tests/html/element.html new file mode 100644 index 00000000..1d80292e --- /dev/null +++ b/src/tests/html/element.html @@ -0,0 +1,52 @@ + +
abcc
+ + + + + + + + + + + diff --git a/src/tests/html/error_event.html b/src/tests/html/error_event.html index fa91acdb..fbc1290b 100644 --- a/src/tests/html/error_event.html +++ b/src/tests/html/error_event.html @@ -22,8 +22,3 @@ testing.expectEqual(8999, e2.colno); testing.expectEqual('under 9000!', e2.error); - - diff --git a/src/tests/html/history.html b/src/tests/html/history.html new file mode 100644 index 00000000..e9ce30ab --- /dev/null +++ b/src/tests/html/history.html @@ -0,0 +1,23 @@ + + + diff --git a/src/tests/html/image.html b/src/tests/html/image.html new file mode 100644 index 00000000..96d0fab1 --- /dev/null +++ b/src/tests/html/image.html @@ -0,0 +1,31 @@ + + + diff --git a/src/tests/html/input.html b/src/tests/html/input.html new file mode 100644 index 00000000..6b85f15d --- /dev/null +++ b/src/tests/html/input.html @@ -0,0 +1,110 @@ + + +
+

+ +

+
+ + + + + + + + diff --git a/src/tests/html/link.html b/src/tests/html/link.html new file mode 100644 index 00000000..ec9761f5 --- /dev/null +++ b/src/tests/html/link.html @@ -0,0 +1,59 @@ + +OK + + diff --git a/src/tests/html/location.html b/src/tests/html/location.html new file mode 100644 index 00000000..6a8c4d17 --- /dev/null +++ b/src/tests/html/location.html @@ -0,0 +1,14 @@ + + + diff --git a/src/tests/html/navigator.html b/src/tests/html/navigator.html new file mode 100644 index 00000000..04151f26 --- /dev/null +++ b/src/tests/html/navigator.html @@ -0,0 +1,7 @@ + + + diff --git a/src/tests/html/script/script.html b/src/tests/html/script/script.html new file mode 100644 index 00000000..1ce00feb --- /dev/null +++ b/src/tests/html/script/script.html @@ -0,0 +1,14 @@ + + + diff --git a/src/tests/html/select.html b/src/tests/html/select.html new file mode 100644 index 00000000..ff522838 --- /dev/null +++ b/src/tests/html/select.html @@ -0,0 +1,74 @@ + + +
+ +
+ + + diff --git a/src/tests/html/html_slot_element.html b/src/tests/html/slot.html similarity index 100% rename from src/tests/html/html_slot_element.html rename to src/tests/html/slot.html diff --git a/src/tests/html/style.html b/src/tests/html/style.html new file mode 100644 index 00000000..94ad2d0a --- /dev/null +++ b/src/tests/html/style.html @@ -0,0 +1,7 @@ + + + diff --git a/src/tests/html/svg.html b/src/tests/html/svg.html new file mode 100644 index 00000000..4e2e544c --- /dev/null +++ b/src/tests/html/svg.html @@ -0,0 +1,5 @@ + + + diff --git a/src/tests/html/template.html b/src/tests/html/template.html new file mode 100644 index 00000000..7cc43770 --- /dev/null +++ b/src/tests/html/template.html @@ -0,0 +1,21 @@ + + +
+ +