summaryrefslogtreecommitdiffstats
path: root/devtools/client/shadereditor/test/browser_webgl-actor-test-15.js
blob: 0a65dbe0ae72c618a18209303814f4af895094e2 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests if program actors are cached when navigating in the bfcache.
 */

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

  // Attach frame scripts if in e10s to perform
  // history navigation via the content
  loadFrameScripts();

  reload(target);
  let firstProgram = yield once(front, "program-linked");
  yield checkFirstCachedPrograms(firstProgram);
  yield checkHighlightingInTheFirstPage(firstProgram);
  ok(true, "The cached programs behave correctly before the navigation.");

  navigate(target, MULTIPLE_CONTEXTS_URL);
  let [secondProgram, thirdProgram] = yield getPrograms(front, 2);
  yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]);
  yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram);
  ok(true, "The cached programs behave correctly after the navigation.");

  once(front, "program-linked").then(() => {
    ok(false, "Shouldn't have received any more program-linked notifications.");
  });

  yield navigateInHistory(target, "back");
  yield checkFirstCachedPrograms(firstProgram);
  yield checkHighlightingInTheFirstPage(firstProgram);
  ok(true, "The cached programs behave correctly after navigating back.");

  yield navigateInHistory(target, "forward");
  yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]);
  yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram);
  ok(true, "The cached programs behave correctly after navigating forward.");

  yield navigateInHistory(target, "back");
  yield checkFirstCachedPrograms(firstProgram);
  yield checkHighlightingInTheFirstPage(firstProgram);
  ok(true, "The cached programs behave correctly after navigating back again.");

  yield navigateInHistory(target, "forward");
  yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]);
  yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram);
  ok(true, "The cached programs behave correctly after navigating forward again.");

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

  function checkFirstCachedPrograms(programActor) {
    return Task.spawn(function* () {
      let programs = yield front.getPrograms();

      is(programs.length, 1,
        "There should be 1 cached program actor.");
      is(programs[0], programActor,
        "The cached program actor was the expected one.");
    });
  }

  function checkSecondCachedPrograms(oldProgramActor, newProgramActors) {
    return Task.spawn(function* () {
      let programs = yield front.getPrograms();

      is(programs.length, 2,
        "There should be 2 cached program actors after the navigation.");
      is(programs[0], newProgramActors[0],
        "The first cached program actor was the expected one after the navigation.");
      is(programs[1], newProgramActors[1],
        "The second cached program actor was the expected one after the navigation.");

      isnot(newProgramActors[0], oldProgramActor,
        "The old program actor is not equal to the new first program actor.");
      isnot(newProgramActors[1], oldProgramActor,
        "The old program actor is not equal to the new second program actor.");
    });
  }

  function checkHighlightingInTheFirstPage(programActor) {
    return Task.spawn(function* () {
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
      yield ensurePixelIs(front, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
      ok(true, "The corner pixel colors are correct before highlighting.");

      yield programActor.highlight([0, 1, 0, 1]);
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
      yield ensurePixelIs(front, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
      ok(true, "The corner pixel colors are correct after highlighting.");

      yield programActor.unhighlight();
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
      yield ensurePixelIs(front, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
      ok(true, "The corner pixel colors are correct after unhighlighting.");
    });
  }

  function checkHighlightingInTheSecondPage(firstProgramActor, secondProgramActor) {
    return Task.spawn(function* () {
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
      yield ensurePixelIs(front, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
      yield ensurePixelIs(front, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
      ok(true, "The two canvases are correctly drawn before highlighting.");

      yield firstProgramActor.highlight([1, 0, 0, 1]);
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
      yield ensurePixelIs(front, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
      yield ensurePixelIs(front, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
      ok(true, "The first canvas was correctly filled after highlighting.");

      yield secondProgramActor.highlight([0, 1, 0, 1]);
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2");
      yield ensurePixelIs(front, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
      yield ensurePixelIs(front, { x: 127, y: 127 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2");
      ok(true, "The second canvas was correctly filled after highlighting.");

      yield firstProgramActor.unhighlight();
      yield secondProgramActor.unhighlight();
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
      yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
      yield ensurePixelIs(front, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
      yield ensurePixelIs(front, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
      ok(true, "The two canvases were correctly filled after unhighlighting.");
    });
  }
}