summaryrefslogtreecommitdiffstats
path: root/browser/components/resistfingerprinting/test/browser/file_hwconcurrency_iframer.html
blob: 3de74bc9a3b090e16085f9d1dfcbcd0c9c519757 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="shared_test_funcs.js"></script>
<script>
async function runTheTest(iframe_domain, cross_origin_domain, mode) {
  var child_reference;
  let url = `https://${iframe_domain}/browser/browser/components/resistfingerprinting/test/browser/file_hwconcurrency_iframee.html?mode=`
  let params = new URLSearchParams(document.location.search);

  if (params.get("mode") == 'iframe') {
    const iframes = document.querySelectorAll("iframe");
    iframes[0].src = url + 'iframe';
    child_reference = iframes[0].contentWindow;
  } else if (params.get("mode") == "popup") {
    let options = "";
    if (params.get("submode") == "noopener") {
      options = "noopener";
    }
    const popup = window.open(url + 'popup', '', options);
    if (params.get("submode") == "noopener") {
      return {};
    }
    child_reference = popup;
  } else {
    throw new Error("Unknown page mode specified");
  }

  await waitForMessage("ready", `https://${iframe_domain}`);

  const promiseForRFPTest = new Promise(resolve => {
    window.addEventListener("message", event => {
      if(event.origin != `https://${iframe_domain}`) {
        throw new Error(`origin should be ${iframe_domain}`);
      }
      resolve(event.data);
    }, { once: true });
  });
  child_reference.postMessage(["gimme", cross_origin_domain], "*");
  var result = await promiseForRFPTest;

  if (params.get("mode") == "popup") {
    child_reference.close();
  }

  return result;
}
</script>
</head>
<body>
<iframe width=100></iframe>
</body>
</html>