Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /webrtc/RTCConfiguration-iceCandidatePoolSize.html - WPT Dashboard Interop Dashboard
<!doctype html>
<meta charset="utf-8">
<!--
4.2.1 RTCConfiguration Dictionary
The RTCConfiguration defines a set of parameters to configure how the peer to peer communication established via RTCPeerConnection is established or re-established.
...
iceCandidatePoolSize of type octet, defaulting to 0
Size of the prefetched ICE pool as defined in [JSEP] (section 3.5.4. and section 4.1.1.).
-->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
/*
dictionary RTCConfiguration {
...
[EnforceRange]
octet iceCandidatePoolSize = 0;
};
... of type octet
*/
test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_idl_attribute(pc, "getConfiguration");
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 0);
}, "Initialize a new RTCPeerConnection with no iceCandidatePoolSize");
test(t => {
const pc = new RTCPeerConnection({
iceCandidatePoolSize: 0
});
t.add_cleanup(() => pc.close());
assert_idl_attribute(pc, "getConfiguration");
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 0);
}, "Initialize a new RTCPeerConnection with iceCandidatePoolSize: 0");
test(t => {
const pc = new RTCPeerConnection({
iceCandidatePoolSize: 255
});
t.add_cleanup(() => pc.close());
assert_idl_attribute(pc, "getConfiguration");
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 255);
}, "Initialize a new RTCPeerConnection with iceCandidatePoolSize: 255");
test(() => {
assert_throws_js(TypeError, () => {
new RTCPeerConnection({
iceCandidatePoolSize: -1
});
});
}, "Initialize a new RTCPeerConnection with iceCandidatePoolSize: -1 (Out Of Range)");
test(() => {
assert_throws_js(TypeError, () => {
new RTCPeerConnection({
iceCandidatePoolSize: 256
});
});
}, "Initialize a new RTCPeerConnection with iceCandidatePoolSize: 256 (Out Of Range)");
/*
Reconfiguration
*/
test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_idl_attribute(pc, "getConfiguration");
assert_idl_attribute(pc, "setConfiguration");
pc.setConfiguration({
iceCandidatePoolSize: 0
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 0);
}, "Reconfigure RTCPeerConnection instance iceCandidatePoolSize to 0");
test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_idl_attribute(pc, "getConfiguration");
assert_idl_attribute(pc, "setConfiguration");
pc.setConfiguration({
iceCandidatePoolSize: 255
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 255);
}, "Reconfigure RTCPeerConnection instance iceCandidatePoolSize to 255");
/*
The following tests include an explicit assertion for the existence of a
setConfiguration function to prevent the assert_throws_js from catching the
TypeError object that will be thrown when attempting to call the
non-existent setConfiguration method (in cases where it has not yet
been implemented). Without this check, these tests will pass incorrectly.
*/
test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_equals(typeof pc.setConfiguration, "function", "RTCPeerConnection.prototype.setConfiguration is not implemented");
assert_throws_js(TypeError, () => {
pc.setConfiguration({
iceCandidatePoolSize: -1
});
});
}, "Reconfigure RTCPeerConnection instance iceCandidatePoolSize to -1 (Out Of Range)");
test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_equals(typeof pc.setConfiguration, "function", "RTCPeerConnection.prototype.setConfiguration is not implemented");
assert_throws_js(TypeError, () => {
pc.setConfiguration({
iceCandidatePoolSize: 256
});
});
}, "Reconfigure RTCPeerConnection instance iceCandidatePoolSize to 256 (Out Of Range)");
/*
4.4.1.5 Set the configuration, step 3.6
If the value of configuration.iceCandidatePoolSize differs from
oldConfig.iceCandidatePoolSize, and setLocalDescription has already been
called, then fail.
*/
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
pc.addTransceiver("audio");
await pc.setLocalDescription();
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
}, "Reconfigure iceCandidatePoolSize after setLocalDescription(offer) throws InvalidModificationError");
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
// No m-sections, so no ICE gathering is started by setLocalDescription.
await pc.setLocalDescription();
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
}, "Reconfigure iceCandidatePoolSize after setLocalDescription with no m-sections throws InvalidModificationError");
promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => {
pc1.close();
pc2.close();
});
pc1.addTransceiver("audio");
await pc2.setRemoteDescription(await pc1.createOffer());
// The answer becomes the current, not the pending, local description.
await pc2.setLocalDescription();
assert_throws_dom("InvalidModificationError", () => {
pc2.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc2.getConfiguration().iceCandidatePoolSize, 1);
}, "Reconfigure iceCandidatePoolSize after setLocalDescription(answer) throws InvalidModificationError");
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
pc.addTransceiver("audio");
await pc.setLocalDescription();
pc.setConfiguration({ iceCandidatePoolSize: 1 });
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
}, "Reconfigure iceCandidatePoolSize to the same value after setLocalDescription is allowed");
/*
The spec only says "setLocalDescription has already been called". It says
nothing about that setLocalDescription call having completed, succeeded,
failed or been rolled back, so the following tests expect the change to
fail in all of those cases. See
*/
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
pc.addTransceiver("audio");
await pc.setLocalDescription();
await pc.setLocalDescription({ type: "rollback" });
assert_equals(pc.localDescription, null,
"rollback should leave no local description");
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
}, "Reconfigure iceCandidatePoolSize after setLocalDescription is rolled back throws InvalidModificationError");
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
pc.addTransceiver("audio");
// The implicit createOffer is still running, so the "real"
// setLocalDescription has not been reached yet.
const sld = pc.setLocalDescription();
assert_equals(pc.localDescription, null,
"no local description should be applied yet");
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
await sld;
}, "Reconfigure iceCandidatePoolSize while parameterless setLocalDescription() creating an offer is pending throws InvalidModificationError");
promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => {
pc1.close();
pc2.close();
});
pc1.addTransceiver("audio");
await pc2.setRemoteDescription(await pc1.createOffer());
// The implicit createAnswer is still running, so the "real"
// setLocalDescription has not been reached yet.
const sld = pc2.setLocalDescription();
assert_equals(pc2.localDescription, null,
"no local description should be applied yet");
assert_equals(pc2.signalingState, "have-remote-offer");
assert_throws_dom("InvalidModificationError", () => {
pc2.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc2.getConfiguration().iceCandidatePoolSize, 1);
await sld;
}, "Reconfigure iceCandidatePoolSize while parameterless setLocalDescription() creating an answer is pending throws InvalidModificationError");
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
pc.addTransceiver("audio");
const offer = await pc.createOffer();
const sld = pc.setLocalDescription(offer);
assert_equals(pc.localDescription, null,
"no local description should be applied yet");
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
await sld;
}, "Reconfigure iceCandidatePoolSize while setLocalDescription(offer) is pending throws InvalidModificationError");
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
await pc.setLocalDescription({ type: "offer", sdp: "not an SDP" }).then(
() => assert_unreached("setLocalDescription with invalid SDP should reject"),
() => {});
assert_equals(pc.localDescription, null,
"a rejected setLocalDescription should leave no local description");
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
}, "Reconfigure iceCandidatePoolSize after setLocalDescription rejects throws InvalidModificationError");
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
pc.addTransceiver("audio");
const offer = await pc.createOffer();
// Rejected by the initial chained steps of setLocalDescription, since the
// sdp does not match [[LastCreatedAnswer]]. Only the rejection matters here.
await pc.setLocalDescription({ type: "answer", sdp: offer.sdp }).then(
() => assert_unreached("setLocalDescription(answer) with an offer's sdp should reject"),
() => {});
assert_equals(pc.localDescription, null,
"a rejected setLocalDescription should leave no local description");
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
}, "Reconfigure iceCandidatePoolSize after setLocalDescription(answer) with an offer's sdp rejects throws InvalidModificationError");
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
// Rejected by the initial steps of "set a local session description", since
// rollback is not valid in the "stable" signaling state.
await promise_rejects_dom(t, "InvalidStateError",
pc.setLocalDescription({ type: "rollback" }));
assert_equals(pc.signalingState, "stable");
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration({ iceCandidatePoolSize: 2 });
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
}, "Reconfigure iceCandidatePoolSize after setLocalDescription(rollback) in stable rejects throws InvalidModificationError");
/*
An RTCConfiguration without iceCandidatePoolSize gets the default of 0, so
it is handled the same as an explicit iceCandidatePoolSize: 0.
*/
for (const [label, config] of [
["omitted", {}],
["explicitly 0", { iceCandidatePoolSize: 0 }],
]) {
test(t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
pc.setConfiguration(config);
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 0);
}, `Reconfigure iceCandidatePoolSize from 1 with iceCandidatePoolSize ${label} before setLocalDescription sets it to 0`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
pc.addTransceiver("audio");
await pc.setLocalDescription();
pc.setConfiguration(config);
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 0);
}, `Reconfigure iceCandidatePoolSize from 0 with iceCandidatePoolSize ${label} after setLocalDescription is allowed`);
promise_test(async t => {
const pc = new RTCPeerConnection({ iceCandidatePoolSize: 1 });
t.add_cleanup(() => pc.close());
pc.addTransceiver("audio");
await pc.setLocalDescription();
assert_throws_dom("InvalidModificationError", () => {
pc.setConfiguration(config);
});
assert_equals(pc.getConfiguration().iceCandidatePoolSize, 1);
}, `Reconfigure iceCandidatePoolSize from 1 with iceCandidatePoolSize ${label} after setLocalDescription throws InvalidModificationError`);
}
</script>