| <!doctype html> |
| <meta charset=utf-8> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <link rel="modulepreload" as="style" href="resources/dummy.css"> |
| <link rel="modulepreload" as="style" href="resources/dummy.css"> |
| <link rel="modulepreload" as="json" href="resources/dummy.json"> |
| <link rel="modulepreload" as="json" href="resources/dummy.json"> |
| <link rel="modulepreload" href="resources/dummy.js"> |
| <link rel="modulepreload" href="resources/dummy.js"> |
| <body> |
| <script> |
| function createModulePreload(type) { |
| const link = document.createElement('link'); |
| link.rel = 'modulepreload'; |
| |
| if(type === 'style') { |
| link.as = 'style'; |
| link.href = 'resources/dummy.css'; |
| } else if (type === 'json') { |
| link.as = 'json'; |
| link.href = 'resources/dummy.json'; |
| } else { |
| link.href = 'resources/dummy.js'; |
| } |
| return link; |
| } |
| |
| function attachAndWaitForLoad(element) { |
| return new Promise((resolve, reject) => { |
| element.onload = resolve; |
| element.onerror = reject; |
| document.body.appendChild(element); |
| }); |
| } |
| |
| promise_test(function(t) { |
| const first_preload = createModulePreload('style'); |
| return attachAndWaitForLoad(first_preload).then(() => { |
| const second_preload = createModulePreload('style'); |
| return attachAndWaitForLoad(second_preload).then(() => { |
| const absoluteURL = new URL(second_preload.href, second_preload.href).href; |
| assert_equals(performance.getEntriesByName(absoluteURL).length, 1, absoluteURL); |
| }); |
| }); |
| }, 'multiple style preloads of the same file do not cause errors'); |
| |
| |
| promise_test(function(t) { |
| const first_preload = createModulePreload('json'); |
| return attachAndWaitForLoad(first_preload).then(() => { |
| const second_preload = createModulePreload('json'); |
| return attachAndWaitForLoad(second_preload).then(() => { |
| const absoluteURL = new URL(second_preload.href, second_preload.href).href; |
| assert_equals(performance.getEntriesByName(absoluteURL).length, 1, absoluteURL); |
| }); |
| }); |
| }, 'multiple json preloads of the same file do not cause errors'); |
| |
| |
| promise_test(function(t) { |
| const first_preload = createModulePreload(); |
| return attachAndWaitForLoad(first_preload).then(() => { |
| const second_preload = createModulePreload(); |
| return attachAndWaitForLoad(second_preload).then(() => { |
| const absoluteURL = new URL(second_preload.href, second_preload.href).href; |
| assert_equals(performance.getEntriesByName(absoluteURL).length, 1, absoluteURL); |
| }); |
| }); |
| }, 'multiple script preloads of the same file do not cause errors'); |
| </script> |