forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackContextMenu.test.js
1197 lines (1045 loc) · 41.2 KB
/
TrackContextMenu.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* 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 * as React from 'react';
import { Provider } from 'react-redux';
import { showMenu } from '@firefox-devtools/react-contextmenu';
import {
render,
screen,
waitFor,
fireEvent,
act,
} from 'firefox-profiler/test/fixtures/testing-library';
import { ensureExists } from '../../utils/flow';
import {
changeSelectedThreads,
changeRightClickedTrack,
} from '../../actions/profile-view';
import { TimelineTrackContextMenu } from '../../components/timeline/TrackContextMenu';
import { getGlobalTracks, getLocalTracks } from '../../selectors/profile';
import {
getHiddenGlobalTracks,
getHiddenLocalTracks,
} from '../../selectors/url-state';
import {
getProfileWithNiceTracks,
getProfileWithMoreNiceTracks,
getHumanReadableTracks,
} from '../fixtures/profiles/tracks';
import {
getScreenshotTrackProfile,
getNetworkTrackProfile,
} from '../fixtures/profiles/processed-profile';
import { storeWithProfile } from '../fixtures/stores';
import { fireFullClick, fireFullKeyPress } from '../fixtures/utils';
import type { Profile, TrackReference } from 'firefox-profiler/types';
describe('timeline/TrackContextMenu', function () {
beforeEach(() => {
jest.useFakeTimers();
});
const clickTracksWithExpectation = async (
matchers: Array<string | RegExp>,
expectations: {|
+checked: boolean,
|}
) => {
const elements = matchers.map((matcher) =>
screen.getByRole('menuitemcheckbox', { name: matcher })
);
elements.forEach((element) => fireFullClick(element));
await waitFor(() => {
for (const element of elements) {
const menuItem = element.closest('.react-contextmenu-item');
expect(menuItem).toHaveAttribute(
'aria-checked',
String(expectations.checked)
);
if (expectations.checked) {
expect(menuItem).toBeChecked();
} else {
expect(menuItem).not.toBeChecked();
}
}
});
};
/**
* getProfileWithNiceTracks() looks like: [
* 'show [thread GeckoMain default]',
* 'show [thread GeckoMain tab]', <- use this global track.
* ' - show [thread DOM Worker]',
* ' - show [thread Style]',
* ]
*/
function setup(profile = getProfileWithNiceTracks()) {
const store = storeWithProfile(profile);
const { getState, dispatch } = store;
const renderResult = render(
<Provider store={store}>
<TimelineTrackContextMenu />
</Provider>
);
const changeSearchFilter = (searchText: string) => {
fireEvent.change(screen.getByPlaceholderText(/Enter filter terms/), {
target: { value: searchText },
});
jest.runAllTimers();
};
const isContextMenuVisible = (): boolean => {
const contextMenu = ensureExists(
document.querySelector('.react-contextmenu'),
`Couldn't find the context menu.`
);
return contextMenu.classList.contains('react-contextmenu--visible');
};
const showContextMenu = () => {
showMenu({
data: null,
id: 'TimelineTrackContextMenu',
position: { x: 0, y: 0 },
});
};
return {
...renderResult,
dispatch,
getState,
profile,
store,
changeSearchFilter,
isContextMenuVisible,
showContextMenu,
};
}
describe('the "show all tracks" menu item', function () {
function setupAllTracks() {
const results = setup();
const selectAllTracksItem = () => screen.getByText('Show all tracks');
const hideAllTracks = async () => {
// We want to hide this tracks before testing 'Show all tracks'
const matchers = [/Parent Process/, 'DOM Worker', 'Style'];
await clickTracksWithExpectation(matchers, { checked: false });
};
return {
...results,
selectAllTracksItem,
hideAllTracks,
};
}
it('selects all tracks', async () => {
const { getState, selectAllTracksItem, hideAllTracks } = setupAllTracks();
// Test behavior when all tracks are already shown
fireFullClick(selectAllTracksItem());
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
// Hide all tracks to test behavior
await hideAllTracks();
expect(getHumanReadableTracks(getState())).toEqual([
// Check if the tracks have been hidden
'hide [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
// All tracks should be visible now
fireFullClick(selectAllTracksItem());
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
});
});
describe('show all matching tracks', function () {
function setupAllTracks() {
const results = setup();
const selectShowAllMatchingTracksItem = () =>
screen.getByText('Show all matching tracks');
const hideAllTracks = async () => {
// To hide the tracks before testing 'Show all tracks'
const matchers = [/Parent Process/, 'DOM Worker', 'Style'];
await clickTracksWithExpectation(matchers, { checked: false });
};
const hideAllTracksExceptMain = async () => {
const matchers = [/Content Process/, 'DOM Worker', 'Style'];
await clickTracksWithExpectation(matchers, { checked: false });
};
return {
...results,
selectShowAllMatchingTracksItem,
hideAllTracks,
hideAllTracksExceptMain,
};
}
it('shows a single track', async () => {
const {
getState,
selectShowAllMatchingTracksItem,
hideAllTracks,
changeSearchFilter,
} = setupAllTracks();
// Hide all tracks to test the behavior.
await hideAllTracks();
expect(getHumanReadableTracks(getState())).toEqual([
// Check if the tracks have been hidden.
'hide [thread GeckoMain default]',
// There must be at least one visible track.
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('Parent Process');
// Click the button.
fireFullClick(selectShowAllMatchingTracksItem());
// GeckoMain should be visible now.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
});
it('shows children of a global track', async () => {
const {
getState,
selectShowAllMatchingTracksItem,
hideAllTracks,
changeSearchFilter,
} = setupAllTracks();
// Hide all tracks to test the behavior.
await hideAllTracks();
expect(getHumanReadableTracks(getState())).toEqual([
// Check if the tracks have been hidden.
'hide [thread GeckoMain default]',
// There must be at least one visible track.
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('Content Process');
// Click the button.
fireFullClick(selectShowAllMatchingTracksItem());
// Children of Content Process should be visible now.
expect(getHumanReadableTracks(getState())).toEqual([
'hide [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
});
it('shows a local track', async () => {
const {
getState,
selectShowAllMatchingTracksItem,
hideAllTracks,
changeSearchFilter,
} = setupAllTracks();
// Hide all tracks to test the behavior.
await hideAllTracks();
expect(getHumanReadableTracks(getState())).toEqual([
// Check if the tracks have been hidden.
'hide [thread GeckoMain default]',
// There must be at least one visible track.
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('DOM Worker');
// Click the button.
fireFullClick(selectShowAllMatchingTracksItem());
// DOM Worker track should be visible now.
expect(getHumanReadableTracks(getState())).toEqual([
'hide [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - hide [thread Style]',
]);
});
it('does not show anything if the list is empty', async () => {
const {
getState,
selectShowAllMatchingTracksItem,
hideAllTracks,
changeSearchFilter,
} = setupAllTracks();
// Hide all tracks to test the behavior.
await hideAllTracks();
expect(getHumanReadableTracks(getState())).toEqual([
// Check if the tracks have been hidden.
'hide [thread GeckoMain default]',
// There must be at least one visible track.
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
// Search something to filter the tracks. This time it's something random.
changeSearchFilter('this should not be in the tracks list');
// Click the button.
fireFullClick(selectShowAllMatchingTracksItem());
// No new track should be visible.
expect(getHumanReadableTracks(getState())).toEqual([
'hide [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
});
it("shows local track's global track even if it wasn't visible before", async () => {
const {
getState,
selectShowAllMatchingTracksItem,
hideAllTracksExceptMain,
changeSearchFilter,
} = setupAllTracks();
// Hide the local tracks and tehe global track with children for this behavior.
await hideAllTracksExceptMain();
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
// These tracks must be hidden at the start.
'hide [thread GeckoMain tab]',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
// Search a local track.
changeSearchFilter('DOM Worker');
// Click the button.
fireFullClick(selectShowAllMatchingTracksItem());
// DOM Worker and its global process should be visible now.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
'show [thread GeckoMain tab]',
' - show [thread DOM Worker]',
' - hide [thread Style]',
]);
});
});
describe('hide all matching tracks', function () {
function setupAllTracks(profile?: Profile) {
const setupResults = setup(profile);
const hideAllMatchingTracksItem = () =>
screen.getByText('Hide all matching tracks');
const hideAllTracksExceptMain = async () => {
const matchers = [/Content Process/, 'DOM Worker', 'Style'];
await clickTracksWithExpectation(matchers, { checked: false });
};
return {
...setupResults,
hideAllMatchingTracksItem,
hideAllTracksExceptMain,
};
}
it('hides a global track', () => {
const { getState, hideAllMatchingTracksItem, changeSearchFilter } =
setupAllTracks();
// Make sure all the tracks are visible at first.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('Parent Process');
// Click the button.
fireFullClick(hideAllMatchingTracksItem());
// GeckoMain should be hidden now.
expect(getHumanReadableTracks(getState())).toEqual([
'hide [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
});
it('hides a local track', () => {
const { getState, hideAllMatchingTracksItem, changeSearchFilter } =
setupAllTracks();
// Make sure all the tracks are visible at first.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('DOM Worker');
// Click the button.
fireFullClick(hideAllMatchingTracksItem());
// DOM Worker track should be hidden now.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - show [thread Style]',
]);
});
it('does not hide anything if search filter does not match', () => {
const { getState, hideAllMatchingTracksItem, changeSearchFilter } =
setupAllTracks();
// Make sure all the tracks are visible at first.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
// Search something to filter the tracks. This time it's something random.
changeSearchFilter('this should not be in the tracks list');
// Click the button.
fireFullClick(hideAllMatchingTracksItem());
// No new track should be hidden.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
});
it('does not hide if it is the last visible track', async () => {
const {
getState,
hideAllMatchingTracksItem,
hideAllTracksExceptMain,
changeSearchFilter,
} = setupAllTracks();
// Hide all tracks except the main to test the behavior.
await hideAllTracksExceptMain();
expect(getHumanReadableTracks(getState())).toEqual([
// This must be the only visible track.
'show [thread GeckoMain default] SELECTED',
'hide [thread GeckoMain tab]',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('Parent Process');
// Click the button.
fireFullClick(hideAllMatchingTracksItem());
// GeckoMain should still be visible.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
'hide [thread GeckoMain tab]',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
});
it('selects another visible track when the selected one becomes hidden', () => {
const { getState, hideAllMatchingTracksItem, changeSearchFilter } =
setupAllTracks();
// Make sure all the tracks are visible at first.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('tab');
// Click the button.
fireFullClick(hideAllMatchingTracksItem());
// GeckoMain should be visible and selected.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
'hide [thread GeckoMain tab]',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
});
it('hides process tracks without a main thread', function () {
const profile = getProfileWithNiceTracks();
// Remove the thread [thread GeckoMain tab]
profile.threads.splice(1, 1);
const { getState, hideAllMatchingTracksItem, changeSearchFilter } =
setupAllTracks(profile);
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
'show [process]',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('DOM Worker');
// Click the button.
fireFullClick(hideAllMatchingTracksItem());
// DOM Worker track should be hidden now.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
'show [process]',
' - hide [thread DOM Worker]',
' - show [thread Style]',
]);
// Search something to filter the tracks.
changeSearchFilter('Style');
// Click the button.
fireFullClick(hideAllMatchingTracksItem());
// Style and process tracks should be hidden now.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
'hide [process]',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
});
it('does not hide if the process without a main thread has only one visible track left', function () {
const profile = getProfileWithNiceTracks();
// Remove the thread [thread GeckoMain tab]
profile.threads.splice(0, 2);
const { getState, hideAllMatchingTracksItem, changeSearchFilter } =
setupAllTracks(profile);
fireFullClick(screen.getByText('Style'));
expect(getHumanReadableTracks(getState())).toEqual([
'show [process]',
' - show [thread DOM Worker] SELECTED',
' - hide [thread Style]',
]);
// Search "DOM Worker" to filter the tracks.
changeSearchFilter('DOM Worker');
// Try to click the button. But it should be disabled and not clickable.
const hideAllMatchingTracksMenuItem = hideAllMatchingTracksItem();
expect(hideAllMatchingTracksMenuItem).toHaveAttribute(
'aria-disabled',
'true'
);
fireFullClick(hideAllMatchingTracksMenuItem);
// Clicking on the "hide all matching tracks" button should not hide the
// DOM Worker or process track.
expect(getHumanReadableTracks(getState())).toEqual([
'show [process]',
' - show [thread DOM Worker] SELECTED',
' - hide [thread Style]',
]);
});
});
describe('when a global track is right clicked', function () {
function setupGlobalTrack(profile, trackIndex = 1) {
const results = setup(profile);
const { dispatch, getState } = results;
const trackReference = {
type: 'global',
trackIndex: trackIndex,
};
const track = getGlobalTracks(getState())[trackIndex];
const threadIndex =
track.type === 'process' ? track.mainThreadIndex : null;
if (threadIndex !== null) {
// Explicitly select the global thread. Tests can pass in a custom profile,
// so don't fail if this doesn't exist.
act(() => {
dispatch(changeSelectedThreads(new Set([threadIndex])));
});
}
act(() => {
dispatch(changeRightClickedTrack(trackReference));
});
const isolateProcessItem = () =>
screen.getByText(/Only show this process/);
// Fluent adds isolation characters \u2068 and \u2069 around Content Process.
const isolateProcessMainThreadItem = () =>
screen.getByText(/Only show “\u2068Content Process\u2069”/);
const isolateScreenshotTrack = () =>
screen.getByText(/Hide other Screenshots tracks/);
// Fluent adds isolation characters \u2068 and \u2069 around Content Process.
const hideContentProcess = () =>
screen.getByText(/Hide “\u2068Content Process\u2069”/);
return {
...results,
trackReference,
trackIndex,
threadIndex,
isolateProcessItem,
isolateProcessMainThreadItem,
isolateScreenshotTrack,
hideContentProcess,
};
}
it('matches the snapshot of a global track', () => {
const { container } = setupGlobalTrack();
expect(container.firstChild).toMatchSnapshot();
});
it('matches the snapshot of a global non-process track', () => {
const { container } = setupGlobalTrack(getScreenshotTrackProfile());
expect(container.firstChild).toMatchSnapshot();
});
it('has the correct selectors into useful parts of the component', function () {
const { getState } = setupGlobalTrack();
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
});
it('can isolate the process', function () {
const { isolateProcessItem, getState } = setupGlobalTrack();
fireFullClick(isolateProcessItem());
expect(getHumanReadableTracks(getState())).toEqual([
'hide [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
});
it("can isolate the process's main thread", function () {
const { isolateProcessMainThreadItem, getState } = setupGlobalTrack();
fireFullClick(isolateProcessMainThreadItem());
expect(getHumanReadableTracks(getState())).toEqual([
'hide [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - hide [thread DOM Worker]',
' - hide [thread Style]',
]);
});
it('isolates a process track without a main thread', function () {
const profile = getProfileWithNiceTracks();
// Remove the thread [thread GeckoMain tab]
profile.threads.splice(1, 1);
const { isolateProcessMainThreadItem, isolateProcessItem, getState } =
setupGlobalTrack(profile);
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
'show [process]',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
expect(isolateProcessMainThreadItem).toThrow();
fireFullClick(isolateProcessItem());
expect(getHumanReadableTracks(getState())).toEqual([
'hide [thread GeckoMain default]',
'show [process]',
' - show [thread DOM Worker] SELECTED',
' - show [thread Style]',
]);
});
it('isolates a screenshot track', () => {
const { isolateScreenshotTrack, getState } = setupGlobalTrack(
getScreenshotTrackProfile()
);
fireFullClick(isolateScreenshotTrack());
expect(getHumanReadableTracks(getState())).toEqual([
'show [screenshots]',
'hide [screenshots]',
'hide [screenshots]',
'show [process]',
' - show [thread Empty] SELECTED',
]);
});
it('can hide the process', function () {
const { hideContentProcess, getState } = setupGlobalTrack();
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
fireFullClick(hideContentProcess());
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default] SELECTED',
'hide [thread GeckoMain tab]',
' - show [thread DOM Worker]',
' - show [thread Style]',
]);
});
it('can toggle a global track by clicking it', async function () {
const { trackIndex, getState } = setupGlobalTrack();
expect(getHiddenGlobalTracks(getState()).has(trackIndex)).toBe(false);
await clickTracksWithExpectation([/^Content Process/], {
checked: false,
});
expect(getHiddenGlobalTracks(getState()).has(trackIndex)).toBe(true);
await clickTracksWithExpectation([/^Content Process/], { checked: true });
expect(getHiddenGlobalTracks(getState()).has(trackIndex)).toBe(false);
});
// TODO - We should wait until we have some real tracks without a thread index.
it.todo('can present a disabled isolate item on non-process tracks');
it('network track will be displayed when a number is not set for ctxId', () => {
const { container } = setupGlobalTrack(getNetworkTrackProfile(), 0);
// We can't use getHumanReadableTracks here because that function doesn't
// use the functions used by context menu directly and gives us wrong results.
expect(container.firstChild).toMatchSnapshot();
});
});
describe('when a local track is right clicked', function () {
function setupLocalTrack(profile) {
const results = setup(profile);
const { dispatch, getState } = results;
// In getProfileWithNiceTracks, the two pids are 111 and 222 for the
// "GeckoMain process" and "GeckoMain tab" respectively. Use 222 since it has
// local tracks.
const pid = '222';
const trackIndex = 0;
const trackReference = {
type: 'local',
pid,
trackIndex,
};
const localTracks = getLocalTracks(getState(), pid);
const localTrack = localTracks[trackIndex];
if (localTrack.type !== 'thread') {
throw new Error('Expected a thread track');
}
const threadIndex = localTrack.threadIndex;
// Explicitly select the global thread.
act(() => {
dispatch(changeSelectedThreads(new Set([threadIndex])));
});
act(() => {
dispatch(changeRightClickedTrack(trackReference));
});
// Fluent adds isolation characters \u2068 and \u2069 around DOM Worker.
const isolateLocalTrackItem = () =>
screen.getByText('Only show “\u2068DOM Worker\u2069”');
const hideDOMWorker = () =>
screen.getByText('Hide “\u2068DOM Worker\u2069”');
const trackItem = () => screen.getByText('DOM Worker');
return {
...results,
trackReference,
trackIndex,
threadIndex,
isolateLocalTrackItem,
hideDOMWorker,
trackItem,
pid,
};
}
it('matches the snapshot of a local track', () => {
const { container } = setupLocalTrack();
expect(container.firstChild).toMatchSnapshot();
});
it('has the correct selectors into useful parts of the component', function () {
const { getState } = setupLocalTrack();
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab]',
' - show [thread DOM Worker] SELECTED',
' - show [thread Style]',
]);
});
it('can isolate the local track', function () {
const { isolateLocalTrackItem, getState } = setupLocalTrack();
fireFullClick(isolateLocalTrackItem());
expect(getHumanReadableTracks(getState())).toEqual([
'hide [thread GeckoMain default]',
'show [thread GeckoMain tab]',
' - show [thread DOM Worker] SELECTED',
' - hide [thread Style]',
]);
});
it('can hide the DOM worker thread', function () {
const { hideDOMWorker, getState } = setupLocalTrack();
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab]',
' - show [thread DOM Worker] SELECTED',
' - show [thread Style]',
]);
fireFullClick(hideDOMWorker());
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
'show [thread GeckoMain tab]',
' - hide [thread DOM Worker]',
' - show [thread Style] SELECTED',
]);
});
it('can toggle a local track by clicking it', function () {
const { trackItem, pid, trackIndex, getState } = setupLocalTrack();
expect(getHiddenLocalTracks(getState(), pid).has(trackIndex)).toBe(false);
fireFullClick(trackItem());
expect(getHiddenLocalTracks(getState(), pid).has(trackIndex)).toBe(true);
fireFullClick(trackItem());
expect(getHiddenLocalTracks(getState(), pid).has(trackIndex)).toBe(false);
});
// TODO - We should wait until we have some real non-thread tracks
it.todo(
'can isolate a non-thread track, as long as there process has a thread index'
);
});
describe('show all local tracks in a process', function () {
function setupMoreTracks() {
const profile = getProfileWithMoreNiceTracks();
const store = storeWithProfile(profile);
render(
<Provider store={store}>
<TimelineTrackContextMenu />
</Provider>
);
function clickAllThreadPoolTracks() {
const threadPoolTracks = screen.getAllByText(/^ThreadPool#\d$/);
for (const track of threadPoolTracks) {
fireFullClick(track);
}
}
return {
...store,
clickAllThreadPoolTracks,
profile,
};
}
// This runs 2 tests: the first right clicks a global track, the second
// right clicks the local track.
it.each([
{ type: 'global', trackIndex: 0 },
{
type: 'local',
pid: '1000',
trackIndex: 0,
},
])(
`from the $type track's context menu`,
(rightClickedTrackReference: TrackReference) => {
const { getState, dispatch, clickAllThreadPoolTracks } =
setupMoreTracks();
act(() => {
dispatch(changeRightClickedTrack(rightClickedTrackReference));
});
clickAllThreadPoolTracks();
// First, check that the initial state is what we expect.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
' - hide [thread ThreadPool#1]',
' - hide [thread ThreadPool#2]',
' - hide [thread ThreadPool#3]',
' - hide [thread ThreadPool#4]',
' - hide [thread ThreadPool#5]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
'show [thread GeckoMain tab]',
' - show [thread AudioPool#1]',
' - show [thread AudioPool#2]',
' - show [thread Renderer]',
]);
// This ensures that the displayed tracks are only from the first process.
// Please make sure the test here is the same than in the next test.
expect(screen.queryByText('DOM Worker')).not.toBeInTheDocument();
// Carry on the test
fireFullClick(screen.getByText('Show all tracks in this process'));
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
' - show [thread ThreadPool#1]',
' - show [thread ThreadPool#2]',
' - show [thread ThreadPool#3]',
' - show [thread ThreadPool#4]',
' - show [thread ThreadPool#5]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
'show [thread GeckoMain tab]',
' - show [thread AudioPool#1]',
' - show [thread AudioPool#2]',
' - show [thread Renderer]',
]);
}
);
it('by double clicking the global process item', () => {
const { getState, clickAllThreadPoolTracks } = setupMoreTracks();
clickAllThreadPoolTracks();
// First, check that the initial state is what we expect.
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
' - hide [thread ThreadPool#1]',
' - hide [thread ThreadPool#2]',
' - hide [thread ThreadPool#3]',
' - hide [thread ThreadPool#4]',
' - hide [thread ThreadPool#5]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
'show [thread GeckoMain tab]',
' - show [thread AudioPool#1]',
' - show [thread AudioPool#2]',
' - show [thread Renderer]',
]);
// This ensures that the displayed tracks are for the whole profile.
// Please make sure the test here is the same than in the previous test.
expect(screen.getByText('DOM Worker')).toBeInTheDocument();
// Then carry one with the test.
const globalTrack = screen.getByText('Parent Process');
fireFullClick(globalTrack, { detail: 1 });
fireFullClick(globalTrack, { detail: 2 });
expect(getHumanReadableTracks(getState())).toEqual([
'show [thread GeckoMain default]',
' - show [thread ThreadPool#1]',
' - show [thread ThreadPool#2]',
' - show [thread ThreadPool#3]',
' - show [thread ThreadPool#4]',
' - show [thread ThreadPool#5]',
'show [thread GeckoMain tab] SELECTED',
' - show [thread DOM Worker]',
' - show [thread Style]',
'show [thread GeckoMain tab]',
' - show [thread AudioPool#1]',
' - show [thread AudioPool#2]',
' - show [thread Renderer]',
]);
});
});
describe('global / local track visibility interplay', function () {
function setupTracks() {
const setupResult = setup();
const { dispatch, getState } = setupResult;