mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
f4abf7b8cc
Create a new mochitest that suspends enumerateDevice(). This can happen when the current window navigates away. This is achieved by using an iframe to enumerate devices and clearing the iframe window before the promise is resolved. Differential Revision: https://phabricator.services.mozilla.com/D2709 --HG-- extra : moz-landing-system : lando
55 lines
1.6 KiB
HTML
55 lines
1.6 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<script src="mediaStreamPlayback.js"></script>
|
|
</head>
|
|
<iframe id="iframe" srcdoc="<script>
|
|
window.enumerateDevices = () =>
|
|
navigator.mediaDevices.enumerateDevices();
|
|
</script>"
|
|
width="100%" height="50%" frameborder="1">
|
|
</iframe>
|
|
<body>
|
|
<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>
|