browser_graphs-10a.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests that graphs properly handle resizing.
  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("window");
  35. doc.body.setAttribute("style",
  36. "position: fixed; width: 100%; height: 100%; margin: 0;");
  37. let graph = new LineGraphWidget(doc.body, "fps");
  38. yield graph.once("ready");
  39. let refreshCount = 0;
  40. graph.on("refresh", () => refreshCount++);
  41. yield testGraph(host, graph);
  42. is(refreshCount, 2, "The graph should've been refreshed 2 times.");
  43. yield graph.destroy();
  44. host.destroy();
  45. }
  46. function* testGraph(host, graph) {
  47. graph.setData(TEST_DATA);
  48. let initialBounds = host.frame.getBoundingClientRect();
  49. host._window.resizeBy(-100, -100);
  50. yield graph.once("refresh");
  51. let newBounds = host.frame.getBoundingClientRect();
  52. is(initialBounds.width - newBounds.width, 100,
  53. "The window was properly resized (1).");
  54. is(initialBounds.height - newBounds.height, 100,
  55. "The window was properly resized (2).");
  56. is(graph.width, newBounds.width * window.devicePixelRatio,
  57. "The graph has the correct width (1).");
  58. is(graph.height, newBounds.height * window.devicePixelRatio,
  59. "The graph has the correct height (1).");
  60. info("Making a selection.");
  61. dragStart(graph, 300);
  62. ok(graph.hasSelectionInProgress(),
  63. "The selection should start (1).");
  64. is(graph.getSelection().start, 300,
  65. "The current selection start value is correct (1).");
  66. is(graph.getSelection().end, 300,
  67. "The current selection end value is correct (1).");
  68. hover(graph, 400);
  69. ok(graph.hasSelectionInProgress(),
  70. "The selection should still be in progress (2).");
  71. is(graph.getSelection().start, 300,
  72. "The current selection start value is correct (2).");
  73. is(graph.getSelection().end, 400,
  74. "The current selection end value is correct (2).");
  75. dragStop(graph, 500);
  76. ok(!graph.hasSelectionInProgress(),
  77. "The selection should have stopped (3).");
  78. is(graph.getSelection().start, 300,
  79. "The current selection start value is correct (3).");
  80. is(graph.getSelection().end, 500,
  81. "The current selection end value is correct (3).");
  82. host._window.resizeBy(100, 100);
  83. yield graph.once("refresh");
  84. let newerBounds = host.frame.getBoundingClientRect();
  85. is(initialBounds.width - newerBounds.width, 0,
  86. "The window was properly resized (3).");
  87. is(initialBounds.height - newerBounds.height, 0,
  88. "The window was properly resized (4).");
  89. is(graph.width, newerBounds.width * window.devicePixelRatio,
  90. "The graph has the correct width (2).");
  91. is(graph.height, newerBounds.height * window.devicePixelRatio,
  92. "The graph has the correct height (2).");
  93. info("Making a new selection.");
  94. dragStart(graph, 200);
  95. ok(graph.hasSelectionInProgress(),
  96. "The selection should start (4).");
  97. is(graph.getSelection().start, 200,
  98. "The current selection start value is correct (4).");
  99. is(graph.getSelection().end, 200,
  100. "The current selection end value is correct (4).");
  101. hover(graph, 300);
  102. ok(graph.hasSelectionInProgress(),
  103. "The selection should still be in progress (5).");
  104. is(graph.getSelection().start, 200,
  105. "The current selection start value is correct (5).");
  106. is(graph.getSelection().end, 300,
  107. "The current selection end value is correct (5).");
  108. dragStop(graph, 400);
  109. ok(!graph.hasSelectionInProgress(),
  110. "The selection should have stopped (6).");
  111. is(graph.getSelection().start, 200,
  112. "The current selection start value is correct (6).");
  113. is(graph.getSelection().end, 400,
  114. "The current selection end value is correct (6).");
  115. }
  116. // EventUtils just doesn't work!
  117. function hover(graph, x, y = 1) {
  118. x /= window.devicePixelRatio;
  119. y /= window.devicePixelRatio;
  120. graph._onMouseMove({ testX: x, testY: y });
  121. }
  122. function dragStart(graph, x, y = 1) {
  123. x /= window.devicePixelRatio;
  124. y /= window.devicePixelRatio;
  125. graph._onMouseMove({ testX: x, testY: y });
  126. graph._onMouseDown({ testX: x, testY: y });
  127. }
  128. function dragStop(graph, x, y = 1) {
  129. x /= window.devicePixelRatio;
  130. y /= window.devicePixelRatio;
  131. graph._onMouseMove({ testX: x, testY: y });
  132. graph._onMouseUp({ testX: x, testY: y });
  133. }