Skip to content

Truly independent web browser

LibWeb: Test font family serialization and round-tripping

Andreas Klinga049c91f6ea2
diff --git a/Tests/LibWeb/Text/expected/css/font-family-serialization.txt b/Tests/LibWeb/Text/expected/css/font-family-serialization.txt
new file mode 100644
index 00000000000..d5a30e3494e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/font-family-serialization.txt
@@ -0,0 +1,17 @@
+Unquoted words: FAIL
+Quoted words: FAIL
+Escaped space: FAIL
+Repeated spaces: PASS
+Leading space: PASS
+Trailing space: PASS
+Leading digit: PASS
+Digit after hyphen: PASS
+Lone hyphen: PASS
+Punctuation: PASS
+Escaped punctuation: FAIL
+CSS-wide keyword: PASS
+Generic family name: PASS
+Quoted identifier: FAIL
+Unicode words: FAIL
+Family list: FAIL
+Custom identifier: PASS
diff --git a/Tests/LibWeb/Text/input/css/font-family-serialization.html b/Tests/LibWeb/Text/input/css/font-family-serialization.html
new file mode 100644
index 00000000000..60a592b6917
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/font-family-serialization.html
@@ -0,0 +1,37 @@
+<!doctype html>
+<meta charset="utf-8">
+<script src="../include.js"></script>
+<script>
+test(() => {
+ const element = document.createElement("div");
+ document.body.appendChild(element);
+ const cases = [
+ ["Unquoted words", "Non-Generic Example Family Name", "Non-Generic Example Family Name"],
+ ["Quoted words", '"Two Words"', "Two Words"],
+ ["Escaped space", "Two\\ Words", "Two Words"],
+ ["Repeated spaces", '"Two Words"', '"Two Words"'],
+ ["Leading space", '" Two Words"', '" Two Words"'],
+ ["Trailing space", '"Two Words "', '"Two Words "'],
+ ["Leading digit", '"21st Century"', '"21st Century"'],
+ ["Digit after hyphen", '"-9 Font"', '"-9 Font"'],
+ ["Lone hyphen", '"-"', '"-"'],
+ ["Punctuation", '"Ahem!"', '"Ahem!"'],
+ ["Escaped punctuation", "Ahem\\!", '"Ahem!"'],
+ ["CSS-wide keyword", '"inherit"', '"inherit"'],
+ ["Generic family name", '"serif"', '"serif"'],
+ ["Quoted identifier", '"NonGeneric"', "NonGeneric"],
+ ["Unicode words", '"雪 字"', "雪 字"],
+ ["Family list", '"Two Words", "21st Century", SERIF', 'Two Words, "21st Century", serif'],
+ ];
+ for (const [label, input, expected] of cases) {
+ element.style.fontFamily = input;
+ const specified = element.style.fontFamily;
+ const computed = getComputedStyle(element).fontFamily;
+ element.style.fontFamily = specified;
+ const roundTrip = getComputedStyle(element).fontFamily;
+ println(`${label}: ${specified === expected && computed === expected && roundTrip === expected ? "PASS" : "FAIL"}`);
+ }
+ element.style.animationName = "Two\\ Words";
+ println(`Custom identifier: ${element.style.animationName === "Two\\ Words" ? "PASS" : "FAIL"}`);
+});
+</script>