browser_graphs-07b.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests if selections can't be added via clicking, while not allowed.
  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. var 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 graph.once("ready");
  37. testGraph(graph);
  38. yield graph.destroy();
  39. host.destroy();
  40. }
  41. function testGraph(graph) {
  42. graph.setData(TEST_DATA);
  43. graph.selectionEnabled = false;
  44. info("Attempting to make a selection.");
  45. dragStart(graph, 300);
  46. is(graph.hasSelection() || graph.hasSelectionInProgress(), false,
  47. "The graph shouldn't have a selection (1).");
  48. hover(graph, 400);
  49. is(graph.hasSelection() || graph.hasSelectionInProgress(), false,
  50. "The graph shouldn't have a selection (2).");
  51. dragStop(graph, 500);
  52. is(graph.hasSelection() || graph.hasSelectionInProgress(), false,
  53. "The graph shouldn't have a selection (3).");
  54. }
  55. // EventUtils just doesn't work!
  56. function hover(graph, x, y = 1) {
  57. x /= window.devicePixelRatio;
  58. y /= window.devicePixelRatio;
  59. graph._onMouseMove({ testX: x, testY: y });
  60. }
  61. function dragStart(graph, x, y = 1) {
  62. x /= window.devicePixelRatio;
  63. y /= window.devicePixelRatio;
  64. graph._onMouseMove({ testX: x, testY: y });
  65. graph._onMouseDown({ testX: x, testY: y });
  66. }
  67. function dragStop(graph, x, y = 1) {
  68. x /= window.devicePixelRatio;
  69. y /= window.devicePixelRatio;
  70. graph._onMouseMove({ testX: x, testY: y });
  71. graph._onMouseUp({ testX: x, testY: y });
  72. }