content/canvas/test/webgl-conformance/conformance/textures/tex-image-with-invalid-data.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="utf-8">
     5     <title>texImage2D and texSubImage2D tests with invalid data</title>
     6   <link rel="stylesheet" href="../../resources/js-test-style.css"/>
     7   <script src="../../resources/js-test-pre.js"></script>
     8   <script src="../resources/webgl-test.js"></script>
     9 </head>
    10 <body>
    11 <div id="description"></div>
    12 <div id="console"></div>
    13 <canvas id="canvas" width="2" height="2"> </canvas>
    14 <script type="text/javascript">
    15 description("texImage2D and texSubImage2D tests with invalid data");
    17 var canvas = document.getElementById("canvas");
    18 var gl = create3DContext(canvas);
    19 if (!gl)
    20   testFailed("Context created.");
    21 else
    22   testPassed("Context created.");
    24 var tex;
    26 function setup() {
    27     tex = gl.createTexture();
    28     gl.bindTexture(gl.TEXTURE_2D, bug32619_tests.tex);
    29     gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    30 }
    32 function teardown() {
    33     gl.deleteTexture(tex);
    34 }
    36 function test(desc, func, expected) {
    37     debug(desc);
    39     var exc = null;
    40     try {
    41 	func();
    42     } catch (x) {
    43 	exc = x;
    44     }
    46     if (expected == gl.INVALID_OPERATION) {
    47 	glErrorShouldBe(gl, expected);
    48     } else if (expected == "exception") {
    49         if (exc) {
    50 	    testPassed("threw exception");
    51 	} else {
    52 	    testFailed("did not throw exception");
    53 	}
    54     }
    55 }
    57 test("Passing a buffer not large enough to texImage2D should generate an INVALID_OPERATION",
    58      function () {
    59 	 var tooSmall = new Uint8Array(64);
    60 	 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
    61      },
    62      gl.INVALID_OPERATION);
    64 test("Passing texImage2D parameter data of Number type should throw an exception",
    65      function () {
    66       gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, 42);
    67      },
    68      "exception");
    70 test("Passing texImage2D parameter data of String type should throw a TypeError",
    71      function () {
    72       gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
    73      },
    74      "exception");
    75 test("Passing a buffer not large enough to texSubImage2D should generate an INVALID_OPERATION",
    76      function () {
    77 	 var tooSmall = new Uint8Array(64);
    78 	 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
    79      },
    80      gl.INVALID_OPERATION);
    82 test("Passing texSubImage2D parameter data of Number type should throw a TypeError",
    83      function () {
    84 	 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, 42);
    85      },
    86      "exception");
    88 test("Passing texSubImage2D parameter data of String type should throw a TypeError",
    89      function () {
    90       gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
    91      },
    92      "exception");
    94 debug("");
    95 successfullyParsed = true;
    96 </script>
    97 <script>finishTest();</script>
    99 </body>
   100 </html>

mercurial