blob: 6057fab2afabb94b84d86e4490a9dfbbca1fc469 [file] [log] [blame]
<script src=../priorities/resources/common.js></script>
<script src=../resources/testharness.js></script>
<script src=../resources/testharnessreport.js></script>
<script>
const tests = [
// rel=style
{
description: 'low importance on <link rel=preload as=style> not fetched by the preload scanner must be fetched with kLow resource load priority',
as: 'style',
importance: 'low',
resource: 'dummy.css',
expected_priority: kLow
},
{
description: 'missing importance on <link rel=preload as=style> not fetched by the preload scanner must have no effect on resource load priority',
as: 'style',
resource: 'dummy.css',
expected_priority: kVeryHigh
},
{
description: 'high importance on <link rel=preload as=style> not fetched by the preload scanner must have no effect on resource load priority',
as: 'style',
importance: 'high',
resource: 'dummy.css',
expected_priority: kVeryHigh
},
// rel=script
{
description: 'low importance on <link rel=preload as=script> not fetched by the preload scanner must be fetched with kLow resource load priority',
as: 'script',
importance: 'low',
resource: 'dummy.js',
expected_priority: kLow
},
{
description: 'missing importance on <link rel=preload as=script> not fetched by the preload scanner must have no effect on resource load priority',
as: 'script',
resource: 'dummy.js',
expected_priority: kHigh
},
{
description: 'high importance on <link rel=preload as=script> not fetched by the preload scanner must have no effect on resource load priority',
as: 'script',
importance: 'high',
resource: 'dummy.js',
expected_priority: kHigh
},
// rel=fetch
{
description: 'low importance on <link rel=preload as=fetch> not fetched by the preload scanner must be fetched with kLow resource load priority',
as: 'fetch',
importance: 'low',
resource: 'dummy.txt',
expected_priority: kLow
},
{
description: 'missing importance on <link rel=preload as=fetch> not fetched by the preload scanner must have no effect on resource load priority',
as: 'fetch',
resource: 'dummy.txt',
expected_priority: kHigh
},
{
description: 'high importance on <link rel=preload as=fetch> not fetched by the preload scanner must have no effect on resource load priority',
as: 'fetch',
importance: 'high',
resource: 'dummy.txt',
expected_priority: kHigh
},
// rel=image
{
description: 'low importance on <link rel=preload as=image> not fetched by the preload scanner must have no effect on resource load priority',
as: 'image',
importance: 'low',
resource: 'square.png',
expected_priority: kLow
},
{
description: 'missing importance on <link rel=preload as=image> not fetched by the preload scanner must have no effect on resource load priority',
as: 'image',
resource: 'square.png',
expected_priority: kLow
},
{
description: 'high importance on <link rel=preload as=image> not fetched by the preload scanner must be fetched with kHigh resource load priority',
as: 'image',
importance: 'high',
resource: 'square.png',
expected_priority: kHigh
}
];
let iteration = 0;
for (const test of tests) {
promise_test(async () => {
const link = document.createElement('link');
link.rel = 'preload';
link.as = test.as;
if (test.importance) link.importance = test.importance;
const url = new URL(`../resources/${test.resource}?${iteration++}`, location);
const priorityPromise = internals.getResourcePriority(url, document);
link.href = url;
document.head.appendChild(link);
const priority = await priorityPromise;
assert_equals(priority, test.expected_priority, test.description);
});
}
</script>