Repository navigation
Expand file tree
/
Copy pathtest-perf-hooks-resourcetiming-attributes.js
More file actions
105 lines (94 loc) Β· 3.18 KB
/
Copy pathtest-perf-hooks-resourcetiming-attributes.js
File metadata and controls
105 lines (94 loc) Β· 3.18 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
'use strict';
require('../common');
const assert = require('assert');
const {
PerformanceResourceTiming,
performance,
} = require('perf_hooks');
// Covers the IDL attributes finalResponseHeadersStart,
// firstInterimResponseStart, renderBlockingStatus, contentType and contentEncoding,
// and the spec requirement that responseStart prefers a non-zero
// firstInterimResponseStart over finalResponseHeadersStart.
function createTimingInfo(overrides = {}) {
return {
startTime: 0,
redirectStartTime: 0,
redirectEndTime: 0,
postRedirectStartTime: 0,
finalServiceWorkerStartTime: 0,
finalNetworkRequestStartTime: 0,
finalNetworkResponseStartTime: 0,
endTime: 0,
encodedBodySize: 0,
decodedBodySize: 0,
finalConnectionTimingInfo: null,
...overrides,
};
}
function markResourceTiming(timingInfo, bodyInfo) {
return performance.markResourceTiming(
timingInfo,
'http://localhost:8080',
'fetch',
{},
'',
bodyInfo,
200,
'',
);
}
// Default values with an empty body info, mirroring what the fetch
// implementation passes for a response with no body metadata.
{
const resource = markResourceTiming(createTimingInfo(), {});
assert.strictEqual(resource.finalResponseHeadersStart, 0);
assert.strictEqual(resource.firstInterimResponseStart, 0);
assert.strictEqual(resource.responseStart, 0);
assert.strictEqual(resource.renderBlockingStatus, 'non-blocking');
assert.strictEqual(resource.contentType, '');
assert.strictEqual(resource.contentEncoding, '');
}
// Values reflected from timing info and body info.
{
const timingInfo = createTimingInfo({
finalNetworkResponseStartTime: 123,
firstInterimNetworkResponseStartTime: 45,
renderBlocking: true,
});
const bodyInfo = {
contentType: 'text/html',
contentEncoding: 'gzip',
};
const resource = markResourceTiming(timingInfo, bodyInfo);
assert.strictEqual(resource.finalResponseHeadersStart, 123);
assert.strictEqual(resource.firstInterimResponseStart, 45);
assert.strictEqual(resource.responseStart, 45);
assert.strictEqual(resource.renderBlockingStatus, 'blocking');
assert.strictEqual(resource.contentType, 'text/html');
assert.strictEqual(resource.contentEncoding, 'gzip');
const json = resource.toJSON();
assert.strictEqual(json.finalResponseHeadersStart, 123);
assert.strictEqual(json.firstInterimResponseStart, 45);
assert.strictEqual(json.responseStart, 45);
assert.strictEqual(json.renderBlockingStatus, 'blocking');
assert.strictEqual(json.contentType, 'text/html');
assert.strictEqual(json.contentEncoding, 'gzip');
}
// The attributes are enumerable getters on the prototype and perform a
// brand check like the other PerformanceResourceTiming attributes.
for (const name of [
'finalResponseHeadersStart',
'firstInterimResponseStart',
'renderBlockingStatus',
'contentType',
'contentEncoding',
]) {
const desc = Object.getOwnPropertyDescriptor(
PerformanceResourceTiming.prototype, name);
assert.strictEqual(desc.enumerable, true, name);
assert.strictEqual(typeof desc.get, 'function', name);
assert.throws(() => desc.get.call({}), {
code: 'ERR_INVALID_THIS',
}, name);
}
performance.clearResourceTimings();