browser_telemetry_button_paintflashing.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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," +
  5. "<p>browser_telemetry_button_paintflashing.js</p>";
  6. // Because we need to gather stats for the period of time that a tool has been
  7. // opened we make use of setTimeout() to create tool active times.
  8. const TOOL_DELAY = 200;
  9. add_task(function* () {
  10. yield addTab(TEST_URI);
  11. let Telemetry = loadTelemetryAndRecordLogs();
  12. let target = TargetFactory.forTab(gBrowser.selectedTab);
  13. let toolbox = yield gDevTools.showToolbox(target, "inspector");
  14. info("inspector opened");
  15. info("testing the paintflashing button");
  16. yield testButton(toolbox, Telemetry);
  17. stopRecordingTelemetryLogs(Telemetry);
  18. yield gDevTools.closeToolbox(target);
  19. gBrowser.removeCurrentTab();
  20. });
  21. function* testButton(toolbox, Telemetry) {
  22. info("Testing command-button-paintflashing");
  23. let button = toolbox.doc.querySelector("#command-button-paintflashing");
  24. ok(button, "Captain, we have the button");
  25. yield* delayedClicks(toolbox, button, 4);
  26. checkResults("_PAINTFLASHING_", Telemetry);
  27. }
  28. function* delayedClicks(toolbox, node, clicks) {
  29. for (let i = 0; i < clicks; i++) {
  30. yield new Promise(resolve => {
  31. // See TOOL_DELAY for why we need setTimeout here
  32. setTimeout(() => resolve(), TOOL_DELAY);
  33. });
  34. // this event will fire once the command execution starts and
  35. // the output object is created
  36. let clicked = toolbox._requisition.commandOutputManager.onOutput.once();
  37. info("Clicking button " + node.id);
  38. node.click();
  39. let outputEvent = yield clicked;
  40. // promise gets resolved once execution finishes and output is ready
  41. yield outputEvent.output.promise;
  42. }
  43. }
  44. function checkResults(histIdFocus, Telemetry) {
  45. let result = Telemetry.prototype.telemetryInfo;
  46. for (let [histId, value] of Object.entries(result)) {
  47. if (histId.startsWith("DEVTOOLS_INSPECTOR_") ||
  48. !histId.includes(histIdFocus)) {
  49. // Inspector stats are tested in
  50. // browser_telemetry_toolboxtabs_{toolname}.js so we skip them here
  51. // because we only open the inspector once for this test.
  52. continue;
  53. }
  54. if (histId.endsWith("OPENED_COUNT")) {
  55. ok(value.length > 1, histId + " has more than one entry");
  56. let okay = value.every(function (element) {
  57. return element === true;
  58. });
  59. ok(okay, "All " + histId + " entries are === true");
  60. } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) {
  61. ok(value.length > 1, histId + " has more than one entry");
  62. let okay = value.every(function (element) {
  63. return element > 0;
  64. });
  65. ok(okay, "All " + histId + " entries have time > 0");
  66. }
  67. }
  68. }