-
Notifications
You must be signed in to change notification settings - Fork 470
Expand file tree
/
Copy pathprofile-tree.test.ts
More file actions
751 lines (694 loc) · 23.5 KB
/
profile-tree.test.ts
File metadata and controls
751 lines (694 loc) · 23.5 KB
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
/* 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/. */
import {
getProfileFromTextSamples,
getMergedProfileFromTextSamples,
} from '../fixtures/profiles/processed-profile';
import {
getCallTree,
computeCallNodeSelfAndSummary,
computeCallTreeTimings,
} from '../../profile-logic/call-tree';
import { computeFlameGraphRows } from '../../profile-logic/flame-graph';
import {
getCallNodeInfo,
getInvertedCallNodeInfo,
getOriginAnnotationForFunc,
filterRawThreadSamplesToRange,
getSampleIndexToCallNodeIndex,
} from '../../profile-logic/profile-data';
import { ResourceType } from 'firefox-profiler/types';
import {
callTreeFromProfile,
functionListTreeFromProfile,
formatTree,
formatTreeIncludeCategories,
addSourceToTable,
} from '../fixtures/utils';
import { ensureExists } from 'firefox-profiler/utils/types';
import type { CallNodePath } from 'firefox-profiler/types';
describe('unfiltered call tree', function () {
// These values are hoisted at the top for the ease of access. In the profile fixture
// for the unfiltered call tree, the indexes for funcs, frames, stacks, and callNodes
// all happen to share the same indexes as there is a 1 to 1 relationship between them.
const A = 0;
const B = 1;
const C = 2;
const D = 3;
const E = 4;
const F = 5;
const G = 6;
const H = 7;
const I = 8;
function getProfile() {
return getProfileFromTextSamples(`
A A A
B B B
C C H
D F I
E G
`);
}
/**
* Before creating a CallTree instance some timings are pre-computed.
* This test ensures that these generated values are correct.
*/
describe('computed counts and timings', function () {
const { derivedThreads, defaultCategory } = getProfile();
const [thread] = derivedThreads;
const callNodeInfo = getCallNodeInfo(
thread.stackTable,
thread.frameTable,
defaultCategory
);
it('yields expected results', function () {
const callTreeTimings = computeCallTreeTimings(
callNodeInfo,
computeCallNodeSelfAndSummary(
thread.samples,
getSampleIndexToCallNodeIndex(
thread.samples.stack,
callNodeInfo.getStackIndexToNonInvertedCallNodeIndex()
),
callNodeInfo.getCallNodeTable().length
)
);
expect(callTreeTimings).toEqual({
type: 'NON_INVERTED',
timings: {
rootTotalSummary: 3,
callNodeHasChildren: new Uint8Array([1, 1, 1, 1, 0, 1, 0, 1, 0]),
self: new Float64Array([0, 0, 0, 0, 1, 0, 1, 0, 1]),
total: new Float64Array([3, 3, 2, 1, 1, 1, 1, 1, 1]),
},
});
});
});
describe('ordered rows of call node indexes for flame graph', function () {
it('returns ordered rows', function () {
// On purpose, we build a profile where the call node indexes won't be in
// the same order than the function names.
const {
derivedThreads,
funcNamesDictPerThread: [{ G, H, I, J, K, M, N, W, X, Y, Z }],
defaultCategory,
} = getProfileFromTextSamples(`
Z Z G G K K
X X H H M N
Y W I J
`);
const [thread] = derivedThreads;
const callNodeInfo = getCallNodeInfo(
thread.stackTable,
thread.frameTable,
defaultCategory
);
const cnZ = callNodeInfo.getCallNodeIndexFromPath([Z]);
const cnZX = callNodeInfo.getCallNodeIndexFromPath([Z, X]);
const cnZXY = callNodeInfo.getCallNodeIndexFromPath([Z, X, Y]);
const cnZXW = callNodeInfo.getCallNodeIndexFromPath([Z, X, W]);
const cnG = callNodeInfo.getCallNodeIndexFromPath([G]);
const cnGH = callNodeInfo.getCallNodeIndexFromPath([G, H]);
const cnGHI = callNodeInfo.getCallNodeIndexFromPath([G, H, I]);
const cnGHJ = callNodeInfo.getCallNodeIndexFromPath([G, H, J]);
const cnK = callNodeInfo.getCallNodeIndexFromPath([K]);
const cnKM = callNodeInfo.getCallNodeIndexFromPath([K, M]);
const cnKN = callNodeInfo.getCallNodeIndexFromPath([K, N]);
const rows = computeFlameGraphRows(
callNodeInfo.getCallNodeTable(),
thread.funcTable,
thread.stringTable
);
expect(rows).toEqual([
// Siblings are ordered in lexically ascending order.
[cnG, cnK, cnZ],
[cnGH, cnKM, cnKN, cnZX],
[cnGHI, cnGHJ, cnZXW, cnZXY],
]);
});
});
/**
* Explicitly test the structure of the unfiltered call tree.
*/
describe('computed structure', function () {
/**
* The profile samples have the following structure:
*
* A -> A -> A
* | | |
* v v v
* B B B
* | | |
* v v v
* C C H
* | | |
* v v v
* D F I
* | |
* v v
* E G
*
* Assert this form for each node where (FuncName:Total,Self)
*
* A:3,0
* |
* v
* B:3,0
* / \
* v v
* C:2,0 H:1,0
* / \ \
* v v v
* D:1,0 F:1,0 I:1,1
* | |
* v v
* E:1,1 G:1,1
*/
const { profile } = getProfileFromTextSamples(`
A A A
B B B
C C H
D F I
E G
`);
const callTree = callTreeFromProfile(profile);
it('computes an unfiltered call tree', function () {
expect(formatTree(callTree)).toEqual([
'- A (total: 3, self: —)',
' - B (total: 3, self: —)',
' - C (total: 2, self: —)',
' - D (total: 1, self: —)',
' - E (total: 1, self: 1)',
' - F (total: 1, self: —)',
' - G (total: 1, self: 1)',
' - H (total: 1, self: —)',
' - I (total: 1, self: 1)',
]);
});
});
it('computes correct numbers when using large weights', function () {
const { profile } = getProfileFromTextSamples(`
A A
B C
`);
// Compute 485407757 + 1222 == 485408979.
// If the weights are stored as floats, this checks that we aren't using
// 32-bit floats - those wouldn't have enough precision.
const [rawThread] = profile.threads;
rawThread.samples.weightType = 'bytes';
rawThread.samples.weight = [485407757, 1222];
const callTree = callTreeFromProfile(profile);
expect(formatTree(callTree)).toEqual([
'- A (total: 485,408,979, self: —)',
' - B (total: 485,407,757, self: 485,407,757)',
' - C (total: 1,222, self: 1,222)',
]);
});
/**
* The same as the previous test, but with categories
*/
describe('computed structure with categories', function () {
/**
* Test that the category of a frame gets inherited down into its subtree
* of the call tree, until reaching a frame that has an explicit category.
*/
const { profile } = getProfileFromTextSamples(`
A A A
B[cat:DOM] B[cat:DOM] B[cat:DOM]
C C H
D F[cat:Graphics] I[cat:Other]
E G
`);
const callTree = callTreeFromProfile(profile);
it('computes an unfiltered call tree', function () {
expect(formatTreeIncludeCategories(callTree)).toEqual([
'- A [Other] (total: 3, self: —)',
' - B [DOM] (total: 3, self: —)',
' - C [DOM] (total: 2, self: —)',
' - D [DOM] (total: 1, self: —)',
' - E [DOM] (total: 1, self: 1)',
' - F [Graphics] (total: 1, self: —)',
' - G [Graphics] (total: 1, self: 1)',
' - H [DOM] (total: 1, self: —)',
' - I [Other] (total: 1, self: 1)',
]);
});
});
/**
* These tests provides coverage for every method of the CallTree. It's less about
* correct tree structure, and more of simple assertions about how the interface
* is supposed to behave. There is probably duplication of coverage with other tests.
*/
describe('CallTree methods', function () {
const { profile } = getProfileFromTextSamples(`
A A A
B B B
C C H
D F I[lib:libI.so]
E G
`);
const callTree = callTreeFromProfile(profile);
describe('getRoots()', function () {
it('returns an array with the root indexes', function () {
expect(callTree.getRoots()).toEqual([A]);
});
});
describe('getChildren()', function () {
it('returns an array with the children indexes', function () {
expect(callTree.getChildren(C)).toEqual([D, F]);
expect(callTree.getChildren(E)).toEqual([]);
});
});
describe('hasChildren()', function () {
it('determines if nodes have children', function () {
expect(callTree.hasChildren(C)).toEqual(true);
expect(callTree.hasChildren(E)).toEqual(false);
});
});
describe('getAllDescendants()', function () {
it('returns a set with the descendant indexes', function () {
expect(callTree.getAllDescendants(C)).toEqual(new Set([D, E, F, G]));
expect(callTree.getAllDescendants(E)).toEqual(new Set([]));
});
});
describe('getParent()', function () {
it("finds a callNode's parent", function () {
expect(callTree.getParent(A)).toBe(-1);
expect(callTree.getParent(B)).toBe(A);
});
});
describe('getDepth()', function () {
it('returns the depth of callNodes in the tree', function () {
expect(callTree.getDepth(A)).toBe(0);
expect(callTree.getDepth(B)).toBe(1);
});
});
describe('getNodeData()', function () {
it('gets a node for a given callNodeIndex', function () {
expect(callTree.getNodeData(A)).toEqual({
funcName: 'A',
total: 3,
totalRelative: 1,
self: 0,
selfRelative: 0,
});
});
});
describe('getDisplayData()', function () {
it('gets a node for a given callNodeIndex', function () {
expect(callTree.getDisplayData(A)).toEqual({
ariaLabel:
'A, running count is 3 samples (100%), self count is 0 samples',
isFrameLabel: true,
iconSrc: null,
icon: null,
lib: '',
name: 'A',
self: '—',
selfWithUnit: '—',
total: '3',
totalWithUnit: '3 samples',
totalPercent: '100%',
categoryColor: 'grey',
categoryName: 'Other',
});
expect(callTree.getDisplayData(I)).toEqual({
ariaLabel:
'I, running count is 1 sample (33%), self count is 1 sample',
isFrameLabel: false,
iconSrc: null,
icon: null,
lib: 'libI.so',
name: 'I',
self: '1',
selfWithUnit: '1 sample',
total: '1',
totalWithUnit: '1 sample',
totalPercent: '33%',
categoryColor: 'grey',
categoryName: 'Other',
});
});
});
describe('icons from the call tree', function () {
it('upgrades http to https', function () {
const { profile, stringTable } = getProfileFromTextSamples(`
A[lib:examplecom.js]
`);
const callTree = callTreeFromProfile(profile);
const hostStringIndex = stringTable.indexForString('examplecom.js');
profile.shared.resourceTable.type[0] = ResourceType.Webhost;
profile.shared.resourceTable.host[0] = hostStringIndex;
// Hijack the string table to provide the proper host name
stringTable._array[hostStringIndex] = 'http://example.com';
expect(callTree.getDisplayData(A).icon).toEqual(
'https://example.com/favicon.ico'
);
});
});
});
/**
* While not specifically part of the call tree, this is a core function
* to help navigate stacks through a list of functions.
*/
describe('getCallNodeIndexFromPath', function () {
const { derivedThreads, defaultCategory } = getProfile();
const [thread] = derivedThreads;
const callNodeInfo = getCallNodeInfo(
thread.stackTable,
thread.frameTable,
defaultCategory
);
// Helper to make the assertions a little less verbose.
function checkStack(
callNodePath: CallNodePath,
index: number,
name: string
) {
it(`finds stack that ends in ${name}`, function () {
expect(callNodeInfo.getCallNodeIndexFromPath(callNodePath)).toBe(index);
});
}
checkStack([A], A, 'A');
checkStack([A, B], B, 'B');
checkStack([A, B, C], C, 'C');
checkStack([A, B, C, D], D, 'D');
checkStack([A, B, C, D, E], E, 'E');
checkStack([A, B, C, F], F, 'F');
checkStack([A, B, C, F, G], G, 'G');
checkStack([A, B, H], H, 'H');
checkStack([A, B, H, I], I, 'I');
it(`doesn't find a non-existent stack`, function () {
expect(callNodeInfo.getCallNodeIndexFromPath([A, B, C, D, E, F, G])).toBe(
null
);
});
});
});
describe('inverted call tree', function () {
/**
* Explicitly test the structure of the inverted call tree.
*/
describe('computed structure', function () {
const { profile, derivedThreads, defaultCategory } =
getProfileFromTextSamples(`
A A A
B[cat:DOM] B[cat:DOM] B[cat:DOM]
C[cat:Graphics] X C[cat:Graphics]
D[cat:Other] Y X
E Z Y
Z
`);
// Check the non-inverted tree first.
const [thread] = derivedThreads;
const callNodeInfo = getCallNodeInfo(
thread.stackTable,
thread.frameTable,
defaultCategory
);
const callTreeTimings = computeCallTreeTimings(
callNodeInfo,
computeCallNodeSelfAndSummary(
thread.samples,
getSampleIndexToCallNodeIndex(
thread.samples.stack,
callNodeInfo.getStackIndexToNonInvertedCallNodeIndex()
),
callNodeInfo.getCallNodeTable().length
)
);
const callTree = getCallTree(
thread,
callNodeInfo,
ensureExists(profile.meta.categories),
thread.samples,
callTreeTimings,
'samples'
);
it('computes a non-inverted call tree', function () {
expect(formatTreeIncludeCategories(callTree)).toEqual([
'- A [Other] (total: 3, self: —)',
' - B [DOM] (total: 3, self: —)',
' - C [Graphics] (total: 2, self: —)',
' - D [Other] (total: 1, self: —)',
' - E [Other] (total: 1, self: 1)',
' - X [Graphics] (total: 1, self: —)',
' - Y [Graphics] (total: 1, self: —)',
' - Z [Graphics] (total: 1, self: 1)',
' - X [DOM] (total: 1, self: —)',
' - Y [DOM] (total: 1, self: —)',
' - Z [DOM] (total: 1, self: 1)',
]);
});
// Now compute the inverted tree and check it.
const invertedCallNodeInfo = getInvertedCallNodeInfo(
callNodeInfo,
defaultCategory,
thread.funcTable.length
);
const invertedCallTreeTimings = computeCallTreeTimings(
invertedCallNodeInfo,
computeCallNodeSelfAndSummary(
thread.samples,
getSampleIndexToCallNodeIndex(
thread.samples.stack,
invertedCallNodeInfo.getStackIndexToNonInvertedCallNodeIndex()
),
invertedCallNodeInfo.getCallNodeTable().length
)
);
const invertedCallTree = getCallTree(
thread,
invertedCallNodeInfo,
ensureExists(profile.meta.categories),
thread.samples,
invertedCallTreeTimings,
'samples'
);
/**
* Assert this tree form for each node.
*
* E:1,1 Z:2,2
* | |
* v v
* D:1,0 Y:2,0
* | |
* v v
* C:1,0 X:2,0
* | / \
* v v v
* B:1,0 B:1,0 C:1,0
* | | |
* v v v
* A:1,0 A:1,0 B:1,0
* |
* v
* A:1,0
*
* ^ ^ ^
* | | |
* L M R <- Label the branches. (left, middle, right)
*
* This test also checks that stacks of conflicting categories end up with
* the "Other" category. In this test, in the non-inverted tree, the nodes
* for the functions X, Y, and Z have different categories depending on
* which subtree they are in: They have category "Graphics" in the subtree
* under C, and the category "DOM" in the subtree that's directly attached
* to B. In the inverted tree, those nodes collapse into each other, and
* their category should be set to "Other".
*/
it('computes an inverted call tree', function () {
expect(formatTreeIncludeCategories(invertedCallTree)).toEqual([
'- Z [Other] (total: 2, self: 2)',
' - Y [Other] (total: 2, self: —)',
' - X [Other] (total: 2, self: —)',
' - B [DOM] (total: 1, self: —)',
' - A [Other] (total: 1, self: —)',
' - C [Graphics] (total: 1, self: —)',
' - B [DOM] (total: 1, self: —)',
' - A [Other] (total: 1, self: —)',
'- E [Other] (total: 1, self: 1)',
' - D [Other] (total: 1, self: —)',
' - C [Graphics] (total: 1, self: —)',
' - B [DOM] (total: 1, self: —)',
' - A [Other] (total: 1, self: —)',
]);
});
});
});
describe('function list', function () {
it('computes an unfiltered function list', function () {
const { profile } = getProfileFromTextSamples(`
A A A
B E B
C C A
B F G
D E
`);
const callTree = functionListTreeFromProfile(profile);
expect(formatTree(callTree)).toEqual([
'- A (total: 3, self: —)',
'- B (total: 2, self: —)',
'- C (total: 2, self: —)',
'- D (total: 1, self: 1)',
'- E (total: 1, self: 1)',
'- F (total: 1, self: —)',
'- G (total: 1, self: 1)',
]);
});
});
describe('diffing trees', function () {
function getProfile() {
return getMergedProfileFromTextSamples([
`
A A A A A A A
B B B B C B B
D D D E F D D
F F F F
`,
`
A A A A A A A
B B B B B B B
D D D G I E I
D D D
`,
]);
}
it('displays a proper call tree, including nodes with total = 0', () => {
const { profile } = getProfile();
const callTree = callTreeFromProfile(profile, /* threadIndex */ 2);
const formattedTree = formatTree(callTree);
expect(formattedTree).toEqual([
'- A (total: —, self: —)',
' - B (total: 1, self: —)',
' - D (total: -2, self: -1)',
' - F (total: -4, self: -4)',
' - D (total: 3, self: 3)',
' - I (total: 2, self: 2)',
' - G (total: 1, self: 1)',
' - C (total: -1, self: —)',
' - F (total: -1, self: -1)',
]);
// There's no A -> B -> E node because the diff makes it completely disappear.
expect(formattedTree).not.toContainEqual(expect.stringMatching(/^\s*- E/));
});
it('displays a proper call tree, even for range-filtered threads', () => {
const { profile } = getProfile();
const rangeStart = 4;
const rangeEnd = 5;
profile.threads = profile.threads.map((thread) =>
filterRawThreadSamplesToRange(thread, rangeStart, rangeEnd)
);
const callTree = callTreeFromProfile(profile, /* threadIndex */ 2);
const formattedTree = formatTree(callTree);
expect(formattedTree).toEqual([
// A -> B -> D and A -> B -> G should be filtered out by the range filtering.
'- A (total: —, self: —)',
' - B (total: 1, self: —)',
' - I (total: 1, self: 1)',
' - C (total: -1, self: —)',
' - F (total: -1, self: -1)',
]);
});
it('finds the heaviest call path even when it has ancestors with low totals', () => {
const { profile, funcNamesDictPerThread } = getProfile();
const { B, D, F } = funcNamesDictPerThread[2];
const callTree = callTreeFromProfile(profile, /* threadIndex */ 2);
// Get the call node index for the node A -> B. TODO: Make this more reliable
const AB = callTree.getChildren(callTree.getRoots()[0])[0];
const invertedPath = callTree.findHeavyPathToSameFunctionAfterInversion(AB);
expect(invertedPath).toEqual([F, D, B]);
});
it('computes a rootTotalSummary that is the absolute count of all intervals', () => {
const { derivedThreads, defaultCategory } = getProfile();
const thread = derivedThreads[2];
const callNodeInfo = getCallNodeInfo(
thread.stackTable,
thread.frameTable,
defaultCategory
);
const callTreeTimings = computeCallTreeTimings(
callNodeInfo,
computeCallNodeSelfAndSummary(
thread.samples,
getSampleIndexToCallNodeIndex(
thread.samples.stack,
callNodeInfo.getStackIndexToNonInvertedCallNodeIndex()
),
callNodeInfo.getCallNodeTable().length
)
);
expect(callTreeTimings.timings.rootTotalSummary).toBe(12);
});
});
describe('origin annotation', function () {
const {
profile,
stringTable,
funcNamesPerThread: [funcNames],
} = getProfileFromTextSamples(`
A
B
C
D
`);
const { shared } = profile;
function addResource(
funcName: string,
name: string,
host: string | null,
location: string | null
) {
const resourceIndex = shared.resourceTable.length;
const funcIndex = funcNames.indexOf(funcName);
shared.funcTable.resource[funcIndex] = resourceIndex;
shared.funcTable.source[funcIndex] = location
? addSourceToTable(shared.sources, stringTable.indexForString(location))
: null;
shared.resourceTable.lib.push(-1);
shared.resourceTable.name.push(stringTable.indexForString(name));
shared.resourceTable.host.push(
host ? stringTable.indexForString(host) : null
);
shared.resourceTable.length++;
}
addResource(
'A',
'http://foobar.com',
'http://foobar.com',
'http://foobar.com/script.js'
);
addResource(
'B',
'Extension "Gecko Profiler"',
'moz-extension://bf3bb73c-919c-4fef-95c4-070a19fdaf85',
'moz-extension://bf3bb73c-919c-4fef-95c4-070a19fdaf85/script.js'
);
addResource('C', 'libxul.so', null, '/home/user/mozilla-central/xul.cpp');
addResource('D', 'libxul.so', null, null);
function getOrigin(funcName: string): string {
return getOriginAnnotationForFunc(
funcNames.indexOf(funcName),
shared.funcTable,
shared.resourceTable,
stringTable,
shared.sources
);
}
it('formats web origins correctly', function () {
expect(getOrigin('A')).toEqual('http://foobar.com/script.js');
});
it('formats extension origins correctly', function () {
expect(getOrigin('B')).toEqual(
'Extension "Gecko Profiler": ' +
'moz-extension://bf3bb73c-919c-4fef-95c4-070a19fdaf85/script.js'
);
});
it('formats library origins correctly', function () {
expect(getOrigin('C')).toEqual(
'libxul.so: /home/user/mozilla-central/xul.cpp'
);
expect(getOrigin('D')).toEqual('libxul.so');
});
});