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

/**
 * Tests if screenshots for arbitrary draw calls are generated properly.
 */

function* ifTestingSupported() {
  let { target, front } = yield initCanvasDebuggerBackend(SIMPLE_CANVAS_TRANSPARENT_URL);

  let navigated = once(target, "navigate");

  yield front.setup({ reload: true });
  ok(true, "The front was setup up successfully.");

  yield navigated;
  ok(true, "Target automatically navigated when the front was set up.");

  let snapshotActor = yield front.recordAnimationFrame();
  let animationOverview = yield snapshotActor.getOverview();

  let functionCalls = animationOverview.calls;
  ok(functionCalls,
    "An array of function call actors was sent after recording.");
  is(functionCalls.length, 8,
    "The number of function call actors is correct.");

  is(functionCalls[0].name, "clearRect",
    "The first called function's name is correct.");
  is(functionCalls[2].name, "fillRect",
    "The second called function's name is correct.");
  is(functionCalls[4].name, "fillRect",
    "The third called function's name is correct.");
  is(functionCalls[6].name, "fillRect",
    "The fourth called function's name is correct.");

  let firstDrawCallScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[0]);
  let secondDrawCallScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[2]);
  let thirdDrawCallScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[4]);
  let fourthDrawCallScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[6]);

  ok(firstDrawCallScreenshot,
    "The first draw call has a screenshot attached.");
  is(firstDrawCallScreenshot.index, 0,
    "The first draw call has the correct screenshot index.");
  is(firstDrawCallScreenshot.width, 128,
    "The first draw call has the correct screenshot width.");
  is(firstDrawCallScreenshot.height, 128,
    "The first draw call has the correct screenshot height.");
  is([].find.call(Uint32(firstDrawCallScreenshot.pixels), e => e > 0), undefined,
    "The first draw call's screenshot's pixels seems to be completely transparent.");

  ok(secondDrawCallScreenshot,
    "The second draw call has a screenshot attached.");
  is(secondDrawCallScreenshot.index, 2,
    "The second draw call has the correct screenshot index.");
  is(secondDrawCallScreenshot.width, 128,
    "The second draw call has the correct screenshot width.");
  is(secondDrawCallScreenshot.height, 128,
    "The second draw call has the correct screenshot height.");
  is([].find.call(Uint32(firstDrawCallScreenshot.pixels), e => e > 0), undefined,
    "The second draw call's screenshot's pixels seems to be completely transparent.");

  ok(thirdDrawCallScreenshot,
    "The third draw call has a screenshot attached.");
  is(thirdDrawCallScreenshot.index, 4,
    "The third draw call has the correct screenshot index.");
  is(thirdDrawCallScreenshot.width, 128,
    "The third draw call has the correct screenshot width.");
  is(thirdDrawCallScreenshot.height, 128,
    "The third draw call has the correct screenshot height.");
  is([].find.call(Uint32(thirdDrawCallScreenshot.pixels), e => e > 0), 2160001024,
    "The third draw call's screenshot's pixels seems to not be completely transparent.");

  ok(fourthDrawCallScreenshot,
    "The fourth draw call has a screenshot attached.");
  is(fourthDrawCallScreenshot.index, 6,
    "The fourth draw call has the correct screenshot index.");
  is(fourthDrawCallScreenshot.width, 128,
    "The fourth draw call has the correct screenshot width.");
  is(fourthDrawCallScreenshot.height, 128,
    "The fourth draw call has the correct screenshot height.");
  is([].find.call(Uint32(fourthDrawCallScreenshot.pixels), e => e > 0), 2147483839,
    "The fourth draw call's screenshot's pixels seems to not be completely transparent.");

  isnot(firstDrawCallScreenshot.pixels, secondDrawCallScreenshot.pixels,
    "The screenshots taken on consecutive draw calls are different (1).");
  isnot(secondDrawCallScreenshot.pixels, thirdDrawCallScreenshot.pixels,
    "The screenshots taken on consecutive draw calls are different (2).");
  isnot(thirdDrawCallScreenshot.pixels, fourthDrawCallScreenshot.pixels,
    "The screenshots taken on consecutive draw calls are different (3).");

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

function Uint32(src) {
  let charView = new Uint8Array(src);
  return new Uint32Array(charView.buffer);
}