| 1 |
<!DOCTYPE html> |
| 2 |
<meta charset="utf-8"> |
| 3 |
<title>fetchpriority: verify basic invariants for adjustments</title> |
| 4 |
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1880528"/> |
| 5 |
<script src="/resources/testharness.js"></script> |
| 6 |
<script src="/resources/testharnessreport.js"></script> |
| 7 |
<script> |
| 8 |
const fetchpriorities = ["auto", "low", "high"]; |
| 9 |
const prioritiesWhenFetchpriorityDisabled = { |
| 10 |
"link-preload-script": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGHEST, |
| 11 |
"module-script": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 12 |
"async-or-defer-script": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 13 |
"script-in-head": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 14 |
"other-script": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 15 |
"link-preload-font": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH, |
| 16 |
"link-preload-fetch": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 17 |
"deferred-style": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 18 |
"link-preload-style": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGHEST, |
| 19 |
"non-deferred-style": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 20 |
"global-fetch-api": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 21 |
"images": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW, |
| 22 |
"media": SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 23 |
}; |
| 24 |
for (const name in prioritiesWhenFetchpriorityDisabled) { |
| 25 |
let adjustments = {}; |
| 26 |
for (const fetchpriority of fetchpriorities) { |
| 27 |
adjustments[fetchpriority] = SpecialPowers.getIntPref(`network.fetchpriority.adjustments.${name}.${fetchpriority}`); |
| 28 |
} |
| 29 |
test(() => { |
| 30 |
// The higher the internal priority, the smaller the integer value. |
| 31 |
assert_less_than_equal(adjustments.high, adjustments.auto, "Internal priority for high is at most the one for auto"); |
| 32 |
assert_less_than_equal(adjustments.auto, adjustments.low, "Internal priority for auto is at most the one for low"); |
| 33 |
}, `${name}: adjusted priorities for low/auto/high have proper ordering.`); |
| 34 |
|
| 35 |
test(() => { |
| 36 |
assert_less_than(adjustments.high, adjustments.low, "Internal priority for high is less than the one for low"); |
| 37 |
}, `${name}: at least one of fetchpriority="high" or fetchpriority="low" has any effect.`); |
| 38 |
|
| 39 |
test(() => { |
| 40 |
const priority = prioritiesWhenFetchpriorityDisabled[name]; |
| 41 |
const predefinedPriorities = [ |
| 42 |
SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGHEST, |
| 43 |
SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH, |
| 44 |
SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL, |
| 45 |
SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW, |
| 46 |
SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOWEST |
| 47 |
]; |
| 48 |
for (const fetchpriority of fetchpriorities) { |
| 49 |
const adjustedPriority = priority + adjustments[fetchpriority]; |
| 50 |
assert_true(predefinedPriorities.includes(adjustedPriority), `Internal priority for ${fetchpriority} is in the predefined set of priorities.`); |
| 51 |
} |
| 52 |
}, `${name}: adjusted priorities belong to the predefined set.`); |
| 53 |
} |
| 54 |
</script> |