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 if error indicators are shown in the editor's gutter and text area michael@0: * when there's a shader compilation error. michael@0: */ michael@0: michael@0: function ifWebGLSupported() { michael@0: let [target, debuggee, panel] = yield initShaderEditor(SIMPLE_CANVAS_URL); michael@0: let { gFront, EVENTS, ShadersEditorsView } = panel.panelWin; michael@0: michael@0: reload(target); michael@0: yield promise.all([ michael@0: once(gFront, "program-linked"), michael@0: once(panel.panelWin, EVENTS.SOURCES_SHOWN) michael@0: ]); michael@0: michael@0: let vsEditor = yield ShadersEditorsView._getEditor("vs"); michael@0: let fsEditor = yield ShadersEditorsView._getEditor("fs"); michael@0: michael@0: vsEditor.replaceText("vec3", { line: 7, ch: 22 }, { line: 7, ch: 26 }); michael@0: let [, vertError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED); michael@0: checkHasVertFirstError(true, vertError); michael@0: checkHasVertSecondError(false, vertError); michael@0: info("Error marks added in the vertex shader editor."); michael@0: michael@0: vsEditor.insertText(" ", { line: 1, ch: 0 }); michael@0: yield once(panel.panelWin, EVENTS.EDITOR_ERROR_MARKERS_REMOVED); michael@0: is(vsEditor.getText(1), " precision lowp float;", "Typed space."); michael@0: checkHasVertFirstError(false, vertError); michael@0: checkHasVertSecondError(false, vertError); michael@0: info("Error marks removed while typing in the vertex shader editor."); michael@0: michael@0: [, vertError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED); michael@0: checkHasVertFirstError(true, vertError); michael@0: checkHasVertSecondError(false, vertError); michael@0: info("Error marks were re-added after recompiling the vertex shader."); michael@0: michael@0: fsEditor.replaceText("vec4", { line: 2, ch: 14 }, { line: 2, ch: 18 }); michael@0: let [, fragError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED); michael@0: checkHasVertFirstError(true, vertError); michael@0: checkHasVertSecondError(false, vertError); michael@0: checkHasFragError(true, fragError); michael@0: info("Error marks added in the fragment shader editor."); michael@0: michael@0: fsEditor.insertText(" ", { line: 1, ch: 0 }); michael@0: yield once(panel.panelWin, EVENTS.EDITOR_ERROR_MARKERS_REMOVED); michael@0: is(fsEditor.getText(1), " precision lowp float;", "Typed space."); michael@0: checkHasVertFirstError(true, vertError); michael@0: checkHasVertSecondError(false, vertError); michael@0: checkHasFragError(false, fragError); michael@0: info("Error marks removed while typing in the fragment shader editor."); michael@0: michael@0: [, fragError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED); michael@0: checkHasVertFirstError(true, vertError); michael@0: checkHasVertSecondError(false, vertError); michael@0: checkHasFragError(true, fragError); michael@0: info("Error marks were re-added after recompiling the fragment shader."); michael@0: michael@0: vsEditor.replaceText("2", { line: 3, ch: 19 }, { line: 3, ch: 20 }); michael@0: yield once(panel.panelWin, EVENTS.EDITOR_ERROR_MARKERS_REMOVED); michael@0: checkHasVertFirstError(false, vertError); michael@0: checkHasVertSecondError(false, vertError); michael@0: checkHasFragError(true, fragError); michael@0: info("Error marks removed while typing in the vertex shader editor again."); michael@0: michael@0: [, vertError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED); michael@0: checkHasVertFirstError(true, vertError); michael@0: checkHasVertSecondError(true, vertError); michael@0: checkHasFragError(true, fragError); michael@0: info("Error marks were re-added after recompiling the fragment shader again."); michael@0: michael@0: yield teardown(panel); michael@0: finish(); michael@0: michael@0: function checkHasVertFirstError(bool, error) { michael@0: ok(error, "Vertex shader compiled with errors."); michael@0: isnot(error.link, "", "The linkage status should not be empty."); michael@0: michael@0: let line = 7; michael@0: info("Checking first vertex shader error on line " + line + "..."); michael@0: michael@0: is(vsEditor.hasMarker(line, "errors", "error"), bool, michael@0: "Error is " + (bool ? "" : "not ") + "shown in the editor's gutter."); michael@0: is(vsEditor.hasLineClass(line, "error-line"), bool, michael@0: "Error style is " + (bool ? "" : "not ") + "applied to the faulty line."); michael@0: michael@0: let parsed = ShadersEditorsView._errors.vs; michael@0: is(parsed.length >= 1, bool, michael@0: "There's " + (bool ? ">= 1" : "< 1") + " parsed vertex shader error(s)."); michael@0: michael@0: if (bool) { michael@0: is(parsed[0].line, line, michael@0: "The correct line was parsed."); michael@0: is(parsed[0].messages.length, 2, michael@0: "There are 2 parsed messages."); michael@0: ok(parsed[0].messages[0].contains("'constructor' : too many arguments"), michael@0: "The correct first message was parsed."); michael@0: ok(parsed[0].messages[1].contains("'assign' : cannot convert from"), michael@0: "The correct second message was parsed."); michael@0: } michael@0: } michael@0: michael@0: function checkHasVertSecondError(bool, error) { michael@0: ok(error, "Vertex shader compiled with errors."); michael@0: isnot(error.link, "", "The linkage status should not be empty."); michael@0: michael@0: let line = 8; michael@0: info("Checking second vertex shader error on line " + line + "..."); michael@0: michael@0: is(vsEditor.hasMarker(line, "errors", "error"), bool, michael@0: "Error is " + (bool ? "" : "not ") + "shown in the editor's gutter."); michael@0: is(vsEditor.hasLineClass(line, "error-line"), bool, michael@0: "Error style is " + (bool ? "" : "not ") + "applied to the faulty line."); michael@0: michael@0: let parsed = ShadersEditorsView._errors.vs; michael@0: is(parsed.length >= 2, bool, michael@0: "There's " + (bool ? ">= 2" : "< 2") + " parsed vertex shader error(s)."); michael@0: michael@0: if (bool) { michael@0: is(parsed[1].line, line, michael@0: "The correct line was parsed."); michael@0: is(parsed[1].messages.length, 1, michael@0: "There is 1 parsed message."); michael@0: ok(parsed[1].messages[0].contains("'assign' : cannot convert from"), michael@0: "The correct message was parsed."); michael@0: } michael@0: } michael@0: michael@0: function checkHasFragError(bool, error) { michael@0: ok(error, "Fragment shader compiled with errors."); michael@0: isnot(error.link, "", "The linkage status should not be empty."); michael@0: michael@0: let line = 5; michael@0: info("Checking first vertex shader error on line " + line + "..."); michael@0: michael@0: is(fsEditor.hasMarker(line, "errors", "error"), bool, michael@0: "Error is " + (bool ? "" : "not ") + "shown in the editor's gutter."); michael@0: is(fsEditor.hasLineClass(line, "error-line"), bool, michael@0: "Error style is " + (bool ? "" : "not ") + "applied to the faulty line."); michael@0: michael@0: let parsed = ShadersEditorsView._errors.fs; michael@0: is(parsed.length >= 1, bool, michael@0: "There's " + (bool ? ">= 2" : "< 1") + " parsed fragment shader error(s)."); michael@0: michael@0: if (bool) { michael@0: is(parsed[0].line, line, michael@0: "The correct line was parsed."); michael@0: is(parsed[0].messages.length, 1, michael@0: "There is 1 parsed message."); michael@0: ok(parsed[0].messages[0].contains("'constructor' : too many arguments"), michael@0: "The correct message was parsed."); michael@0: } michael@0: } michael@0: }