summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/helpers/actions.js
blob: e6c70e565c03167490748996744f0aa80084de5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

const { Constants } = require("devtools/client/performance/modules/constants");
const { once, times } = require("devtools/client/performance/test/helpers/event-utils");
const { waitUntil } = require("devtools/client/performance/test/helpers/wait-utils");

/**
 * Starts a manual recording in the given performance tool panel and
 * waits for it to finish starting.
 */
exports.startRecording = function (panel, options = {}) {
  let controller = panel.panelWin.PerformanceController;

  return Promise.all([
    controller.startRecording(),
    exports.waitForRecordingStartedEvents(panel, options)
  ]);
};

/**
 * Stops the latest recording in the given performance tool panel and
 * waits for it to finish stopping.
 */
exports.stopRecording = function (panel, options = {}) {
  let controller = panel.panelWin.PerformanceController;

  return Promise.all([
    controller.stopRecording(),
    exports.waitForRecordingStoppedEvents(panel, options)
  ]);
};

/**
 * Waits for all the necessary events to be emitted after a recording starts.
 */
exports.waitForRecordingStartedEvents = function (panel, options = {}) {
  options.expectedViewState = options.expectedViewState || /^(console-)?recording$/;

  let EVENTS = panel.panelWin.EVENTS;
  let controller = panel.panelWin.PerformanceController;
  let view = panel.panelWin.PerformanceView;
  let overview = panel.panelWin.OverviewView;

  return Promise.all([
    options.skipWaitingForBackendReady
      ? null
      : once(controller, EVENTS.BACKEND_READY_AFTER_RECORDING_START),
    options.skipWaitingForRecordingStarted
      ? null
      : once(controller, EVENTS.RECORDING_STATE_CHANGE, {
        expectedArgs: { "1": "recording-started" }
      }),
    options.skipWaitingForViewState
      ? null
      : once(view, EVENTS.UI_STATE_CHANGED, {
        expectedArgs: { "1": options.expectedViewState }
      }),
    options.skipWaitingForOverview
      ? null
      : once(overview, EVENTS.UI_OVERVIEW_RENDERED, {
        expectedArgs: { "1": Constants.FRAMERATE_GRAPH_LOW_RES_INTERVAL }
      }),
  ]);
};

/**
 * Waits for all the necessary events to be emitted after a recording finishes.
 */
exports.waitForRecordingStoppedEvents = function (panel, options = {}) {
  options.expectedViewClass = options.expectedViewClass || "WaterfallView";
  options.expectedViewEvent = options.expectedViewEvent || "UI_WATERFALL_RENDERED";
  options.expectedViewState = options.expectedViewState || "recorded";

  let EVENTS = panel.panelWin.EVENTS;
  let controller = panel.panelWin.PerformanceController;
  let view = panel.panelWin.PerformanceView;
  let overview = panel.panelWin.OverviewView;
  let subview = panel.panelWin[options.expectedViewClass];

  return Promise.all([
    options.skipWaitingForBackendReady
      ? null
      : once(controller, EVENTS.BACKEND_READY_AFTER_RECORDING_STOP),
    options.skipWaitingForRecordingStop
      ? null
      : once(controller, EVENTS.RECORDING_STATE_CHANGE, {
        expectedArgs: { "1": "recording-stopping" }
      }),
    options.skipWaitingForRecordingStop
      ? null
      : once(controller, EVENTS.RECORDING_STATE_CHANGE, {
        expectedArgs: { "1": "recording-stopped" }
      }),
    options.skipWaitingForViewState
      ? null
      : once(view, EVENTS.UI_STATE_CHANGED, {
        expectedArgs: { "1": options.expectedViewState }
      }),
    options.skipWaitingForOverview
      ? null
      : once(overview, EVENTS.UI_OVERVIEW_RENDERED, {
        expectedArgs: { "1": Constants.FRAMERATE_GRAPH_HIGH_RES_INTERVAL }
      }),
    options.skipWaitingForSubview
      ? null
      : once(subview, EVENTS[options.expectedViewEvent]),
  ]);
};

/**
 * Waits for rendering to happen once on all the performance tool's widgets.
 */
exports.waitForAllWidgetsRendered = (panel) => {
  let { panelWin } = panel;
  let { EVENTS } = panelWin;

  return Promise.all([
    once(panelWin.OverviewView, EVENTS.UI_MARKERS_GRAPH_RENDERED),
    once(panelWin.OverviewView, EVENTS.UI_MEMORY_GRAPH_RENDERED),
    once(panelWin.OverviewView, EVENTS.UI_FRAMERATE_GRAPH_RENDERED),
    once(panelWin.OverviewView, EVENTS.UI_OVERVIEW_RENDERED),
    once(panelWin.WaterfallView, EVENTS.UI_WATERFALL_RENDERED),
    once(panelWin.JsCallTreeView, EVENTS.UI_JS_CALL_TREE_RENDERED),
    once(panelWin.JsFlameGraphView, EVENTS.UI_JS_FLAMEGRAPH_RENDERED),
    once(panelWin.MemoryCallTreeView, EVENTS.UI_MEMORY_CALL_TREE_RENDERED),
    once(panelWin.MemoryFlameGraphView, EVENTS.UI_MEMORY_FLAMEGRAPH_RENDERED)
  ]);
};

/**
 * Waits for rendering to happen on the performance tool's overview graph,
 * making sure some markers were also rendered.
 */
exports.waitForOverviewRenderedWithMarkers = (panel, minTimes = 3, minMarkers = 1) => {
  let { EVENTS, OverviewView, PerformanceController } = panel.panelWin;

  return Promise.all([
    times(OverviewView, EVENTS.UI_OVERVIEW_RENDERED, minTimes, {
      expectedArgs: { "1": Constants.FRAMERATE_GRAPH_LOW_RES_INTERVAL }
    }),
    waitUntil(() =>
      PerformanceController.getCurrentRecording().getMarkers().length >= minMarkers
    ),
  ]);
};

/**
 * Reloads the given tab target.
 */
exports.reload = (target) => {
  target.activeTab.reload();
  return once(target, "navigate");
};