browser_perf-details-01-toggle.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 details view toggles subviews.
  6. */
  7. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  8. const { initPerformanceInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
  9. const { startRecording, stopRecording } = require("devtools/client/performance/test/helpers/actions");
  10. const { once } = require("devtools/client/performance/test/helpers/event-utils");
  11. const { command } = require("devtools/client/performance/test/helpers/input-utils");
  12. add_task(function* () {
  13. let { panel } = yield initPerformanceInNewTab({
  14. url: SIMPLE_URL,
  15. win: window
  16. });
  17. let { EVENTS, $, DetailsView } = panel.panelWin;
  18. yield startRecording(panel);
  19. yield stopRecording(panel);
  20. info("Checking views on startup.");
  21. checkViews(DetailsView, $, "waterfall");
  22. // Select calltree view.
  23. let viewChanged = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED,
  24. { spreadArgs: true });
  25. command($("toolbarbutton[data-view='js-calltree']"));
  26. let [, viewName] = yield viewChanged;
  27. is(viewName, "js-calltree", "UI_DETAILS_VIEW_SELECTED fired with view name");
  28. checkViews(DetailsView, $, "js-calltree");
  29. // Select js flamegraph view.
  30. viewChanged = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED, { spreadArgs: true });
  31. command($("toolbarbutton[data-view='js-flamegraph']"));
  32. [, viewName] = yield viewChanged;
  33. is(viewName, "js-flamegraph", "UI_DETAILS_VIEW_SELECTED fired with view name");
  34. checkViews(DetailsView, $, "js-flamegraph");
  35. // Select waterfall view.
  36. viewChanged = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED, { spreadArgs: true });
  37. command($("toolbarbutton[data-view='waterfall']"));
  38. [, viewName] = yield viewChanged;
  39. is(viewName, "waterfall", "UI_DETAILS_VIEW_SELECTED fired with view name");
  40. checkViews(DetailsView, $, "waterfall");
  41. yield teardownToolboxAndRemoveTab(panel);
  42. });
  43. function checkViews(DetailsView, $, currentView) {
  44. for (let viewName in DetailsView.components) {
  45. let button = $(`toolbarbutton[data-view="${viewName}"]`);
  46. is(DetailsView.el.selectedPanel.id, DetailsView.components[currentView].id,
  47. `DetailsView correctly has ${currentView} selected.`);
  48. if (viewName == currentView) {
  49. ok(button.getAttribute("checked"), `${viewName} button checked.`);
  50. } else {
  51. ok(!button.getAttribute("checked"), `${viewName} button not checked.`);
  52. }
  53. }
  54. }