Bug 1096633 - Update request mismatch test for aliasing support. - r=kamidphish
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 10 Nov 2014 19:15:45 -0800
changeset 216164 f85d4a0211e9f232b2c130b482c492f44b818aa5
parent 216163 7025a18fc63bdd98b777a038f8aeda2184d439c4
child 216165 56b7833f99ff3a62c8eeb82ce84711aa4b7b8d53
push id27842
push usercbook@mozilla.com
push dateTue, 18 Nov 2014 16:25:55 +0000
treeherdermozilla-central@084441e904d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1096633
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1096633 - Update request mismatch test for aliasing support. - r=kamidphish
dom/canvas/test/webgl-mochitest/test_webgl_request_mismatch.html
--- a/dom/canvas/test/webgl-mochitest/test_webgl_request_mismatch.html
+++ b/dom/canvas/test/webgl-mochitest/test_webgl_request_mismatch.html
@@ -1,35 +1,90 @@
 <!DOCTYPE HTML>
-<title>WebGL test: Mismatched 'webgl' and 'experimental-webgl' context requests</title>
+<html>
+<head>
 <script src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
+</head>
 <body>
-<canvas id="c1"></canvas>
-<canvas id="c2"></canvas>
-<canvas id="c3"></canvas>
-<canvas id="c4"></canvas>
 <script>
 
-function testContextRetrieval(canvasId, creationId, requestId) {
-  var canvas = document.getElementById(canvasId);
-  ok(canvas, 'Invalid `canvasId`: ' + canvasId);
+WEBGL_TYPES = {};
+WEBGL_TYPES['experimental-webgl'] = true;
+WEBGL_TYPES['webgl'] = true;
 
-  var createdGL = canvas.getContext(creationId);
-  if (!createdGL)
-    return; // No WebGL on this machine?
+function AreBothIn(a, b, set) {
+    return (a in set) && (b in set);
+}
 
-  var requestedGL = canvas.getContext(requestId);
-  if (creationId == requestId) {
-    ok(requestedGL, 'Request for \'' + requestId + '\' on from \'' + creationId + '\' should succeed.');
-    ok(requestedGL == createdGL, 'Request for \'' + requestId + '\' on from \'' + creationId + '\' should match.');
-  } else {
-    ok(!requestedGL, 'Request for \'' + requestId + '\' on from \'' + creationId + '\' should fail.');
-  }
+function IsAlias(typeA, typeB) {
+    if (typeA == typeB)
+        return true;
+
+    if (AreBothIn(typeA, typeB, WEBGL_TYPES))
+        return true;
+
+    return false;
 }
 
-testContextRetrieval('c1', 'experimental-webgl', 'webgl');
-testContextRetrieval('c2', 'webgl', 'experimental-webgl');
-testContextRetrieval('c3', 'experimental-webgl', 'experimental-webgl');
-testContextRetrieval('c4', 'webgl', 'webgl');
+function TestContextRetrieval(creationType, requestType, functionalTypeSet) {
+    var canvas = document.createElement('canvas');
+    var createdGL = canvas.getContext(creationType);
+
+    var didCreationSucceed = (createdGL != null);
+    if (creationType in functionalTypeSet) {
+        ok(createdGL, 'Context creation should succeed for type \'' +
+                      creationType + '\'');
+    } else {
+        ok(!createdGL, 'Context creation should fail for type \'' +
+                       creationType + '\'');
+        return;
+    }
+
+    var requestedGL = canvas.getContext(requestType);
+
+    if (requestType in functionalTypeSet &&
+        IsAlias(creationType, requestType))
+    {
+        ok(requestedGL, 'Request for \'' + requestType + '\' from \'' +
+                        creationType + '\' should succeed.');
+        ok(requestedGL == createdGL, 'Request for \'' + requestType +
+                                     '\' from \'' + creationType +
+                                     '\' should match.');
+    } else {
+        ok(!requestedGL, 'Request for \'' + requestType + '\' from \'' +
+                         creationType + '\' should fail.');
+    }
+}
+
+function IsWebGLFunctional() {
+    var canvas = document.createElement('canvas');
+    return canvas.getContext('experimental-webgl') != null;
+}
+
+function IsWebGLConformant() {
+    var canvas = document.createElement('canvas');
+    return canvas.getContext('webgl') != null;
+}
+
+var typeList = ['2d', 'experimental-webgl', 'webgl'];
+var functionalTypeSet = {};
+functionalTypeSet['2d'] = true;
+
+if (IsWebGLFunctional())
+    functionalTypeSet['experimental-webgl'] = true;
+
+if (IsWebGLConformant())
+    functionalTypeSet['webgl'] = true;
+
+for (var i in typeList) {
+    var creationType = typeList[i];
+
+    for (var j in typeList) {
+        var requestType = typeList[j];
+
+        TestContextRetrieval(creationType, requestType, functionalTypeSet);
+    }
+}
 
 </script>
-
+</body>
+</html>