summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/iceTestUtils.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /dom/media/webrtc/tests/mochitests/iceTestUtils.js
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-upstream/125.0.1.tar.xz
firefox-upstream/125.0.1.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webrtc/tests/mochitests/iceTestUtils.js')
-rw-r--r--dom/media/webrtc/tests/mochitests/iceTestUtils.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/dom/media/webrtc/tests/mochitests/iceTestUtils.js b/dom/media/webrtc/tests/mochitests/iceTestUtils.js
index d4d1f5c4b4..9e76e3f7df 100644
--- a/dom/media/webrtc/tests/mochitests/iceTestUtils.js
+++ b/dom/media/webrtc/tests/mochitests/iceTestUtils.js
@@ -300,3 +300,129 @@ async function checkNoRelay(iceServers) {
);
pc.close();
}
+
+function gatheringStateReached(object, state) {
+ if (object instanceof RTCIceTransport) {
+ return new Promise(r =>
+ object.addEventListener("gatheringstatechange", function listener() {
+ if (object.gatheringState == state) {
+ object.removeEventListener("gatheringstatechange", listener);
+ r(state);
+ }
+ })
+ );
+ } else if (object instanceof RTCPeerConnection) {
+ return new Promise(r =>
+ object.addEventListener("icegatheringstatechange", function listener() {
+ if (object.iceGatheringState == state) {
+ object.removeEventListener("icegatheringstatechange", listener);
+ r(state);
+ }
+ })
+ );
+ } else {
+ throw "First parameter is neither an RTCIceTransport nor an RTCPeerConnection";
+ }
+}
+
+function nextGatheringState(object) {
+ if (object instanceof RTCIceTransport) {
+ return new Promise(resolve =>
+ object.addEventListener(
+ "gatheringstatechange",
+ () => resolve(object.gatheringState),
+ { once: true }
+ )
+ );
+ } else if (object instanceof RTCPeerConnection) {
+ return new Promise(resolve =>
+ object.addEventListener(
+ "icegatheringstatechange",
+ () => resolve(object.iceGatheringState),
+ { once: true }
+ )
+ );
+ } else {
+ throw "First parameter is neither an RTCIceTransport nor an RTCPeerConnection";
+ }
+}
+
+function emptyCandidate(pc) {
+ return new Promise(r =>
+ pc.addEventListener("icecandidate", function listener(e) {
+ if (e.candidate && e.candidate.candidate == "") {
+ pc.removeEventListener("icecandidate", listener);
+ r(e);
+ }
+ })
+ );
+}
+
+function nullCandidate(pc) {
+ return new Promise(r =>
+ pc.addEventListener("icecandidate", function listener(e) {
+ if (!e.candidate) {
+ pc.removeEventListener("icecandidate", listener);
+ r(e);
+ }
+ })
+ );
+}
+
+function connectionStateReached(object, state) {
+ if (object instanceof RTCIceTransport || object instanceof RTCDtlsTransport) {
+ return new Promise(resolve =>
+ object.addEventListener("statechange", function listener() {
+ if (object.state == state) {
+ object.removeEventListener("statechange", listener);
+ resolve(state);
+ }
+ })
+ );
+ } else if (object instanceof RTCPeerConnection) {
+ return new Promise(resolve =>
+ object.addEventListener("connectionstatechange", function listener() {
+ if (object.connectionState == state) {
+ object.removeEventListener("connectionstatechange", listener);
+ resolve(state);
+ }
+ })
+ );
+ } else {
+ throw "First parameter is neither an RTCIceTransport, an RTCDtlsTransport, nor an RTCPeerConnection";
+ }
+}
+
+function nextConnectionState(object) {
+ if (object instanceof RTCIceTransport || object instanceof RTCDtlsTransport) {
+ return new Promise(resolve =>
+ object.addEventListener("statechange", () => resolve(object.state), {
+ once: true,
+ })
+ );
+ } else if (object instanceof RTCPeerConnection) {
+ return new Promise(resolve =>
+ object.addEventListener(
+ "connectionstatechange",
+ () => resolve(object.connectionState),
+ { once: true }
+ )
+ );
+ } else {
+ throw "First parameter is neither an RTCIceTransport, an RTCDtlsTransport, nor an RTCPeerConnection";
+ }
+}
+
+function nextIceConnectionState(pc) {
+ if (pc instanceof RTCPeerConnection) {
+ return new Promise(resolve =>
+ pc.addEventListener(
+ "iceconnectionstatechange",
+ () => resolve(pc.iceConnectionState),
+ { once: true }
+ )
+ );
+ } else {
+ throw "First parameter is not an RTCPeerConnection";
+ }
+}