summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/browser_perf-details-04-toolbar-buttons.js
blob: 9dec9fe7c5ea78165b6dcb48f82d7217a3e6bca8 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

/**
 * Tests that the details view hides the toolbar buttons when a recording
 * doesn't exist or is in progress.
 */

const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
const { initPerformanceInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
const { startRecording, stopRecording } = require("devtools/client/performance/test/helpers/actions");
const { once } = require("devtools/client/performance/test/helpers/event-utils");
const { setSelectedRecording, getSelectedRecordingIndex } = require("devtools/client/performance/test/helpers/recording-utils");

add_task(function* () {
  let { panel } = yield initPerformanceInNewTab({
    url: SIMPLE_URL,
    win: window
  });

  let {
    EVENTS,
    $,
    PerformanceController,
    WaterfallView
  } = panel.panelWin;

  let waterfallBtn = $("toolbarbutton[data-view='waterfall']");
  let jsFlameBtn = $("toolbarbutton[data-view='js-flamegraph']");
  let jsCallBtn = $("toolbarbutton[data-view='js-calltree']");
  let memFlameBtn = $("toolbarbutton[data-view='memory-flamegraph']");
  let memCallBtn = $("toolbarbutton[data-view='memory-calltree']");

  is(waterfallBtn.hidden, true,
    "The `waterfall` button is hidden when tool starts.");
  is(jsFlameBtn.hidden, true,
    "The `js-flamegraph` button is hidden when tool starts.");
  is(jsCallBtn.hidden, true,
    "The `js-calltree` button is hidden when tool starts.");
  is(memFlameBtn.hidden, true,
    "The `memory-flamegraph` button is hidden when tool starts.");
  is(memCallBtn.hidden, true,
    "The `memory-calltree` button is hidden when tool starts.");

  yield startRecording(panel);

  is(waterfallBtn.hidden, true,
    "The `waterfall` button is hidden when recording starts.");
  is(jsFlameBtn.hidden, true,
    "The `js-flamegraph` button is hidden when recording starts.");
  is(jsCallBtn.hidden, true,
    "The `js-calltree` button is hidden when recording starts.");
  is(memFlameBtn.hidden, true,
    "The `memory-flamegraph` button is hidden when recording starts.");
  is(memCallBtn.hidden, true,
    "The `memory-calltree` button is hidden when recording starts.");

  yield stopRecording(panel);

  is(waterfallBtn.hidden, false,
    "The `waterfall` button is visible when recording ends.");
  is(jsFlameBtn.hidden, false,
    "The `js-flamegraph` button is visible when recording ends.");
  is(jsCallBtn.hidden, false,
    "The `js-calltree` button is visible when recording ends.");
  is(memFlameBtn.hidden, true,
    "The `memory-flamegraph` button is hidden when recording ends.");
  is(memCallBtn.hidden, true,
    "The `memory-calltree` button is hidden when recording ends.");

  yield startRecording(panel);

  is(waterfallBtn.hidden, true,
    "The `waterfall` button is hidden when another recording starts.");
  is(jsFlameBtn.hidden, true,
    "The `js-flamegraph` button is hidden when another recording starts.");
  is(jsCallBtn.hidden, true,
    "The `js-calltree` button is hidden when another recording starts.");
  is(memFlameBtn.hidden, true,
    "The `memory-flamegraph` button is hidden when another recording starts.");
  is(memCallBtn.hidden, true,
    "The `memory-calltree` button is hidden when another recording starts.");

  let selected = once(PerformanceController, EVENTS.RECORDING_SELECTED);
  let rendered = once(WaterfallView, EVENTS.UI_WATERFALL_RENDERED);
  setSelectedRecording(panel, 0);
  yield selected;
  yield rendered;

  let selectedIndex = getSelectedRecordingIndex(panel);
  is(selectedIndex, 0,
    "The first recording was selected again.");

  is(waterfallBtn.hidden, false,
    "The `waterfall` button is visible when first recording selected.");
  is(jsFlameBtn.hidden, false,
    "The `js-flamegraph` button is visible when first recording selected.");
  is(jsCallBtn.hidden, false,
    "The `js-calltree` button is visible when first recording selected.");
  is(memFlameBtn.hidden, true,
    "The `memory-flamegraph` button is hidden when first recording selected.");
  is(memCallBtn.hidden, true,
    "The `memory-calltree` button is hidden when first recording selected.");

  selected = once(PerformanceController, EVENTS.RECORDING_SELECTED);
  setSelectedRecording(panel, 1);
  yield selected;

  selectedIndex = getSelectedRecordingIndex(panel);
  is(selectedIndex, 1,
    "The second recording was selected again.");

  is(waterfallBtn.hidden, true,
    "The `waterfall button` still is hidden when second recording selected.");
  is(jsFlameBtn.hidden, true,
    "The `js-flamegraph button` still is hidden when second recording selected.");
  is(jsCallBtn.hidden, true,
    "The `js-calltree button` still is hidden when second recording selected.");
  is(memFlameBtn.hidden, true,
    "The `memory-flamegraph button` still is hidden when second recording selected.");
  is(memCallBtn.hidden, true,
    "The `memory-calltree button` still is hidden when second recording selected.");

  rendered = once(WaterfallView, EVENTS.UI_WATERFALL_RENDERED);
  yield stopRecording(panel);
  yield rendered;

  selectedIndex = getSelectedRecordingIndex(panel);
  is(selectedIndex, 1,
    "The second recording is still selected.");

  is(waterfallBtn.hidden, false,
    "The `waterfall` button is visible when second recording finished.");
  is(jsFlameBtn.hidden, false,
    "The `js-flamegraph` button is visible when second recording finished.");
  is(jsCallBtn.hidden, false,
    "The `js-calltree` button is visible when second recording finished.");
  is(memFlameBtn.hidden, true,
    "The `memory-flamegraph` button is hidden when second recording finished.");
  is(memCallBtn.hidden, true,
    "The `memory-calltree` button is hidden when second recording finished.");

  yield teardownToolboxAndRemoveTab(panel);
});