browser_telemetry_sidebar.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. const TEST_URI = "data:text/html;charset=utf-8,<p>browser_telemetry_sidebar.js</p>";
  5. // Because we need to gather stats for the period of time that a tool has been
  6. // opened we make use of setTimeout() to create tool active times.
  7. const TOOL_DELAY = 200;
  8. add_task(function* () {
  9. yield addTab(TEST_URI);
  10. let Telemetry = loadTelemetryAndRecordLogs();
  11. let target = TargetFactory.forTab(gBrowser.selectedTab);
  12. let toolbox = yield gDevTools.showToolbox(target, "inspector");
  13. info("inspector opened");
  14. yield testSidebar(toolbox);
  15. checkResults(Telemetry);
  16. stopRecordingTelemetryLogs(Telemetry);
  17. yield gDevTools.closeToolbox(target);
  18. gBrowser.removeCurrentTab();
  19. });
  20. function* testSidebar(toolbox) {
  21. info("Testing sidebar");
  22. let inspector = toolbox.getCurrentPanel();
  23. let sidebarTools = ["ruleview", "computedview", "fontinspector",
  24. "animationinspector"];
  25. // Concatenate the array with itself so that we can open each tool twice.
  26. sidebarTools.push.apply(sidebarTools, sidebarTools);
  27. return new Promise(resolve => {
  28. // See TOOL_DELAY for why we need setTimeout here
  29. setTimeout(function selectSidebarTab() {
  30. let tool = sidebarTools.pop();
  31. if (tool) {
  32. inspector.sidebar.select(tool);
  33. setTimeout(function () {
  34. setTimeout(selectSidebarTab, TOOL_DELAY);
  35. }, TOOL_DELAY);
  36. } else {
  37. resolve();
  38. }
  39. }, TOOL_DELAY);
  40. });
  41. }
  42. function checkResults(Telemetry) {
  43. let result = Telemetry.prototype.telemetryInfo;
  44. for (let [histId, value] of Object.entries(result)) {
  45. if (histId.startsWith("DEVTOOLS_INSPECTOR_")) {
  46. // Inspector stats are tested in browser_telemetry_toolboxtabs.js so we
  47. // skip them here because we only open the inspector once for this test.
  48. continue;
  49. }
  50. if (histId === "DEVTOOLS_TOOLBOX_OPENED_COUNT") {
  51. is(value.length, 1, histId + " has only one entry");
  52. } else if (histId.endsWith("OPENED_COUNT")) {
  53. ok(value.length > 1, histId + " has more than one entry");
  54. let okay = value.every(function (element) {
  55. return element === true;
  56. });
  57. ok(okay, "All " + histId + " entries are === true");
  58. } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) {
  59. ok(value.length > 1, histId + " has more than one entry");
  60. let okay = value.every(function (element) {
  61. return element > 0;
  62. });
  63. ok(okay, "All " + histId + " entries have time > 0");
  64. }
  65. }
  66. }