1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/misc/instanceof-test.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<title>WebGL instanceof test.</title> 1.14 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.15 +<script src="../../resources/js-test-pre.js"></script> 1.16 +<script src="../resources/webgl-test.js"> </script> 1.17 +<script src="../resources/webgl-test-utils.js"> </script> 1.18 +</head> 1.19 +<body> 1.20 +<canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas> 1.21 +<div id="description"></div> 1.22 +<div id="console"></div> 1.23 +<script id="vshader" type="x-shader/x-vertex"> 1.24 +attribute vec4 vPosition; 1.25 +varying vec2 texCoord; 1.26 +void main() 1.27 +{ 1.28 + gl_Position = vPosition; 1.29 +} 1.30 +</script> 1.31 + 1.32 +<script id="fshader" type="x-shader/x-fragment"> 1.33 +precision mediump float; 1.34 +uniform vec4 color; 1.35 +void main() 1.36 +{ 1.37 + gl_FragColor = color; 1.38 +} 1.39 +</script> 1.40 +<script> 1.41 +var wtu = WebGLTestUtils; 1.42 +description(document.title); 1.43 +debug("Tests that instanceof works on WebGL objects."); 1.44 +debug(""); 1.45 +var gl = wtu.create3DContext("canvas"); 1.46 +shouldBeTrue('gl instanceof WebGLRenderingContext'); 1.47 +shouldBeTrue('gl.createBuffer() instanceof WebGLBuffer'); 1.48 +shouldBeTrue('gl.createFramebuffer() instanceof WebGLFramebuffer'); 1.49 +shouldBeTrue('gl.createProgram() instanceof WebGLProgram'); 1.50 +shouldBeTrue('gl.createRenderbuffer() instanceof WebGLRenderbuffer'); 1.51 +shouldBeTrue('gl.createShader(gl.VERTEX_SHADER) instanceof WebGLShader'); 1.52 +shouldBeTrue('gl.createTexture() instanceof WebGLTexture'); 1.53 + 1.54 +var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['vPosition'], [0]); 1.55 + 1.56 +shouldBeTrue('gl.getUniformLocation(program, "color") instanceof WebGLUniformLocation'); 1.57 +shouldBeTrue('gl.getActiveAttrib(program, 0) instanceof WebGLActiveInfo'); 1.58 +shouldBeTrue('gl.getActiveUniform(program, 0) instanceof WebGLActiveInfo'); 1.59 + 1.60 +debug(""); 1.61 +debug("Tests that those WebGL objects can not be constructed through new operator"); 1.62 +debug(""); 1.63 + 1.64 +function shouldThrowWithNew(objectType, objectName) 1.65 +{ 1.66 + try { 1.67 + new objectType; 1.68 + testFailed('new ' + objectName + ' did not throw'); 1.69 + } catch (e) { 1.70 + testPassed('new ' + objectName + ' threw an error'); 1.71 + } 1.72 +} 1.73 + 1.74 +shouldThrowWithNew(window.WebGLRenderingContext, 'WebGLRenderingContext'); 1.75 +shouldThrowWithNew(window.WebGLActiveInfo, 'WebGLActiveInfo'); 1.76 +shouldThrowWithNew(window.WebGLBuffer, 'WebGLBuffer'); 1.77 +shouldThrowWithNew(window.WebGLFramebuffer, 'WebGLFramebuffer'); 1.78 +shouldThrowWithNew(window.WebGLProgram, 'WebGLProgram'); 1.79 +shouldThrowWithNew(window.WebGLRenderbuffer, 'WebGLRenderbuffer'); 1.80 +shouldThrowWithNew(window.WebGLShader, 'WebGLShader'); 1.81 +shouldThrowWithNew(window.WebGLTexture, 'WebGLTexture'); 1.82 +shouldThrowWithNew(window.WebGLUniformLocation, 'WebGLUniformLocation'); 1.83 +shouldThrowWithNew(window.WebGLShaderPrecisionFormat, 'WebGLShaderPrecisionFormat'); 1.84 + 1.85 +successfullyParsed = true; 1.86 +</script> 1.87 +<script>finishTest();</script> 1.88 + 1.89 +</body> 1.90 +</html> 1.91 + 1.92 +