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 editing a vertex and a fragment shader works properly. 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: is(vsEditor.getText().indexOf("gl_Position"), 170, michael@0: "The vertex shader editor contains the correct text."); michael@0: is(fsEditor.getText().indexOf("gl_FragColor"), 97, michael@0: "The fragment shader editor contains the correct text."); michael@0: michael@0: is($("#vs-editor-label").hasAttribute("selected"), false, michael@0: "The vertex shader editor shouldn't be initially selected."); michael@0: is($("#fs-editor-label").hasAttribute("selected"), false, michael@0: "The vertex shader editor shouldn't be initially selected."); 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: 128, y: 128 }, { r: 191, g: 64, 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: michael@0: vsEditor.focus(); michael@0: michael@0: is($("#vs-editor-label").hasAttribute("selected"), true, michael@0: "The vertex shader editor should now be selected."); michael@0: is($("#fs-editor-label").hasAttribute("selected"), false, michael@0: "The vertex shader editor shouldn't still not be selected."); michael@0: michael@0: vsEditor.replaceText("2.0", { line: 7, ch: 44 }, { line: 7, ch: 47 }); michael@0: yield once(panel.panelWin, EVENTS.SHADER_COMPILED); michael@0: michael@0: ok(true, "Vertex shader was changed."); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: michael@0: ok(true, "The vertex shader was recompiled successfully."); michael@0: michael@0: fsEditor.focus(); michael@0: michael@0: is($("#vs-editor-label").hasAttribute("selected"), false, michael@0: "The vertex shader editor should now be deselected."); michael@0: is($("#fs-editor-label").hasAttribute("selected"), true, michael@0: "The vertex shader editor should now be selected."); michael@0: michael@0: fsEditor.replaceText("0.5", { line: 5, ch: 44 }, { line: 5, ch: 47 }); michael@0: yield once(panel.panelWin, EVENTS.SHADER_COMPILED); michael@0: michael@0: ok(true, "Fragment shader was changed."); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 127 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: michael@0: ok(true, "The fragment shader was recompiled successfully."); michael@0: michael@0: yield teardown(panel); michael@0: finish(); michael@0: }