summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-fonts/generic-family-keywords-003.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/css/css-fonts/generic-family-keywords-003.html')
-rw-r--r--testing/web-platform/tests/css/css-fonts/generic-family-keywords-003.html53
1 files changed, 53 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-fonts/generic-family-keywords-003.html b/testing/web-platform/tests/css/css-fonts/generic-family-keywords-003.html
new file mode 100644
index 0000000000..c787b59fb2
--- /dev/null
+++ b/testing/web-platform/tests/css/css-fonts/generic-family-keywords-003.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<title>Test quotes vs. no-quotes matchings of generic font family keywords in a CanvasRenderingContext2D</title>
+<link rel="help" href="https://drafts.csswg.org/css-fonts-4/#family-name-syntax">
+<link rel="author" title="Frédéric Wang" href="mailto:fwang@igalia.com">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/css/css-fonts/support/font-family-keywords.js"></script>
+<link rel="stylesheet" type="text/css" href="/fonts/ahem.css"/>
+<body>
+<canvas id="canvas" width="400" height="150"></canvas>
+<script>
+ setup({ explicit_done: true });
+ window.addEventListener("load", () => { document.fonts.ready.then(runTests); });
+ function runTests() {
+ const measured_text = "|||||";
+ const canvas = document.getElementById("canvas");
+ const ctx = canvas.getContext("2d");
+ ctx.font = `25px Ahem`;
+ let ahem_expected_width = ctx.measureText(measured_text).width;
+
+ kGenericFontFamilyKeywords.forEach(keyword => {
+ test(() => {
+ ctx.font = `25px ${keyword}`;
+ let expected_width = ctx.measureText(measured_text).width;
+
+ // Insert the @font-face rules for quoted and unquoted keywords.
+ document.documentElement.insertAdjacentHTML('beforeend', `
+<style>
+@font-face {
+ font-family: ${keyword};
+ src: local(Ahem), url('/fonts/Ahem.ttf');
+}
+</style>
+<style>
+@font-face {
+ font-family: "${keyword}";
+ src: local(Ahem), url('/fonts/Ahem.ttf');
+}
+</style>`);
+
+ ctx.font = `25px ${keyword}`;
+ let unquoted_width = ctx.measureText(measured_text).width;
+ assert_equals(unquoted_width, expected_width, `unquoted ${keyword} does not match @font-face rule`);
+
+ ctx.font = `25px "${keyword}"`;
+ let quoted_width = ctx.measureText(measured_text).width;
+ assert_equals(quoted_width, ahem_expected_width, `quoted ${keyword} matches @font-face rule`);
+ }, `@font-face matching for quoted and unquoted ${keyword} (drawing text in a canvas)`);
+ });
+ done();
+ }
+</script>
+</body>