chromium/third_party/blink/web_tests/http/tests/priority-hints/link-preload-dynamic-insertion.html

<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 fetchPriority on <link rel=preload as=style> not loaded by the preload scanner must be fetched with kHigh resource load priority',
      as: 'style',
      fetchPriority: 'low',
      resource: 'dummy.css',
      expected_priority: kHigh
    },
    {
      description: 'missing fetchPriority on <link rel=preload as=style> not loaded by the preload scanner must be fetched with kVeryHigh resource load priority',
      as: 'style',
      resource: 'dummy.css',
      expected_priority: kVeryHigh
    },
    {
      description: 'high fetchPriority on <link rel=preload as=style> not loaded by the preload scanner must be fetched with kVeryHigh resource load priority',
      as: 'style',
      fetchPriority: 'high',
      resource: 'dummy.css',
      expected_priority: kVeryHigh
    },
    // rel=script
    {
      description: 'low fetchPriority on <link rel=preload as=script> not loaded by the preload scanner must be fetched with kLow resource load priority',
      as: 'script',
      fetchPriority: 'low',
      resource: 'dummy.js',
      expected_priority: kLow
    },
    {
      description: 'missing fetchPriority on <link rel=preload as=script> not loaded by the preload scanner must be fetched with kHigh resource load priority',
      as: 'script',
      resource: 'dummy.js',
      expected_priority: kHigh
    },
    {
      description: 'high fetchPriority on <link rel=preload as=script> not loaded by the preload scanner must be fetched with kHigh resource load priority',
      as: 'script',
      fetchPriority: 'high',
      resource: 'dummy.js',
      expected_priority: kHigh
    },
    // rel=fetch
    {
      description: 'low fetchPriority on <link rel=preload as=fetch> not loaded by the preload scanner must be fetched with kLow resource load priority',
      as: 'fetch',
      fetchPriority: 'low',
      resource: 'dummy.txt',
      expected_priority: kLow
    },
    {
      description: 'missing fetchPriority on <link rel=preload as=fetch> not loaded by the preload scanner must be fetched with kHigh resource load priority',
      as: 'fetch',
      resource: 'dummy.txt',
      expected_priority: kHigh
    },
    {
      description: 'high fetchPriority on <link rel=preload as=fetch> not loaded by the preload scanner must be fetched with kHigh resource load priority',
      as: 'fetch',
      fetchPriority: 'high',
      resource: 'dummy.txt',
      expected_priority: kHigh
    },
    // rel=image
    {
      description: 'low fetchPriority on <link rel=preload as=image> not loaded by the preload scanner must be fetched with kLow resource load priority',
      as: 'image',
      fetchPriority: 'low',
      resource: 'square.png',
      expected_priority: kLow
    },
    {
      description: 'missing fetchPriority on <link rel=preload as=image> not loaded by the preload scanner must be fetched with kLow resource load priority',
      as: 'image',
      resource: 'square.png',
      expected_priority: kLow
    },
    {
      description: 'high fetchPriority on <link rel=preload as=image> not loaded by the preload scanner must be fetched with kHigh resource load priority',
      as: 'image',
      fetchPriority: '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.fetchPriority) link.fetchPriority = test.fetchPriority;

      const url = new URL(`../resources/${test.resource}?${iteration++}`, location);
      const priorityPromise = internals.getInitialResourcePriority(url, document);
      link.href = url;
      document.head.appendChild(link);
      const load_priority = await priorityPromise;
      assert_equals(load_priority, test.expected_priority, test.description);
    });
  }
</script>