| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="UTF-8"> |
| 5 |
<title>fetchpriority affects the urgency parameter of HTTP</title> |
| 6 |
<script src="/resources/testharness.js"></script> |
| 7 |
<script src="/resources/testharnessreport.js"></script> |
| 8 |
<script src="/common/utils.js"></script> |
| 9 |
<script src="support/priority-dependent-content.js"></script> |
| 10 |
<link rel="stylesheet" href="support/resources/priority-dependent-content.py?as-type=style&resource-id=style_low" fetchpriority="low"> |
| 11 |
<link rel="stylesheet" href="support/resources/priority-dependent-content.py?as-type=style&resource-id=style_high" fetchpriority="high"> |
| 12 |
<link rel="stylesheet" href="support/resources/priority-dependent-content.py?as-type=style&resource-id=style_auto" fetchpriority="auto"> |
| 13 |
<link rel="stylesheet" href="support/resources/priority-dependent-content.py?as-type=style&resource-id=style_default"> |
| 14 |
<script src="support/resources/priority-dependent-content.py?as-type=script&resource-id=script_low" fetchpriority="low"></script> |
| 15 |
<script src="support/resources/priority-dependent-content.py?as-type=script&resource-id=script_high" fetchpriority="high"></script> |
| 16 |
<script src="support/resources/priority-dependent-content.py?as-type=script&resource-id=script_auto" fetchpriority="auto" ></script> |
| 17 |
<script src="support/resources/priority-dependent-content.py?as-type=script&resource-id=script_default"></script> |
| 18 |
</head> |
| 19 |
<body> |
| 20 |
<img src="support/resources/priority-dependent-content.py?as-type=image&resource-id=image_low" id="image_low" fetchpriority="low"/> |
| 21 |
<img src="support/resources/priority-dependent-content.py?as-type=image&resource-id=image_high" id="image_high" fetchpriority="high"/> |
| 22 |
<img src="support/resources/priority-dependent-content.py?as-type=image&resource-id=image_auto" id="image_auto" fetchpriority="auto"/> |
| 23 |
<img src="support/resources/priority-dependent-content.py?as-type=image&resource-id=image_default" id="image_default"/> |
| 24 |
<div id="urgency_square_style_low"></div> |
| 25 |
<div id="urgency_square_style_high"></div> |
| 26 |
<div id="urgency_square_style_auto"></div> |
| 27 |
<div id="urgency_square_style_default"></div> |
| 28 |
<span id="glyph_font_low" style="font: 10px font_family_low">M</span> |
| 29 |
<span id="glyph_font_high" style="font: 10px font_family_high">M</span> |
| 30 |
<span id="glyph_font_auto" style="font: 10px font_family_auto">M</span> |
| 31 |
<span id="glyph_font_default" style="font: 10px font_family_default">M</span> |
| 32 |
|
| 33 |
<script> |
| 34 |
onload = () => { |
| 35 |
test(function() { |
| 36 |
// See kExpectedRequestsOfInitialLoad from image-test-data.js and |
| 37 |
// nsHttpHandler::UrgencyFromCoSFlags. |
| 38 |
let normalUrgency = 4; |
| 39 |
assert_equals(getElementUrgencyFromSize("image_low"), normalUrgency + 2); |
| 40 |
assert_equals(getElementUrgencyFromSize("image_high"), normalUrgency - 1); |
| 41 |
assert_equals(getElementUrgencyFromSize("image_auto"), normalUrgency + 1); |
| 42 |
assert_equals(getElementUrgencyFromSize("image_default"), normalUrgency + 1); |
| 43 |
}, "Adjustment of urgency parameter for images"); |
| 44 |
|
| 45 |
test(function() { |
| 46 |
// See kExpectedRequestsForScriptsInHead from script-test-data.js |
| 47 |
// and nsHttpHandler::UrgencyFromCoSFlags. |
| 48 |
let normalUrgency = 2; |
| 49 |
assert_equals(getScriptUrgency("script_low"), normalUrgency + 1); |
| 50 |
assert_equals(getScriptUrgency("script_high"), normalUrgency - 1); |
| 51 |
assert_equals(getScriptUrgency("script_auto"), normalUrgency); |
| 52 |
assert_equals(getScriptUrgency("script_default"), normalUrgency); |
| 53 |
}, "Adjustment of urgency parameter for scripts"); |
| 54 |
|
| 55 |
test(function() { |
| 56 |
// See kExpectedRequestsOfLoadStylesheet from link-tests-data.js |
| 57 |
// and nsHttpHandler::UrgencyFromCoSFlags. |
| 58 |
let normalUrgency = 2; |
| 59 |
assert_equals(getStyleUrgency("style_low"), normalUrgency); |
| 60 |
assert_equals(getStyleUrgency("style_high"), normalUrgency - 2); |
| 61 |
assert_equals(getStyleUrgency("style_auto"), normalUrgency); |
| 62 |
assert_equals(getStyleUrgency("style_default"), normalUrgency); |
| 63 |
}, "Adjustment of urgency parameter for styles"); |
| 64 |
|
| 65 |
promise_test(async function() { |
| 66 |
async function fetchAndExtractUrgency(priority) { |
| 67 |
let request_init; |
| 68 |
if (priority !== "default") { |
| 69 |
request_init = {priority: priority}; |
| 70 |
} |
| 71 |
let response = await fetch(`support/resources/priority-dependent-content.py?as-type=text&resource-id=fetch_${priority}`, request_init); |
| 72 |
return getResourceUrgencyFromRawText(await response.text()); |
| 73 |
} |
| 74 |
|
| 75 |
// See kExpectedRequestsOfFetchAPI from link-tests-data.js |
| 76 |
// and nsHttpHandler::UrgencyFromCoSFlags. |
| 77 |
let normalUrgency = 4; |
| 78 |
assert_equals(await fetchAndExtractUrgency("low"), normalUrgency + 1); |
| 79 |
assert_equals(await fetchAndExtractUrgency("high"), normalUrgency - 1); |
| 80 |
assert_equals(await fetchAndExtractUrgency("auto"), normalUrgency); |
| 81 |
assert_equals(await fetchAndExtractUrgency("default"), normalUrgency); |
| 82 |
}, "Adjustment of urgency parameter for global fetch"); |
| 83 |
|
| 84 |
promise_test(async function() { |
| 85 |
async function loadFontAndExtractUrgency(priority) { |
| 86 |
let link = document.createElement("link"); |
| 87 |
if (priority != "default") |
| 88 |
link.fetchPriority = priority; |
| 89 |
link.rel = "preload"; |
| 90 |
link.as = "font"; |
| 91 |
link.crossOrigin = ""; |
| 92 |
await new Promise((resolve, reject) => { |
| 93 |
link.onload = resolve; |
| 94 |
link.onerror = reject; |
| 95 |
link.href = `support/resources/priority-dependent-content.py?as-type=font&resource-id=font_${priority}_${token()}&use-cache=true`; |
| 96 |
document.body.appendChild(link); |
| 97 |
}); |
| 98 |
let response = await fetch(link.href, {cache: "force-cache"}); |
| 99 |
let font_face = new FontFace(`font_family_${priority}`, |
| 100 |
await response.arrayBuffer()); |
| 101 |
document.fonts.add(font_face); |
| 102 |
let size = document.getElementById(`glyph_font_${priority}`).getBoundingClientRect().width; |
| 103 |
return convertSizeToUrgency(size); |
| 104 |
} |
| 105 |
// See kExpectedRequestsOfLinkPreloadFont from link-tests-data.js |
| 106 |
// and nsHttpHandler::UrgencyFromCoSFlags. |
| 107 |
let normalUrgency = 2; |
| 108 |
assert_equals(await loadFontAndExtractUrgency("low"), normalUrgency + 2); |
| 109 |
assert_equals(await loadFontAndExtractUrgency("high"), normalUrgency - 1); |
| 110 |
assert_equals(await loadFontAndExtractUrgency("auto"), normalUrgency); |
| 111 |
assert_equals(await loadFontAndExtractUrgency("default"), normalUrgency); |
| 112 |
}, "Adjustment of urgency parameter for fonts"); |
| 113 |
} |
| 114 |
</script> |
| 115 |
</body> |
| 116 |
</html> |