browser_perf-calltree-js-events.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 call tree up/down events work for js calltrees.
  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 { synthesizeProfile } = require("devtools/client/performance/test/helpers/synth-utils");
  11. const { once } = require("devtools/client/performance/test/helpers/event-utils");
  12. const { ThreadNode } = require("devtools/client/performance/modules/logic/tree-model");
  13. add_task(function* () {
  14. let { panel } = yield initPerformanceInNewTab({
  15. url: SIMPLE_URL,
  16. win: window
  17. });
  18. let { EVENTS, $, DetailsView, OverviewView, JsCallTreeView } = panel.panelWin;
  19. yield startRecording(panel);
  20. yield stopRecording(panel);
  21. let rendered = once(JsCallTreeView, EVENTS.UI_JS_CALL_TREE_RENDERED);
  22. yield DetailsView.selectView("js-calltree");
  23. yield rendered;
  24. // Mock the profile used so we can get a deterministic tree created.
  25. let profile = synthesizeProfile();
  26. let threadNode = new ThreadNode(profile.threads[0], OverviewView.getTimeInterval());
  27. JsCallTreeView._populateCallTree(threadNode);
  28. JsCallTreeView.emit(EVENTS.UI_JS_CALL_TREE_RENDERED);
  29. let firstTreeItem = $("#js-calltree-view .call-tree-item");
  30. // DE-XUL: There are focus issues with XUL. Focus first, then synthesize the clicks
  31. // so that keyboard events work correctly.
  32. firstTreeItem.focus();
  33. let count = 0;
  34. let onFocus = () => count++;
  35. JsCallTreeView.on("focus", onFocus);
  36. click(firstTreeItem);
  37. key("VK_DOWN");
  38. key("VK_DOWN");
  39. key("VK_DOWN");
  40. key("VK_DOWN");
  41. JsCallTreeView.off("focus", onFocus);
  42. is(count, 4, "Several focus events are fired for the calltree.");
  43. yield teardownToolboxAndRemoveTab(panel);
  44. });