summaryrefslogtreecommitdiffstats
path: root/devtools/client/shadereditor/test/browser_se_shaders-edit-01.js
blob: 0cb52ac1964423f0adf8c737ae6cbbc4819f4ab8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests if editing a vertex and a fragment shader works properly.
 */

function* ifWebGLSupported() {
  let { target, panel } = yield initShaderEditor(SIMPLE_CANVAS_URL);
  let { gFront, $, EVENTS, ShadersEditorsView } = panel.panelWin;

  reload(target);
  yield promise.all([
    once(gFront, "program-linked"),
    once(panel.panelWin, EVENTS.SOURCES_SHOWN)
  ]);

  let vsEditor = yield ShadersEditorsView._getEditor("vs");
  let fsEditor = yield ShadersEditorsView._getEditor("fs");

  is(vsEditor.getText().indexOf("gl_Position"), 170,
    "The vertex shader editor contains the correct text.");
  is(fsEditor.getText().indexOf("gl_FragColor"), 97,
    "The fragment shader editor contains the correct text.");

  is($("#vs-editor-label").hasAttribute("selected"), false,
    "The vertex shader editor shouldn't be initially selected.");
  is($("#fs-editor-label").hasAttribute("selected"), false,
    "The vertex shader editor shouldn't be initially selected.");

  yield ensurePixelIs(gFront, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
  yield ensurePixelIs(gFront, { x: 128, y: 128 }, { r: 191, g: 64, b: 0, a: 255 }, true);
  yield ensurePixelIs(gFront, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);

  vsEditor.focus();

  is($("#vs-editor-label").hasAttribute("selected"), true,
    "The vertex shader editor should now be selected.");
  is($("#fs-editor-label").hasAttribute("selected"), false,
    "The vertex shader editor shouldn't still not be selected.");

  vsEditor.replaceText("2.0", { line: 7, ch: 44 }, { line: 7, ch: 47 });
  yield once(panel.panelWin, EVENTS.SHADER_COMPILED);

  ok(true, "Vertex shader was changed.");

  yield ensurePixelIs(gFront, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  yield ensurePixelIs(gFront, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 255 }, true);
  yield ensurePixelIs(gFront, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true);

  ok(true, "The vertex shader was recompiled successfully.");

  fsEditor.focus();

  is($("#vs-editor-label").hasAttribute("selected"), false,
    "The vertex shader editor should now be deselected.");
  is($("#fs-editor-label").hasAttribute("selected"), true,
    "The vertex shader editor should now be selected.");

  fsEditor.replaceText("0.5", { line: 5, ch: 44 }, { line: 5, ch: 47 });
  yield once(panel.panelWin, EVENTS.SHADER_COMPILED);

  ok(true, "Fragment shader was changed.");

  yield ensurePixelIs(gFront, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  yield ensurePixelIs(gFront, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 127 }, true);
  yield ensurePixelIs(gFront, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true);

  ok(true, "The fragment shader was recompiled successfully.");

  yield teardown(panel);
  finish();
}