ServiceWorkers API should reject promises when calling objects inside detached frames
[WebKit-https.git] / LayoutTests / http / tests / media / media-stream / disconnected-frame-permission-denied.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../../resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <script>
8 description("Tests that when a getUserMedia request is made, permission is denied and its Frame is disconnected before a callback is made, the error callback is invoked with PERMISSION_DENIED.");
9 window.jsTestIsAsync = true;
10
11 if (window.testRunner)
12     testRunner.setUserMediaPermission(false);
13 else
14     debug('This test can not be run without the testRunner');
15
16 var error;
17 var options = {audio: true, video: true};
18 function onIframeLoaded() {
19     iframeNavigator = iframe.contentWindow.navigator;
20     iframe.contentWindow.onunload = onIframeUnloaded;
21     iframeNavigator.mediaDevices.getUserMedia(options)
22         .then(stream => {
23             testFailed('Success callback invoked unexpectedly');
24             finishJSTest();
25         })
26         .catch(err => {
27             error = err;
28             shouldBeEqualToString('error.name', 'NotAllowedError');
29             debug('');
30             iframe.src = 'data:text/html,This frame should be visible when the test completes';
31         });
32 }
33
34 function onIframeUnloaded() {
35     // Make another request, with permission already denied.
36     iframeNavigator.mediaDevices.getUserMedia(options)
37         .then(stream => {
38             testFailed('Success callback invoked unexpectedly');
39             finishJSTest();
40         })
41         .catch(err => {
42             testPassed('Error callback invoked');
43             finishJSTest();
44         });
45     setTimeout(function() {
46         testFailed('No callbacks invoked');
47         finishJSTest();
48     }, 100);
49 }
50
51 var iframe = document.createElement('iframe');
52 iframe.src = 'resources/disconnected-frame-inner.html';
53 document.body.appendChild(iframe);
54
55 </script>
56 <script src="../../../../resources/js-test-post.js"></script>
57 </body>
58 </html>