summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-mochitest/test_fuzzing_bugs.html
blob: 3b0b1016c8e65a6e70ae23d70dd1f47f57c4fb3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE HTML>
<title>WebGL fuzzy bugs</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script src="driver-info.js"></script>
<script src="webgl-util.js"></script>
<body>
<script>

// Test the framebufferTexture2D() call with a unbound texture.
function framebufferTexture2D_bug1257593() {
  var canvas = document.createElement('canvas');

  var gl = null;
  gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
  if (!gl) {
    todo(false, 'WebGL framebufferTexture2D test, webgl is unavailable.');
    return;
  }

  var texture = gl.createTexture(); // only createTexture(), but no bindBuffer()
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, texture, 0);

  ok(true, 'WebGL framebufferTexture2D with unbound texture');
}

// Test to call ClearBufferXXX() during context lost.
function webGL2ClearBufferXXX_bug1252414() {
  var canvas = document.createElement('canvas');

  var gl = canvas.getContext('webgl2');
  if (!gl) {
    todo(false, 'WebGL2 is not supported');
    return;
  }

  var ext = gl.getExtension('WEBGL_lose_context');
  if (!ext) {
    todo(false, 'WebGL ClearBufferXXX test, ext WEBGL_lose_context is unavailable.');
    return;
  }

  // Force to lose context.
  ext.loseContext();

  // Even thought the context is lost, all clearBuffer* function should still
  // work without crash.
  gl.clearBufferiv(gl.COLOR, 0, new Int32Array(10));
  gl.clearBufferuiv(gl.COLOR, 0, new Uint32Array(10));
  gl.clearBufferfv(gl.DEPTH, 0, new Float32Array(10));
  gl.clearBufferfi(gl.DEPTH_STENCIL, 0, 0.0, 0);

  ok(true, 'WebGL2 clearBufferXXX call during loseContext');
}

// Test gl function for multiple gl contexts switch.
function getFramebufferAttachmentParameter_bug1267100()
{
  var canvas1 = document.createElement('canvas');
  var canvas2 = document.createElement('canvas');

  var gl1 = null;
  gl1 = canvas1.getContext('webgl') || canvas1.getContext('experimental-webgl');
  if (!gl1) {
    todo(false, 'WebGL getFramebufferAttachmentParameter test, webgl is unavailable.');
    return;
  }
  var gl2 = null;
  gl2 = canvas2.getContext('webgl') || canvas2.getContext('experimental-webgl');
  if (!gl2) {
    todo(false, 'WebGL getFramebufferAttachmentParameter test, webgl is unavailable.');
    return;
  }

  gl1.bindFramebuffer(gl1.FRAMEBUFFER, gl1.createFramebuffer());
  gl2.scissor(0, 1, 2, 3);
  // The gl call should still work even though we use another gl context before.
  gl1.getFramebufferAttachmentParameter(gl1.FRAMEBUFFER,
                                        gl1.COLOR_ATTACHMENT0,
                                        gl1.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);

  ok(true, 'WebGL test getFramebufferAttachmentParameter');
}

// Test to call getFragDataLocation() when the fragment shader is detatched.
function getFragDataLocation_bug1259702() {
  var canvas = document.createElement('canvas');

  var gl = canvas.getContext('webgl2');

  if (!gl) {
    todo(false, 'WebGL2 is not supported');
    return;
  }

  var program = gl.createProgram();

  var vertexShaderSrc =
    "void main(void) { \
       gl_Position = vec4(1.0, 1.0, 1.0, 1.0); \
    }";
  var fragmentShaderSrc =
    "void main(void) { \
       gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); \
    }";

  var vertexShader = gl.createShader(gl.VERTEX_SHADER);
  var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);

  gl.shaderSource(vertexShader, vertexShaderSrc);
  gl.compileShader(vertexShader);
  gl.attachShader(program, vertexShader);

  gl.shaderSource(fragmentShader, fragmentShaderSrc);
  gl.compileShader(fragmentShader);
  gl.attachShader(program, fragmentShader);

  gl.linkProgram(program);
  if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
    var lastError = gl.getProgramInfoLog(program);
    ok(false, 'WebGL getFragDataLocation() test, error in linking:' +
        lastError);
    return;
  }

  gl.useProgram(program);

  gl.detachShader(program, fragmentShader);
  // Test the getFragDataLocation() call after detatch the shader.
  // This call should not hit crash.
  gl.getFragDataLocation(program, "foobar");

  ok(true, 'WebGL getFragDataLocation() call after detatch fragment shader');
}

function run() {
  webGL2ClearBufferXXX_bug1252414();
  framebufferTexture2D_bug1257593();
  getFramebufferAttachmentParameter_bug1267100();
  getFragDataLocation_bug1259702();

  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();

try {
  var prefArrArr = [
    ['webgl.force-enabled', true],
    ['webgl.enable-webgl2', true],
  ];
  var prefEnv = {'set': prefArrArr};
  SpecialPowers.pushPrefEnv(prefEnv, run);
} catch (e) {
  warning('No SpecialPowers, but trying WebGL2 anyway...');
  run();
}
</script>