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
content / test / data / gpu / webgl-domain-unblocking.html [blame]
<html>
<head>
<script type="text/javascript">
var gl;
var contextLostReceived = false;
var contextRestored = false;
var numContextLosses = 0;
function sendToAutomationController(msg) {
if (window.domAutomationController) {
window.domAutomationController.send(msg);
}
console.log(msg);
}
function init()
{
var canvas = document.getElementById('c');
canvas.addEventListener('webglcontextlost', function(e) {
e.preventDefault();
++numContextLosses;
// This bakes in knowledge that GpuDataManagerImplPrivate blocks
// WebGL contexts from restoration after two context losses on the
// same domain.
if (numContextLosses > 1) {
// Make 100% sure that we can't fetch a WebGL context at this point.
var c2 = document.getElementById('c2');
if (c2.getContext('webgl') != null) {
sendToAutomationController("FAILED");
console.log('TEST FAILED - WebGL should have been blocked');
}
}
window.contextLostReceived = true;
window.contextRestored = false;
}, false);
canvas.addEventListener('webglcontextrestored', function(e) {
e.preventDefault();
window.contextLostReceived = false;
window.contextRestored = true;
}, false);
gl = canvas.getContext('webgl');
if (gl) {
sendToAutomationController("SUCCESS");
} else {
sendToAutomationController("FAILED");
console.log('TEST FAILED - WebGL should not have been blocked yet');
}
sendToAutomationController("LOADED");
}
</script>
</head>
<body bgcolor="lightgray" onload="init()">
<canvas id="c" width="400" height="300" style="border-width: 1px; border-style: solid;"></canvas>
<canvas id="c2" width="400" height="300" style="border-width: 1px; border-style: solid;"></canvas>
</body>
</html>