browser/devtools/shadereditor/test/browser_se_editors-error-gutter.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_editors-error-gutter.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,156 @@
     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 error indicators are shown in the editor's gutter and text area
     1.9 + * when there's a shader compilation error.
    1.10 + */
    1.11 +
    1.12 +function ifWebGLSupported() {
    1.13 +  let [target, debuggee, panel] = yield initShaderEditor(SIMPLE_CANVAS_URL);
    1.14 +  let { gFront, EVENTS, ShadersEditorsView } = panel.panelWin;
    1.15 +
    1.16 +  reload(target);
    1.17 +  yield promise.all([
    1.18 +    once(gFront, "program-linked"),
    1.19 +    once(panel.panelWin, EVENTS.SOURCES_SHOWN)
    1.20 +  ]);
    1.21 +
    1.22 +  let vsEditor = yield ShadersEditorsView._getEditor("vs");
    1.23 +  let fsEditor = yield ShadersEditorsView._getEditor("fs");
    1.24 +
    1.25 +  vsEditor.replaceText("vec3", { line: 7, ch: 22 }, { line: 7, ch: 26 });
    1.26 +  let [, vertError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED);
    1.27 +  checkHasVertFirstError(true, vertError);
    1.28 +  checkHasVertSecondError(false, vertError);
    1.29 +  info("Error marks added in the vertex shader editor.");
    1.30 +
    1.31 +  vsEditor.insertText(" ", { line: 1, ch: 0 });
    1.32 +  yield once(panel.panelWin, EVENTS.EDITOR_ERROR_MARKERS_REMOVED);
    1.33 +  is(vsEditor.getText(1), "       precision lowp float;", "Typed space.");
    1.34 +  checkHasVertFirstError(false, vertError);
    1.35 +  checkHasVertSecondError(false, vertError);
    1.36 +  info("Error marks removed while typing in the vertex shader editor.");
    1.37 +
    1.38 +  [, vertError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED);
    1.39 +  checkHasVertFirstError(true, vertError);
    1.40 +  checkHasVertSecondError(false, vertError);
    1.41 +  info("Error marks were re-added after recompiling the vertex shader.");
    1.42 +
    1.43 +  fsEditor.replaceText("vec4", { line: 2, ch: 14 }, { line: 2, ch: 18 });
    1.44 +  let [, fragError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED);
    1.45 +  checkHasVertFirstError(true, vertError);
    1.46 +  checkHasVertSecondError(false, vertError);
    1.47 +  checkHasFragError(true, fragError);
    1.48 +  info("Error marks added in the fragment shader editor.");
    1.49 +
    1.50 +  fsEditor.insertText(" ", { line: 1, ch: 0 });
    1.51 +  yield once(panel.panelWin, EVENTS.EDITOR_ERROR_MARKERS_REMOVED);
    1.52 +  is(fsEditor.getText(1), "       precision lowp float;", "Typed space.");
    1.53 +  checkHasVertFirstError(true, vertError);
    1.54 +  checkHasVertSecondError(false, vertError);
    1.55 +  checkHasFragError(false, fragError);
    1.56 +  info("Error marks removed while typing in the fragment shader editor.");
    1.57 +
    1.58 +  [, fragError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED);
    1.59 +  checkHasVertFirstError(true, vertError);
    1.60 +  checkHasVertSecondError(false, vertError);
    1.61 +  checkHasFragError(true, fragError);
    1.62 +  info("Error marks were re-added after recompiling the fragment shader.");
    1.63 +
    1.64 +  vsEditor.replaceText("2", { line: 3, ch: 19 }, { line: 3, ch: 20 });
    1.65 +  yield once(panel.panelWin, EVENTS.EDITOR_ERROR_MARKERS_REMOVED);
    1.66 +  checkHasVertFirstError(false, vertError);
    1.67 +  checkHasVertSecondError(false, vertError);
    1.68 +  checkHasFragError(true, fragError);
    1.69 +  info("Error marks removed while typing in the vertex shader editor again.");
    1.70 +
    1.71 +  [, vertError] = yield onceSpread(panel.panelWin, EVENTS.SHADER_COMPILED);
    1.72 +  checkHasVertFirstError(true, vertError);
    1.73 +  checkHasVertSecondError(true, vertError);
    1.74 +  checkHasFragError(true, fragError);
    1.75 +  info("Error marks were re-added after recompiling the fragment shader again.");
    1.76 +
    1.77 +  yield teardown(panel);
    1.78 +  finish();
    1.79 +
    1.80 +  function checkHasVertFirstError(bool, error) {
    1.81 +    ok(error, "Vertex shader compiled with errors.");
    1.82 +    isnot(error.link, "", "The linkage status should not be empty.");
    1.83 +
    1.84 +    let line = 7;
    1.85 +    info("Checking first vertex shader error on line " + line + "...");
    1.86 +
    1.87 +    is(vsEditor.hasMarker(line, "errors", "error"), bool,
    1.88 +      "Error is " + (bool ? "" : "not ") + "shown in the editor's gutter.");
    1.89 +    is(vsEditor.hasLineClass(line, "error-line"), bool,
    1.90 +      "Error style is " + (bool ? "" : "not ") + "applied to the faulty line.");
    1.91 +
    1.92 +    let parsed = ShadersEditorsView._errors.vs;
    1.93 +    is(parsed.length >= 1, bool,
    1.94 +      "There's " + (bool ? ">= 1" : "< 1") + " parsed vertex shader error(s).");
    1.95 +
    1.96 +    if (bool) {
    1.97 +      is(parsed[0].line, line,
    1.98 +        "The correct line was parsed.");
    1.99 +      is(parsed[0].messages.length, 2,
   1.100 +        "There are 2 parsed messages.");
   1.101 +      ok(parsed[0].messages[0].contains("'constructor' : too many arguments"),
   1.102 +        "The correct first message was parsed.");
   1.103 +      ok(parsed[0].messages[1].contains("'assign' : cannot convert from"),
   1.104 +        "The correct second message was parsed.");
   1.105 +    }
   1.106 +  }
   1.107 +
   1.108 +  function checkHasVertSecondError(bool, error) {
   1.109 +    ok(error, "Vertex shader compiled with errors.");
   1.110 +    isnot(error.link, "", "The linkage status should not be empty.");
   1.111 +
   1.112 +    let line = 8;
   1.113 +    info("Checking second vertex shader error on line " + line + "...");
   1.114 +
   1.115 +    is(vsEditor.hasMarker(line, "errors", "error"), bool,
   1.116 +      "Error is " + (bool ? "" : "not ") + "shown in the editor's gutter.");
   1.117 +    is(vsEditor.hasLineClass(line, "error-line"), bool,
   1.118 +      "Error style is " + (bool ? "" : "not ") + "applied to the faulty line.");
   1.119 +
   1.120 +    let parsed = ShadersEditorsView._errors.vs;
   1.121 +    is(parsed.length >= 2, bool,
   1.122 +      "There's " + (bool ? ">= 2" : "< 2") + " parsed vertex shader error(s).");
   1.123 +
   1.124 +    if (bool) {
   1.125 +      is(parsed[1].line, line,
   1.126 +        "The correct line was parsed.");
   1.127 +      is(parsed[1].messages.length, 1,
   1.128 +        "There is 1 parsed message.");
   1.129 +      ok(parsed[1].messages[0].contains("'assign' : cannot convert from"),
   1.130 +        "The correct message was parsed.");
   1.131 +    }
   1.132 +  }
   1.133 +
   1.134 +  function checkHasFragError(bool, error) {
   1.135 +    ok(error, "Fragment shader compiled with errors.");
   1.136 +    isnot(error.link, "", "The linkage status should not be empty.");
   1.137 +
   1.138 +    let line = 5;
   1.139 +    info("Checking first vertex shader error on line " + line + "...");
   1.140 +
   1.141 +    is(fsEditor.hasMarker(line, "errors", "error"), bool,
   1.142 +      "Error is " + (bool ? "" : "not ") + "shown in the editor's gutter.");
   1.143 +    is(fsEditor.hasLineClass(line, "error-line"), bool,
   1.144 +      "Error style is " + (bool ? "" : "not ") + "applied to the faulty line.");
   1.145 +
   1.146 +    let parsed = ShadersEditorsView._errors.fs;
   1.147 +    is(parsed.length >= 1, bool,
   1.148 +      "There's " + (bool ? ">= 2" : "< 1") + " parsed fragment shader error(s).");
   1.149 +
   1.150 +    if (bool) {
   1.151 +      is(parsed[0].line, line,
   1.152 +        "The correct line was parsed.");
   1.153 +      is(parsed[0].messages.length, 1,
   1.154 +        "There is 1 parsed message.");
   1.155 +      ok(parsed[0].messages[0].contains("'constructor' : too many arguments"),
   1.156 +        "The correct message was parsed.");
   1.157 +    }
   1.158 +  }
   1.159 +}

mercurial