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
|
<!DOCTYPE HTML>
<head>
<title>Canvas test: drawFocusIfNeeded with Path2D</title>
<script src="../../resources/js-test.js"></script>
</head>
<body style="padding: 0; margin: 0">
<canvas id="canvas" class="output" width="300" height="350">
<button id="button1"></button>
<button id="button2"></button>
</canvas>
<script>
if (window.testRunner)
testRunner.dumpAsText();
document.getElementById("button1").focus();
var canvas = document.getElementById("canvas").getContext("2d");
shouldThrow('canvas.drawFocusIfNeeded(undefined);');
shouldThrow('canvas.drawFocusIfNeeded(undefined, undefined);');
shouldThrow('canvas.drawFocusIfNeeded(null);');
shouldThrow('canvas.drawFocusIfNeeded(null, null);');
shouldThrow('canvas.drawFocusIfNeeded();');
var path = new Path2D();
path.rect(50, 50, 200, 100);
canvas.fillStyle = "#ccf";
canvas.fill(path);
// re-test null case after having defined a path (regression test for crbug.com/353248)
shouldThrow('canvas.drawFocusIfNeeded(null);');
shouldThrow('canvas.drawFocusIfNeeded(null, null);');
canvas.drawFocusIfNeeded(path, document.getElementById("button1"));
path = new Path2D();
path.rect(50, 200, 200, 100);
canvas.fillStyle = "#cfc";
canvas.fill(path);
canvas.drawFocusIfNeeded(path, document.getElementById("button2"));
// The top rect"s focus ring is tied to button1, which is focused.
// It should have an outline in some color other than the background color.
var imageData = canvas.getImageData(49, 50, 1, 1);
var data = imageData.data;
shouldBe("data[0] != 0 || data[1] != 0 || data[2] != 0", "true");
// The bottom rect"s focus ring is tied to button2, which is not focused.
imageData = canvas.getImageData(49, 200, 1, 1);
data = imageData.data;
shouldBe("data[0] == 0 && data[1] == 0 && data[2] == 0", "true");
</script>
</body>
|