browser/devtools/canvasdebugger/test/browser_canvas-actor-test-07.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/canvasdebugger/test/browser_canvas-actor-test-07.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests if screenshots for non-draw calls can still be retrieved properly,
     1.9 + * by deferring the the most recent previous draw-call.
    1.10 + */
    1.11 +
    1.12 +function ifTestingSupported() {
    1.13 +  let [target, debuggee, front] = yield initCanavsDebuggerBackend(SIMPLE_CANVAS_URL);
    1.14 +
    1.15 +  let navigated = once(target, "navigate");
    1.16 +
    1.17 +  yield front.setup({ reload: true });
    1.18 +  ok(true, "The front was setup up successfully.");
    1.19 +
    1.20 +  yield navigated;
    1.21 +  ok(true, "Target automatically navigated when the front was set up.");
    1.22 +
    1.23 +  let snapshotActor = yield front.recordAnimationFrame();
    1.24 +  let animationOverview = yield snapshotActor.getOverview();
    1.25 +
    1.26 +  let functionCalls = animationOverview.calls;
    1.27 +  ok(functionCalls,
    1.28 +    "An array of function call actors was sent after recording.");
    1.29 +  is(functionCalls.length, 8,
    1.30 +    "The number of function call actors is correct.");
    1.31 +
    1.32 +  let firstNonDrawCall = yield functionCalls[1].getDetails();
    1.33 +  let secondNonDrawCall = yield functionCalls[3].getDetails();
    1.34 +  let lastNonDrawCall = yield functionCalls[7].getDetails();
    1.35 +
    1.36 +  is(firstNonDrawCall.name, "fillStyle",
    1.37 +    "The first non-draw function's name is correct.");
    1.38 +  is(secondNonDrawCall.name, "fillStyle",
    1.39 +    "The second non-draw function's name is correct.");
    1.40 +  is(lastNonDrawCall.name, "requestAnimationFrame",
    1.41 +    "The last non-draw function's name is correct.");
    1.42 +
    1.43 +  let firstScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[1]);
    1.44 +  let secondScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[3]);
    1.45 +  let lastScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[7]);
    1.46 +
    1.47 +  ok(firstScreenshot,
    1.48 +    "A screenshot was successfully retrieved for the first non-draw function.");
    1.49 +  ok(secondScreenshot,
    1.50 +    "A screenshot was successfully retrieved for the second non-draw function.");
    1.51 +  ok(lastScreenshot,
    1.52 +    "A screenshot was successfully retrieved for the last non-draw function.");
    1.53 +
    1.54 +  let firstActualScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[0]);
    1.55 +  ok(sameArray(firstScreenshot.pixels, firstActualScreenshot.pixels),
    1.56 +    "The screenshot for the first non-draw function is correct.");
    1.57 +  is(firstScreenshot.width, 128,
    1.58 +    "The screenshot for the first non-draw function has the correct width.");
    1.59 +  is(firstScreenshot.height, 128,
    1.60 +    "The screenshot for the first non-draw function has the correct height.");
    1.61 +
    1.62 +  let secondActualScreenshot =  yield snapshotActor.generateScreenshotFor(functionCalls[2]);
    1.63 +  ok(sameArray(secondScreenshot.pixels, secondActualScreenshot.pixels),
    1.64 +    "The screenshot for the second non-draw function is correct.");
    1.65 +  is(secondScreenshot.width, 128,
    1.66 +    "The screenshot for the second non-draw function has the correct width.");
    1.67 +  is(secondScreenshot.height, 128,
    1.68 +    "The screenshot for the second non-draw function has the correct height.");
    1.69 +
    1.70 +  let lastActualScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[6]);
    1.71 +  ok(sameArray(lastScreenshot.pixels, lastActualScreenshot.pixels),
    1.72 +    "The screenshot for the last non-draw function is correct.");
    1.73 +  is(lastScreenshot.width, 128,
    1.74 +    "The screenshot for the last non-draw function has the correct width.");
    1.75 +  is(lastScreenshot.height, 128,
    1.76 +    "The screenshot for the last non-draw function has the correct height.");
    1.77 +
    1.78 +  ok(!sameArray(firstScreenshot.pixels, secondScreenshot.pixels),
    1.79 +    "The screenshots taken on consecutive draw calls are different (1).");
    1.80 +  ok(!sameArray(secondScreenshot.pixels, lastScreenshot.pixels),
    1.81 +    "The screenshots taken on consecutive draw calls are different (2).");
    1.82 +
    1.83 +  yield removeTab(target.tab);
    1.84 +  finish();
    1.85 +}
    1.86 +
    1.87 +function sameArray(a, b) {
    1.88 +  if (a.length != b.length) {
    1.89 +    return false;
    1.90 +  }
    1.91 +  for (let i = 0; i < a.length; i++) {
    1.92 +    if (a[i] !== b[i]) {
    1.93 +      return false;
    1.94 +    }
    1.95 +  }
    1.96 +  return true;
    1.97 +}

mercurial