summaryrefslogtreecommitdiff
path: root/toolkit/devtools/profiler/test/browser_profiler_recordings-clear.js
blob: e95c8bc2060b2334924fb6ed109d957863ae9003 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests if the profiler is able clear all recordings.
 */

let test = Task.async(function*() {
  let [target, debuggee, panel] = yield initFrontend(SIMPLE_URL);
  let { $, gFront, EVENTS, RecordingsListView, ProfileView } = panel.panelWin;

  // Start and finish a manual recording.
  yield startRecording(panel);
  yield stopRecording(panel, { waitForDisplay: true });

  // Start and finish a console recording.
  yield consoleProfile(gFront, "test 1");
  yield consoleProfileEnd(gFront, { waitForDisplayOn: panel });

  // Start a new manual and console recording, but keep them in progress.
  yield startRecording(panel);
  yield consoleProfile(gFront, "test 2");

  is(RecordingsListView.itemCount, 4,
    "There should be four recordings visible now.");
  is(RecordingsListView.selectedIndex, 1,
    "The second recording should be selected.");
  is($("#profile-pane").selectedPanel, $("#profile-content"),
    "The profile content should be displayed in the profile view.");

  let whenRecordingLost = panel.panelWin.once(EVENTS.RECORDING_LOST);
  EventUtils.synthesizeMouseAtCenter($("#clear-button"), {}, panel.panelWin);
  yield whenRecordingLost;

  yield teardown(panel);
  finish();
});

function* consoleProfile(front, label) {
  let notified = front.once("profile");
  console.profile(label);
  yield notified;
}

function* consoleProfileEnd(front, { waitForDisplayOn: panel }) {
  let notified = front.once("profileEnd");
  let displayed = panel.panelWin.once(panel.panelWin.EVENTS.RECORDING_DISPLAYED);
  console.profileEnd();
  yield promise.all([notified, displayed]);
}