From 327b4e4e37d2f1b70bcb52f7531db75c291942b7 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 4 Sep 2025 13:11:15 +0800 Subject: [PATCH] migrate to htmlRunner --- src/browser/cssom/CSSParser.zig | 12 +- src/browser/cssom/CSSRuleList.zig | 12 +- src/browser/cssom/CSSStyleDeclaration.zig | 174 ++++-------------- src/browser/cssom/CSSStyleSheet.zig | 24 +-- .../webcomponents/custom_element_registry.zig | 93 ---------- src/browser/xmlserializer/xmlserializer.zig | 18 +- src/tests/cssom/css_rule_list.html | 7 + src/tests/cssom/css_style_declaration.html | 101 ++++++++++ src/tests/cssom/css_stylesheet.html | 15 ++ src/tests/xmlserializer.html | 8 + 10 files changed, 177 insertions(+), 287 deletions(-) delete mode 100644 src/browser/webcomponents/custom_element_registry.zig create mode 100644 src/tests/cssom/css_rule_list.html create mode 100644 src/tests/cssom/css_style_declaration.html create mode 100644 src/tests/cssom/css_stylesheet.html create mode 100644 src/tests/xmlserializer.html diff --git a/src/browser/cssom/CSSParser.zig b/src/browser/cssom/CSSParser.zig index 20938c9e..70cbbf06 100644 --- a/src/browser/cssom/CSSParser.zig +++ b/src/browser/cssom/CSSParser.zig @@ -199,7 +199,7 @@ fn finalize(self: *CSSParser, arena: Allocator, declarations: *std.ArrayListUnma } const testing = @import("../../testing.zig"); -test "CSSParser - Simple property" { +test "Browser: CSS.Parser - Simple property" { defer testing.reset(); const text = "color: red;"; @@ -213,7 +213,7 @@ test "CSSParser - Simple property" { try testing.expectEqual(false, declarations[0].is_important); } -test "CSSParser - Property with !important" { +test "Browser: CSS.Parser - Property with !important" { defer testing.reset(); const text = "margin: 10px !important;"; const allocator = testing.arena_allocator; @@ -226,7 +226,7 @@ test "CSSParser - Property with !important" { try testing.expectEqual(true, declarations[0].is_important); } -test "CSSParser - Multiple properties" { +test "Browser: CSS.Parser - Multiple properties" { defer testing.reset(); const text = "color: red; font-size: 12px; margin: 5px !important;"; const allocator = testing.arena_allocator; @@ -248,7 +248,7 @@ test "CSSParser - Multiple properties" { try testing.expectEqual(true, declarations[2].is_important); } -test "CSSParser - Quoted value with semicolon" { +test "Browser: CSS.Parser - Quoted value with semicolon" { defer testing.reset(); const text = "content: \"Hello; world!\";"; const allocator = testing.arena_allocator; @@ -261,7 +261,7 @@ test "CSSParser - Quoted value with semicolon" { try testing.expectEqual(false, declarations[0].is_important); } -test "CSSParser - URL value" { +test "Browser: CSS.Parser - URL value" { defer testing.reset(); const text = "background-image: url(\"test.png\");"; const allocator = testing.arena_allocator; @@ -274,7 +274,7 @@ test "CSSParser - URL value" { try testing.expectEqual(false, declarations[0].is_important); } -test "CSSParser - Whitespace handling" { +test "Browser: CSS.Parser - Whitespace handling" { defer testing.reset(); const text = " color : purple ; margin : 10px ; "; const allocator = testing.arena_allocator; diff --git a/src/browser/cssom/CSSRuleList.zig b/src/browser/cssom/CSSRuleList.zig index f17697bb..0da4cd0b 100644 --- a/src/browser/cssom/CSSRuleList.zig +++ b/src/browser/cssom/CSSRuleList.zig @@ -47,14 +47,6 @@ pub fn get_length(self: *CSSRuleList) u32 { } const testing = @import("../../testing.zig"); -test "Browser.CSS.CSSRuleList" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "let list = new CSSRuleList()", "undefined" }, - .{ "list instanceof CSSRuleList", "true" }, - .{ "list.length", "0" }, - .{ "list.item(0)", "null" }, - }, .{}); +test "Browser: CSS.CSSRuleList" { + try testing.htmlRunner("cssom/css_rule_list.html"); } diff --git a/src/browser/cssom/CSSStyleDeclaration.zig b/src/browser/cssom/CSSStyleDeclaration.zig index df1a2545..8431958f 100644 --- a/src/browser/cssom/CSSStyleDeclaration.zig +++ b/src/browser/cssom/CSSStyleDeclaration.zig @@ -507,117 +507,11 @@ fn lengthOfLongestValue(values: []const []const u8) usize { } const testing = @import("../../testing.zig"); -test "CSSOM.CSSStyleDeclaration" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ - .html = "", - }); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "let style = document.createElement('div').style", null }, - .{ "style.cssText = 'color: red; font-size: 12px; margin: 5px !important;'", "color: red; font-size: 12px; margin: 5px !important;" }, - .{ "style.length", "3" }, - }, .{}); - - try runner.testCases(&.{ - .{ "style.getPropertyValue('color')", "red" }, - .{ "style.getPropertyValue('font-size')", "12px" }, - .{ "style.getPropertyValue('unknown-property')", "" }, - - .{ "style.getPropertyPriority('margin')", "important" }, - .{ "style.getPropertyPriority('color')", "" }, - .{ "style.getPropertyPriority('unknown-property')", "" }, - - .{ "style.item(0)", "color" }, - .{ "style.item(1)", "font-size" }, - .{ "style.item(2)", "margin" }, - .{ "style.item(3)", "" }, - }, .{}); - - try runner.testCases(&.{ - .{ "style.setProperty('background-color', 'blue')", "undefined" }, - .{ "style.getPropertyValue('background-color')", "blue" }, - .{ "style.length", "4" }, - - .{ "style.setProperty('color', 'green')", "undefined" }, - .{ "style.getPropertyValue('color')", "green" }, - .{ "style.length", "4" }, - .{ "style.color", "green" }, - - .{ "style.setProperty('padding', '10px', 'important')", "undefined" }, - .{ "style.getPropertyValue('padding')", "10px" }, - .{ "style.getPropertyPriority('padding')", "important" }, - - .{ "style.setProperty('border', '1px solid black', 'IMPORTANT')", "undefined" }, - .{ "style.getPropertyPriority('border')", "important" }, - }, .{}); - - try runner.testCases(&.{ - .{ "style.removeProperty('color')", "green" }, - .{ "style.getPropertyValue('color')", "" }, - .{ "style.length", "5" }, - - .{ "style.removeProperty('unknown-property')", "" }, - }, .{}); - - try runner.testCases(&.{ - .{ "style.cssText.includes('font-size: 12px;')", "true" }, - .{ "style.cssText.includes('margin: 5px !important;')", "true" }, - .{ "style.cssText.includes('padding: 10px !important;')", "true" }, - .{ "style.cssText.includes('border: 1px solid black !important;')", "true" }, - - .{ "style.cssText = 'color: purple; text-align: center;'", "color: purple; text-align: center;" }, - .{ "style.length", "2" }, - .{ "style.getPropertyValue('color')", "purple" }, - .{ "style.getPropertyValue('text-align')", "center" }, - .{ "style.getPropertyValue('font-size')", "" }, - - .{ "style.setProperty('cont', 'Hello; world!')", "undefined" }, - .{ "style.getPropertyValue('cont')", "Hello; world!" }, - - .{ "style.cssText = 'content: \"Hello; world!\"; background-image: url(\"test.png\");'", "content: \"Hello; world!\"; background-image: url(\"test.png\");" }, - .{ "style.getPropertyValue('content')", "\"Hello; world!\"" }, - .{ "style.getPropertyValue('background-image')", "url(\"test.png\")" }, - }, .{}); - - try runner.testCases(&.{ - .{ "style.cssFloat", "" }, - .{ "style.cssFloat = 'left'", "left" }, - .{ "style.cssFloat", "left" }, - .{ "style.getPropertyValue('float')", "left" }, - - .{ "style.cssFloat = 'right'", "right" }, - .{ "style.cssFloat", "right" }, - - .{ "style.cssFloat = null", "null" }, - .{ "style.cssFloat", "" }, - }, .{}); - - try runner.testCases(&.{ - .{ "style.setProperty('display', '')", "undefined" }, - .{ "style.getPropertyValue('display')", "" }, - - .{ "style.cssText = ' color : purple ; margin : 10px ; '", " color : purple ; margin : 10px ; " }, - .{ "style.getPropertyValue('color')", "purple" }, - .{ "style.getPropertyValue('margin')", "10px" }, - - .{ "style.setProperty('border-bottom-left-radius', '5px')", "undefined" }, - .{ "style.getPropertyValue('border-bottom-left-radius')", "5px" }, - }, .{}); - - try runner.testCases(&.{ - .{ "style.visibility", "visible" }, - .{ "style.getPropertyValue('visibility')", "visible" }, - }, .{}); - - try runner.testCases(&.{ - .{ "style.margin", "10px" }, - .{ "style.margin = 'auto'", null }, - .{ "style.margin", "auto" }, - }, .{}); +test "Browser: CSS.StyleDeclaration" { + try testing.htmlRunner("cssom/css_style_declaration.html"); } -test "CSSOM.CSSStyleDeclaration: isNumericWithUnit - valid numbers with units" { +test "Browser: CSS.StyleDeclaration: isNumericWithUnit - valid numbers with units" { try testing.expect(isNumericWithUnit("10px")); try testing.expect(isNumericWithUnit("3.14em")); try testing.expect(isNumericWithUnit("-5rem")); @@ -626,14 +520,14 @@ test "CSSOM.CSSStyleDeclaration: isNumericWithUnit - valid numbers with units" { try testing.expect(isNumericWithUnit(".5vw")); } -test "CSSOM.CSSStyleDeclaration: isNumericWithUnit - scientific notation" { +test "Browser: CSS.StyleDeclaration: isNumericWithUnit - scientific notation" { try testing.expect(isNumericWithUnit("1e5px")); try testing.expect(isNumericWithUnit("2.5E-3em")); try testing.expect(isNumericWithUnit("1e+2rem")); try testing.expect(isNumericWithUnit("-3.14e10px")); } -test "CSSOM.CSSStyleDeclaration: isNumericWithUnit - edge cases and invalid inputs" { +test "Browser: CSS.StyleDeclaration: isNumericWithUnit - edge cases and invalid inputs" { try testing.expect(!isNumericWithUnit("")); try testing.expect(!isNumericWithUnit("px")); @@ -655,7 +549,7 @@ test "CSSOM.CSSStyleDeclaration: isNumericWithUnit - edge cases and invalid inpu try testing.expect(isNumericWithUnit("-5")); } -test "CSSOM.CSSStyleDeclaration: isHexColor - valid hex colors" { +test "Browser: CSS.StyleDeclaration: isHexColor - valid hex colors" { try testing.expect(isHexColor("#000")); try testing.expect(isHexColor("#fff")); try testing.expect(isHexColor("#123456")); @@ -664,7 +558,7 @@ test "CSSOM.CSSStyleDeclaration: isHexColor - valid hex colors" { try testing.expect(isHexColor("#12345678")); } -test "CSSOM.CSSStyleDeclaration: isHexColor - invalid hex colors" { +test "Browser: CSS.StyleDeclaration: isHexColor - invalid hex colors" { try testing.expect(!isHexColor("")); try testing.expect(!isHexColor("#")); try testing.expect(!isHexColor("000")); @@ -677,7 +571,7 @@ test "CSSOM.CSSStyleDeclaration: isHexColor - invalid hex colors" { try testing.expect(!isHexColor("#123xyz")); } -test "CSSOM.CSSStyleDeclaration: isMultiValueProperty - valid multi-value properties" { +test "Browser: CSS.StyleDeclaration: isMultiValueProperty - valid multi-value properties" { try testing.expect(isMultiValueProperty("10px 20px")); try testing.expect(isMultiValueProperty("solid red")); try testing.expect(isMultiValueProperty("#fff black")); @@ -685,7 +579,7 @@ test "CSSOM.CSSStyleDeclaration: isMultiValueProperty - valid multi-value proper try testing.expect(isMultiValueProperty("rgb(255,0,0) solid")); } -test "CSSOM.CSSStyleDeclaration: isMultiValueProperty - invalid multi-value properties" { +test "Browser: CSS.StyleDeclaration: isMultiValueProperty - invalid multi-value properties" { try testing.expect(!isMultiValueProperty("")); try testing.expect(!isMultiValueProperty("10px")); try testing.expect(!isMultiValueProperty("invalid unknown")); @@ -693,7 +587,7 @@ test "CSSOM.CSSStyleDeclaration: isMultiValueProperty - invalid multi-value prop try testing.expect(!isMultiValueProperty(" ")); } -test "CSSOM.CSSStyleDeclaration: isAlreadyQuoted - various quoting scenarios" { +test "Browser: CSS.StyleDeclaration: isAlreadyQuoted - various quoting scenarios" { try testing.expect(isAlreadyQuoted("\"hello\"")); try testing.expect(isAlreadyQuoted("'world'")); try testing.expect(isAlreadyQuoted("\"\"")); @@ -709,7 +603,7 @@ test "CSSOM.CSSStyleDeclaration: isAlreadyQuoted - various quoting scenarios" { try testing.expect(!isAlreadyQuoted("hello\"")); } -test "CSSOM.CSSStyleDeclaration: isValidPropertyName - valid property names" { +test "Browser: CSS.StyleDeclaration: isValidPropertyName - valid property names" { try testing.expect(isValidPropertyName("color")); try testing.expect(isValidPropertyName("background-color")); try testing.expect(isValidPropertyName("-webkit-transform")); @@ -719,7 +613,7 @@ test "CSSOM.CSSStyleDeclaration: isValidPropertyName - valid property names" { try testing.expect(isValidPropertyName("line-height")); } -test "CSSOM.CSSStyleDeclaration: isValidPropertyName - invalid property names" { +test "Browser: CSS.StyleDeclaration: isValidPropertyName - invalid property names" { try testing.expect(!isValidPropertyName("")); try testing.expect(!isValidPropertyName("123color")); try testing.expect(!isValidPropertyName("color!")); @@ -729,7 +623,7 @@ test "CSSOM.CSSStyleDeclaration: isValidPropertyName - invalid property names" { try testing.expect(!isValidPropertyName("color_test")); } -test "CSSOM.CSSStyleDeclaration: extractImportant - with and without !important" { +test "Browser: CSS.StyleDeclaration: extractImportant - with and without !important" { var result = extractImportant("red !important"); try testing.expect(result.is_important); try testing.expectEqual("red", result.value); @@ -751,7 +645,7 @@ test "CSSOM.CSSStyleDeclaration: extractImportant - with and without !important" try testing.expectEqual("important", result.value); } -test "CSSOM.CSSStyleDeclaration: needsQuotes - various scenarios" { +test "Browser: CSS.StyleDeclaration: needsQuotes - various scenarios" { try testing.expect(needsQuotes("")); try testing.expect(needsQuotes("hello world")); try testing.expect(needsQuotes("test;")); @@ -766,7 +660,7 @@ test "CSSOM.CSSStyleDeclaration: needsQuotes - various scenarios" { try testing.expect(!needsQuotes("simple")); } -test "CSSOM.CSSStyleDeclaration: escapeCSSValue - escaping various characters" { +test "Browser: CSS.StyleDeclaration: escapeCSSValue - escaping various characters" { const allocator = testing.arena_allocator; var result = try escapeCSSValue(allocator, "simple"); @@ -785,7 +679,7 @@ test "CSSOM.CSSStyleDeclaration: escapeCSSValue - escaping various characters" { try testing.expectEqual("\"test\\\\back\"", result); } -test "CSSOM.CSSStyleDeclaration: CSSKeywords.isKnownKeyword - case sensitivity" { +test "Browser: CSS.StyleDeclaration: CSSKeywords.isKnownKeyword - case sensitivity" { try testing.expect(CSSKeywords.isKnownKeyword("red")); try testing.expect(CSSKeywords.isKnownKeyword("solid")); try testing.expect(CSSKeywords.isKnownKeyword("center")); @@ -801,7 +695,7 @@ test "CSSOM.CSSStyleDeclaration: CSSKeywords.isKnownKeyword - case sensitivity" try testing.expect(!CSSKeywords.isKnownKeyword("")); } -test "CSSOM.CSSStyleDeclaration: CSSKeywords.containsSpecialChar - various special characters" { +test "Browser: CSS.StyleDeclaration: CSSKeywords.containsSpecialChar - various special characters" { try testing.expect(CSSKeywords.containsSpecialChar("test\"quote")); try testing.expect(CSSKeywords.containsSpecialChar("test'quote")); try testing.expect(CSSKeywords.containsSpecialChar("test;end")); @@ -817,7 +711,7 @@ test "CSSOM.CSSStyleDeclaration: CSSKeywords.containsSpecialChar - various speci try testing.expect(!CSSKeywords.containsSpecialChar("")); } -test "CSSOM.CSSStyleDeclaration: CSSKeywords.isValidUnit - various units" { +test "Browser: CSS.StyleDeclaration: CSSKeywords.isValidUnit - various units" { try testing.expect(CSSKeywords.isValidUnit("px")); try testing.expect(CSSKeywords.isValidUnit("em")); try testing.expect(CSSKeywords.isValidUnit("rem")); @@ -835,7 +729,7 @@ test "CSSOM.CSSStyleDeclaration: CSSKeywords.isValidUnit - various units" { try testing.expect(!CSSKeywords.isValidUnit("")); } -test "CSSOM.CSSStyleDeclaration: CSSKeywords.startsWithFunction - function detection" { +test "Browser: CSS.StyleDeclaration: CSSKeywords.startsWithFunction - function detection" { try testing.expect(CSSKeywords.startsWithFunction("rgb(255, 0, 0)")); try testing.expect(CSSKeywords.startsWithFunction("rgba(255, 0, 0, 0.5)")); try testing.expect(CSSKeywords.startsWithFunction("url(image.png)")); @@ -853,14 +747,14 @@ test "CSSOM.CSSStyleDeclaration: CSSKeywords.startsWithFunction - function detec try testing.expect(!CSSKeywords.startsWithFunction("rgb")); } -test "CSSOM.CSSStyleDeclaration: isNumericWithUnit - whitespace handling" { +test "Browser: CSS.StyleDeclaration: isNumericWithUnit - whitespace handling" { try testing.expect(!isNumericWithUnit(" 10px")); try testing.expect(!isNumericWithUnit("10 px")); try testing.expect(!isNumericWithUnit("10px ")); try testing.expect(!isNumericWithUnit(" 10 px ")); } -test "CSSOM.CSSStyleDeclaration: extractImportant - whitespace edge cases" { +test "Browser: CSS.StyleDeclaration: extractImportant - whitespace edge cases" { var result = extractImportant(" "); try testing.expect(!result.is_important); try testing.expectEqual("", result.value); @@ -874,14 +768,14 @@ test "CSSOM.CSSStyleDeclaration: extractImportant - whitespace edge cases" { try testing.expectEqual("red", result.value); } -test "CSSOM.CSSStyleDeclaration: isHexColor - mixed case handling" { +test "Browser: CSS.StyleDeclaration: isHexColor - mixed case handling" { try testing.expect(isHexColor("#AbC")); try testing.expect(isHexColor("#123aBc")); try testing.expect(isHexColor("#FFffFF")); try testing.expect(isHexColor("#000FFF")); } -test "CSSOM.CSSStyleDeclaration: edge case - very long inputs" { +test "Browser: CSS.StyleDeclaration: edge case - very long inputs" { const long_valid = "a" ** 1000 ++ "px"; try testing.expect(!isNumericWithUnit(long_valid)); // not numeric @@ -892,7 +786,7 @@ test "CSSOM.CSSStyleDeclaration: edge case - very long inputs" { try testing.expect(!isHexColor(long_hex)); } -test "CSSOM.CSSStyleDeclaration: boundary conditions - numeric parsing" { +test "Browser: CSS.StyleDeclaration: boundary conditions - numeric parsing" { try testing.expect(isNumericWithUnit("0px")); try testing.expect(isNumericWithUnit("0.0px")); try testing.expect(isNumericWithUnit(".0px")); @@ -905,7 +799,7 @@ test "CSSOM.CSSStyleDeclaration: boundary conditions - numeric parsing" { try testing.expect(isNumericWithUnit("1e-100px")); } -test "CSSOM.CSSStyleDeclaration: extractImportant - malformed important declarations" { +test "Browser: CSS.StyleDeclaration: extractImportant - malformed important declarations" { var result = extractImportant("red ! important"); try testing.expect(!result.is_important); try testing.expectEqual("red ! important", result.value); @@ -927,7 +821,7 @@ test "CSSOM.CSSStyleDeclaration: extractImportant - malformed important declarat try testing.expectEqual("red !important", result.value); } -test "CSSOM.CSSStyleDeclaration: isMultiValueProperty - complex spacing scenarios" { +test "Browser: CSS.StyleDeclaration: isMultiValueProperty - complex spacing scenarios" { try testing.expect(isMultiValueProperty("10px 20px")); try testing.expect(isMultiValueProperty("solid red")); @@ -939,7 +833,7 @@ test "CSSOM.CSSStyleDeclaration: isMultiValueProperty - complex spacing scenario try testing.expect(isMultiValueProperty("10px 20px 30px")); } -test "CSSOM.CSSStyleDeclaration: isAlreadyQuoted - edge cases with quotes" { +test "Browser: CSS.StyleDeclaration: isAlreadyQuoted - edge cases with quotes" { try testing.expect(isAlreadyQuoted("\"'hello'\"")); try testing.expect(isAlreadyQuoted("'\"hello\"'")); @@ -955,7 +849,7 @@ test "CSSOM.CSSStyleDeclaration: isAlreadyQuoted - edge cases with quotes" { try testing.expect(isAlreadyQuoted("'b'")); } -test "CSSOM.CSSStyleDeclaration: needsQuotes - function and URL edge cases" { +test "Browser: CSS.StyleDeclaration: needsQuotes - function and URL edge cases" { try testing.expect(!needsQuotes("rgb(255, 0, 0)")); try testing.expect(!needsQuotes("calc(100% - 20px)")); @@ -966,7 +860,7 @@ test "CSSOM.CSSStyleDeclaration: needsQuotes - function and URL edge cases" { try testing.expect(needsQuotes("rgb(255, 0, 0")); } -test "CSSOM.CSSStyleDeclaration: escapeCSSValue - control characters and Unicode" { +test "Browser: CSS.StyleDeclaration: escapeCSSValue - control characters and Unicode" { const allocator = testing.arena_allocator; var result = try escapeCSSValue(allocator, "test\ttab"); @@ -985,7 +879,7 @@ test "CSSOM.CSSStyleDeclaration: escapeCSSValue - control characters and Unicode try testing.expectEqual("\"test\\\"quote\\A line\\\\back\"", result); } -test "CSSOM.CSSStyleDeclaration: isValidPropertyName - CSS custom properties and vendor prefixes" { +test "Browser: CSS.StyleDeclaration: isValidPropertyName - CSS custom properties and vendor prefixes" { try testing.expect(isValidPropertyName("--custom-color")); try testing.expect(isValidPropertyName("--my-variable")); try testing.expect(isValidPropertyName("--123")); @@ -1000,7 +894,7 @@ test "CSSOM.CSSStyleDeclaration: isValidPropertyName - CSS custom properties and try testing.expect(!isValidPropertyName("-")); } -test "CSSOM.CSSStyleDeclaration: startsWithFunction - case sensitivity and partial matches" { +test "Browser: CSS.StyleDeclaration: startsWithFunction - case sensitivity and partial matches" { try testing.expect(CSSKeywords.startsWithFunction("RGB(255, 0, 0)")); try testing.expect(CSSKeywords.startsWithFunction("Rgb(255, 0, 0)")); try testing.expect(CSSKeywords.startsWithFunction("URL(image.png)")); @@ -1017,7 +911,7 @@ test "CSSOM.CSSStyleDeclaration: startsWithFunction - case sensitivity and parti try testing.expect(!CSSKeywords.startsWithFunction("123function(test)")); } -test "CSSOM.CSSStyleDeclaration: isHexColor - Unicode and invalid characters" { +test "Browser: CSS.StyleDeclaration: isHexColor - Unicode and invalid characters" { try testing.expect(!isHexColor("#ghijkl")); try testing.expect(!isHexColor("#12345g")); try testing.expect(!isHexColor("#xyz")); @@ -1028,7 +922,7 @@ test "CSSOM.CSSStyleDeclaration: isHexColor - Unicode and invalid characters" { try testing.expect(!isHexColor("#g2345678")); } -test "CSSOM.CSSStyleDeclaration: complex integration scenarios" { +test "Browser: CSS.StyleDeclaration: complex integration scenarios" { const allocator = testing.arena_allocator; try testing.expect(isMultiValueProperty("rgb(255,0,0) url(bg.jpg)")); @@ -1043,7 +937,7 @@ test "CSSOM.CSSStyleDeclaration: complex integration scenarios" { try testing.expectEqual("rgb(255,0,0)", important_result.value); } -test "CSSOM.CSSStyleDeclaration: performance edge cases - empty and minimal inputs" { +test "Browser: CSS.StyleDeclaration: performance edge cases - empty and minimal inputs" { try testing.expect(!isNumericWithUnit("")); try testing.expect(!isHexColor("")); try testing.expect(!isMultiValueProperty("")); diff --git a/src/browser/cssom/CSSStyleSheet.zig b/src/browser/cssom/CSSStyleSheet.zig index ba6dc381..b963cc57 100644 --- a/src/browser/cssom/CSSStyleSheet.zig +++ b/src/browser/cssom/CSSStyleSheet.zig @@ -92,26 +92,6 @@ pub fn _replaceSync(self: *CSSStyleSheet, text: []const u8) !void { } const testing = @import("../../testing.zig"); -test "Browser.CSS.StyleSheet" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "let css = new CSSStyleSheet()", "undefined" }, - .{ "css instanceof CSSStyleSheet", "true" }, - .{ "css.cssRules.length", "0" }, - .{ "css.ownerRule", "null" }, - .{ "let index1 = css.insertRule('body { color: red; }', 0)", "undefined" }, - .{ "index1", "0" }, - .{ "css.cssRules.length", "1" }, - - .{ - \\ let replaced = false; - \\ css.replace('body{}').then(() => replaced = true); - , - null, - }, - // microtasks are run between each statement - .{ "replaced", "true" }, - }, .{}); +test "Browser: CSS.StyleSheet" { + try testing.htmlRunner("cssom/css_stylesheet.html"); } diff --git a/src/browser/webcomponents/custom_element_registry.zig b/src/browser/webcomponents/custom_element_registry.zig deleted file mode 100644 index 4666a1ad..00000000 --- a/src/browser/webcomponents/custom_element_registry.zig +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (C) 2023-2024 Lightpanda (Selecy SAS) -// -// Francis Bouvier -// Pierre Tachoire -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Currently not used. Relying on polyfill instead - -const std = @import("std"); -const log = @import("../../log.zig"); -const v8 = @import("v8"); - -const Env = @import("../env.zig").Env; -const Page = @import("../page.zig").Page; - -const Element = @import("../dom/element.zig").Element; - -pub const CustomElementRegistry = struct { - // tag_name -> Function - lookup: std.StringHashMapUnmanaged(Env.Function) = .empty, - - pub fn _define(self: *CustomElementRegistry, tag_name: []const u8, fun: Env.Function, page: *Page) !void { - log.info(.browser, "define custom element", .{ .name = tag_name }); - - const arena = page.arena; - const gop = try self.lookup.getOrPut(arena, tag_name); - if (!gop.found_existing) { - errdefer _ = self.lookup.remove(tag_name); - const owned_tag_name = try arena.dupe(u8, tag_name); - gop.key_ptr.* = owned_tag_name; - } - gop.value_ptr.* = fun; - fun.setName(tag_name); - } - - pub fn _get(self: *CustomElementRegistry, name: []const u8) ?Env.Function { - return self.lookup.get(name); - } -}; - -const testing = @import("../../testing.zig"); - -test "Browser.CustomElementRegistry" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - try runner.testCases(&.{ - // Basic registry access - .{ "typeof customElements", "object" }, - .{ "customElements instanceof CustomElementRegistry", "true" }, - - // Define a simple custom element - .{ - \\ class MyElement extends HTMLElement { - \\ constructor() { - \\ super(); - \\ this.textContent = 'Hello World'; - \\ } - \\ } - , - null, - }, - .{ "customElements.define('my-element', MyElement)", "undefined" }, - - // Check if element is defined - .{ "customElements.get('my-element') === MyElement", "true" }, - // .{ "customElements.get('non-existent')", "null" }, - - // Create element via document.createElement - .{ "let el = document.createElement('my-element')", "undefined" }, - .{ "el instanceof MyElement", "true" }, - .{ "el instanceof HTMLElement", "true" }, - .{ "el.tagName", "MY-ELEMENT" }, - .{ "el.textContent", "Hello World" }, - - // Create element via HTML parsing - // .{ "document.body.innerHTML = ''", "undefined" }, - // .{ "let parsed = document.querySelector('my-element')", "undefined" }, - // .{ "parsed instanceof MyElement", "true" }, - // .{ "parsed.textContent", "Hello World" }, - }, .{}); -} diff --git a/src/browser/xmlserializer/xmlserializer.zig b/src/browser/xmlserializer/xmlserializer.zig index b268d21d..444b77ab 100644 --- a/src/browser/xmlserializer/xmlserializer.zig +++ b/src/browser/xmlserializer/xmlserializer.zig @@ -45,20 +45,6 @@ pub const XMLSerializer = struct { }; const testing = @import("../../testing.zig"); -test "Browser.XMLSerializer" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "const s = new XMLSerializer()", "undefined" }, - .{ "s.serializeToString(document.getElementById('para'))", "

And

" }, - }, .{}); -} -test "Browser.XMLSerializer with DOCTYPE" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "" }); - defer runner.deinit(); - - try runner.testCases(&.{ - .{ "new XMLSerializer().serializeToString(document.doctype)", "" }, - }, .{}); +test "Browser: XMLSerializer" { + try testing.htmlRunner("xmlserializer.html"); } diff --git a/src/tests/cssom/css_rule_list.html b/src/tests/cssom/css_rule_list.html new file mode 100644 index 00000000..7daf4c8a --- /dev/null +++ b/src/tests/cssom/css_rule_list.html @@ -0,0 +1,7 @@ + + diff --git a/src/tests/cssom/css_style_declaration.html b/src/tests/cssom/css_style_declaration.html new file mode 100644 index 00000000..50bb205a --- /dev/null +++ b/src/tests/cssom/css_style_declaration.html @@ -0,0 +1,101 @@ + + + + + + + + + + + + + diff --git a/src/tests/cssom/css_stylesheet.html b/src/tests/cssom/css_stylesheet.html new file mode 100644 index 00000000..33ff32a1 --- /dev/null +++ b/src/tests/cssom/css_stylesheet.html @@ -0,0 +1,15 @@ + + diff --git a/src/tests/xmlserializer.html b/src/tests/xmlserializer.html new file mode 100644 index 00000000..0d3d4628 --- /dev/null +++ b/src/tests/xmlserializer.html @@ -0,0 +1,8 @@ + + +

And

+