Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / textures / misc / tex-image-with-bad-args-from-dom-elements.html
blob34ece056998aff87cff751bb32a6293a92011a6b
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
11 <script src="../../../js/js-test-pre.js"></script>
12 <script src="../../../js/webgl-test-utils.js"></script>
13 </head>
14 <body>
15 <canvas id="c" width="16" height="16"></canvas>
16 <div id="description"></div>
17 <div id="console"></div>
18 <script>
19 "use strict";
20 description('Tests texImage2D with invalid internalformat/format/type combinations from various dom elements');
22 debug("<a href='https://www.khronos.org/registry/webgl/specs/latest/2.0/#TEXTURE_TYPES_FORMATS_FROM_DOM_ELEMENTS_TABLE'>Valid internalformat/format/type combinations</a>");
23 debug("");
25 var wtu = WebGLTestUtils;
26 var gl = wtu.create3DContext("c", undefined, 2);
28 var doTexImage = function(domElement) {
29 var tex = gl.createTexture();
30 gl.bindTexture(gl.TEXTURE_2D, tex);
31 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB10_A2UI, gl.RGBA_INTEGER, gl.UNSIGNED_INT_2_10_10_10_REV, domElement);
32 wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_ENUM, gl.INVALID_OPERATION], "TexImage2D taking RGB10_A2UI/RGBA_INTEGER/UNSIGNED_INT_2_10_10_10_REV should fail");
33 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG8, gl.RG, gl.FLOAT, domElement);
34 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "TexImage2D taking RG8/RG/FLOAT should fail");
35 gl.deleteTexture(tex);
38 var createCanvas2DContext = function(width, height) {
39 var canvas = document.createElement("canvas");
40 canvas.width = width;
41 canvas.height = height;
42 var ctx = canvas.getContext("2d");
43 ctx.fillRect(0, 0, width, height);
44 return ctx;
47 var testImage = function(test) {
48 debug("HTMLImageElement");
49 var img = wtu.makeImage(test.src, function() {
50 doTexImage(img);
51 setTimeout(runNextTest, 0);
52 });
55 var testVideo = function(test) {
56 debug("HTMLVideoElement (" + test.videoType + ")");
57 var video = wtu.makeVideo(test.src);
58 if(!video.canPlayType(test.videoType).replace(/no/, '')) {
59 debug(test.videoType + " unsupported");
60 setTimeout(runNextTest, 0);
61 return;
63 wtu.startPlayingAndWaitForVideo(video, function() {
64 doTexImage(video);
65 setTimeout(runNextTest, 0);
66 });
69 var testCanvas = function(test) {
70 var ctx = createCanvas2DContext(test.width, test.height);
71 debug("HTMLCanvasElement");
72 doTexImage(ctx.canvas);
73 setTimeout(runNextTest, 0);
76 var testImageData = function(test) {
77 var ctx = createCanvas2DContext(test.width, test.height);
78 var imageData = ctx.getImageData(0, 0, test.width, test.height);
79 debug("ImageData");
80 doTexImage(imageData);
81 setTimeout(runNextTest, 0);
84 var testImageBitmap = function(test) {
85 debug("ImageBitmap");
86 if(!window.createImageBitmap || !window.ImageBitmap) {
87 debug("ImageBitmap isn't supported");
88 setTimeout(runNextTest, 0);
89 return;
91 var ctx = createCanvas2DContext(test.width, test.height);
92 createImageBitmap(ctx.canvas, 0, 0, test.width, test.height).then(function(imageBitmap) {
93 doTexImage(imageBitmap);
94 setTimeout(runNextTest, 0);
95 }, function() {
96 debug("createImageBitmap was rejected");
97 setTimeout(runNextTest, 0);
98 });
101 var tests = [
102 { type: "canvas", width: 64, height: 64, run: testCanvas },
103 { type: "image", src: "../../../resources/red-green.png", run: testImage },
104 { type: "ImageBitmap",width: 64, height: 64, run: testImageBitmap },
105 { type: "ImageData", width: 64, height: 64, run: testImageData },
106 { type: "video", src: "../../../resources/red-green.mp4", videoType: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', run: testVideo },
107 { type: "video", src: "../../../resources/red-green.bt601.vp9.webm", videoType: 'video/webm; codecs="vp9"', run: testVideo },
108 { type: "video", src: "../../../resources/red-green.webmvp8.webm", videoType: 'video/webm; codecs="vp8, vorbis"', run: testVideo },
111 var testIndex = 0;
112 var runNextTest = function() {
113 if (testIndex < tests.length) {
114 debug("");
115 var test = tests[testIndex];
116 ++testIndex;
117 test.run(test);
118 } else {
119 finishTest();
123 runNextTest();
125 </script>
126 </body>
127 </html>