browser_graphs-07d.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests that selections are drawn onto the canvas.
  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 TEST_REGIONS = [{ start: 320, end: 460 }, { start: 780, end: 860 }];
  28. const LineGraphWidget = require("devtools/client/shared/widgets/LineGraphWidget");
  29. add_task(function* () {
  30. yield addTab("about:blank");
  31. yield performTest();
  32. gBrowser.removeCurrentTab();
  33. });
  34. function* performTest() {
  35. let [host,, doc] = yield createHost();
  36. let graph = new LineGraphWidget(doc.body, "fps");
  37. yield graph.once("ready");
  38. testGraph(graph);
  39. yield graph.destroy();
  40. host.destroy();
  41. }
  42. function testGraph(graph) {
  43. graph.setData(TEST_DATA);
  44. graph.setRegions(TEST_REGIONS);
  45. // Measure the color of the first pixel before any selection is made.
  46. graph._onAnimationFrame();
  47. let pixelNoSelection = graph._ctx.getImageData(1, 1, 1, 1).data;
  48. graph.setSelection({ start: 0, end: 10 });
  49. graph._onAnimationFrame();
  50. let pixelNormalSelection = graph._ctx.getImageData(1, 1, 1, 1).data;
  51. Assert.notDeepEqual(pixelNormalSelection, pixelNoSelection,
  52. "The first pixel is part of the drawn selection.");
  53. graph.setSelection({ start: graph.width + 100, end: -100 });
  54. graph._onAnimationFrame();
  55. let pixelFullSelection = graph._ctx.getImageData(1, 1, 1, 1).data;
  56. Assert.deepEqual(pixelFullSelection, pixelNormalSelection,
  57. "The first pixel is still part of the drawn selection.");
  58. }