summaryrefslogtreecommitdiffstats
path: root/dom/media/tests/mochitest/test_peerConnection_closeDuringIce.html
blob: eb8228d03c716ec38f5b5f170a717b9e8e041161 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1087629",
    title: "Close PCs during ICE connectivity check"
  });

// Test closeDuringIce to simulate problems during peer connections


function PC_LOCAL_SETUP_NULL_ICE_HANDLER(test) {
  test.pcLocal.setupIceCandidateHandler(test, function() {}, function () {});
}
function PC_REMOTE_SETUP_NULL_ICE_HANDLER(test) {
  test.pcRemote.setupIceCandidateHandler(test, function() {}, function () {});
}
function PC_REMOTE_ADD_FAKE_ICE_CANDIDATE(test) {
  var cand = new RTCIceCandidate({"candidate":"candidate:0 1 UDP 2130379007 192.0.2.1 12345 typ host","sdpMid":"","sdpMLineIndex":0});
  test.pcRemote.storeOrAddIceCandidate(cand);
  info(test.pcRemote + " Stored fake candidate: " + JSON.stringify(cand));
}
function PC_LOCAL_ADD_FAKE_ICE_CANDIDATE(test) {
  var cand = new RTCIceCandidate({"candidate":"candidate:0 1 UDP 2130379007 192.0.2.2 56789 typ host","sdpMid":"","sdpMLineIndex":0});
    test.pcLocal.storeOrAddIceCandidate(cand);
  info(test.pcLocal + " Stored fake candidate: " + JSON.stringify(cand));
}
function PC_LOCAL_CLOSE_DURING_ICE(test) {
  return test.pcLocal.iceChecking.then(() => {
    test.pcLocal.onsignalingstatechange = function () {};
    test.pcLocal.close();
    });
}
function PC_REMOTE_CLOSE_DURING_ICE(test) {
  return test.pcRemote.iceChecking.then(() => {
    test.pcRemote.onsignalingstatechange = function () {};
    test.pcRemote.close();
    });
}
function PC_LOCAL_WAIT_FOR_ICE_CHECKING(test) {
  var resolveIceChecking;
  test.pcLocal.iceChecking = new Promise(r => resolveIceChecking = r);
  test.pcLocal.ice_connection_callbacks.checkIceStatus = () => {
	if (test.pcLocal._pc.iceConnectionState === "checking") {
	  resolveIceChecking();
	}
  }
}
function PC_REMOTE_WAIT_FOR_ICE_CHECKING(test) {
  var resolveIceChecking;
  test.pcRemote.iceChecking = new Promise(r => resolveIceChecking = r);
  test.pcRemote.ice_connection_callbacks.checkIceStatus = () => {
	if (test.pcRemote._pc.iceConnectionState === "checking") {
	  resolveIceChecking();
	}
  }
}

runNetworkTest(() => {
  var test = new PeerConnectionTest();
  test.setMediaConstraints([{audio: true}], [{audio: true}]);
  test.chain.replace("PC_LOCAL_SETUP_ICE_HANDLER", PC_LOCAL_SETUP_NULL_ICE_HANDLER);
  test.chain.replace("PC_REMOTE_SETUP_ICE_HANDLER", PC_REMOTE_SETUP_NULL_ICE_HANDLER);
  test.chain.insertAfter("PC_REMOTE_SETUP_NULL_ICE_HANDLER", PC_LOCAL_WAIT_FOR_ICE_CHECKING);
  test.chain.insertAfter("PC_LOCAL_WAIT_FOR_ICE_CHECKING", PC_REMOTE_WAIT_FOR_ICE_CHECKING);
  test.chain.removeAfter("PC_LOCAL_SET_REMOTE_DESCRIPTION");
  test.chain.append([PC_REMOTE_ADD_FAKE_ICE_CANDIDATE, PC_LOCAL_ADD_FAKE_ICE_CANDIDATE,
	PC_LOCAL_CLOSE_DURING_ICE, PC_REMOTE_CLOSE_DURING_ICE]);
  test.run();
});
</script>
</pre>
</body>
</html>