blob: 42ca0f374280d2c28efaa8447f278aed4920bd51 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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>
|