blob: ec412cb3393c4658b566bfbe61225df7a71243fe (
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
64
65
66
67
68
69
70
71
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
description("Tests to ensure correct behaviour of canvas loss and restoration when size is extremely large then, restored to a reasonable value.");
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
var canvas = document.createElement('canvas')
canvas.addEventListener('contextlost', contextLost);
canvas.addEventListener('contextrestored', contextRestored);
var ctx = canvas.getContext('2d');
var lostEventHasFired = false;
verifyContextLost(false);
// WebIDL defines width and height as int. 2147483647 is int max.
var extremelyLargeNumber = 2147483647;
canvas.width = extremelyLargeNumber;
canvas.height = extremelyLargeNumber;
verifyContextLost(true);
canvas.width = extremelyLargeNumber;
verifyContextLost(true);
canvas.width = 100;
canvas.height = 100;
verifyContextLost(true); // Restoration is async.
// Restore a sane dimension
function verifyContextLost(shouldBeLost) {
// Verify context loss experimentally as well as isContextLost()
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 1, 1);
contextLostTest = ctx.getImageData(0, 0, 1, 1).data[1] == 0;
if (shouldBeLost) {
shouldBeTrue('contextLostTest');
shouldBeTrue('ctx.isContextLost()');
} else {
shouldBeFalse('contextLostTest');
shouldBeFalse('ctx.isContextLost()');
}
}
function contextLost() {
if (lostEventHasFired) {
testFailed('Context lost event was dispatched more than once.');
} else {
testPassed('Graphics context lost event dispatched.');
}
lostEventHasFired = true;
verifyContextLost(true);
}
function contextRestored() {
if (lostEventHasFired) {
testPassed('Context restored event dispatched after context lost.');
} else {
testFailed('Context restored event was dispatched before a context lost event.');
}
verifyContextLost(false);
if (window.testRunner) {
testRunner.notifyDone();
}
}
</script>
</body>
</html>
|