browser_perf-button-states.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 recording button states are set as expected.
  6. */
  7. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  8. const { initPerformanceInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
  9. const { once } = require("devtools/client/performance/test/helpers/event-utils");
  10. add_task(function* () {
  11. let { panel } = yield initPerformanceInNewTab({
  12. url: SIMPLE_URL,
  13. win: window
  14. });
  15. let { $, $$, EVENTS, PerformanceController, PerformanceView } = panel.panelWin;
  16. let recordButton = $("#main-record-button");
  17. checkRecordButtonsStates(false, false);
  18. let uiStartClick = once(PerformanceView, EVENTS.UI_START_RECORDING);
  19. let recordingStarted = once(PerformanceController, EVENTS.RECORDING_STATE_CHANGE, {
  20. expectedArgs: { "1": "recording-started" }
  21. });
  22. let backendStartReady = once(PerformanceController,
  23. EVENTS.BACKEND_READY_AFTER_RECORDING_START);
  24. let uiStateRecording = once(PerformanceView, EVENTS.UI_STATE_CHANGED, {
  25. expectedArgs: { "1": "recording" }
  26. });
  27. click(recordButton);
  28. yield uiStartClick;
  29. checkRecordButtonsStates(true, true);
  30. yield recordingStarted;
  31. checkRecordButtonsStates(true, false);
  32. yield backendStartReady;
  33. yield uiStateRecording;
  34. let uiStopClick = once(PerformanceView, EVENTS.UI_STOP_RECORDING);
  35. let recordingStopped = once(PerformanceController, EVENTS.RECORDING_STATE_CHANGE, {
  36. expectedArgs: { "1": "recording-stopped" }
  37. });
  38. let backendStopReady = once(PerformanceController,
  39. EVENTS.BACKEND_READY_AFTER_RECORDING_STOP);
  40. let uiStateRecorded = once(PerformanceView, EVENTS.UI_STATE_CHANGED, {
  41. expectedArgs: { "1": "recorded" }
  42. });
  43. click(recordButton);
  44. yield uiStopClick;
  45. yield recordingStopped;
  46. checkRecordButtonsStates(false, false);
  47. yield backendStopReady;
  48. yield uiStateRecorded;
  49. yield teardownToolboxAndRemoveTab(panel);
  50. function checkRecordButtonsStates(checked, locked) {
  51. for (let button of $$(".record-button")) {
  52. is(button.classList.contains("checked"), checked,
  53. "The record button checked state should be " + checked);
  54. is(button.disabled, locked,
  55. "The record button locked state should be " + locked);
  56. }
  57. }
  58. });