dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html
author Byron Campen [:bwc] <docfaraday@gmail.com>
Wed, 13 Mar 2019 02:23:39 +0000
changeset 521711 add69e4bd9af8b952a29e66b6cf0df33be47f214
parent 454622 d5a5ad1dbbf2c53a80386e7397ba6b32153b2b8e
child 521720 5899671d28c9c424f549666af6749ef93da8c92a
permissions -rw-r--r--
Bug 1531075: Allow offers to be created/set without any transceivers, re-enable some tests, and fix a mochitest. r=jib Differential Revision: https://phabricator.services.mozilla.com/D23022

<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "857765",
    title: "Throw in PeerConnection callbacks"
  });

runNetworkTest(function () {
  function finish() {
    window.onerror = oldOnError;
    is(error_count, 7, "Seven expected errors verified.");
    networkTestFinished();
  }

  function getFail() {
    return err => {
      window.onerror = oldOnError;
      generateErrorCallback()(err);
    };
  }

  let error_count = 0;
  let oldOnError = window.onerror;
  window.onerror = (errorMsg, url, lineNumber) => {
    if (!errorMsg.includes("Expected")) {
      getFail()(errorMsg);
    }
    error_count += 1;
    info("onerror " + error_count + ": " + errorMsg);
    if (error_count == 7) {
      finish();
    }
    throw new Error("window.onerror may throw");
    return false;
  }

  let pc0, pc1, pc2;
  // Test failure callbacks (limited to 1 for now)
  pc0 = new RTCPeerConnection();
  pc0.close();
  pc0.createOffer(getFail(), function(err) {
    pc1 = new RTCPeerConnection();
    pc2 = new RTCPeerConnection();

    // Test success callbacks (happy path)
    navigator.mozGetUserMedia({video:true}, function(video1) {
      pc1.addStream(video1);
      pc1.createOffer(function(offer) {
        pc1.setLocalDescription(offer, function() {
          pc2.setRemoteDescription(offer, function() {
            pc2.createAnswer(function(answer) {
              pc2.setLocalDescription(answer, function() {
                pc1.setRemoteDescription(answer, function() {
                  throw new Error("Expected");
                }, getFail());
                throw new Error("Expected");
              }, getFail());
              throw new Error("Expected");
            }, getFail());
            throw new Error("Expected");
          }, getFail());
          throw new Error("Expected");
        }, getFail());
        throw new Error("Expected");
      }, getFail());
    }, getFail());
    throw new Error("Expected");
  });
});

</script>
</pre>
</body>
</html>