Backed out changeset 713114c0331a (bug 1938707) by developer request CLOSED TREE
[gecko.git] / dom / canvas / test / webgl-mochitest / test_webgl_request_mismatch.html
blob1dcab1c167ab92c35ab0c07d5b1c3e19975b983e
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>
10 WEBGL_TYPES = {};
11 WEBGL_TYPES['experimental-webgl'] = true;
12 WEBGL_TYPES.webgl = true;
14 function AreBothIn(a, b, set) {
15 return (a in set) && (b in set);
18 function IsAlias(typeA, typeB) {
19 if (typeA == typeB)
20 return true;
22 if (AreBothIn(typeA, typeB, WEBGL_TYPES))
23 return true;
25 return false;
28 function TestContextRetrieval(creationType, requestType, functionalTypeSet) {
29 var canvas = document.createElement('canvas');
30 var createdGL = canvas.getContext(creationType);
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;
42 var requestedGL = canvas.getContext(requestType);
44 if (requestType in functionalTypeSet &&
45 IsAlias(creationType, requestType))
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.');
58 function IsWebGLFunctional() {
59 var canvas = document.createElement('canvas');
60 return canvas.getContext('experimental-webgl') != null;
63 function IsWebGLConformant() {
64 var canvas = document.createElement('canvas');
65 return canvas.getContext('webgl') != null;
68 var typeList = ['2d', 'experimental-webgl', 'webgl'];
69 var functionalTypeSet = {};
70 functionalTypeSet['2d'] = true;
72 if (IsWebGLFunctional())
73 functionalTypeSet['experimental-webgl'] = true;
75 if (IsWebGLConformant())
76 functionalTypeSet.webgl = true;
78 for (var i in typeList) {
79 var creationType = typeList[i];
81 for (var j in typeList) {
82 var requestType = typeList[j];
84 TestContextRetrieval(creationType, requestType, functionalTypeSet);
88 </script>
89 </body>
90 </html>