Skip to content

Truly independent web browser

LibWeb: Resolve the font shorthand's system font keywords

sideshowbarker877b35910a79
diff --git a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
index 465fb7fddfa..39234e86cd1 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
@@ -4812,12 +4812,73 @@ fn parse_font_variant_shorthand(context: &ParseContext, values: &[ComponentValue
)))
}
+/// The family and size a system font keyword stands for: the font the platform draws that part of its UI with.
+/// https://drafts.csswg.org/css-fonts-4/#system-font-family-name-value
+fn system_font_for_keyword(ident: &[u16]) -> Option<(&'static [u8], &'static [u8])> {
+ // AD-HOC: The sizes are the ones macOS draws its controls, menus, dialogs, small labels, and status bars with
+ // (13px, 13px, 13px, 13px, 11px, 10px), on every platform, and the family is always the platform's UI font.
+ const SYSTEM_FONTS: [(&[u8], &[u8]); 6] = [
+ (b"caption", b"13px"),
+ (b"icon", b"13px"),
+ (b"menu", b"13px"),
+ (b"message-box", b"13px"),
+ (b"small-caption", b"11px"),
+ (b"status-bar", b"10px"),
+ ];
+ SYSTEM_FONTS
+ .iter()
+ .find(|(keyword, _)| equals_ascii_case_insensitive(ident, keyword))
+ .map(|&(_, size)| (b"system-ui" as &[u8], size))
+}
+
fn parse_font_shorthand(context: &ParseContext, values: &[ComponentValue]) -> ParseOutcome {
let components = values
.iter()
.filter(|value| !value.is_whitespace())
.cloned()
.collect::<Vec<_>>();
+ // A system font keyword on its own sets every longhand: the keyword's family and size, and the initial value of
+ // the rest.
+ if let [component] = components.as_slice()
+ && let Some(ident) = component.ident()
+ && let Some((family, size)) = system_font_for_keyword(ident)
+ {
+ let parse = |property: u16, source: &[u8]| {
+ let values = consume_a_list_of_component_values(tokenize_for_parser(source)).ok()?;
+ parse_slice_for_property(context, property, &values)
+ };
+ let (Some(font_family), Some(font_size)) = (
+ parse(property_id::FONT_FAMILY, family),
+ parse(property_id::FONT_SIZE, size),
+ ) else {
+ return ParseOutcome::Invalid;
+ };
+ // font-variant is a shorthand of its own, so its "normal" comes from its own parser.
+ let font_variant = consume_a_list_of_component_values(tokenize_for_parser(b"normal"))
+ .ok()
+ .and_then(|values| match parse_font_variant_shorthand(context, &values) {
+ ParseOutcome::Parsed(value) => Some((*value).clone()),
+ _ => None,
+ });
+ let longhands = longhands_for_shorthand(property_id::FONT);
+ let Some(output) = longhands
+ .iter()
+ .map(|&longhand| match longhand {
+ property_id::FONT_FAMILY => Some(font_family.clone()),
+ property_id::FONT_SIZE => Some(font_size.clone()),
+ property_id::FONT_VARIANT => font_variant.clone(),
+ _ => parse_initial_longhand(context, longhand),
+ })
+ .collect::<Option<Vec<_>>>()
+ else {
+ return ParseOutcome::Invalid;
+ };
+ return ParseOutcome::Parsed(shared_style_value(shorthand_value(
+ property_id::FONT,
+ longhands.to_vec(),
+ output,
+ )));
+ }
let mut font_style = None;
let mut font_variant = None;
let mut font_weight = None;
diff --git a/Tests/LibWeb/Layout/expected/pdf-viewer.txt b/Tests/LibWeb/Layout/expected/pdf-viewer.txt
index 11c88c159e5..a5a5fedc4f1 100644
--- a/Tests/LibWeb/Layout/expected/pdf-viewer.txt
+++ b/Tests/LibWeb/Layout/expected/pdf-viewer.txt
@@ -29,10 +29,10 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [15,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [31,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [31,16 56.34375x32]
- frag 0 from TextNode start: 0, length: 6, rect: [31,16 56.34375x16] baseline: 12.796875
+ BlockContainer <span> at [31,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [31,16 45.78125x26]
+ frag 0 from TextNode start: 0, length: 6, rect: [31,16 45.78125x13] baseline: 10.390625
"Manage"
- frag 1 from TextNode start: 7, length: 5, rect: [31,32 44.390625x16] baseline: 12.796875
+ frag 1 from TextNode start: 7, length: 5, rect: [31,29 36.0625x13] baseline: 10.390625
"pages"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -51,8 +51,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [75,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [91,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [91,16 34.578125x16]
- frag 0 from TextNode start: 0, length: 4, rect: [91,16 34.578125x16] baseline: 12.796875
+ BlockContainer <span> at [91,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [91,16 28.09375x13]
+ frag 0 from TextNode start: 0, length: 4, rect: [91,16 28.09375x13] baseline: 10.390625
"Find"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -70,8 +70,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [104,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [120,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [120,16 71.3125x16]
- frag 0 from TextNode start: 0, length: 8, rect: [120,16 71.3125x16] baseline: 12.796875
+ BlockContainer <span> at [120,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [120,16 57.953125x13]
+ frag 0 from TextNode start: 0, length: 8, rect: [120,16 57.953125x13] baseline: 10.390625
"Previous"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -85,8 +85,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [135,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [151,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [151,16 35.5625x16]
- frag 0 from TextNode start: 0, length: 4, rect: [151,16 35.5625x16] baseline: 12.796875
+ BlockContainer <span> at [151,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [151,16 28.90625x13]
+ frag 0 from TextNode start: 0, length: 4, rect: [151,16 28.90625x13] baseline: 10.390625
"Next"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -102,10 +102,10 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
TextInputBox <input#pageNumber.toolbarField> at [166,8] flex-item [0+1+7 40 7+1+0] [3+1+4 16 4+1+3] [BFC] children: not-inline
- Box <div> at [166,8] flex-container(row) [0+0+0 40 0+0+0] [0+0+0 16 0+0+0] [FFC] children: not-inline
- Box <div> at [166,8] flex-container(row) flex-item [0+0+0 40 0+0+0] [0+0+0 16 0+0+0] [FFC] children: not-inline
- BlockContainer <div> at [166,8] flex-item [0+0+0 40 0+0+0] [0+0+0 16 0+0+0] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 1, rect: [201.234375,10 4.765625x12] baseline: 9.59375
+ Box <div> at [166,8] flex-container(row) [0+0+0 40 0+0+0] [0+0+0 13 0+0+0] [FFC] children: not-inline
+ Box <div> at [166,8] flex-container(row) flex-item [0+0+0 40 0+0+0] [0+0+0 13 0+0+0] [FFC] children: not-inline
+ BlockContainer <div> at [166,8] flex-item [0+0+0 40 0+0+0] [0+0+0 13 0+0+0] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [200.84375,8 5.15625x13] baseline: 10.390625
"1"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -133,10 +133,10 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [319.9375,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [335.9375,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [335.9375,16 45.53125x32]
- frag 0 from TextNode start: 0, length: 4, rect: [335.9375,16 45.53125x16] baseline: 12.796875
+ BlockContainer <span> at [335.9375,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [335.9375,16 37.015625x26]
+ frag 0 from TextNode start: 0, length: 4, rect: [335.9375,16 37.015625x13] baseline: 10.390625
"Zoom"
- frag 1 from TextNode start: 5, length: 3, rect: [335.9375,32 28.109375x16] baseline: 12.796875
+ frag 1 from TextNode start: 5, length: 3, rect: [335.9375,29 22.84375x13] baseline: 10.390625
"Out"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -150,10 +150,10 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [350.9375,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [366.9375,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [366.9375,16 45.53125x32]
- frag 0 from TextNode start: 0, length: 4, rect: [366.9375,16 45.53125x16] baseline: 12.796875
+ BlockContainer <span> at [366.9375,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [366.9375,16 37.015625x26]
+ frag 0 from TextNode start: 0, length: 4, rect: [366.9375,16 37.015625x13] baseline: 10.390625
"Zoom"
- frag 1 from TextNode start: 5, length: 2, rect: [366.9375,32 14.203125x16] baseline: 12.796875
+ frag 1 from TextNode start: 5, length: 2, rect: [366.9375,29 11.546875x13] baseline: 10.390625
"In"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -195,8 +195,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [591,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [607,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [607,16 66.171875x16]
- frag 0 from TextNode start: 0, length: 9, rect: [607,16 66.171875x16] baseline: 12.796875
+ BlockContainer <span> at [607,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [607,16 53.734375x13]
+ frag 0 from TextNode start: 0, length: 9, rect: [607,16 53.734375x13] baseline: 10.390625
"Highlight"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -213,8 +213,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [620,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [636,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [636,16 37.578125x16]
- frag 0 from TextNode start: 0, length: 4, rect: [636,16 37.578125x16] baseline: 12.796875
+ BlockContainer <span> at [636,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [636,16 30.53125x13]
+ frag 0 from TextNode start: 0, length: 4, rect: [636,16 30.53125x13] baseline: 10.390625
"Text"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -231,8 +231,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [649,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [665,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [665,16 40.53125x16]
- frag 0 from TextNode start: 0, length: 4, rect: [665,16 40.53125x16] baseline: 12.796875
+ BlockContainer <span> at [665,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [665,16 32.921875x13]
+ frag 0 from TextNode start: 0, length: 4, rect: [665,16 32.921875x13] baseline: 10.390625
"Draw"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -249,14 +249,14 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [678,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [694,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [694,16 51.734375x64]
- frag 0 from TextNode start: 0, length: 3, rect: [694,16 29.984375x16] baseline: 12.796875
+ BlockContainer <span> at [694,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [694,16 42.03125x52]
+ frag 0 from TextNode start: 0, length: 3, rect: [694,16 24.375x13] baseline: 10.390625
"Add"
- frag 1 from TextNode start: 4, length: 2, rect: [694,32 19.1875x16] baseline: 12.796875
+ frag 1 from TextNode start: 4, length: 2, rect: [694,29 15.59375x13] baseline: 10.390625
"or"
- frag 2 from TextNode start: 7, length: 4, rect: [694,48 28x16] baseline: 12.796875
+ frag 2 from TextNode start: 7, length: 4, rect: [694,42 22.75x13] baseline: 10.390625
"edit"
- frag 3 from TextNode start: 12, length: 6, rect: [694,64 51.734375x16] baseline: 12.796875
+ frag 3 from TextNode start: 12, length: 6, rect: [694,55 42.03125x13] baseline: 10.390625
"images"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -278,8 +278,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [713,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [729,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [729,16 41.390625x16]
- frag 0 from TextNode start: 0, length: 5, rect: [729,16 41.390625x16] baseline: 12.796875
+ BlockContainer <span> at [729,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [729,16 33.640625x13]
+ frag 0 from TextNode start: 0, length: 5, rect: [729,16 33.640625x13] baseline: 10.390625
"Print"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -290,8 +290,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [742,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [758,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [758,16 38.234375x16]
- frag 0 from TextNode start: 0, length: 4, rect: [758,16 38.234375x16] baseline: 12.796875
+ BlockContainer <span> at [758,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [758,16 31.0625x13]
+ frag 0 from TextNode start: 0, length: 4, rect: [758,16 31.0625x13] baseline: 10.390625
"Save"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -310,8 +310,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [777,8] flex-item [0+0+0 16 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
TextNode <#text> (not painted)
- BlockContainer <span> at [793,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [793,16 46.59375x16]
- frag 0 from TextNode start: 0, length: 5, rect: [793,16 46.59375x16] baseline: 12.796875
+ BlockContainer <span> at [793,16] flex-item [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: inline overflow: [793,16 37.859375x13]
+ frag 0 from TextNode start: 0, length: 5, rect: [793,16 37.859375x13] baseline: 10.390625
"Tools"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
diff --git a/Tests/LibWeb/Text/expected/css/font-shorthand-system-fonts.txt b/Tests/LibWeb/Text/expected/css/font-shorthand-system-fonts.txt
new file mode 100644
index 00000000000..cc9a5051eb6
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/font-shorthand-system-fonts.txt
@@ -0,0 +1,7 @@
+caption: system-ui 13px 400 normal normal
+icon: system-ui 13px 400 normal normal
+menu: system-ui 13px 400 normal normal
+message-box: system-ui 13px 400 normal normal
+small-caption: system-ui 11px 400 normal normal
+status-bar: system-ui 10px 400 normal normal
+caption serif: rejected system-ui
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/system-fonts-serialization.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/system-fonts-serialization.tentative.txt
new file mode 100644
index 00000000000..31cbcd76e70
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/system-fonts-serialization.tentative.txt
@@ -0,0 +1,11 @@
+Harness status: OK
+
+Found 6 tests
+
+6 Fail
+Fail caption
+Fail icon
+Fail menu
+Fail message-box
+Fail small-caption
+Fail status-bar
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font.txt
index 1d8f2175a25..6b20c7dcc1a 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font.txt
@@ -2,10 +2,9 @@ Harness status: OK
Found 5 tests
-4 Pass
-1 Fail
+5 Pass
Pass 'font' does not support '1.2em "Fira Sans", sans-serif'
Pass 'font' does not support 'italic 1.2em "Fira Sans", serif'
Pass 'font' does not support 'italic small-caps bold 16px/2 cursive'
Pass 'font' does not support 'small-caps bold 24px/1 sans-serif'
-Fail 'font' does not support 'caption'
\ No newline at end of file
+Pass 'font' does not support 'caption'
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/css/font-shorthand-system-fonts.html b/Tests/LibWeb/Text/input/css/font-shorthand-system-fonts.html
new file mode 100644
index 00000000000..c83ed4f2a75
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/font-shorthand-system-fonts.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<div id="target"></div>
+<script>
+ // A system font keyword in the font shorthand resolves to the platform's UI font at the size that part of the UI
+ // uses, and resets the other font longhands.
+ test(() => {
+ const target = document.getElementById("target");
+ for (const keyword of ["caption", "icon", "menu", "message-box", "small-caption", "status-bar"]) {
+ target.style.cssText = "font-weight: bold; font-style: italic; line-height: 3";
+ target.style.font = keyword;
+ const style = getComputedStyle(target);
+ println(`${keyword}: ${style.fontFamily} ${style.fontSize} ${style.fontWeight} ${style.fontStyle} ${style.lineHeight}`);
+ }
+ // A system font keyword stands alone, so "caption serif" is invalid and leaves the declared font as it was.
+ const before = target.style.font;
+ target.style.font = "caption serif";
+ println(`caption serif: ${target.style.font === before ? "rejected" : "accepted"} ${getComputedStyle(target).fontFamily}`);
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-fonts/system-fonts-serialization.tentative.html b/Tests/LibWeb/Text/input/wpt-import/css/css-fonts/system-fonts-serialization.tentative.html
new file mode 100644
index 00000000000..19516c140b4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-fonts/system-fonts-serialization.tentative.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Fonts Test: Serialization of system fonts</title>
+<link rel="help" href="https://drafts.csswg.org/css-fonts/#valdef-font-caption">
+<link rel="author" title="Oriol Brufau" href="mailto:[email protected]">
+<div id="target"></div>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script>
+const target = document.getElementById("target");
+target.style.font = "initial";
+const fontLonghands = [...target.style];
+
+const cs = getComputedStyle(target);
+function copyComputedStyle() {
+ const data = {};
+ data.font = cs.font;
+ for (const longhand of fontLonghands) {
+ data[longhand] = cs[longhand];
+ }
+ return data;
+}
+
+function check(systemFont) {
+ target.style.cssText = "";
+ target.style.font = systemFont;
+
+ assert_equals(target.style.font, systemFont, "System font serializes as-is");
+ assert_array_equals([...target.style], fontLonghands, "System font sets all longhands");
+ for (const longhand of fontLonghands) {
+ assert_equals(target.style[longhand], "", `Longhand '${longhand}' serializes as empty string`);
+ }
+
+ const copy = copyComputedStyle();
+ for (const longhand of fontLonghands) {
+ const resolvedStyle = cs[longhand];
+ assert_not_equals(resolvedStyle, "");
+
+ target.style[longhand] = resolvedStyle;
+ assert_equals(target.style[longhand], resolvedStyle, `Can set longhand '${longhand}'`);
+
+ assert_equals(target.style.font, "", `Shorthand serializes as empty string after setting '${longhand}'`);
+ assert_object_equals(copyComputedStyle(), copy, `Other longhands still work after setting '${longhand}'`);
+
+ target.style.font = systemFont;
+ }
+}
+
+// Standard system fonts
+const systemFonts = ["caption", "icon", "menu", "message-box", "small-caption", "status-bar"];
+
+// Some browsers also support these non-standard system fonts
+const extras = ["-webkit-mini-control", "-webkit-small-control", "-webkit-control"];
+
+for (const extra of extras) {
+ if (CSS.supports("font", extra)) {
+ systemFonts.push(extra);
+ }
+}
+
+for (let systemFont of systemFonts) {
+ test(() => check(systemFont), systemFont);
+}
+</script>