browser_perf-telemetry-04.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests that the performance telemetry module records events at appropriate times.
  6. */
  7. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  8. const { initPerformanceInTab, initConsoleInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
  9. const { waitForRecordingStartedEvents, waitForRecordingStoppedEvents } = require("devtools/client/performance/test/helpers/actions");
  10. add_task(function* () {
  11. let { target, console } = yield initConsoleInNewTab({
  12. url: SIMPLE_URL,
  13. win: window
  14. });
  15. let { panel } = yield initPerformanceInTab({ tab: target.tab });
  16. let { PerformanceController } = panel.panelWin;
  17. let telemetry = PerformanceController._telemetry;
  18. let logs = telemetry.getLogs();
  19. let DURATION = "DEVTOOLS_PERFTOOLS_RECORDING_DURATION_MS";
  20. let CONSOLE_COUNT = "DEVTOOLS_PERFTOOLS_CONSOLE_RECORDING_COUNT";
  21. let FEATURES = "DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED";
  22. let started = waitForRecordingStartedEvents(panel, {
  23. // only emitted for manual recordings
  24. skipWaitingForBackendReady: true
  25. });
  26. yield console.profile("rust");
  27. yield started;
  28. let stopped = waitForRecordingStoppedEvents(panel, {
  29. // only emitted for manual recordings
  30. skipWaitingForBackendReady: true
  31. });
  32. yield console.profileEnd("rust");
  33. yield stopped;
  34. is(logs[DURATION].length, 1, `There is one entry for ${DURATION}.`);
  35. ok(logs[DURATION].every(d => typeof d === "number"),
  36. `Every ${DURATION} entry is a number.`);
  37. is(logs[CONSOLE_COUNT].length, 1, `There is one entry for ${CONSOLE_COUNT}.`);
  38. is(logs[FEATURES].length, 4,
  39. `There is one recording worth of entries for ${FEATURES}.`);
  40. yield teardownToolboxAndRemoveTab(panel);
  41. });