fune/dom/media/tests/mochitest/test_enumerateDevices_navigation.html
Razvan Maries 887634a649 Backed out 3 changesets (bug 1665713) for perma failures on test_peerConnection_capturedVideo.html. CLOSED TREE
Backed out changeset 296d5facd7bd (bug 1665713)
Backed out changeset 770d63754715 (bug 1665713)
Backed out changeset 433d8f92b482 (bug 1665713)
2020-09-25 02:58:57 +03:00

54 lines
1.6 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<script src="mediaStreamPlayback.js"></script>
</head>
<body>
<iframe id="iframe" srcdoc="<script>
window.enumerateDevices = () =>
navigator.mediaDevices.enumerateDevices();
</script>"
width="100%" height="50%" frameborder="1">
</iframe>
<pre id="test">
<script type="application/javascript">
createHTML({ title: "Suspend enumerateDevices code ", bug: "1479840" });
/**
This test covers the case that the enumerateDevices method is suspended by
navigating away the current window. In order to implement that the enumeration
is executed in an iframe which is cleared before the enumeration has been resolved
*/
runTest(async () => {
// Run enumerate devices and mesure the time it will take.
const start = new Date().getTime();
try {
await iframe.contentWindow.enumerateDevices();
} catch (e) {
info("Failed to enumerate devices, error: " + e);
}
const elapsed = new Date().getTime() - start;
// Run again and navigate away. Expected to remain pending.
let p = iframe.contentWindow.enumerateDevices()
p.then( devices => {
ok(false, "Enumerate devices promise resolved unexpectedly, found " + devices.length + " devices.");
})
.catch ( error => {
ok(false, "Enumerate devices promise rejected unexpectedly: " + error);
});
iframe.srcdoc = "";
// Wait enough time.
try {
await timeout(p, 5 * elapsed, "timeout");
ok(false, "Enumerate devices promise resolved unexpectedly");
} catch (e) {
is(e.message, "timeout", "We should time out without enumerateDevices rejecting");
}
});
</script>
</pre>
</body>
</html>