browser_perf-options-flatten-tree-recursion-01.js 2.7 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 js flamegraphs get rerendered when toggling `flatten-tree-recursion`.
  6. */
  7. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  8. const { UI_FLATTEN_RECURSION_PREF } = require("devtools/client/performance/test/helpers/prefs");
  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 {
  18. EVENTS,
  19. PerformanceController,
  20. DetailsView,
  21. JsFlameGraphView,
  22. FlameGraphUtils
  23. } = panel.panelWin;
  24. Services.prefs.setBoolPref(UI_FLATTEN_RECURSION_PREF, true);
  25. yield startRecording(panel);
  26. yield stopRecording(panel);
  27. let rendered = once(JsFlameGraphView, EVENTS.UI_JS_FLAMEGRAPH_RENDERED);
  28. yield DetailsView.selectView("js-flamegraph");
  29. yield rendered;
  30. let thread1 = PerformanceController.getCurrentRecording().getProfile().threads[0];
  31. let rendering1 = FlameGraphUtils._cache.get(thread1);
  32. ok(thread1,
  33. "The samples were retrieved from the controller.");
  34. ok(rendering1,
  35. "The rendering data was cached.");
  36. rendered = once(JsFlameGraphView, EVENTS.UI_JS_FLAMEGRAPH_RENDERED);
  37. Services.prefs.setBoolPref(UI_FLATTEN_RECURSION_PREF, false);
  38. yield rendered;
  39. ok(true, "JsFlameGraphView rerendered when toggling flatten-tree-recursion.");
  40. let thread2 = PerformanceController.getCurrentRecording().getProfile().threads[0];
  41. let rendering2 = FlameGraphUtils._cache.get(thread2);
  42. is(thread1, thread2,
  43. "The same samples data should be retrieved from the controller (1).");
  44. isnot(rendering1, rendering2,
  45. "The rendering data should be different because other options were used (1).");
  46. rendered = once(JsFlameGraphView, EVENTS.UI_JS_FLAMEGRAPH_RENDERED);
  47. Services.prefs.setBoolPref(UI_FLATTEN_RECURSION_PREF, true);
  48. yield rendered;
  49. ok(true, "JsFlameGraphView rerendered when toggling back flatten-tree-recursion.");
  50. let thread3 = PerformanceController.getCurrentRecording().getProfile().threads[0];
  51. let rendering3 = FlameGraphUtils._cache.get(thread3);
  52. is(thread2, thread3,
  53. "The same samples data should be retrieved from the controller (2).");
  54. isnot(rendering2, rendering3,
  55. "The rendering data should be different because other options were used (2).");
  56. yield teardownToolboxAndRemoveTab(panel);
  57. });