browser_perf-overview-time-interval.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests that the `setTimeInterval` and `getTimeInterval` functions
  6. * work properly.
  7. */
  8. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  9. const { initPerformanceInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
  10. const { startRecording, stopRecording } = require("devtools/client/performance/test/helpers/actions");
  11. const { once } = require("devtools/client/performance/test/helpers/event-utils");
  12. add_task(function* () {
  13. let { panel } = yield initPerformanceInNewTab({
  14. url: SIMPLE_URL,
  15. win: window
  16. });
  17. let { EVENTS, OverviewView } = panel.panelWin;
  18. try {
  19. OverviewView.setTimeInterval({ starTime: 0, endTime: 1 });
  20. ok(false, "Setting a time interval shouldn't have worked.");
  21. } catch (e) {
  22. ok(true, "Setting a time interval didn't work, as expected.");
  23. }
  24. try {
  25. OverviewView.getTimeInterval();
  26. ok(false, "Getting the time interval shouldn't have worked.");
  27. } catch (e) {
  28. ok(true, "Getting the time interval didn't work, as expected.");
  29. }
  30. yield startRecording(panel);
  31. yield stopRecording(panel);
  32. // Get/set the time interval and wait for the event propagation.
  33. let rangeSelected = once(OverviewView, EVENTS.UI_OVERVIEW_RANGE_SELECTED);
  34. OverviewView.setTimeInterval({ startTime: 10, endTime: 20 });
  35. yield rangeSelected;
  36. let firstInterval = OverviewView.getTimeInterval();
  37. info("First interval start time: " + firstInterval.startTime);
  38. info("First interval end time: " + firstInterval.endTime);
  39. is(Math.round(firstInterval.startTime), 10,
  40. "The interval's start time was properly set.");
  41. is(Math.round(firstInterval.endTime), 20,
  42. "The interval's end time was properly set.");
  43. // Get/set another time interval and make sure there's no event propagation.
  44. function fail() {
  45. ok(false, "The selection event should not have propagated.");
  46. }
  47. OverviewView.on(EVENTS.UI_OVERVIEW_RANGE_SELECTED, fail);
  48. OverviewView.setTimeInterval({ startTime: 30, endTime: 40 }, { stopPropagation: true });
  49. OverviewView.off(EVENTS.UI_OVERVIEW_RANGE_SELECTED, fail);
  50. let secondInterval = OverviewView.getTimeInterval();
  51. info("Second interval start time: " + secondInterval.startTime);
  52. info("Second interval end time: " + secondInterval.endTime);
  53. is(Math.round(secondInterval.startTime), 30,
  54. "The interval's start time was properly set again.");
  55. is(Math.round(secondInterval.endTime), 40,
  56. "The interval's end time was properly set again.");
  57. yield teardownToolboxAndRemoveTab(panel);
  58. });