browser_graphs-14.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests that graph widgets correctly emit mouse input events.
  5. const TEST_DATA = [
  6. { delta: 112, value: 48 }, { delta: 213, value: 59 },
  7. { delta: 313, value: 60 }, { delta: 413, value: 59 },
  8. { delta: 530, value: 59 }, { delta: 646, value: 58 },
  9. { delta: 747, value: 60 }, { delta: 863, value: 48 },
  10. { delta: 980, value: 37 }, { delta: 1097, value: 30 },
  11. { delta: 1213, value: 29 }, { delta: 1330, value: 23 },
  12. { delta: 1430, value: 10 }, { delta: 1534, value: 17 },
  13. { delta: 1645, value: 20 }, { delta: 1746, value: 22 },
  14. { delta: 1846, value: 39 }, { delta: 1963, value: 26 },
  15. { delta: 2080, value: 27 }, { delta: 2197, value: 35 },
  16. { delta: 2312, value: 47 }, { delta: 2412, value: 53 },
  17. { delta: 2514, value: 60 }, { delta: 2630, value: 37 },
  18. { delta: 2730, value: 36 }, { delta: 2830, value: 37 },
  19. { delta: 2946, value: 36 }, { delta: 3046, value: 40 },
  20. { delta: 3163, value: 47 }, { delta: 3280, value: 41 },
  21. { delta: 3380, value: 35 }, { delta: 3480, value: 27 },
  22. { delta: 3580, value: 39 }, { delta: 3680, value: 42 },
  23. { delta: 3780, value: 49 }, { delta: 3880, value: 55 },
  24. { delta: 3980, value: 60 }, { delta: 4080, value: 60 },
  25. { delta: 4180, value: 60 }
  26. ];
  27. const LineGraphWidget = require("devtools/client/shared/widgets/LineGraphWidget");
  28. add_task(function* () {
  29. yield addTab("about:blank");
  30. yield performTest();
  31. gBrowser.removeCurrentTab();
  32. });
  33. function* performTest() {
  34. let [host,, doc] = yield createHost();
  35. let graph = new LineGraphWidget(doc.body, "fps");
  36. yield testGraph(graph);
  37. yield graph.destroy();
  38. host.destroy();
  39. }
  40. function* testGraph(graph) {
  41. let mouseDownEvents = 0;
  42. let mouseUpEvents = 0;
  43. let scrollEvents = 0;
  44. graph.on("mousedown", () => mouseDownEvents++);
  45. graph.on("mouseup", () => mouseUpEvents++);
  46. graph.on("scroll", () => scrollEvents++);
  47. yield graph.setDataWhenReady(TEST_DATA);
  48. info("Making a selection.");
  49. dragStart(graph, 300);
  50. dragStop(graph, 500);
  51. is(graph.getSelection().start, 300,
  52. "The current selection start value is correct (1).");
  53. is(graph.getSelection().end, 500,
  54. "The current selection end value is correct (1).");
  55. is(mouseDownEvents, 1,
  56. "One mousedown event should have been fired.");
  57. is(mouseUpEvents, 1,
  58. "One mouseup event should have been fired.");
  59. is(scrollEvents, 0,
  60. "No scroll event should have been fired.");
  61. info("Zooming in by scrolling inside the selection.");
  62. scroll(graph, -1000, 400);
  63. is(graph.getSelection().start, 375,
  64. "The current selection start value is correct (2).");
  65. is(graph.getSelection().end, 425,
  66. "The current selection end value is correct (2).");
  67. is(mouseDownEvents, 1,
  68. "No more mousedown events should have been fired.");
  69. is(mouseUpEvents, 1,
  70. "No more mouseup events should have been fired.");
  71. is(scrollEvents, 1,
  72. "One scroll event should have been fired.");
  73. }
  74. // EventUtils just doesn't work!
  75. function dragStart(graph, x, y = 1) {
  76. x /= window.devicePixelRatio;
  77. y /= window.devicePixelRatio;
  78. graph._onMouseMove({ testX: x, testY: y });
  79. graph._onMouseDown({ testX: x, testY: y });
  80. }
  81. function dragStop(graph, x, y = 1) {
  82. x /= window.devicePixelRatio;
  83. y /= window.devicePixelRatio;
  84. graph._onMouseMove({ testX: x, testY: y });
  85. graph._onMouseUp({ testX: x, testY: y });
  86. }
  87. function scroll(graph, wheel, x, y = 1) {
  88. x /= window.devicePixelRatio;
  89. y /= window.devicePixelRatio;
  90. graph._onMouseMove({ testX: x, testY: y });
  91. graph._onMouseWheel({ testX: x, testY: y, detail: wheel });
  92. }