browser_canvas-actor-test-06.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Tests if screenshots for arbitrary draw calls are generated properly.
  5. */
  6. function* ifTestingSupported() {
  7. let { target, front } = yield initCanvasDebuggerBackend(SIMPLE_CANVAS_TRANSPARENT_URL);
  8. let navigated = once(target, "navigate");
  9. yield front.setup({ reload: true });
  10. ok(true, "The front was setup up successfully.");
  11. yield navigated;
  12. ok(true, "Target automatically navigated when the front was set up.");
  13. let snapshotActor = yield front.recordAnimationFrame();
  14. let animationOverview = yield snapshotActor.getOverview();
  15. let functionCalls = animationOverview.calls;
  16. ok(functionCalls,
  17. "An array of function call actors was sent after recording.");
  18. is(functionCalls.length, 8,
  19. "The number of function call actors is correct.");
  20. is(functionCalls[0].name, "clearRect",
  21. "The first called function's name is correct.");
  22. is(functionCalls[2].name, "fillRect",
  23. "The second called function's name is correct.");
  24. is(functionCalls[4].name, "fillRect",
  25. "The third called function's name is correct.");
  26. is(functionCalls[6].name, "fillRect",
  27. "The fourth called function's name is correct.");
  28. let firstDrawCallScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[0]);
  29. let secondDrawCallScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[2]);
  30. let thirdDrawCallScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[4]);
  31. let fourthDrawCallScreenshot = yield snapshotActor.generateScreenshotFor(functionCalls[6]);
  32. ok(firstDrawCallScreenshot,
  33. "The first draw call has a screenshot attached.");
  34. is(firstDrawCallScreenshot.index, 0,
  35. "The first draw call has the correct screenshot index.");
  36. is(firstDrawCallScreenshot.width, 128,
  37. "The first draw call has the correct screenshot width.");
  38. is(firstDrawCallScreenshot.height, 128,
  39. "The first draw call has the correct screenshot height.");
  40. is([].find.call(Uint32(firstDrawCallScreenshot.pixels), e => e > 0), undefined,
  41. "The first draw call's screenshot's pixels seems to be completely transparent.");
  42. ok(secondDrawCallScreenshot,
  43. "The second draw call has a screenshot attached.");
  44. is(secondDrawCallScreenshot.index, 2,
  45. "The second draw call has the correct screenshot index.");
  46. is(secondDrawCallScreenshot.width, 128,
  47. "The second draw call has the correct screenshot width.");
  48. is(secondDrawCallScreenshot.height, 128,
  49. "The second draw call has the correct screenshot height.");
  50. is([].find.call(Uint32(firstDrawCallScreenshot.pixels), e => e > 0), undefined,
  51. "The second draw call's screenshot's pixels seems to be completely transparent.");
  52. ok(thirdDrawCallScreenshot,
  53. "The third draw call has a screenshot attached.");
  54. is(thirdDrawCallScreenshot.index, 4,
  55. "The third draw call has the correct screenshot index.");
  56. is(thirdDrawCallScreenshot.width, 128,
  57. "The third draw call has the correct screenshot width.");
  58. is(thirdDrawCallScreenshot.height, 128,
  59. "The third draw call has the correct screenshot height.");
  60. is([].find.call(Uint32(thirdDrawCallScreenshot.pixels), e => e > 0), 2160001024,
  61. "The third draw call's screenshot's pixels seems to not be completely transparent.");
  62. ok(fourthDrawCallScreenshot,
  63. "The fourth draw call has a screenshot attached.");
  64. is(fourthDrawCallScreenshot.index, 6,
  65. "The fourth draw call has the correct screenshot index.");
  66. is(fourthDrawCallScreenshot.width, 128,
  67. "The fourth draw call has the correct screenshot width.");
  68. is(fourthDrawCallScreenshot.height, 128,
  69. "The fourth draw call has the correct screenshot height.");
  70. is([].find.call(Uint32(fourthDrawCallScreenshot.pixels), e => e > 0), 2147483839,
  71. "The fourth draw call's screenshot's pixels seems to not be completely transparent.");
  72. isnot(firstDrawCallScreenshot.pixels, secondDrawCallScreenshot.pixels,
  73. "The screenshots taken on consecutive draw calls are different (1).");
  74. isnot(secondDrawCallScreenshot.pixels, thirdDrawCallScreenshot.pixels,
  75. "The screenshots taken on consecutive draw calls are different (2).");
  76. isnot(thirdDrawCallScreenshot.pixels, fourthDrawCallScreenshot.pixels,
  77. "The screenshots taken on consecutive draw calls are different (3).");
  78. yield removeTab(target.tab);
  79. finish();
  80. }
  81. function Uint32(src) {
  82. let charView = new Uint8Array(src);
  83. return new Uint32Array(charView.buffer);
  84. }