test_webgl_request_mismatch.html (2446B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 6 </head> 7 <body> 8 <script> 9 10 WEBGL_TYPES = {}; 11 WEBGL_TYPES['experimental-webgl'] = true; 12 WEBGL_TYPES.webgl = true; 13 14 function AreBothIn(a, b, set) { 15 return (a in set) && (b in set); 16 } 17 18 function IsAlias(typeA, typeB) { 19 if (typeA == typeB) 20 return true; 21 22 if (AreBothIn(typeA, typeB, WEBGL_TYPES)) 23 return true; 24 25 return false; 26 } 27 28 function TestContextRetrieval(creationType, requestType, functionalTypeSet) { 29 var canvas = document.createElement('canvas'); 30 var createdGL = canvas.getContext(creationType); 31 32 var didCreationSucceed = (createdGL != null); 33 if (creationType in functionalTypeSet) { 34 ok(createdGL, 'Context creation should succeed for type \'' + 35 creationType + '\''); 36 } else { 37 ok(!createdGL, 'Context creation should fail for type \'' + 38 creationType + '\''); 39 return; 40 } 41 42 var requestedGL = canvas.getContext(requestType); 43 44 if (requestType in functionalTypeSet && 45 IsAlias(creationType, requestType)) 46 { 47 ok(requestedGL, 'Request for \'' + requestType + '\' from \'' + 48 creationType + '\' should succeed.'); 49 ok(requestedGL == createdGL, 'Request for \'' + requestType + 50 '\' from \'' + creationType + 51 '\' should match.'); 52 } else { 53 ok(!requestedGL, 'Request for \'' + requestType + '\' from \'' + 54 creationType + '\' should fail.'); 55 } 56 } 57 58 function IsWebGLFunctional() { 59 var canvas = document.createElement('canvas'); 60 return canvas.getContext('experimental-webgl') != null; 61 } 62 63 function IsWebGLConformant() { 64 var canvas = document.createElement('canvas'); 65 return canvas.getContext('webgl') != null; 66 } 67 68 var typeList = ['2d', 'experimental-webgl', 'webgl']; 69 var functionalTypeSet = {}; 70 functionalTypeSet['2d'] = true; 71 72 if (IsWebGLFunctional()) 73 functionalTypeSet['experimental-webgl'] = true; 74 75 if (IsWebGLConformant()) 76 functionalTypeSet.webgl = true; 77 78 for (var i in typeList) { 79 var creationType = typeList[i]; 80 81 for (var j in typeList) { 82 var requestType = typeList[j]; 83 84 TestContextRetrieval(creationType, requestType, functionalTypeSet); 85 } 86 } 87 88 </script> 89 </body> 90 </html>