browser_flame-graph-03b.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests that selections in the flame graph widget work properly on HiDPI.
  5. const TEST_DATA = [
  6. {
  7. color: "#f00",
  8. blocks: [
  9. { x: 0, y: 0, width: 50, height: 20, text: "FOO" },
  10. { x: 50, y: 0, width: 100, height: 20, text: "BAR" }
  11. ]
  12. },
  13. {
  14. color: "#00f",
  15. blocks: [
  16. { x: 0, y: 30, width: 30, height: 20, text: "BAZ" }
  17. ]
  18. }
  19. ];
  20. const TEST_BOUNDS = { startTime: 0, endTime: 150 };
  21. const TEST_WIDTH = 200;
  22. const TEST_HEIGHT = 100;
  23. const TEST_DPI_DENSITIY = 2;
  24. var {FlameGraph} = require("devtools/client/shared/widgets/FlameGraph");
  25. add_task(function* () {
  26. yield addTab("about:blank");
  27. yield performTest();
  28. gBrowser.removeCurrentTab();
  29. });
  30. function* performTest() {
  31. let [host,, doc] = yield createHost();
  32. doc.body.setAttribute("style",
  33. "position: fixed; width: 100%; height: 100%; margin: 0;");
  34. let graph = new FlameGraph(doc.body, TEST_DPI_DENSITIY);
  35. graph.fixedWidth = TEST_WIDTH;
  36. graph.fixedHeight = TEST_HEIGHT;
  37. yield graph.ready();
  38. testGraph(graph);
  39. yield graph.destroy();
  40. host.destroy();
  41. }
  42. function testGraph(graph) {
  43. graph.setData({ data: TEST_DATA, bounds: TEST_BOUNDS });
  44. is(graph.getViewRange().startTime, 0,
  45. "The selection start boundary is correct on HiDPI (1).");
  46. is(graph.getViewRange().endTime, 150,
  47. "The selection end boundary is correct on HiDPI (1).");
  48. is(graph.getOuterBounds().startTime, 0,
  49. "The bounds start boundary is correct on HiDPI (1).");
  50. is(graph.getOuterBounds().endTime, 150,
  51. "The bounds end boundary is correct on HiDPI (1).");
  52. scroll(graph, 10000, HORIZONTAL_AXIS, 1);
  53. is(Math.round(graph.getViewRange().startTime), 150,
  54. "The selection start boundary is correct on HiDPI (2).");
  55. is(Math.round(graph.getViewRange().endTime), 150,
  56. "The selection end boundary is correct on HiDPI (2).");
  57. is(graph.getOuterBounds().startTime, 0,
  58. "The bounds start boundary is correct on HiDPI (2).");
  59. is(graph.getOuterBounds().endTime, 150,
  60. "The bounds end boundary is correct on HiDPI (2).");
  61. }
  62. // EventUtils just doesn't work!
  63. var HORIZONTAL_AXIS = 1;
  64. var VERTICAL_AXIS = 2;
  65. function scroll(graph, wheel, axis, x, y = 1) {
  66. x /= window.devicePixelRatio;
  67. y /= window.devicePixelRatio;
  68. graph._onMouseMove({ testX: x, testY: y });
  69. graph._onMouseWheel({ testX: x, testY: y, axis, detail: wheel,
  70. HORIZONTAL_AXIS,
  71. VERTICAL_AXIS
  72. });
  73. }