browser_canvas-frontend-snapshot-select-01.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Tests if selecting snapshots in the frontend displays the appropriate data
  5. * respective to their recorded animation frame.
  6. */
  7. function* ifTestingSupported() {
  8. let { target, panel } = yield initCanvasDebuggerFrontend(SIMPLE_CANVAS_URL);
  9. let { window, $, EVENTS, SnapshotsListView, CallsListView } = panel.panelWin;
  10. yield reload(target);
  11. yield recordAndWaitForFirstSnapshot();
  12. info("First snapshot recorded.");
  13. is(SnapshotsListView.selectedIndex, 0,
  14. "A snapshot should be automatically selected after first recording.");
  15. is(CallsListView.selectedIndex, -1,
  16. "There should be no call item automatically selected in the snapshot.");
  17. yield recordAndWaitForAnotherSnapshot();
  18. info("Second snapshot recorded.");
  19. is(SnapshotsListView.selectedIndex, 0,
  20. "A snapshot should not be automatically selected after another recording.");
  21. is(CallsListView.selectedIndex, -1,
  22. "There should still be no call item automatically selected in the snapshot.");
  23. let secondSnapshotTarget = SnapshotsListView.getItemAtIndex(1).target;
  24. let snapshotSelected = waitForSnapshotSelection();
  25. EventUtils.sendMouseEvent({ type: "mousedown" }, secondSnapshotTarget, window);
  26. yield snapshotSelected;
  27. info("Second snapshot selected.");
  28. is(SnapshotsListView.selectedIndex, 1,
  29. "The second snapshot should now be selected.");
  30. is(CallsListView.selectedIndex, -1,
  31. "There should still be no call item automatically selected in the snapshot.");
  32. let firstDrawCallContents = $(".call-item-contents", CallsListView.getItemAtIndex(2).target);
  33. let screenshotDisplayed = once(window, EVENTS.CALL_SCREENSHOT_DISPLAYED);
  34. EventUtils.sendMouseEvent({ type: "mousedown" }, firstDrawCallContents, window);
  35. yield screenshotDisplayed;
  36. info("First draw call in the second snapshot selected.");
  37. is(SnapshotsListView.selectedIndex, 1,
  38. "The second snapshot should still be selected.");
  39. is(CallsListView.selectedIndex, 2,
  40. "The first draw call should now be selected in the snapshot.");
  41. let firstSnapshotTarget = SnapshotsListView.getItemAtIndex(0).target;
  42. snapshotSelected = waitForSnapshotSelection();
  43. EventUtils.sendMouseEvent({ type: "mousedown" }, firstSnapshotTarget, window);
  44. yield snapshotSelected;
  45. info("First snapshot re-selected.");
  46. is(SnapshotsListView.selectedIndex, 0,
  47. "The first snapshot should now be re-selected.");
  48. is(CallsListView.selectedIndex, -1,
  49. "There should still be no call item automatically selected in the snapshot.");
  50. function recordAndWaitForFirstSnapshot() {
  51. let recordingFinished = once(window, EVENTS.SNAPSHOT_RECORDING_FINISHED);
  52. let snapshotSelected = waitForSnapshotSelection();
  53. SnapshotsListView._onRecordButtonClick();
  54. return promise.all([recordingFinished, snapshotSelected]);
  55. }
  56. function recordAndWaitForAnotherSnapshot() {
  57. let recordingFinished = once(window, EVENTS.SNAPSHOT_RECORDING_FINISHED);
  58. SnapshotsListView._onRecordButtonClick();
  59. return recordingFinished;
  60. }
  61. function waitForSnapshotSelection() {
  62. let callListPopulated = once(window, EVENTS.CALL_LIST_POPULATED);
  63. let thumbnailsDisplayed = once(window, EVENTS.THUMBNAILS_DISPLAYED);
  64. let screenshotDisplayed = once(window, EVENTS.CALL_SCREENSHOT_DISPLAYED);
  65. return promise.all([
  66. callListPopulated,
  67. thumbnailsDisplayed,
  68. screenshotDisplayed
  69. ]);
  70. }
  71. yield teardown(panel);
  72. finish();
  73. }