Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / offscreencanvas / context-lost-restored.html
blob20281174626f318de439e8dbaaba06ed49771d71
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
11 <script src="../../js/js-test-pre.js"></script>
12 <script src="../../js/webgl-test-utils.js"></script>
13 <script src="../../js/tests/canvas-tests-utils.js"></script>
14 <script>
16 function init()
18 description("Tests behavior under a restored context for OffscreenCanvas.");
20 if (!window.OffscreenCanvas) {
21 testPassed("No OffscreenCanvas support");
22 finishTest();
23 return;
26 if (!setupTest()) {
27 testFailed("Cannot initialize test");
28 finishTest();
29 return;
32 canvas.addEventListener("webglcontextlost", function(e) {
33 if (!testLostContext(e)) {
34 testFailed("Some test failed");
35 finishTest();
36 return;
38 // restore the context after this event has exited.
39 setTimeout(function() {
40 // we didn't call prevent default so we should not be able to restore the context
41 if (!compareGLError(gl.INVALID_OPERATION, "WEBGL_lose_context.restoreContext()")) {
42 testFailed("Some test failed");
43 finishTest();
44 return;
46 testLosingAndRestoringContext().then(function(s) {
47 testPassed("Test passed");
48 finishTest();
49 return;
50 }, function(s) {
51 testFailed("Test failed: " + s);
52 finishTest();
53 return;
54 });
55 }, 0);
56 });
57 canvas.addEventListener("webglcontextrestored", function() {
58 testFailed("Some test failed");
59 finishTest();
60 return;
61 });
62 allowRestore = false;
63 contextLostEventFired = false;
64 contextRestoredEventFired = false;
66 if (!testOriginalContext()) {
67 testFailed("Some test failed");
68 finishTest();
69 return;
71 WEBGL_lose_context.loseContext();
72 // The context should be lost immediately.
73 shouldBeTrue("gl.isContextLost()");
74 shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
75 shouldBe("gl.getError()", "gl.NO_ERROR");
76 // gl methods should be no-ops
77 shouldBeTrue(compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)"));
78 // but the event should not have been fired.
79 shouldBeFalse("contextLostEventFired");
82 </script>
83 </head>
84 <body onload="init()">
85 <div id="description"></div>
86 <div id="console"></div>
87 </body>
88 </html>