context-mode.html (1663B)
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 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>WebGL2 Canvas Context Mode Conformance Tests</title> 12 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 13 <script src="../../js/js-test-pre.js"></script> 14 <script src="../../js/webgl-test-utils.js"></script> 15 </head> 16 <body> 17 <div id="description"></div> 18 <div id="console"></div> 19 <script> 20 "use strict"; 21 description("This test ensures WebGL 2.0 implementations respect the canvas's context mode."); 22 23 debug(""); 24 25 assertMsg(window.WebGLRenderingContext, 26 "WebGL2RenderingContext should be a member of window"); 27 assertMsg('WebGL2RenderingContext' in window, 28 "WebGL2RenderingContext should be 'in' window"); 29 30 function testContextMode(mode, altMode) { 31 debug("Testing " + mode + " context type"); 32 33 let c = document.createElement('canvas'); 34 c.width = 2; 35 c.height = 2; 36 let gl = c.getContext(mode); 37 assertMsg(c.getContext(mode) == gl, 38 "Canvas.getContext('" + mode + "') should return the same value every time"); 39 try { 40 assertMsg(c.getContext(altMode) == null, 41 "Canvas.getContext('" + altMode + "') after getContext('" + mode + "') should return null"); 42 } catch (e) { 43 testFailed("Canvas.getContext('" + altMode + "') after getContext('" + mode + "') should not throw an exception"); 44 } 45 } 46 47 testContextMode('webgl2', 'webgl'); 48 testContextMode('webgl', 'webgl2'); 49 50 debug(""); 51 var successfullyParsed = true; 52 </script> 53 <script src="../../js/js-test-post.js"></script> 54 55 </body> 56 </html>