Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / webgl / index-validation.html
blob9e8e5b673bfd3105eec0c2b855feebc556f18e79
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <script src="../../../resources/js-test.js"></script>
6 <script src="resources/webgl-test.js"></script>
7 </head>
8 <body>
9 <div id="description"></div>
10 <div id="console"></div>
12 <script>
13 description("Tests that index validation verifies the correct number of indices");
15 if (window.internals)
16 window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
18 function sizeInBytes(type) {
19 switch (type) {
20 case gl.BYTE:
21 case gl.UNSIGNED_BYTE:
22 return 1;
23 case gl.SHORT:
24 case gl.UNSIGNED_SHORT:
25 return 2;
26 case gl.INT:
27 case gl.UNSIGNED_INT:
28 case gl.FLOAT:
29 return 4;
30 default:
31 throw "unknown type";
35 var gl = create3DContext();
36 var program = loadStandardProgram(gl);
38 // 3 vertices => 1 triangle, interleaved data
39 var dataComplete = new Float32Array([0, 0, 0, 1,
40 0, 0, 1,
41 1, 0, 0, 1,
42 0, 0, 1,
43 1, 1, 1, 1,
44 0, 0, 1]);
45 var dataIncomplete = new Float32Array([0, 0, 0, 1,
46 0, 0, 1,
47 1, 0, 0, 1,
48 0, 0, 1,
49 1, 1, 1, 1]);
50 var indices = new Uint16Array([0, 1, 2]);
52 debug("Testing with valid indices");
54 var bufferComplete = gl.createBuffer();
55 gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete);
56 gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW);
57 var elements = gl.createBuffer();
58 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
59 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
60 gl.useProgram(program);
61 var vertexLoc = gl.getAttribLocation(program, "a_vertex");
62 var normalLoc = gl.getAttribLocation(program, "a_normal");
63 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
64 gl.enableVertexAttribArray(vertexLoc);
65 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
66 gl.enableVertexAttribArray(normalLoc);
67 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
68 glErrorShouldBe(gl, gl.NO_ERROR);
69 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
70 glErrorShouldBe(gl, gl.NO_ERROR);
72 debug("Testing with out-of-range indices");
74 var bufferIncomplete = gl.createBuffer();
75 gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete);
76 gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW);
77 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
78 gl.enableVertexAttribArray(vertexLoc);
79 gl.disableVertexAttribArray(normalLoc);
80 debug("Enable vertices, valid");
81 glErrorShouldBe(gl, gl.NO_ERROR);
82 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
83 glErrorShouldBe(gl, gl.NO_ERROR);
84 debug("Enable normals, out-of-range");
85 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
86 gl.enableVertexAttribArray(normalLoc);
87 glErrorShouldBe(gl, gl.NO_ERROR);
88 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
89 glErrorShouldBe(gl, gl.INVALID_OPERATION);
91 debug("Test with enabled attribute that does not belong to current program");
93 gl.disableVertexAttribArray(normalLoc);
94 var extraLoc = Math.max(vertexLoc, normalLoc) + 1;
95 gl.enableVertexAttribArray(extraLoc);
96 debug("Enable an extra attribute with null");
97 glErrorShouldBe(gl, gl.NO_ERROR);
98 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
99 glErrorShouldBe(gl, gl.INVALID_OPERATION);
100 debug("Enable an extra attribute with insufficient data buffer");
101 gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
102 glErrorShouldBe(gl, gl.NO_ERROR);
103 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
104 debug("Pass large negative index to vertexAttribPointer");
105 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), -2000000000 * sizeInBytes(gl.FLOAT));
106 glErrorShouldBe(gl, gl.INVALID_VALUE);
107 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
109 successfullyParsed = true;
110 </script>
112 </body>
113 </html>