summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/2d.text.draw.fill.maxWidth.verySmall.html
blob: b98b1c901ee3f21df9ad25def7268e79e51b2ee1 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<head>
<style>
@font-face {
  font-family: Ahem;
  src: url('../../resources/Ahem.ttf');
}
</style>
</head>
<body>
<p>On success, there should only be a green rectangle.</p>
<canvas id="c" class="output" width="100" height="100"><p class="fallback">FAIL (fallback content)</p></canvas>
<div id="console"></div>

<script>
function drawCanvas(ctx) {
  ctx.fillStyle = '#0f0';
  ctx.fillRect(0,0,100,100);
  ctx.fillStyle = '#f00';
  ctx.fillText("XX", -10, 100, 10);
}

function doDeferredTest() {
  drawCanvas(ctx);

  // Check that the letter rendered appropriately
  var renderedCorrectly = true;

  // Check that there is only a green rectangle
  var imageData = ctx.getImageData(50,50,1,1);
  if (imageData.data[0] != 0) renderedCorrectly = false;
  if (imageData.data[1] != 255) renderedCorrectly = false;
  if (imageData.data[2] != 0) renderedCorrectly = false;
  if (imageData.data[3] != 255) renderedCorrectly = false;

  if (renderedCorrectly)
    document.getElementById("console").innerHTML = "TEST PASSED";
  else
    document.getElementById("console").innerHTML = "TEST FAILED";

  if (window.testRunner)
    testRunner.notifyDone();
}

if (window.testRunner) {
  testRunner.dumpAsText();
  testRunner.waitUntilDone();
}

var canvas = document.getElementById('c');
var ctx = canvas.getContext("2d");
ctx.font = "100px Ahem";

// Kick off loading of the font
ctx.fillText(" ", 0, 0);

// Wait for the font to load, then run
setTimeout(function() {
  doDeferredTest();
}, 50);
</script>
</body>
</html>