browser_perf-details-03-without-allocations.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 hides the allocations buttons when a recording
  6. * does not have allocations data ("withAllocations": false), and that when an
  7. * allocations panel is selected to a panel that does not have allocations goes
  8. * to a default panel instead.
  9. */
  10. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  11. const { UI_ENABLE_ALLOCATIONS_PREF } = require("devtools/client/performance/test/helpers/prefs");
  12. const { initPerformanceInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
  13. const { startRecording, stopRecording } = require("devtools/client/performance/test/helpers/actions");
  14. const { once } = require("devtools/client/performance/test/helpers/event-utils");
  15. const { setSelectedRecording } = require("devtools/client/performance/test/helpers/recording-utils");
  16. add_task(function* () {
  17. let { panel } = yield initPerformanceInNewTab({
  18. url: SIMPLE_URL,
  19. win: window
  20. });
  21. let {
  22. EVENTS,
  23. $,
  24. DetailsView,
  25. WaterfallView,
  26. MemoryCallTreeView,
  27. MemoryFlameGraphView
  28. } = panel.panelWin;
  29. let flameBtn = $("toolbarbutton[data-view='memory-flamegraph']");
  30. let callBtn = $("toolbarbutton[data-view='memory-calltree']");
  31. // Disable allocations to prevent recording them.
  32. Services.prefs.setBoolPref(UI_ENABLE_ALLOCATIONS_PREF, false);
  33. yield startRecording(panel);
  34. yield stopRecording(panel);
  35. ok(DetailsView.isViewSelected(WaterfallView),
  36. "The waterfall view is selected by default in the details view.");
  37. // Re-enable allocations to test.
  38. Services.prefs.setBoolPref(UI_ENABLE_ALLOCATIONS_PREF, true);
  39. // The toolbar buttons will always be hidden when a recording isn't available,
  40. // so make sure we have one that's finished.
  41. yield startRecording(panel);
  42. yield stopRecording(panel);
  43. ok(DetailsView.isViewSelected(WaterfallView),
  44. "The waterfall view is still selected in the details view.");
  45. is(callBtn.hidden, false,
  46. "The `memory-calltree` button is shown when recording has memory data.");
  47. is(flameBtn.hidden, false,
  48. "The `memory-flamegraph` button is shown when recording has memory data.");
  49. let selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  50. let rendered = once(MemoryCallTreeView, EVENTS.UI_MEMORY_CALL_TREE_RENDERED);
  51. DetailsView.selectView("memory-calltree");
  52. yield selected;
  53. yield rendered;
  54. ok(DetailsView.isViewSelected(MemoryCallTreeView),
  55. "The memory call tree view can now be selected.");
  56. selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  57. rendered = once(MemoryFlameGraphView, EVENTS.UI_MEMORY_FLAMEGRAPH_RENDERED);
  58. DetailsView.selectView("memory-flamegraph");
  59. yield selected;
  60. yield rendered;
  61. ok(DetailsView.isViewSelected(MemoryFlameGraphView),
  62. "The memory flamegraph view can now be selected.");
  63. // Select the first recording with no memory data.
  64. selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  65. rendered = once(WaterfallView, EVENTS.UI_WATERFALL_RENDERED);
  66. setSelectedRecording(panel, 0);
  67. yield selected;
  68. yield rendered;
  69. ok(DetailsView.isViewSelected(WaterfallView), "The waterfall view is now selected " +
  70. "when switching back to a recording that does not have memory data.");
  71. is(callBtn.hidden, true,
  72. "The `memory-calltree` button is hidden when recording has no memory data.");
  73. is(flameBtn.hidden, true,
  74. "The `memory-flamegraph` button is hidden when recording has no memory data.");
  75. // Go back to the recording with memory data.
  76. rendered = once(WaterfallView, EVENTS.UI_WATERFALL_RENDERED);
  77. setSelectedRecording(panel, 1);
  78. yield rendered;
  79. ok(DetailsView.isViewSelected(WaterfallView),
  80. "The waterfall view is still selected in the details view.");
  81. is(callBtn.hidden, false,
  82. "The `memory-calltree` button is shown when recording has memory data.");
  83. is(flameBtn.hidden, false,
  84. "The `memory-flamegraph` button is shown when recording has memory data.");
  85. selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  86. rendered = once(MemoryCallTreeView, EVENTS.UI_MEMORY_CALL_TREE_RENDERED);
  87. DetailsView.selectView("memory-calltree");
  88. yield selected;
  89. yield rendered;
  90. ok(DetailsView.isViewSelected(MemoryCallTreeView), "The memory call tree view can be " +
  91. "selected again after going back to the view with memory data.");
  92. selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  93. rendered = once(MemoryFlameGraphView, EVENTS.UI_MEMORY_FLAMEGRAPH_RENDERED);
  94. DetailsView.selectView("memory-flamegraph");
  95. yield selected;
  96. yield rendered;
  97. ok(DetailsView.isViewSelected(MemoryFlameGraphView), "The memory flamegraph view can " +
  98. "be selected again after going back to the view with memory data.");
  99. yield teardownToolboxAndRemoveTab(panel);
  100. });