Bug 1414977 - Add test for drawing without index validation. - r=daoshengmu
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 06 Nov 2017 18:06:30 -0800
changeset 390485 25856ffb9083d2b133178c3aad624b6fd3329559
parent 390484 c0a66ad2d873254abdb670ed3bfeb1058c9e2490
child 390486 d2580222abc787c50573436a761be699778115d8
push id32830
push userarchaeopteryx@coole-files.de
push dateTue, 07 Nov 2017 10:56:46 +0000
treeherdermozilla-central@923836aebbc3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaoshengmu
bugs1414977
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1414977 - Add test for drawing without index validation. - r=daoshengmu MozReview-Commit-ID: 530Qj4dumIR
dom/canvas/test/webgl-mochitest/mochi-to-testcase.py
dom/canvas/test/webgl-mochitest/mochitest.ini
dom/canvas/test/webgl-mochitest/test_without_index_validation.html
--- a/dom/canvas/test/webgl-mochitest/mochi-to-testcase.py
+++ b/dom/canvas/test/webgl-mochitest/mochi-to-testcase.py
@@ -1,8 +1,9 @@
+#!python2
 import sys
 import os.path
 import re
 
 assert len(sys.argv) == 2
 mochiPath = sys.argv[1]
 
 extDotPos = mochiPath.find('.html')
@@ -54,16 +55,23 @@ function addLoadEvent(func) {
   window.addEventListener('load', func, false);
 }
 
 SimpleTest = {
   waitForExplicitFinish: function() {},
   finish: function() {},
   requestFlakyTimeout: function() {},
 };
+
+SpecialPowers = {
+  pushPrefEnv: function(env, func) {
+    console.log('SpecialPowers.pushPrefEnv: ' + JSON.stringify(env));
+    setTimeout(func, 0);
+  },
+};
 </script>
 <div id='mochi-to-testcase-output'></div>
 
 '''
 
 fin = open(mochiPath, 'rb')
 fout = open(testPath, 'wb')
 includePattern = re.compile('<script\\s*src=[\'"](.*)\\.js[\'"]>\\s*</script>')
--- a/dom/canvas/test/webgl-mochitest/mochitest.ini
+++ b/dom/canvas/test/webgl-mochitest/mochitest.ini
@@ -101,8 +101,9 @@ skip-if = toolkit == 'android' #bug 8654
 [test_fuzzing_bugs.html]
 [test_video_fastpath_mp4.html]
 [test_video_fastpath_theora.html]
 [test_video_fastpath_vp8.html]
 [test_video_fastpath_vp9.html]
 [test_webglcontextcreationerror.html]
 [test_webgl_fingerprinting_resistance.html]
 fail-if = (os == 'mac') || (os == 'win') # on try server, LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE = 512 on mac and LOCAL_GL_ALIASED_LINE_WIDTH_RANGE = [1, 1] on win
+[test_without_index_validation.html]
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-mochitest/test_without_index_validation.html
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset='utf-8'>
+<title>WebGL test: Drawing without index validation</title>
+<script src='/tests/SimpleTest/SimpleTest.js'></script>
+<link rel='stylesheet' href='/tests/SimpleTest/test.css'>
+
+<script id='vertSource' type='none'>
+void main(void) {
+  gl_PointSize = 1.0;
+  gl_Position = vec4(0, 0, 0, 1);
+}
+</script>
+
+<script id='fragSource' type='none'>
+precision mediump float;
+
+void main(void) {
+  gl_FragColor = vec4(0, 1, 0, 1);
+}
+</script>
+</head>
+<body>
+<script>
+
+function test() {
+  const c = document.createElement('canvas');
+  c.width = c.height = 1;
+  const gl = c.getContext('webgl');
+  if (!gl) {
+    todo(false, 'WebGL is unavailable.');
+    return;
+  }
+  document.body.appendChild(c);
+
+  const vs = gl.createShader(gl.VERTEX_SHADER);
+  gl.shaderSource(vs, vertSource.innerHTML.trim());
+  gl.compileShader(vs);
+  const fs = gl.createShader(gl.FRAGMENT_SHADER);
+  gl.shaderSource(fs, fragSource.innerHTML.trim());
+  gl.compileShader(fs);
+  const prog = gl.createProgram();
+  gl.attachShader(prog, vs);
+  gl.attachShader(prog, fs);
+  gl.linkProgram(prog);
+  gl.useProgram(prog);
+
+  gl.clearColor(1,0,0,1);
+  const pixel = new Uint32Array(1);
+  const pixelData = new Uint8Array(pixel.buffer);
+
+  function expectPixel(expected, info) {
+    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
+    ok(pixel[0] == expected,
+       '[' + info + '] Expected 0x' + expected.toString(16) + ', was 0x' + pixel[0].toString(16));
+  }
+
+  gl.clear(gl.COLOR_BUFFER_BIT);
+  expectPixel(0xFF0000FF, 'Clear');
+
+  gl.drawArrays(gl.POINTS, 0, 1);
+  expectPixel(0xFF00FF00, 'DrawArrays');
+
+  const indexBuffer = gl.createBuffer();
+  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
+  gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([0]), gl.STATIC_DRAW);
+
+  gl.clear(gl.COLOR_BUFFER_BIT);
+  gl.drawElements(gl.POINTS, 1, gl.UNSIGNED_SHORT, 0);
+  expectPixel(0xFF00FF00, 'DrawElements');
+
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+
+const prefArrArr = [
+  ['webgl.force-index-validation', -1]
+];
+const prefEnv = {'set': prefArrArr};
+SpecialPowers.pushPrefEnv(prefEnv, test);
+
+</script>
+</body>
+</html>
\ No newline at end of file