summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/webgl/WebGLContextEvent.html
blob: f05701eb8bde250b65d1c4972d045f6d2fd6d75f (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
72
73
74
75
76
77
78
79
80
81
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="resources/webgl-test.js"></script>
<script src="resources/webgl-test-utils.js"></script>
<script>

var evt;
var canvas;
var context;
var extension;

function createNewCanvas()
{
    canvas = document.createElement("canvas");
    canvas.width = 1;
    canvas.height = 1;

    context = WebGLTestUtils.create3DContext(canvas);
    extension = context.getExtension("WEBGL_lose_context");
    if (!extension) {
        debug("Could not find the WEBGL_lose_context extension.");
        return;
    }
}

function runTest1()
{
    if (window.initNonKhronosFramework)
        window.initNonKhronosFramework(true);
    createNewCanvas();
    canvas.addEventListener("webglcontextlost", function(e) {
        evt = e;
        debug("Test that the event passed to a listener of webglcontextlost is a WebGLContextEvent.")
        shouldBe("evt.toString()", "'[object WebGLContextEvent]'");
        shouldBe("evt.statusMessage", "''");
        // Start the next test when event dispatch has finished.
        setTimeout(function() {
          runTest2();
        }, 0);
    }, false);
    extension.loseContext();
}

function runTest2()
{
    createNewCanvas();
    canvas.addEventListener("webglcontextlost", function(e) {
        e.preventDefault();
        // Restore the context after event dispatch has finished.
        setTimeout(function() {
          // Because context restoration is specified as being asynchronous, we can not verify
          // that the GL error state is empty here.
          extension.restoreContext();
        }, 0);
    }, false);
    canvas.addEventListener("webglcontextrestored", function(e) {
        evt = e;
        shouldBe("context.getError()", "context.NO_ERROR");
        debug("Test that the event passed to a listener of webglcontextrestored is a WebGLContextEvent.")
        shouldBe("evt.toString()", "'[object WebGLContextEvent]'");
        shouldBe("evt.statusMessage", "''");

        setTimeout(finish, 0);
    }, false);
    extension.loseContext();
}

function finish() {
    finishJSTest();
}

</script>

</head>
<body onload="runTest1()">
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas">
</body>
</html>