<script src=../priorities/resources/common.js></script>
<script src=../resources/testharness.js></script>
<script src=../resources/testharnessreport.js></script>
<script>
const priority_tests = [
{
promise: internals.getInitialResourcePriority(new URL('../resources/square.png', location), document),
expected_priority: kHigh,
description: 'high fetchpriority on <img> must translate to kHigh resource load priority'
},
{
promise: internals.getInitialResourcePriority(new URL('../resources/square.png?1', location), document),
expected_priority: kLow,
description: 'low fetchpriority on <img> must translate to kLow resource load priority'
},
{
promise: internals.getInitialResourcePriority(new URL('../resources/square.png?2', location), document),
expected_priority: kMedium,
description: 'auto fetchpriority on early <img> must translate to kMedium resource load priority'
},
{
promise: internals.getInitialResourcePriority(new URL('../resources/square.png?3', location), document),
expected_priority: kMedium,
description: 'invalid fetchpriority on early <img> must translate to kMedium resource load priority'
},
{
promise: internals.getInitialResourcePriority(new URL('../resources/square.png?4', location), document),
expected_priority: kMedium,
description: 'missing fetchpriority on early <img> must translate to kMedium resource load priority'
}
];
</script>
<img id=img1 fetchpriority=high src=../resources/square.png alt=img>
<img id=img2 fetchpriority=low src=../resources/square.png?1 alt=img>
<img id=img3 fetchpriority=auto src=../resources/square.png?2 alt=img>
<img id=img4 fetchpriority=xyz src=../resources/square.png?3 alt=img>
<img id=img5 src=../resources/square.png?4 alt=img>
<script>
promise_test(async (t) => {
await new Promise(resolve => {
addEventListener('DOMContentLoaded', resolve);
});
const base_msg = " was fetched by the preload scanner";
assert_true(internals.isPreloaded(img1.src), img1.src + base_msg);
assert_true(internals.isPreloaded(img2.src), img2.src + base_msg);
assert_true(internals.isPreloaded(img3.src), img3.src + base_msg);
assert_true(internals.isPreloaded(img4.src), img4.src + base_msg);
assert_true(internals.isPreloaded(img5.src), img5.src + base_msg);
}, 'all images must be fetched by the preload scanner');
// Setup the tests described by |priority_tests|.
for (const test of priority_tests) {
promise_test(async () => {
const priority = await test.promise;
assert_equals(priority, test.expected_priority);
}, test.description);
}
</script>