Bug 1446232 - Add test for font family serialization. r=emilio draft
authorXidorn Quan <me@upsuper.org>
Fri, 16 Mar 2018 11:48:03 +1100
changeset 770424 8538117ad3009e566e65e6696294b9ec58279122
parent 770423 ab396840fa0df270f0ba843c344ff8d7400180e1
push id103409
push userxquan@mozilla.com
push dateWed, 21 Mar 2018 09:13:59 +0000
reviewersemilio
bugs1446232
milestone61.0a1
Bug 1446232 - Add test for font family serialization. r=emilio MozReview-Commit-ID: IsQ02ra2wvE
layout/style/test/mochitest.ini
layout/style/test/test_font_family_serialization.html
--- a/layout/style/test/mochitest.ini
+++ b/layout/style/test/mochitest.ini
@@ -223,16 +223,18 @@ skip-if = !stylo # Gecko fails this and 
 support-files = flexbox_layout_testcases.js
 [test_flexbox_order.html]
 [test_flexbox_order_abspos.html]
 [test_flexbox_order_table.html]
 [test_flexbox_reflow_counts.html]
 [test_font_face_cascade.html]
 [test_font_face_parser.html]
 [test_font_family_parsing.html]
+[test_font_family_serialization.html]
+skip-if = !stylo
 [test_font_loading_api.html]
 support-files =
   BitPattern.woff
   file_font_loading_api_vframe.html
 [test_garbage_at_end_of_declarations.html]
 [test_grid_container_shorthands.html]
 [test_grid_item_shorthands.html]
 [test_grid_shorthand_serialization.html]
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_font_family_serialization.html
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<meta charset="UTF-8">
+<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<div id="display"></div>
+<script>
+// This cannot be a web-platform test because this doesn't match what
+// the spec says at the moment. Specifically, the spec wants to have
+// all font family serialized to string, while in practice, all browsers
+// serialize simple them to identifiers in some cases.
+// We want to check our current behavior. This can be changed once
+// browsers have an agreement on the exact behavior to spec.
+
+// format: [input, expected serialization]
+const tests = [
+  // Basic cases
+  ['simple', 'simple'],
+  ['    simple    ', 'simple'],
+  ['multi idents font', 'multi idents font'],
+  ['    multi   idents   font    ', 'multi idents font'],
+  ['"wrapped name"', '"wrapped name"'],
+  ['"   wrapped  name   "', '"   wrapped  name   "'],
+
+  // Special whitespaces
+  ['\\ leading ws', '" leading ws"'],
+  [' \\   leading ws', '"  leading ws"'],
+  ['\\ \\ leading ws', '"  leading ws"'],
+  [' \\ \\   leading ws', '"   leading ws"'],
+  ['\\ \\ \\ leading ws', '"   leading ws"'],
+  ['trailing ws\\ ', '"trailing ws "'],
+  ['trailing ws\\   ', '"trailing ws "'],
+  ['trailing ws   \\ ', '"trailing ws  "'],
+  ['trailing ws\\ \\ ', '"trailing ws  "'],
+  ['escaped\\ ws', 'escaped ws'],
+  ['escaped\\    ws', '"escaped  ws"'],
+  ['escaped\\ \\ ws', '"escaped  ws"'],
+  ['escaped   \\ ws', '"escaped  ws"'],
+  ['escaped \\  ws', '"escaped   ws"'],
+];
+
+let el = document.getElementById("display");
+for (let [input, expected] of tests) {
+  test(function() {
+    el.style.fontFamily = input;
+    assert_equals(el.style.fontFamily, expected);
+  }, "Reserialization for " + JSON.stringify(input));
+}
+</script>