summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/context/context-type-test-2.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance2/context/context-type-test-2.html')
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance2/context/context-type-test-2.html80
1 files changed, 80 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/context/context-type-test-2.html b/dom/canvas/test/webgl-conf/checkout/conformance2/context/context-type-test-2.html
new file mode 100644
index 0000000000..42ca0f3742
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance2/context/context-type-test-2.html
@@ -0,0 +1,80 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>WebGL2 Canvas Conformance Tests</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<canvas id="canvas1" style="width: 50px; height: 50px;"> </canvas>
+<canvas id="canvas2" style="width: 50px; height: 50px;"> </canvas>
+<script>
+"use strict";
+description("This test ensures WebGL2 implementations interact correctly with the canvas tag.");
+
+debug("");
+debug("Canvas.getContext");
+
+function runTest() {
+ assertMsg(window.WebGL2RenderingContext,
+ "WebGL2RenderingContext should be a member of window");
+ assertMsg('WebGL2RenderingContext' in window,
+ "WebGL2RenderingContext should be 'in' window");
+
+ const wtu = WebGLTestUtils;
+ let canvas2 = document.getElementById("canvas2");
+ let gl2 = wtu.create3DContext(canvas2, null, 2);
+ if (!gl2) {
+ testFailed("Could not fetch WebGL 2.0 context");
+ return;
+ }
+ testPassed("Fetched WebGL2 context successfully");
+
+ debug("Checking WebGL2 context type");
+ assertMsg(gl2 instanceof WebGL2RenderingContext,
+ "context type should be WebGL2RenderingContext");
+
+ // WebGL1 contexts do not respond to the WebGL2 context type, and vice versa.
+ let canvas1 = document.getElementById("canvas1");
+ let gl1 = wtu.create3DContext(canvas1, null, 1);
+ if (!gl1) {
+ testFailed("Could not fetch WebGL 1.0 context");
+ return;
+ }
+
+ debug("Checking WebGL1 context type");
+ assertMsg(gl1 instanceof WebGLRenderingContext,
+ "context type should be WebGLRenderingContext");
+
+ let msg1 = "A canvas which has created a WebGL 1.0 context should not return it for a 'webgl2' context request";
+ if (canvas1.getContext("webgl2"))
+ testFailed(msg1);
+ else
+ testPassed(msg1);
+
+ let msg2 = "A canvas which has created a WebGL 2.0 context should not return it for a 'webgl' context request";
+ if (canvas2.getContext("webgl"))
+ testFailed(msg2);
+ else
+ testPassed(msg2);
+}
+
+runTest();
+debug("");
+
+var successfullyParsed = true;
+</script>
+<script src="../../js/js-test-post.js"></script>
+
+</body>
+</html>