[MediaStream] 'devicechange' event should not fire in frames that can't access captur...
[WebKit-https.git] / LayoutTests / fast / mediastream / device-change-event.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <meta charset="utf-8">
5     <title>'devicechange' event tests</title>
6     <script src="../../resources/testharness.js"></script>
7     <script src="../../resources/testharnessreport.js"></script>
8     <script>
9     let deviceIds = [];
10     promise_test((test) => {
11         if (window.testRunner)
12             testRunner.setUserMediaPermission(true);
13
14         return navigator.mediaDevices.enumerateDevices().then((devices) => {
15             return new Promise((resolve, reject) => {
16                 devices.forEach(function(device) { deviceIds.push(device.deviceId); });
17                 navigator.mediaDevices.ondevicechange = (event) => { resolve(event); };
18                 setTimeout(() => resolve(new Event('devicechange')), 100);
19             });
20         }).then((event) => {
21             assert_equals(event.type, "devicechange", "correct event type");
22             return new Promise((resolve, reject) => {
23                 return navigator.mediaDevices.enumerateDevices().then((devices) => {
24                     let deviceIDs2 = [];
25                     devices.forEach(function(device) { deviceIDs2.push(device.deviceId); });
26                     try {
27                         assert_true(deviceIDs2.indexOf(deviceIds[0]) != -1, "device not reported by enumerateDevices");
28                         assert_equals(deviceIDs2.length, deviceIds.length, "correct number of devices");
29                     } catch(e) {
30                         reject(e);
31                         return;
32                     }
33
34                     navigator.mediaDevices.ondevicechange = (event) => { resolve(event); };
35                     setTimeout(() => resolve(new Event('devicechange')), 100);
36                 });
37             });
38         }).then((event) => {
39             assert_equals(event.type, "devicechange", "correct event type");
40             return new Promise((resolve, reject) => {
41                 return navigator.mediaDevices.enumerateDevices().then((devices) => {
42                     let deviceIDs2 = [];
43                     devices.forEach(function(device) { deviceIDs2.push(device.deviceId); });
44                     try {
45                         assert_in_array(deviceIds[0], deviceIDs2, "device reported by enumerateDevices again");
46                         assert_equals(deviceIDs2.length, deviceIds.length, "correct number of devices");
47                     } catch(e) {
48                         reject(e);
49                         return;
50                     }
51
52                     resolve();
53                 });
54             });
55         });
56
57     }, "'devicechange' event fired when device list changes");
58     </script>
59 </head>
60 <body>
61 </body>
62 </html>