summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webstorage/resources/partitioning-utils.js
blob: 9d9e0b8ac5ccdff2fd4358766fa219979b1ad589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function getOrCreateID(key) {
  if (!localStorage.getItem(key)) {
    const newID = +new Date() + "-" + Math.random();
    localStorage.setItem(key, newID);
  }
  return localStorage.getItem(key);
}

function addIframePromise(url) {
  return new Promise(resolve => {
    const iframe = document.createElement("iframe");
    iframe.style.display = "none";
    iframe.src = url;
    iframe.addEventListener("load", (e) => {
      resolve(iframe);
    }, {once: true});

    document.body.appendChild(iframe);
  });
}