Import 2dcontext Web Platform Tests
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / 2dcontext / drawing-text-to-the-canvas / 2d.text.measure.advances.html
1 <!DOCTYPE html>
2 <!-- DO NOT EDIT! This test has been generated by tools/gentest.py. -->
3 <title>Canvas test: 2d.text.measure.advances</title>
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <script src="/common/canvas-tests.js"></script>
7 <link rel="stylesheet" href="/common/canvas-tests.css">
8 <style>
9 @font-face {
10   font-family: CanvasTest;
11   src: url("/fonts/CanvasTest.ttf");
12 }
13 </style>
14 <body class="show_output">
15
16 <h1>2d.text.measure.advances</h1>
17 <p class="desc">Testing width advances</p>
18
19
20 <span style="font-family: CanvasTest; position: absolute; visibility: hidden">A</span>
21 <p class="output">Actual output:</p>
22 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
23
24 <ul id="d"></ul>
25 <script>
26 var t = async_test("Testing width advances");
27 _addTest(function(canvas, ctx) {
28
29 deferTest();
30 step_timeout(t.step_func_done(function () {
31     ctx.font = '50px CanvasTest';
32     ctx.direction = 'ltr';
33     ctx.align = 'left'
34     // Some platforms may return '-0'.
35     _assertSame(Math.abs(ctx.measureText('Hello').advances[0]), 0, "Math.abs(ctx.measureText('Hello').advances[\""+(0)+"\"])", "0");
36     // Different platforms may render text slightly different.
37     _assert(ctx.measureText('Hello').advances[1] >= 36, "ctx.measureText('Hello').advances[\""+(1)+"\"] >= 36");
38     _assert(ctx.measureText('Hello').advances[2] >= 58, "ctx.measureText('Hello').advances[\""+(2)+"\"] >= 58");
39     _assert(ctx.measureText('Hello').advances[3] >= 70, "ctx.measureText('Hello').advances[\""+(3)+"\"] >= 70");
40     _assert(ctx.measureText('Hello').advances[4] >= 80, "ctx.measureText('Hello').advances[\""+(4)+"\"] >= 80");
41
42     var tm = ctx.measureText('Hello');
43     _assertSame(ctx.measureText('Hello').advances[0], tm.advances[0], "ctx.measureText('Hello').advances[\""+(0)+"\"]", "tm.advances[\""+(0)+"\"]");
44     _assertSame(ctx.measureText('Hello').advances[1], tm.advances[1], "ctx.measureText('Hello').advances[\""+(1)+"\"]", "tm.advances[\""+(1)+"\"]");
45     _assertSame(ctx.measureText('Hello').advances[2], tm.advances[2], "ctx.measureText('Hello').advances[\""+(2)+"\"]", "tm.advances[\""+(2)+"\"]");
46     _assertSame(ctx.measureText('Hello').advances[3], tm.advances[3], "ctx.measureText('Hello').advances[\""+(3)+"\"]", "tm.advances[\""+(3)+"\"]");
47     _assertSame(ctx.measureText('Hello').advances[4], tm.advances[4], "ctx.measureText('Hello').advances[\""+(4)+"\"]", "tm.advances[\""+(4)+"\"]");
48 }), 500);
49
50
51 });
52 </script>
53