summaryrefslogtreecommitdiffstats
path: root/devtools/client/shadereditor/test/browser_webgl-actor-test-07.js
blob: a7634de4435375ba858552df112d05268c222253 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that vertex and fragment shader sources can be changed.
 */

function* ifWebGLSupported() {
  let { target, front } = yield initBackend(SIMPLE_CANVAS_URL);
  front.setup({ reload: true });

  let programActor = yield once(front, "program-linked");
  let vertexShader = yield programActor.getVertexShader();
  let fragmentShader = yield programActor.getFragmentShader();

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

  let vertSource = yield vertexShader.getText();
  let fragSource = yield fragmentShader.getText();
  ok(!vertSource.includes("2.0"),
    "The vertex shader source is correct before changing it.");
  ok(!fragSource.includes("0.5"),
    "The fragment shader source is correct before changing it.");

  let newVertSource = vertSource.replace("1.0", "2.0");
  let status = yield vertexShader.compile(newVertSource);
  ok(!status,
    "The new vertex shader source was compiled without errors.");

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

  vertSource = yield vertexShader.getText();
  fragSource = yield fragmentShader.getText();
  ok(vertSource.includes("2.0"),
    "The vertex shader source is correct after changing it.");
  ok(!fragSource.includes("0.5"),
    "The fragment shader source is correct after changing the vertex shader.");

  let newFragSource = fragSource.replace("1.0", "0.5");
  status = yield fragmentShader.compile(newFragSource);
  ok(!status,
    "The new fragment shader source was compiled without errors.");

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

  vertSource = yield vertexShader.getText();
  fragSource = yield fragmentShader.getText();
  ok(vertSource.includes("2.0"),
    "The vertex shader source is correct after changing the fragment shader.");
  ok(fragSource.includes("0.5"),
    "The fragment shader source is correct after changing it.");

  yield removeTab(target.tab);
  finish();
}