Bug 1918529 - fix some subpixel misalignment issues with gfx.webrender.svg-filter...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / textures / misc / tex-image-with-invalid-data.html
blob4500624c813f64fd11107cc2ec7200ac86055119
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 <title>texImage2D and texSubImage2D tests with invalid data</title>
11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
12 <script src="../../../js/js-test-pre.js"></script>
13 <script src="../../../js/webgl-test-utils.js"></script>
14 </head>
15 <body>
16 <div id="description"></div>
17 <div id="console"></div>
18 <canvas id="canvas" width="2" height="2"> </canvas>
19 <script type="application/javascript">
20 description("texImage2D and texSubImage2D tests with invalid data");
22 var wtu = WebGLTestUtils;
23 var canvas = document.getElementById("canvas");
24 var contextVersion = wtu.getDefault3DContextVersion();
25 var gl = wtu.create3DContext(canvas);
26 if (!gl)
27 testFailed("Context created.");
28 else
29 testPassed("Context created.");
31 var tex;
33 function setup() {
34 tex = gl.createTexture();
35 gl.bindTexture(gl.TEXTURE_2D, tex);
36 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
39 function teardown() {
40 gl.deleteTexture(tex);
43 function test(desc, func, expected) {
44 debug(desc);
46 var exc = null;
47 try {
48 func();
49 } catch (x) {
50 exc = x;
53 if (expected == gl.INVALID_OPERATION) {
54 wtu.glErrorShouldBe(gl, expected);
55 } else if (expected == "exception") {
56 if (exc) {
57 testPassed("threw exception");
58 } else {
59 testFailed("did not throw exception");
64 test("Calling texImage2D with no WebGLTexture bound generates INVALID_OPERATION",
65 function () {
66 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
68 gl.INVALID_OPERATION);
70 test("Calling texSubImage2D with no WebGLTexture bound generates INVALID_OPERATION",
71 function () {
72 var buffer = new Uint8Array(4);
73 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
75 gl.INVALID_OPERATION);
77 setup();
79 test("Passing a buffer not large enough to texImage2D should generate an INVALID_OPERATION",
80 function () {
81 var tooSmall = new Uint8Array(64);
82 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
84 gl.INVALID_OPERATION);
86 if (contextVersion < 2) {
87 test("Passing texImage2D parameter data of Number type should throw an exception",
88 function () {
89 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, 42);
91 "exception");
92 } else {
93 test("Passing texImage2D parameter data of Number type should generate an INVALID_OPERATION",
94 function () {
95 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, 42);
97 gl.INVALID_OPERATION);
100 if (contextVersion < 2) {
101 test("Passing texImage2D parameter data of String type should throw a TypeError",
102 function () {
103 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
105 "exception");
106 } else {
107 test("Passing texImage2D parameter data of String type should generate an INVALID_OPERATION",
108 function () {
109 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
111 gl.INVALID_OPERATION);
114 test("Passing a buffer not large enough to texSubImage2D should generate an INVALID_OPERATION",
115 function () {
116 var tooSmall = new Uint8Array(64);
117 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
119 gl.INVALID_OPERATION);
121 if (contextVersion < 2) {
122 test("Passing texSubImage2D parameter data of Number type should throw a TypeError",
123 function () {
124 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, 42);
126 "exception");
127 } else {
128 test("Passing texSubImage2D parameter data of Number type should generate an INVALID_OPERATION",
129 function () {
130 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, 42);
132 gl.INVALID_OPERATION);
135 if (contextVersion < 2) {
136 test("Passing texSubImage2D parameter data of String type should throw a TypeError",
137 function () {
138 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
140 "exception");
141 } else {
142 test("Passing texSubImage2D parameter data of String type should generate an INVALID_OPERATION",
143 function () {
144 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
146 gl.INVALID_OPERATION);
149 teardown();
151 debug("");
152 var successfullyParsed = true;
153 </script>
154 <script src="../../../js/js-test-post.js"></script>
156 </body>
157 </html>