testing/talos/talos/tests/cpstartup/cpstartup.html
author Andrew Swan <aswan@mozilla.com>
Tue, 23 Oct 2018 21:39:17 +0000
changeset 442648 e19cd8da255dd2fedd21c69a99545d4b5f0f1ef3
parent 430085 testing/talos/talos/tests/cpstartup/content/cpstartup.html@cd76057ca094e27d7c633a1e9565f79cd04583c4
permissions -rw-r--r--
Bug 1499609 Convert cpstartup to a webextension r=mconley Differential Revision: https://phabricator.services.mozilla.com/D9411

<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>