summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/offscreen/manual/draw-generic-family/2d.text.draw.generic.family.html
blob: a5fd7ab066112a0cb65162f8524a2e5512dd5c1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<title>OffscreenCanvas test: 2d.text.draw.generic.family</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<script>
function drawCanvas(ctx, family)
{
    ctx.font = '16px ' + family;
    ctx.fillText(family, 0, 16);
}

function testDrawGenericFamily(family)
{
    let offscreenCanvas = new OffscreenCanvas(88, 24);
    let oCtx = offscreenCanvas.getContext('2d');
    drawCanvas(oCtx, family);
    let canvas = document.createElement('canvas');
    let ctx = canvas.getContext('2d');
    drawCanvas(ctx, family);

    let data1 = oCtx.getImageData(0, 0, 88, 24).data;
    let data2 = ctx.getImageData(0, 0, 88, 24).data;
    assert_array_equals(data1, data2,
      "The image data generated by drawing generic font family '" + family +
      "' should be the same for both OffscreenCanvas and regular canvas");
}

test(function() {
    testDrawGenericFamily('sans-serif');
}, "Test that drawing sans-serif produces the same result between canvas and OffscreenCanvas");

test(function() {
    testDrawGenericFamily('serif');
}, "Test that drawing serif produces the same result between canvas and OffscreenCanvas");

test(function() {
    testDrawGenericFamily('cursive');
}, "Test that drawing cursive produces the same result between canvas and OffscreenCanvas");

test(function() {
    testDrawGenericFamily('fantasy');
}, "Test that drawing fantasy produces the same result between canvas and OffscreenCanvas");

test(function() {
    testDrawGenericFamily('monospace');
}, "Test that drawing monospace produces the same result between canvas and OffscreenCanvas");
</script>