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

/**
 * Tests that the details view hides the allocations buttons when a recording
 * does not have allocations data ("withAllocations": false), and that when an
 * allocations panel is selected to a panel that does not have allocations goes
 * to a default panel instead.
 */

const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
const { UI_ENABLE_ALLOCATIONS_PREF } = require("devtools/client/performance/test/helpers/prefs");
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 } = require("devtools/client/performance/test/helpers/recording-utils");

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

  let {
    EVENTS,
    $,
    DetailsView,
    WaterfallView,
    MemoryCallTreeView,
    MemoryFlameGraphView
  } = panel.panelWin;

  let flameBtn = $("toolbarbutton[data-view='memory-flamegraph']");
  let callBtn = $("toolbarbutton[data-view='memory-calltree']");

  // Disable allocations to prevent recording them.
  Services.prefs.setBoolPref(UI_ENABLE_ALLOCATIONS_PREF, false);

  yield startRecording(panel);
  yield stopRecording(panel);

  ok(DetailsView.isViewSelected(WaterfallView),
    "The waterfall view is selected by default in the details view.");

  // Re-enable allocations to test.
  Services.prefs.setBoolPref(UI_ENABLE_ALLOCATIONS_PREF, true);

  // The toolbar buttons will always be hidden when a recording isn't available,
  // so make sure we have one that's finished.
  yield startRecording(panel);
  yield stopRecording(panel);

  ok(DetailsView.isViewSelected(WaterfallView),
    "The waterfall view is still selected in the details view.");

  is(callBtn.hidden, false,
    "The `memory-calltree` button is shown when recording has memory data.");
  is(flameBtn.hidden, false,
    "The `memory-flamegraph` button is shown when recording has memory data.");

  let selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  let rendered = once(MemoryCallTreeView, EVENTS.UI_MEMORY_CALL_TREE_RENDERED);
  DetailsView.selectView("memory-calltree");
  yield selected;
  yield rendered;

  ok(DetailsView.isViewSelected(MemoryCallTreeView),
    "The memory call tree view can now be selected.");

  selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  rendered = once(MemoryFlameGraphView, EVENTS.UI_MEMORY_FLAMEGRAPH_RENDERED);
  DetailsView.selectView("memory-flamegraph");
  yield selected;
  yield rendered;

  ok(DetailsView.isViewSelected(MemoryFlameGraphView),
    "The memory flamegraph view can now be selected.");

  // Select the first recording with no memory data.
  selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  rendered = once(WaterfallView, EVENTS.UI_WATERFALL_RENDERED);
  setSelectedRecording(panel, 0);
  yield selected;
  yield rendered;

  ok(DetailsView.isViewSelected(WaterfallView), "The waterfall view is now selected " +
    "when switching back to a recording that does not have memory data.");

  is(callBtn.hidden, true,
    "The `memory-calltree` button is hidden when recording has no memory data.");
  is(flameBtn.hidden, true,
    "The `memory-flamegraph` button is hidden when recording has no memory data.");

  // Go back to the recording with memory data.
  rendered = once(WaterfallView, EVENTS.UI_WATERFALL_RENDERED);
  setSelectedRecording(panel, 1);
  yield rendered;

  ok(DetailsView.isViewSelected(WaterfallView),
    "The waterfall view is still selected in the details view.");

  is(callBtn.hidden, false,
    "The `memory-calltree` button is shown when recording has memory data.");
  is(flameBtn.hidden, false,
    "The `memory-flamegraph` button is shown when recording has memory data.");

  selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  rendered = once(MemoryCallTreeView, EVENTS.UI_MEMORY_CALL_TREE_RENDERED);
  DetailsView.selectView("memory-calltree");
  yield selected;
  yield rendered;

  ok(DetailsView.isViewSelected(MemoryCallTreeView), "The memory call tree view can be " +
    "selected again after going back to the view with memory data.");

  selected = once(DetailsView, EVENTS.UI_DETAILS_VIEW_SELECTED);
  rendered = once(MemoryFlameGraphView, EVENTS.UI_MEMORY_FLAMEGRAPH_RENDERED);
  DetailsView.selectView("memory-flamegraph");
  yield selected;
  yield rendered;

  ok(DetailsView.isViewSelected(MemoryFlameGraphView), "The memory flamegraph view can " +
    "be selected again after going back to the view with memory data.");

  yield teardownToolboxAndRemoveTab(panel);
});