browser/devtools/shadereditor/test/browser_se_shaders-edit-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/shadereditor/test/browser_se_shaders-edit-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests if editing a vertex and a fragment shader works properly.
     1.9 + */
    1.10 +
    1.11 +function ifWebGLSupported() {
    1.12 +  let [target, debuggee, panel] = yield initShaderEditor(SIMPLE_CANVAS_URL);
    1.13 +  let { gFront, $, EVENTS, ShadersEditorsView } = panel.panelWin;
    1.14 +
    1.15 +  reload(target);
    1.16 +  yield promise.all([
    1.17 +    once(gFront, "program-linked"),
    1.18 +    once(panel.panelWin, EVENTS.SOURCES_SHOWN)
    1.19 +  ]);
    1.20 +
    1.21 +  let vsEditor = yield ShadersEditorsView._getEditor("vs");
    1.22 +  let fsEditor = yield ShadersEditorsView._getEditor("fs");
    1.23 +
    1.24 +  is(vsEditor.getText().indexOf("gl_Position"), 170,
    1.25 +    "The vertex shader editor contains the correct text.");
    1.26 +  is(fsEditor.getText().indexOf("gl_FragColor"), 97,
    1.27 +    "The fragment shader editor contains the correct text.");
    1.28 +
    1.29 +  is($("#vs-editor-label").hasAttribute("selected"), false,
    1.30 +    "The vertex shader editor shouldn't be initially selected.");
    1.31 +  is($("#fs-editor-label").hasAttribute("selected"), false,
    1.32 +    "The vertex shader editor shouldn't be initially selected.");
    1.33 +
    1.34 +  yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    1.35 +  yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 191, g: 64, b: 0, a: 255 }, true);
    1.36 +  yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    1.37 +
    1.38 +  vsEditor.focus();
    1.39 +
    1.40 +  is($("#vs-editor-label").hasAttribute("selected"), true,
    1.41 +    "The vertex shader editor should now be selected.");
    1.42 +  is($("#fs-editor-label").hasAttribute("selected"), false,
    1.43 +    "The vertex shader editor shouldn't still not be selected.");
    1.44 +
    1.45 +  vsEditor.replaceText("2.0", { line: 7, ch: 44 }, { line: 7, ch: 47 });
    1.46 +  yield once(panel.panelWin, EVENTS.SHADER_COMPILED);
    1.47 +
    1.48 +  ok(true, "Vertex shader was changed.");
    1.49 +
    1.50 +  yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
    1.51 +  yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    1.52 +  yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true);
    1.53 +
    1.54 +  ok(true, "The vertex shader was recompiled successfully.");
    1.55 +
    1.56 +  fsEditor.focus();
    1.57 +
    1.58 +  is($("#vs-editor-label").hasAttribute("selected"), false,
    1.59 +    "The vertex shader editor should now be deselected.");
    1.60 +  is($("#fs-editor-label").hasAttribute("selected"), true,
    1.61 +    "The vertex shader editor should now be selected.");
    1.62 +
    1.63 +  fsEditor.replaceText("0.5", { line: 5, ch: 44 }, { line: 5, ch: 47 });
    1.64 +  yield once(panel.panelWin, EVENTS.SHADER_COMPILED);
    1.65 +
    1.66 +  ok(true, "Fragment shader was changed.");
    1.67 +
    1.68 +  yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
    1.69 +  yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 127 }, true);
    1.70 +  yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true);
    1.71 +
    1.72 +  ok(true, "The fragment shader was recompiled successfully.");
    1.73 +
    1.74 +  yield teardown(panel);
    1.75 +  finish();
    1.76 +}

mercurial