browser_graphs-15.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 FAST_FPS = 60;
  6. const SLOW_FPS = 10;
  7. // Each element represents a second
  8. const FRAMES = [FAST_FPS, FAST_FPS, FAST_FPS, SLOW_FPS, FAST_FPS];
  9. const TEST_DATA = [];
  10. const INTERVAL = 100;
  11. const DURATION = 5000;
  12. var t = 0;
  13. for (let frameRate of FRAMES) {
  14. for (let i = 0; i < frameRate; i++) {
  15. // Duration between frames at this rate
  16. let delta = Math.floor(1000 / frameRate);
  17. t += delta;
  18. TEST_DATA.push(t);
  19. }
  20. }
  21. const LineGraphWidget = require("devtools/client/shared/widgets/LineGraphWidget");
  22. add_task(function* () {
  23. yield addTab("about:blank");
  24. yield performTest();
  25. gBrowser.removeCurrentTab();
  26. });
  27. function* performTest() {
  28. let [host,, doc] = yield createHost();
  29. let graph = new LineGraphWidget(doc.body, "fps");
  30. yield testGraph(graph);
  31. yield graph.destroy();
  32. host.destroy();
  33. }
  34. function* testGraph(graph) {
  35. console.log("test data", TEST_DATA);
  36. yield graph.setDataFromTimestamps(TEST_DATA, INTERVAL, DURATION);
  37. is(graph._avgTooltip.querySelector("[text=value]").textContent, "50",
  38. "The average tooltip displays the correct value.");
  39. }