michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests that errors are properly handled when trying to compile a michael@0: * defective shader source. michael@0: */ michael@0: michael@0: function ifWebGLSupported() { michael@0: let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL); michael@0: front.setup({ reload: true }); michael@0: michael@0: let programActor = yield once(front, "program-linked"); michael@0: let vertexShader = yield programActor.getVertexShader(); michael@0: let fragmentShader = yield programActor.getFragmentShader(); michael@0: michael@0: let oldVertSource = yield vertexShader.getText(); michael@0: let newVertSource = oldVertSource.replace("vec4", "vec3"); michael@0: michael@0: try { michael@0: yield vertexShader.compile(newVertSource); michael@0: ok(false, "Vertex shader was compiled with a defective source!"); michael@0: } catch (error) { michael@0: ok(error, michael@0: "The new vertex shader source was compiled with errors."); michael@0: is(error.compile, "", michael@0: "The compilation status should be empty."); michael@0: isnot(error.link, "", michael@0: "The linkage status should not be empty."); michael@0: is(error.link.split("ERROR").length - 1, 2, michael@0: "The linkage status contains two errors."); michael@0: ok(error.link.contains("ERROR: 0:8: 'constructor'"), michael@0: "A constructor error is contained in the linkage status."); michael@0: ok(error.link.contains("ERROR: 0:8: 'assign'"), michael@0: "An assignment error is contained in the linkage status."); michael@0: } michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); michael@0: ok(true, "The shader was reverted to the old source."); michael@0: michael@0: let vertSource = yield vertexShader.getText(); michael@0: ok(vertSource.contains("vec4(aVertexPosition, 1.0);"), michael@0: "The previous correct vertex shader source was preserved."); michael@0: michael@0: let oldFragSource = yield fragmentShader.getText(); michael@0: let newFragSource = oldFragSource.replace("vec3", "vec4"); michael@0: michael@0: try { michael@0: yield fragmentShader.compile(newFragSource); michael@0: ok(false, "Fragment shader was compiled with a defective source!"); michael@0: } catch (error) { michael@0: ok(error, michael@0: "The new fragment shader source was compiled with errors."); michael@0: is(error.compile, "", michael@0: "The compilation status should be empty."); michael@0: isnot(error.link, "", michael@0: "The linkage status should not be empty."); michael@0: is(error.link.split("ERROR").length - 1, 1, michael@0: "The linkage status contains one error."); michael@0: ok(error.link.contains("ERROR: 0:6: 'constructor'"), michael@0: "A constructor error is contained in the linkage status."); michael@0: } michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); michael@0: ok(true, "The shader was reverted to the old source."); michael@0: michael@0: let fragSource = yield fragmentShader.getText(); michael@0: ok(fragSource.contains("vec3 vFragmentColor;"), michael@0: "The previous correct fragment shader source was preserved."); michael@0: michael@0: yield programActor.highlight([0, 1, 0, 1]); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); michael@0: ok(true, "Highlighting worked after setting a defective fragment source."); michael@0: michael@0: yield programActor.unhighlight(); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); michael@0: ok(true, "Unhighlighting worked after setting a defective vertex source."); michael@0: michael@0: yield removeTab(target.tab); michael@0: finish(); michael@0: }