browser_canvas-actor-test-07.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Tests if screenshots for non-draw calls can still be retrieved properly,
  5. * by deferring the the most recent previous draw-call.
  6. */
  7. function* ifTestingSupported() {
  8. let { target, front } = yield initCanvasDebuggerBackend(SIMPLE_CANVAS_URL);
  9. let navigated = once(target, "navigate");
  10. yield front.setup({ reload: true });
  11. ok(true, "The front was setup up successfully.");
  12. yield navigated;
  13. ok(true, "Target automatically navigated when the front was set up.");
  14. let snapshotActor = yield front.recordAnimationFrame();
  15. let animationOverview = yield snapshotActor.getOverview();
  16. let functionCalls = animationOverview.calls;
  17. ok(functionCalls,
  18. "An array of function call actors was sent after recording.");
  19. is(functionCalls.length, 8,
  20. "The number of function call actors is correct.");
  21. let firstNonDrawCall = yield functionCalls[1].getDetails();
  22. let secondNonDrawCall = yield functionCalls[3].getDetails();
  23. let lastNonDrawCall = yield functionCalls[7].getDetails();
  24. is(firstNonDrawCall.name, "fillStyle",
  25. "The first non-draw function's name is correct.");
  26. is(secondNonDrawCall.name, "fillStyle",
  27. "The second non-draw function's name is correct.");
  28. is(lastNonDrawCall.name, "requestAnimationFrame",
  29. "The last non-draw function's name is correct.");
  30. let firstScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[1]);
  31. let secondScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[3]);
  32. let lastScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[7]);
  33. ok(firstScreenshot,
  34. "A screenshot was successfully retrieved for the first non-draw function.");
  35. ok(secondScreenshot,
  36. "A screenshot was successfully retrieved for the second non-draw function.");
  37. ok(lastScreenshot,
  38. "A screenshot was successfully retrieved for the last non-draw function.");
  39. let firstActualScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[0]);
  40. ok(sameArray(firstScreenshot.pixels, firstActualScreenshot.pixels),
  41. "The screenshot for the first non-draw function is correct.");
  42. is(firstScreenshot.width, 128,
  43. "The screenshot for the first non-draw function has the correct width.");
  44. is(firstScreenshot.height, 128,
  45. "The screenshot for the first non-draw function has the correct height.");
  46. let secondActualScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[2]);
  47. ok(sameArray(secondScreenshot.pixels, secondActualScreenshot.pixels),
  48. "The screenshot for the second non-draw function is correct.");
  49. is(secondScreenshot.width, 128,
  50. "The screenshot for the second non-draw function has the correct width.");
  51. is(secondScreenshot.height, 128,
  52. "The screenshot for the second non-draw function has the correct height.");
  53. let lastActualScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[6]);
  54. ok(sameArray(lastScreenshot.pixels, lastActualScreenshot.pixels),
  55. "The screenshot for the last non-draw function is correct.");
  56. is(lastScreenshot.width, 128,
  57. "The screenshot for the last non-draw function has the correct width.");
  58. is(lastScreenshot.height, 128,
  59. "The screenshot for the last non-draw function has the correct height.");
  60. ok(!sameArray(firstScreenshot.pixels, secondScreenshot.pixels),
  61. "The screenshots taken on consecutive draw calls are different (1).");
  62. ok(!sameArray(secondScreenshot.pixels, lastScreenshot.pixels),
  63. "The screenshots taken on consecutive draw calls are different (2).");
  64. yield removeTab(target.tab);
  65. finish();
  66. }
  67. function sameArray(a, b) {
  68. if (a.length != b.length) {
  69. return false;
  70. }
  71. for (let i = 0; i < a.length; i++) {
  72. if (a[i] !== b[i]) {
  73. return false;
  74. }
  75. }
  76. return true;
  77. }