summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/browser_perf-console-record-07.js
blob: af8dc5144a40145b00b4bf8110236b8ccb93d337 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

/**
 * Tests that a call to console.profileEnd() with no label ends the
 * most recent console recording, and console.profileEnd() with a label that
 * does not match any pending recordings does nothing.
 */

const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
const { initPerformanceInTab, initConsoleInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
const { waitForRecordingStartedEvents, waitForRecordingStoppedEvents } = require("devtools/client/performance/test/helpers/actions");
const { idleWait } = require("devtools/client/performance/test/helpers/wait-utils");
const { getSelectedRecording } = require("devtools/client/performance/test/helpers/recording-utils");

add_task(function* () {
  let { target, console } = yield initConsoleInNewTab({
    url: SIMPLE_URL,
    win: window
  });

  let { panel } = yield initPerformanceInTab({ tab: target.tab });
  let { PerformanceController } = panel.panelWin;

  let started = waitForRecordingStartedEvents(panel, {
    // only emitted for manual recordings
    skipWaitingForBackendReady: true
  });
  yield console.profile();
  yield started;

  started = waitForRecordingStartedEvents(panel, {
    // only emitted for manual recordings
    skipWaitingForBackendReady: true,
    // only emitted when an in-progress recording is selected
    skipWaitingForOverview: true,
    // the view state won't switch to "console-recording" unless the new
    // in-progress recording is selected, which won't happen
    skipWaitingForViewState: true,
  });
  yield console.profile("1");
  yield started;

  started = waitForRecordingStartedEvents(panel, {
    // only emitted for manual recordings
    skipWaitingForBackendReady: true,
    // only emitted when an in-progress recording is selected
    skipWaitingForOverview: true,
    // the view state won't switch to "console-recording" unless the new
    // in-progress recording is selected, which won't happen
    skipWaitingForViewState: true,
  });
  yield console.profile("2");
  yield started;

  let recordings = PerformanceController.getRecordings();
  let selected = getSelectedRecording(panel);
  is(recordings.length, 3, "Three recordings found in the performance panel.");
  is(recordings[0].getLabel(), "", "Checking label of recording 1");
  is(recordings[1].getLabel(), "1", "Checking label of recording 2");
  is(recordings[2].getLabel(), "2", "Checking label of recording 3");
  is(selected, recordings[0],
    "The first console recording should be selected.");

  is(recordings[0].isRecording(), true,
    "All recordings should now be started. (1)");
  is(recordings[1].isRecording(), true,
    "All recordings should now be started. (2)");
  is(recordings[2].isRecording(), true,
    "All recordings should now be started. (3)");

  let stopped = waitForRecordingStoppedEvents(panel, {
    // only emitted for manual recordings
    skipWaitingForBackendReady: true,
    // only emitted when a finished recording is selected
    skipWaitingForOverview: true,
    skipWaitingForSubview: true,
    // the view state won't switch to "recorded" unless the new
    // finished recording is selected, which won't happen
    skipWaitingForViewState: true,
  });
  yield console.profileEnd();
  yield stopped;

  selected = getSelectedRecording(panel);
  recordings = PerformanceController.getRecordings();
  is(recordings.length, 3, "Three recordings found in the performance panel.");
  is(selected, recordings[0],
    "The first console recording should still be selected.");

  is(recordings[0].isRecording(), true, "The not most recent recording should not stop " +
    "when calling console.profileEnd with no args.");
  is(recordings[1].isRecording(), true, "The not most recent recording should not stop " +
    "when calling console.profileEnd with no args.");
  is(recordings[2].isRecording(), false, "Only the most recent recording should stop " +
    "when calling console.profileEnd with no args.");

  info("Trying to `profileEnd` a non-existent console recording.");
  console.profileEnd("fxos");
  yield idleWait(1000);

  selected = getSelectedRecording(panel);
  recordings = PerformanceController.getRecordings();
  is(recordings.length, 3, "Three recordings found in the performance panel.");
  is(selected, recordings[0],
    "The first console recording should still be selected.");

  is(recordings[0].isRecording(), true,
    "The first recording should not be ended yet.");
  is(recordings[1].isRecording(), true,
    "The second recording should not be ended yet.");
  is(recordings[2].isRecording(), false,
    "The third recording should still be ended.");

  stopped = waitForRecordingStoppedEvents(panel, {
    // only emitted for manual recordings
    skipWaitingForBackendReady: true,
    // only emitted when a finished recording is selected
    skipWaitingForOverview: true,
    skipWaitingForSubview: true,
    // the view state won't switch to "recorded" unless the new
    // finished recording is selected, which won't happen
    skipWaitingForViewState: true,
  });
  yield console.profileEnd();
  yield stopped;

  selected = getSelectedRecording(panel);
  recordings = PerformanceController.getRecordings();
  is(recordings.length, 3, "Three recordings found in the performance panel.");
  is(selected, recordings[0],
    "The first console recording should still be selected.");

  is(recordings[0].isRecording(), true,
    "The first recording should not be ended yet.");
  is(recordings[1].isRecording(), false,
    "The second recording should not be ended yet.");
  is(recordings[2].isRecording(), false,
    "The third recording should still be ended.");

  stopped = waitForRecordingStoppedEvents(panel, {
    // only emitted for manual recordings
    skipWaitingForBackendReady: true
  });
  yield console.profileEnd();
  yield stopped;

  selected = getSelectedRecording(panel);
  recordings = PerformanceController.getRecordings();
  is(recordings.length, 3, "Three recordings found in the performance panel.");
  is(selected, recordings[0],
    "The first console recording should be selected.");

  is(recordings[0].isRecording(), false,
    "All recordings should now be ended. (1)");
  is(recordings[1].isRecording(), false,
    "All recordings should now be ended. (2)");
  is(recordings[2].isRecording(), false,
    "All recordings should now be ended. (3)");

  info("Trying to `profileEnd` with no pending recordings.");
  console.profileEnd();
  yield idleWait(1000);

  ok(true, "Calling console.profileEnd() with no argument and no pending recordings " +
    "does not throw.");

  yield teardownToolboxAndRemoveTab(panel);
});