OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="/resources/testharness.js"></script> |
| 3 <script src="/resources/testharnessreport.js"></script> |
| 4 <script src="resources/fake-devices.js"></script> |
| 5 <script src="resources/usb-helpers.js"></script> |
| 6 <script> |
| 7 'use strict'; |
| 8 |
| 9 function runIframeDisconnectTest(onDeviceConnected) { |
| 10 return new Promise((resolve, reject) => { |
| 11 let opened = false; |
| 12 |
| 13 let iframe = document.createElement('iframe'); |
| 14 iframe.src = 'resources/open-in-iframe.html'; |
| 15 iframe.onload = () => { |
| 16 navigator.usb.test.attachToWindow(iframe.contentWindow).then(() => { |
| 17 iframe.contentWindow.postMessage('Ready', '*'); |
| 18 }); |
| 19 }; |
| 20 |
| 21 window.onmessage = messageEvent => { |
| 22 if (messageEvent.data == 'Ready') { |
| 23 let fakeDevice = navigator.usb.test.addFakeDevice(fakeDeviceInit); |
| 24 fakeDevice.onclose = () => { |
| 25 assert_true(opened); |
| 26 resolve(); |
| 27 }; |
| 28 } else if (messageEvent.data == 'Success') { |
| 29 opened = true; |
| 30 onDeviceConnected(iframe); |
| 31 } else { |
| 32 reject(messageEvent.data); |
| 33 } |
| 34 }; |
| 35 |
| 36 document.body.appendChild(iframe); |
| 37 }); |
| 38 } |
| 39 |
| 40 usb_test(() => { |
| 41 return runIframeDisconnectTest(iframe => { |
| 42 document.body.removeChild(iframe); |
| 43 }); |
| 44 }, 'detaching iframe disconnects device.'); |
| 45 |
| 46 usb_test(() => { |
| 47 return runIframeDisconnectTest(iframe => { |
| 48 iframe.src = 'about:blank'; |
| 49 }); |
| 50 }, 'navigating iframe disconnects device.'); |
| 51 </script> |
OLD | NEW |