|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if editing a vertex and a fragment shader works properly. |
|
6 */ |
|
7 |
|
8 function ifWebGLSupported() { |
|
9 let [target, debuggee, panel] = yield initShaderEditor(SIMPLE_CANVAS_URL); |
|
10 let { gFront, $, EVENTS, ShadersEditorsView } = panel.panelWin; |
|
11 |
|
12 reload(target); |
|
13 yield promise.all([ |
|
14 once(gFront, "program-linked"), |
|
15 once(panel.panelWin, EVENTS.SOURCES_SHOWN) |
|
16 ]); |
|
17 |
|
18 let vsEditor = yield ShadersEditorsView._getEditor("vs"); |
|
19 let fsEditor = yield ShadersEditorsView._getEditor("fs"); |
|
20 |
|
21 is(vsEditor.getText().indexOf("gl_Position"), 170, |
|
22 "The vertex shader editor contains the correct text."); |
|
23 is(fsEditor.getText().indexOf("gl_FragColor"), 97, |
|
24 "The fragment shader editor contains the correct text."); |
|
25 |
|
26 is($("#vs-editor-label").hasAttribute("selected"), false, |
|
27 "The vertex shader editor shouldn't be initially selected."); |
|
28 is($("#fs-editor-label").hasAttribute("selected"), false, |
|
29 "The vertex shader editor shouldn't be initially selected."); |
|
30 |
|
31 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); |
|
32 yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 191, g: 64, b: 0, a: 255 }, true); |
|
33 yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); |
|
34 |
|
35 vsEditor.focus(); |
|
36 |
|
37 is($("#vs-editor-label").hasAttribute("selected"), true, |
|
38 "The vertex shader editor should now be selected."); |
|
39 is($("#fs-editor-label").hasAttribute("selected"), false, |
|
40 "The vertex shader editor shouldn't still not be selected."); |
|
41 |
|
42 vsEditor.replaceText("2.0", { line: 7, ch: 44 }, { line: 7, ch: 47 }); |
|
43 yield once(panel.panelWin, EVENTS.SHADER_COMPILED); |
|
44 |
|
45 ok(true, "Vertex shader was changed."); |
|
46 |
|
47 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); |
|
48 yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 255 }, true); |
|
49 yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true); |
|
50 |
|
51 ok(true, "The vertex shader was recompiled successfully."); |
|
52 |
|
53 fsEditor.focus(); |
|
54 |
|
55 is($("#vs-editor-label").hasAttribute("selected"), false, |
|
56 "The vertex shader editor should now be deselected."); |
|
57 is($("#fs-editor-label").hasAttribute("selected"), true, |
|
58 "The vertex shader editor should now be selected."); |
|
59 |
|
60 fsEditor.replaceText("0.5", { line: 5, ch: 44 }, { line: 5, ch: 47 }); |
|
61 yield once(panel.panelWin, EVENTS.SHADER_COMPILED); |
|
62 |
|
63 ok(true, "Fragment shader was changed."); |
|
64 |
|
65 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); |
|
66 yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 127 }, true); |
|
67 yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true); |
|
68 |
|
69 ok(true, "The fragment shader was recompiled successfully."); |
|
70 |
|
71 yield teardown(panel); |
|
72 finish(); |
|
73 } |