browser_perf-tree-view-06.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests if the profiler's tree view implementation works properly and
  6. * correctly emits events when certain DOM nodes are clicked.
  7. */
  8. const { ThreadNode } = require("devtools/client/performance/modules/logic/tree-model");
  9. const { CallView } = require("devtools/client/performance/modules/widgets/tree-view");
  10. const { synthesizeProfile } = require("devtools/client/performance/test/helpers/synth-utils");
  11. const { idleWait, waitUntil } = require("devtools/client/performance/test/helpers/wait-utils");
  12. add_task(function* () {
  13. let profile = synthesizeProfile();
  14. let threadNode = new ThreadNode(profile.threads[0], { startTime: 0, endTime: 20 });
  15. // Don't display the synthesized (root) and the real (root) node twice.
  16. threadNode.calls = threadNode.calls[0].calls;
  17. let treeRoot = new CallView({ frame: threadNode });
  18. let container = document.createElement("vbox");
  19. treeRoot.attachTo(container);
  20. let A = treeRoot.getChild();
  21. let B = A.getChild();
  22. let D = B.getChild();
  23. let linkEvent = null;
  24. let handler = (_, e) => {
  25. linkEvent = e;
  26. };
  27. treeRoot.on("link", handler);
  28. // Fire right click.
  29. rightMousedown(D.target.querySelector(".call-tree-url"));
  30. // Ensure link was not called for right click.
  31. yield idleWait(100);
  32. ok(!linkEvent, "The `link` event not fired for right click.");
  33. // Fire left click.
  34. mousedown(D.target.querySelector(".call-tree-url"));
  35. // Ensure link was called for left click.
  36. yield waitUntil(() => linkEvent);
  37. is(linkEvent, D, "The `link` event target is correct.");
  38. treeRoot.off("link", handler);
  39. });