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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Tests that errors are properly handled when trying to compile a
     6  * defective shader source.
     7  */
     9 function ifWebGLSupported() {
    10   let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL);
    11   front.setup({ reload: true });
    13   let programActor = yield once(front, "program-linked");
    14   let vertexShader = yield programActor.getVertexShader();
    15   let fragmentShader = yield programActor.getFragmentShader();
    17   let oldVertSource = yield vertexShader.getText();
    18   let newVertSource = oldVertSource.replace("vec4", "vec3");
    20   try {
    21     yield vertexShader.compile(newVertSource);
    22     ok(false, "Vertex shader was compiled with a defective source!");
    23   } catch (error) {
    24     ok(error,
    25       "The new vertex shader source was compiled with errors.");
    26     is(error.compile, "",
    27       "The compilation status should be empty.");
    28     isnot(error.link, "",
    29       "The linkage status should not be empty.");
    30     is(error.link.split("ERROR").length - 1, 2,
    31       "The linkage status contains two errors.");
    32     ok(error.link.contains("ERROR: 0:8: 'constructor'"),
    33       "A constructor error is contained in the linkage status.");
    34     ok(error.link.contains("ERROR: 0:8: 'assign'"),
    35       "An assignment error is contained in the linkage status.");
    36   }
    38   yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    39   yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    40   ok(true, "The shader was reverted to the old source.");
    42   let vertSource = yield vertexShader.getText();
    43   ok(vertSource.contains("vec4(aVertexPosition, 1.0);"),
    44     "The previous correct vertex shader source was preserved.");
    46   let oldFragSource = yield fragmentShader.getText();
    47   let newFragSource = oldFragSource.replace("vec3", "vec4");
    49   try {
    50     yield fragmentShader.compile(newFragSource);
    51     ok(false, "Fragment shader was compiled with a defective source!");
    52   } catch (error) {
    53     ok(error,
    54       "The new fragment shader source was compiled with errors.");
    55     is(error.compile, "",
    56       "The compilation status should be empty.");
    57     isnot(error.link, "",
    58       "The linkage status should not be empty.");
    59     is(error.link.split("ERROR").length - 1, 1,
    60       "The linkage status contains one error.");
    61     ok(error.link.contains("ERROR: 0:6: 'constructor'"),
    62       "A constructor error is contained in the linkage status.");
    63   }
    65   yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    66   yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    67   ok(true, "The shader was reverted to the old source.");
    69   let fragSource = yield fragmentShader.getText();
    70   ok(fragSource.contains("vec3 vFragmentColor;"),
    71     "The previous correct fragment shader source was preserved.");
    73   yield programActor.highlight([0, 1, 0, 1]);
    74   yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
    75   yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    76   ok(true, "Highlighting worked after setting a defective fragment source.");
    78   yield programActor.unhighlight();
    79   yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    80   yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    81   ok(true, "Unhighlighting worked after setting a defective vertex source.");
    83   yield removeTab(target.tab);
    84   finish();
    85 }

mercurial