summaryrefslogtreecommitdiffstats
path: root/testing/talos/talos/tests/cpstartup/cpstartup.html
blob: ddac3629bcb5bcf3d668dfca2a7b8d91bc07e3c6 (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
<html>
<head>
<script>

function init() {
  window.addEventListener("CPStartup:FinalResults", function onResults(event) {
    let results = event.detail;
    tpRecordTime(results, 0, "content-process-startup");
  }, {once: true});

  async function tryPing() {
    let pingPromise = new Promise(resolve => {
      window.addEventListener("CPStartup:Pong", resolve, {once: true});
      dispatchEvent(new CustomEvent("CPStartup:Ping", {bubbles: true}));
    });
    let timeoutPromise = new Promise((resolve, reject) => setTimeout(reject, 500));

    try {
      await Promise.race([pingPromise, timeoutPromise]);
    } catch (e) {
      return tryPing();
    }
    return null;
  }

  let target = document.location.href.replace(/cpstartup.html$/, "target.html");
  tryPing().then(() => {
    dispatchEvent(new CustomEvent("CPStartup:Go", {
      bubbles: true,
      detail: {target},
    }));
  });
}

</script>
</head>

<body onload="init();">
  Hello, Talos!

  <a href="#" id="target" target="_blank">I'll open a new tab</a>
</body>
</html>