content/canvas/test/test_canvas_font_setter.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/test_canvas_font_setter.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug </title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
    1.16 +<canvas id="display" height="200" width="200"></canvas>
    1.17 +<pre id="test">
    1.18 +<script type="application/javascript">
    1.19 +
    1.20 +var canvas = document.getElementById("display");
    1.21 +var cx = canvas.getContext("2d");
    1.22 +
    1.23 +is(cx.font, "10px sans-serif", "initial font of canvas context");
    1.24 +
    1.25 +cx.font = "italic 16px sans-serif";
    1.26 +is(cx.font, "italic 16px sans-serif", "valid font should round-trip");
    1.27 +cx.font = "bold 12px serif; background: green";
    1.28 +is(cx.font, "italic 16px sans-serif", "invalid font should be ignored");
    1.29 +
    1.30 +cx.font = "bold 12px/3.0 serif";
    1.31 +is(cx.font, "bold 12px serif", "line-height should be dropped");
    1.32 +cx.font = "inherit";
    1.33 +is(cx.font, "bold 12px serif", "inherit should be ignored");
    1.34 +cx.font = "boold 18px sans-serif";
    1.35 +is(cx.font, "bold 12px serif", "syntax error should be ignored");
    1.36 +cx.font = "menu";
    1.37 +todo_is(cx.font, "menu", "system fonts should work");
    1.38 +
    1.39 +function textmeas() {
    1.40 +  return cx.measureText("hello").width;
    1.41 +}
    1.42 +
    1.43 +cx.font = "66px serif";
    1.44 +var w_at_66 = textmeas();
    1.45 +cx.font = "20px serif";
    1.46 +var w_at_20 = textmeas();
    1.47 +ok(w_at_66 > w_at_20, "text should be wider at 66px than at 20px");
    1.48 +
    1.49 +canvas.style.fontSize = "33px";
    1.50 +cx.font = "2em serif";
    1.51 +is(cx.font, "2em serif", "serialization of em");
    1.52 +is(textmeas(), w_at_66, "em should be relative to canvas font size");
    1.53 +canvas.style.fontSize = "16px";
    1.54 +is(cx.font, "2em serif", "serialization of em");
    1.55 +is(textmeas(), w_at_66,
    1.56 +   "em should be relative to canvas font size at time of setting");
    1.57 +document.body.removeChild(canvas);
    1.58 +is(cx.font, "2em serif", "serialization of em");
    1.59 +is(textmeas(), w_at_66,
    1.60 +   "em should be relative to canvas font size at time of setting");
    1.61 +canvas.style.fontSize = "33px";
    1.62 +cx.font = "2em serif";
    1.63 +is(cx.font, "2em serif", "serialization of em");
    1.64 +is(textmeas(), w_at_20,
    1.65 +   "em should be relative to 10px when canvas not in document");
    1.66 +document.body.appendChild(canvas);
    1.67 +
    1.68 +</script>
    1.69 +</pre>
    1.70 +</body>
    1.71 +</html>

mercurial