browser_perf-telemetry-01.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * Specificaly the state about a recording process.
  7. */
  8. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  9. const { UI_ENABLE_MEMORY_PREF } = require("devtools/client/performance/test/helpers/prefs");
  10. const { initPerformanceInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
  11. const { startRecording, stopRecording } = require("devtools/client/performance/test/helpers/actions");
  12. add_task(function* () {
  13. let { panel } = yield initPerformanceInNewTab({
  14. url: SIMPLE_URL,
  15. win: window
  16. });
  17. let { PerformanceController } = panel.panelWin;
  18. let telemetry = PerformanceController._telemetry;
  19. let logs = telemetry.getLogs();
  20. let DURATION = "DEVTOOLS_PERFTOOLS_RECORDING_DURATION_MS";
  21. let COUNT = "DEVTOOLS_PERFTOOLS_RECORDING_COUNT";
  22. let CONSOLE_COUNT = "DEVTOOLS_PERFTOOLS_CONSOLE_RECORDING_COUNT";
  23. let FEATURES = "DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED";
  24. Services.prefs.setBoolPref(UI_ENABLE_MEMORY_PREF, false);
  25. yield startRecording(panel);
  26. yield stopRecording(panel);
  27. Services.prefs.setBoolPref(UI_ENABLE_MEMORY_PREF, true);
  28. yield startRecording(panel);
  29. yield stopRecording(panel);
  30. is(logs[DURATION].length, 2, `There are two entries for ${DURATION}.`);
  31. ok(logs[DURATION].every(d => typeof d === "number"),
  32. `Every ${DURATION} entry is a number.`);
  33. is(logs[COUNT].length, 2, `There are two entries for ${COUNT}.`);
  34. is(logs[CONSOLE_COUNT], void 0, `There are no entries for ${CONSOLE_COUNT}.`);
  35. is(logs[FEATURES].length, 8,
  36. `There are two recordings worth of entries for ${FEATURES}.`);
  37. ok(logs[FEATURES].find(r => r[0] === "withMemory" && r[1] === true),
  38. "One feature entry for memory enabled.");
  39. ok(logs[FEATURES].find(r => r[0] === "withMemory" && r[1] === false),
  40. "One feature entry for memory disabled.");
  41. yield teardownToolboxAndRemoveTab(panel);
  42. });