browser/devtools/shadereditor/test/browser_webgl-actor-test-09.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/shadereditor/test/browser_webgl-actor-test-09.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     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 that errors are properly handled when trying to compile a
     1.9 + * defective shader source.
    1.10 + */
    1.11 +
    1.12 +function ifWebGLSupported() {
    1.13 +  let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL);
    1.14 +  front.setup({ reload: true });
    1.15 +
    1.16 +  let programActor = yield once(front, "program-linked");
    1.17 +  let vertexShader = yield programActor.getVertexShader();
    1.18 +  let fragmentShader = yield programActor.getFragmentShader();
    1.19 +
    1.20 +  let oldVertSource = yield vertexShader.getText();
    1.21 +  let newVertSource = oldVertSource.replace("vec4", "vec3");
    1.22 +
    1.23 +  try {
    1.24 +    yield vertexShader.compile(newVertSource);
    1.25 +    ok(false, "Vertex shader was compiled with a defective source!");
    1.26 +  } catch (error) {
    1.27 +    ok(error,
    1.28 +      "The new vertex shader source was compiled with errors.");
    1.29 +    is(error.compile, "",
    1.30 +      "The compilation status should be empty.");
    1.31 +    isnot(error.link, "",
    1.32 +      "The linkage status should not be empty.");
    1.33 +    is(error.link.split("ERROR").length - 1, 2,
    1.34 +      "The linkage status contains two errors.");
    1.35 +    ok(error.link.contains("ERROR: 0:8: 'constructor'"),
    1.36 +      "A constructor error is contained in the linkage status.");
    1.37 +    ok(error.link.contains("ERROR: 0:8: 'assign'"),
    1.38 +      "An assignment error is contained in the linkage status.");
    1.39 +  }
    1.40 +
    1.41 +  yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    1.42 +  yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    1.43 +  ok(true, "The shader was reverted to the old source.");
    1.44 +
    1.45 +  let vertSource = yield vertexShader.getText();
    1.46 +  ok(vertSource.contains("vec4(aVertexPosition, 1.0);"),
    1.47 +    "The previous correct vertex shader source was preserved.");
    1.48 +
    1.49 +  let oldFragSource = yield fragmentShader.getText();
    1.50 +  let newFragSource = oldFragSource.replace("vec3", "vec4");
    1.51 +
    1.52 +  try {
    1.53 +    yield fragmentShader.compile(newFragSource);
    1.54 +    ok(false, "Fragment shader was compiled with a defective source!");
    1.55 +  } catch (error) {
    1.56 +    ok(error,
    1.57 +      "The new fragment shader source was compiled with errors.");
    1.58 +    is(error.compile, "",
    1.59 +      "The compilation status should be empty.");
    1.60 +    isnot(error.link, "",
    1.61 +      "The linkage status should not be empty.");
    1.62 +    is(error.link.split("ERROR").length - 1, 1,
    1.63 +      "The linkage status contains one error.");
    1.64 +    ok(error.link.contains("ERROR: 0:6: 'constructor'"),
    1.65 +      "A constructor error is contained in the linkage status.");
    1.66 +  }
    1.67 +
    1.68 +  yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    1.69 +  yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    1.70 +  ok(true, "The shader was reverted to the old source.");
    1.71 +
    1.72 +  let fragSource = yield fragmentShader.getText();
    1.73 +  ok(fragSource.contains("vec3 vFragmentColor;"),
    1.74 +    "The previous correct fragment shader source was preserved.");
    1.75 +
    1.76 +  yield programActor.highlight([0, 1, 0, 1]);
    1.77 +  yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
    1.78 +  yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    1.79 +  ok(true, "Highlighting worked after setting a defective fragment source.");
    1.80 +
    1.81 +  yield programActor.unhighlight();
    1.82 +  yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    1.83 +  yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    1.84 +  ok(true, "Unhighlighting worked after setting a defective vertex source.");
    1.85 +
    1.86 +  yield removeTab(target.tab);
    1.87 +  finish();
    1.88 +}

mercurial