Debian Codegraph @

testing/web-platform/mozilla/tests/fetch/fetchpriority/support/priority-dependent-content.js

raw
1 // See get_content in priority-dependent-content.py
2
3 function convertSizeToUrgency(size) {
4 return Math.round(size / 10 - 1);
5 }
6
7 function convertRectToUrgency(rect) {
8 if (rect.width != rect.height) {
9 throw "not a square";
10 }
11 return convertSizeToUrgency(rect.width);
12 }
13
14 function convertDurationToUrgency(duration) {
15 // Duration is not accurate, but floor gives better result than round.
16 return Math.floor(duration * 100 - 1);
17 }
18
19 function getElementUrgencyFromSize(id) {
20 let rect = document.getElementById(id).getBoundingClientRect();
21 return convertRectToUrgency(rect);
22 }
23
24 function getScriptUrgency(id) {
25 return self.scriptUrgency[id];
26 }
27
28 function getStyleUrgency(id) {
29 return getElementUrgencyFromSize(`urgency_square_${id}`)
30 }
31
32 function getResourceUrgencyFromRawText(content) {
33 const regexpUrgency = /id=\w+,u=([0-7])/;
34 let matches = regexpUrgency.exec(content);
35 if (!matches) {
36 throw "cannot extract urgency from content"
37 }
38 return parseInt(matches[1]);
39 }