Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/permission-element/microphone/microphone-set-constraints.https.html - WPT Dashboard Interop Dashboard
<!doctype html>
<meta charset="utf-8" />
<meta name="timeout" content="long" />
<title>HTMLMicrophoneElement setConstraints(), track initialization, and sanitization</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="../usermedia/resources/pepc-helper.js"></script>
<body>
<script>
promise_test(async (t) => {
await test_driver.set_permission({ name: "microphone" }, "granted");
const mic = document.createElement("microphone");
document.body.appendChild(mic);
t.add_cleanup(() => {
if (mic.parentNode) {
document.body.removeChild(mic);
}
});
const track_promise = new Promise((resolve) => {
mic.ontrack = resolve;
});
mic.setConstraints({ sampleSize: 16 });
// Wait until the element is clickable.
await new Promise((r) => t.step_timeout(r, PEPC_CLICK_DELAY));
await test_driver.click(mic);
await track_promise;
const track = mic.track;
t.add_cleanup(() => {
if (track) {
track.stop();
}
});
assert_true(track instanceof MediaStreamTrack, "mic.track is instance of MediaStreamTrack");
assert_equals(track.kind, "audio", "mic.track must be audio kind");
assert_not_equals(track.kind, "video", "microphone must never have video track");
}, "HTMLMicrophoneElement initializes audio track and never video track");
promise_test(async (t) => {
await test_driver.set_permission({ name: "microphone" }, "granted");
const mic = document.createElement("microphone");
document.body.appendChild(mic);
t.add_cleanup(() => {
if (mic.parentNode) {
document.body.removeChild(mic);
}
});
const track_promise = new Promise((resolve) => {
mic.ontrack = resolve;
});
// Pass complex range parameters (exact/ideal) and video properties to test sanitization.
mic.setConstraints({
sampleSize: 16,
echoCancellation: { exact: true },
width: 1280,
frameRate: { ideal: 60 }
});
await new Promise((r) => t.step_timeout(r, PEPC_CLICK_DELAY));
await test_driver.click(mic);
await track_promise;
const track = mic.track;
t.add_cleanup(() => {
if (track) {
track.stop();
}
});
assert_true(track instanceof MediaStreamTrack, "sanitized microphone track successfully created");
assert_equals(track.kind, "audio", "sanitized track kind is audio");
}, "HTMLMicrophoneElement setConstraints sanitization strips complex ranges without crashing");
</script>
</body>