Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <script src="../../../resources/testharness.js"></script> | |
| 5 <script src="../../../resources/testharnessreport.js"></script> | |
| 6 <script src="./resources/webgl-test-utils-full.js"></script> | |
| 7 </head> | |
| 8 | |
| 9 <body> | |
| 10 <script> | |
| 11 var wtu = WebGLTestUtils; | |
| 12 var canvas; | |
| 13 var gl; | |
| 14 var WEBGL_lose_context; | |
| 15 var allowRestore; | |
| 16 var contextLostEventFired; | |
| 17 var contextRestoredEventFired; | |
| 18 | |
| 19 function setupTest() | |
| 20 { | |
| 21 canvas = new OffscreenCanvas(10, 10); | |
| 22 gl = canvas.getContext('webgl'); | |
| 23 WEBGL_lose_context = getExtensionAndAddProperty(gl, "WEBGL_lose_context"); | |
| 24 if (!WEBGL_lose_context) { | |
| 25 return false; | |
| 26 } | |
| 27 | |
| 28 return true; | |
| 29 } | |
| 30 | |
| 31 function getExtensionAndAddProperty(gl, name) { | |
| 32 var ext = wtu.getExtensionWithKnownPrefixes(gl, name); | |
| 33 if (ext) { | |
| 34 ext.webglTestProperty = true; | |
| 35 } | |
| 36 return ext; | |
| 37 } | |
| 38 | |
| 39 function testOriginalContext() | |
| 40 { | |
| 41 assert_false(gl.isContextLost()); | |
| 42 assert_equals(gl.getError(), gl.NO_ERROR); | |
| 43 } | |
| 44 | |
| 45 function testLostContext(e) | |
| 46 { | |
| 47 assert_false(contextLostEventFired); | |
| 48 contextLostEventFired = true; | |
| 49 assert_true(gl.isContextLost()); | |
| 50 assert_equals(gl.getError(), gl.NO_ERROR); | |
| 51 if (allowRestore) | |
| 52 e.preventDefault(); | |
| 53 } | |
| 54 | |
| 55 function testShouldNotRestoreContext(e) | |
| 56 { | |
| 57 assert_true(false, "Should not restore the context unless preventDefault is called on the context lost event"); | |
| 58 } | |
| 59 | |
| 60 function compareGLError(glError, evalStr) { | |
| 61 var exception; | |
| 62 try { | |
| 63 eval(evalStr); | |
| 64 } catch(e) { | |
| 65 exception = e; | |
| 66 } | |
| 67 if (exception) { | |
| 68 assert_true(false, evalStr + " threw exception " + exception); | |
| 69 } else { | |
| 70 assert_equals(gl.getError(), glError); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 function testRestoredContext() | |
| 75 { | |
| 76 assert_false(contextRestoredEventFired); | |
| 77 contextRestoredEventFired = true; | |
| 78 // assert_false(gl.isContextLost()); | |
|
xidachen
2016/11/13 01:53:41
kbr@, zmo@: could you please provide some suggesti
| |
| 79 assert_equals(gl.getError(), gl.NO_ERROR); | |
| 80 } | |
| 81 | |
| 82 async_test(function(t) { | |
| 83 if (!setupTest()) | |
| 84 assert_true(false, "Cannot initialize test"); | |
| 85 testOriginalContext(); | |
| 86 | |
| 87 canvas.addEventListener("webglcontextrestored", testShouldNotRestoreContext) ; | |
| 88 canvas.addEventListener("webglcontextlost", function(e) { | |
| 89 testLostContext(e); | |
| 90 // restore the context after this event has exited. | |
| 91 setTimeout(t.step_func(function() { | |
| 92 // we didn't call prevent default so we should not be able to restore the context | |
| 93 compareGLError(gl.INVALID_OPERATION, "WEBGL_lose_context.restoreContext ()"); | |
| 94 assert_true(gl.isContextLost()); | |
| 95 assert_equals(gl.getError(), gl.NO_ERROR); | |
| 96 // gl methods should still be no-ops | |
| 97 compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUB E_MAP)"); | |
| 98 setTimeout(t.step_func_done(function() { | |
| 99 testRestoredContext(); | |
| 100 }, 0)); | |
| 101 }, 0)); | |
| 102 }); | |
| 103 allowRestore = false; | |
| 104 contextLostEventFired = false; | |
| 105 contextRestoredEventFired = false; | |
| 106 | |
| 107 WEBGL_lose_context.loseContext(); | |
| 108 // The context should be lost immediately. | |
| 109 assert_true(gl.isContextLost()); | |
| 110 assert_equals(gl.getError(), gl.CONTEXT_LOST_WEBGL); | |
| 111 assert_equals(gl.getError(), gl.NO_ERROR); | |
| 112 // gl methods should be no-ops | |
| 113 compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP )"); | |
| 114 // but the event should not have been fired. | |
| 115 assert_false(contextLostEventFired); | |
| 116 }, 'Test behavior under a restored context with OffscreenCanvas'); | |
| 117 | |
| 118 </script> | |
| 119 </body> | |
| 120 </html> | |
| OLD | NEW |