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.

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

mercurial