content/canvas/test/webgl-conformance/conformance/misc/instanceof-test.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:29503b367036
1 <!--
2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <title>WebGL instanceof test.</title>
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../resources/js-test-pre.js"></script>
13 <script src="../resources/webgl-test.js"> </script>
14 <script src="../resources/webgl-test-utils.js"> </script>
15 </head>
16 <body>
17 <canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
20 <script id="vshader" type="x-shader/x-vertex">
21 attribute vec4 vPosition;
22 varying vec2 texCoord;
23 void main()
24 {
25 gl_Position = vPosition;
26 }
27 </script>
28
29 <script id="fshader" type="x-shader/x-fragment">
30 precision mediump float;
31 uniform vec4 color;
32 void main()
33 {
34 gl_FragColor = color;
35 }
36 </script>
37 <script>
38 var wtu = WebGLTestUtils;
39 description(document.title);
40 debug("Tests that instanceof works on WebGL objects.");
41 debug("");
42 var gl = wtu.create3DContext("canvas");
43 shouldBeTrue('gl instanceof WebGLRenderingContext');
44 shouldBeTrue('gl.createBuffer() instanceof WebGLBuffer');
45 shouldBeTrue('gl.createFramebuffer() instanceof WebGLFramebuffer');
46 shouldBeTrue('gl.createProgram() instanceof WebGLProgram');
47 shouldBeTrue('gl.createRenderbuffer() instanceof WebGLRenderbuffer');
48 shouldBeTrue('gl.createShader(gl.VERTEX_SHADER) instanceof WebGLShader');
49 shouldBeTrue('gl.createTexture() instanceof WebGLTexture');
50
51 var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['vPosition'], [0]);
52
53 shouldBeTrue('gl.getUniformLocation(program, "color") instanceof WebGLUniformLocation');
54 shouldBeTrue('gl.getActiveAttrib(program, 0) instanceof WebGLActiveInfo');
55 shouldBeTrue('gl.getActiveUniform(program, 0) instanceof WebGLActiveInfo');
56
57 debug("");
58 debug("Tests that those WebGL objects can not be constructed through new operator");
59 debug("");
60
61 function shouldThrowWithNew(objectType, objectName)
62 {
63 try {
64 new objectType;
65 testFailed('new ' + objectName + ' did not throw');
66 } catch (e) {
67 testPassed('new ' + objectName + ' threw an error');
68 }
69 }
70
71 shouldThrowWithNew(window.WebGLRenderingContext, 'WebGLRenderingContext');
72 shouldThrowWithNew(window.WebGLActiveInfo, 'WebGLActiveInfo');
73 shouldThrowWithNew(window.WebGLBuffer, 'WebGLBuffer');
74 shouldThrowWithNew(window.WebGLFramebuffer, 'WebGLFramebuffer');
75 shouldThrowWithNew(window.WebGLProgram, 'WebGLProgram');
76 shouldThrowWithNew(window.WebGLRenderbuffer, 'WebGLRenderbuffer');
77 shouldThrowWithNew(window.WebGLShader, 'WebGLShader');
78 shouldThrowWithNew(window.WebGLTexture, 'WebGLTexture');
79 shouldThrowWithNew(window.WebGLUniformLocation, 'WebGLUniformLocation');
80 shouldThrowWithNew(window.WebGLShaderPrecisionFormat, 'WebGLShaderPrecisionFormat');
81
82 successfullyParsed = true;
83 </script>
84 <script>finishTest();</script>
85
86 </body>
87 </html>
88
89

mercurial