summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/range/resources/utils.js
blob: ad2853b33dc7474293df1423dd8af459571736b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function loadScript(url, { doc = document }={}) {
  return new Promise((resolve, reject) => {
    const script = doc.createElement('script');
    script.onload = () => resolve();
    script.onerror = () => reject(Error("Script load failed"));
    script.src = url;
    doc.body.appendChild(script);
  })
}

function preloadImage(url, { doc = document }={}) {
  return new Promise((resolve, reject) => {
    const preload = doc.createElement('link');
    preload.rel = 'preload';
    preload.as = 'image';
    preload.onload = () => resolve();
    preload.onerror = () => resolve();
    preload.href = url;
    doc.body.appendChild(preload);
  })
}

/**
 *
 * @param {Document} document
 * @param {string|URL} url
 * @returns {HTMLAudioElement}
 */
function appendAudio(document, url) {
  const audio = document.createElement('audio');
  audio.muted = true;
  audio.src = url;
  audio.preload = true;
  document.body.appendChild(audio);
  return audio;
}