summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_enumerateDevices_navigation.html
blob: bf7650223f3e512ede4e7ebf72331dd5c75bd3c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!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>