-
Notifications
You must be signed in to change notification settings - Fork 392
/
active-tab.test.js
368 lines (329 loc) · 11.3 KB
/
active-tab.test.js
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import {
changeTimelineTrackOrganization,
viewProfile,
} from '../../actions/receive-profile';
import {
getHumanReadableActiveTabTracks,
getProfileWithNiceTracks,
} from '../fixtures/profiles/tracks';
import {
getScreenshotTrackProfile,
addActiveTabInformationToProfile,
addMarkersToThreadWithCorrespondingSamples,
getProfileWithThreadCPUDelta,
getProfileFromTextSamples,
addInnerWindowIdToStacks,
} from '../fixtures/profiles/processed-profile';
import { storeWithProfile, blankStore } from '../fixtures/stores';
import { getView } from '../../selectors/app';
import {
getTimelineTrackOrganization,
getTimelineType,
} from '../../selectors/url-state';
import { stateFromLocation } from '../../app-logic/url-handling';
import { ensureExists } from '../../utils/flow';
import type { Profile } from 'firefox-profiler/types';
describe('ActiveTab', function () {
function setup(
p = getProfileWithNiceTracks(),
addInnerWindowID = true,
pageInfo = null
) {
let profile = p;
if (!pageInfo) {
({ profile, ...pageInfo } = addActiveTabInformationToProfile(profile));
}
// Add the innerWindowIDs so we can compute the first thread as main track.
if (addInnerWindowID) {
profile.threads[0].frameTable.innerWindowID[0] =
pageInfo.parentInnerWindowIDsWithChildren;
if (profile.threads[0].frameTable.length < 1) {
profile.threads[0].frameTable.length = 1;
}
}
const { dispatch, getState } = storeWithProfile(profile);
dispatch(
changeTimelineTrackOrganization({
type: 'active-tab',
tabID: pageInfo.activeTabID,
})
);
return {
// Store:
dispatch,
getState,
// TabIDs and InnerWindowIDs of pages:
...pageInfo,
};
}
describe('global tracks', function () {
it('can initialize with active tab information', function () {
const { getState } = setup();
expect(getHumanReadableActiveTabTracks(getState())).toEqual([
'main track [tab] SELECTED',
]);
});
it('can extract a screenshots track', function () {
const profile = getScreenshotTrackProfile();
profile.threads[0].name = 'GeckoMain';
profile.threads[0].isMainThread = true;
const { getState } = setup(profile);
expect(getHumanReadableActiveTabTracks(getState())).toEqual([
'screenshots',
'screenshots',
'screenshots',
'main track [tab] SELECTED',
]);
});
it('do not rely on network markers while calculating the tracks', function () {
// Network markers are not reliable to compute the tracks because some network
// markers of an iframe comes from the parent frame. Therefore, their
// innerWindowID will be the parent window's innerWindowID.
const profile = getProfileWithNiceTracks();
addMarkersToThreadWithCorrespondingSamples(profile.threads[0], [
[
'Load 1 will be filtered',
7,
8,
{
type: 'Network',
URI: 'URI 1',
id: 5,
pri: 1,
status: 'STATUS_STOP',
startTime: 7,
endTime: 8,
},
],
]);
const { getState } = setup(profile, false);
expect(getHumanReadableActiveTabTracks(getState()).length).toBe(0);
});
it('can compute global tracks even when there are several tab ids in one thread', () => {
const {
profile,
funcNamesDictPerThread: [firstThread, { A, B, Cjs, Djs }],
} = getProfileFromTextSamples(
// First thread is the main thread of the first tab (which is the
// active tab)
`
A
`,
// In this second thread, the first sample is from tab 2, the second sample is
// from an iframe of the tab 1 which is the active tab.
`
A A
B B
Cjs Djs
`
);
profile.threads[0].name = 'GeckoMain';
profile.threads[0].isMainThread = true;
profile.threads[1].name = 'GeckoMain';
profile.threads[1].isMainThread = true;
const {
firstTabInnerWindowIDs,
iframeInnerWindowIDsWithChild,
secondTabInnerWindowIDs,
} = addActiveTabInformationToProfile(profile);
addInnerWindowIdToStacks(
profile.threads[0],
/* listOfOperations */
[
// first tab is the active tab.
{
innerWindowID: firstTabInnerWindowIDs[0],
callNodes: [[firstThread.A]],
},
]
);
addInnerWindowIdToStacks(
profile.threads[1],
/* listOfOperations */
[
// Second tab points to the first sample.
{
innerWindowID: secondTabInnerWindowIDs[0],
callNodes: [[A, B, Cjs]],
},
// First tab is the active tab, we're using the iframe's innerWindowID.
{
innerWindowID: iframeInnerWindowIDsWithChild,
callNodes: [[A, B, Djs]],
},
]
);
const { getState } = setup(profile, false);
expect(getHumanReadableActiveTabTracks(getState())).toEqual([
'main track [tab] SELECTED',
' - iframe: https://www.youtube.com/',
]);
});
it('do not show the thread when it fails to find the iframe resource name', function () {
const {
profile: p,
funcNamesDictPerThread: [firstThread],
} = getProfileFromTextSamples(
// First thread is the main thread of the first tab (which is the
// active tab)
`A`,
// The second thread is an iframe of the first thread.
`B`
);
p.threads[0].name = 'GeckoMain';
p.threads[0].isMainThread = true;
p.threads[1].name = 'GeckoMain';
p.threads[1].isMainThread = true;
const { profile, ...pageInfo } = addActiveTabInformationToProfile(p);
addInnerWindowIdToStacks(
profile.threads[0],
/* listOfOperations */
[
// first tab is the active tab.
{
innerWindowID: pageInfo.firstTabInnerWindowIDs[0],
callNodes: [[firstThread.A]],
},
]
);
addMarkersToThreadWithCorrespondingSamples(profile.threads[1], [
// All about:blank or about:newtab markers are ignored during the
// track name computation because they don't provide the correct innerWindowID.
// This thread SHOULD NOT be shown in the tracks.
[
'This marker will be filtered',
1,
2,
{
type: 'tracing',
category: 'Navigation',
innerWindowID: pageInfo.iframeInnerWindowIDsWithChild,
},
],
]);
// Lastly, we need to put the iframe innerWindowID url to about:blank to test this case.
ensureExists(profile.pages)[1].url = 'about:blank';
const { getState } = setup(profile, false, pageInfo);
expect(getHumanReadableActiveTabTracks(getState())).toEqual([
'main track [tab] SELECTED',
]);
});
});
});
describe('finalizeProfileView', function () {
function setup({
profile = addActiveTabInformationToProfile(getProfileWithNiceTracks())
.profile,
search,
noPages,
activeTabID,
}: {
profile?: Profile,
search: string,
noPages?: boolean,
activeTabID?: number | null,
}) {
const newUrlState = stateFromLocation({
pathname: '/public/FAKEHASH/calltree/',
search: '?' + search,
hash: '',
});
if (noPages) {
delete profile.pages;
}
if (activeTabID !== undefined) {
// Update the activeTabID if it's explicitly provided.
profile.meta.configuration = {
...profile.meta.configuration,
// null is represented by 0 for activeTab in the back-end.
activeTabID: activeTabID ?? 0,
};
}
// Create the store and dispatch the url state.
const store = blankStore();
store.dispatch({
type: 'UPDATE_URL_STATE',
newUrlState,
});
// Lastly, load the profile to test finalizeProfileView.
store.dispatch(viewProfile(profile));
return store;
}
it('loads the profile with only `view=active-tab` in active tab view', async function () {
const { getState } = setup({ search: '?view=active-tab&v=5' });
// Check if we can successfully finalized the profile view for active tab.
expect(getView(getState()).phase).toBe('DATA_LOADED');
expect(getTimelineTrackOrganization(getState())).toEqual({
type: 'active-tab',
tabID: null,
});
});
it('switches back to full view if there is no `pages` array', async function () {
const { getState } = setup({
search: '?view=active-tab&v=5',
noPages: true,
});
// Check if we can successfully finalized the profile view for full view.
expect(getView(getState()).phase).toBe('DATA_LOADED');
expect(getTimelineTrackOrganization(getState())).toEqual({
type: 'full',
});
});
it('switches back to full view if there is no `activeTabID` value', function () {
const { getState } = setup({
search: '?view=active-tab&v=5',
activeTabID: null,
});
// Check if we can successfully finalized the profile view for full view.
expect(getView(getState()).phase).toBe('DATA_LOADED');
expect(getTimelineTrackOrganization(getState())).toEqual({
type: 'full',
});
});
it('switches back to full view if there is no relevant page with the given `activeTabID` value', function () {
const activeTabIDWithNoRelevantPage = 99999;
const { getState } = setup({
search: '?view=active-tab&v=5',
activeTabID: activeTabIDWithNoRelevantPage,
});
// Check if we can successfully finalized the profile view for full view.
expect(getView(getState()).phase).toBe('DATA_LOADED');
expect(getTimelineTrackOrganization(getState())).toEqual({
type: 'full',
});
});
it('sets the timeline type to "categories with CPU" if there are CPU usage values in the profile', function () {
const { profile } = addActiveTabInformationToProfile(
getProfileWithThreadCPUDelta([[1, 2]])
);
const { getState } = setup({
profile,
search: '?view=active-tab&v=5',
});
// Check if we can successfully finalized the profile view for active tab view.
expect(getView(getState()).phase).toBe('DATA_LOADED');
expect(getTimelineTrackOrganization(getState())).toEqual({
type: 'active-tab',
tabID: null,
});
// Check if we have the 'cpu-categories' as the timelineType
expect(getTimelineType(getState())).toBe('cpu-category');
});
it('sets the timeline type to "categories" if there are no CPU usage values in the profile', function () {
const { getState } = setup({
search: '?view=active-tab&v=5',
});
// Check if we can successfully finalized the profile view for active tab view.
expect(getView(getState()).phase).toBe('DATA_LOADED');
expect(getTimelineTrackOrganization(getState())).toEqual({
type: 'active-tab',
tabID: null,
});
// Check if we have the 'categories' as the timelineType
expect(getTimelineType(getState())).toBe('category');
});
});