| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="../resources/mojo-helpers.js"></script> |
| 5 <script src="resources/fake-devices.js"></script> |
| 6 <script src="resources/usb-helpers.js"></script> |
| 7 <script> |
| 8 'use strict'; |
| 9 |
| 10 const visibilityError = |
| 11 'Connection is only allowed while the page is visible. This is a ' + |
| 12 'temporary measure until we are able to effectively communicate to the ' + |
| 13 'user that the page is connected to a device.'; |
| 14 |
| 15 usb_test(usb => { |
| 16 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 17 testRunner.setPageVisibility('visible'); |
| 18 return navigator.usb.getDevices().then(devices => { |
| 19 assert_equals(devices.length, 1); |
| 20 let device = devices[0]; |
| 21 testRunner.setPageVisibility('hidden'); |
| 22 return assertRejectsWithError( |
| 23 device.open(), 'SecurityError', visibilityError).then(() => { |
| 24 assert_false(device.opened); |
| 25 }); |
| 26 }); |
| 27 }, 'device connection is disallowed while the tab is hidden'); |
| 28 |
| 29 usb_test(usb => { |
| 30 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 31 testRunner.setPageVisibility('visible'); |
| 32 return navigator.usb.getDevices().then(devices => { |
| 33 assert_equals(devices.length, 1); |
| 34 let device = devices[0]; |
| 35 let promise = assertRejectsWithError( |
| 36 device.open(), 'SecurityError', visibilityError); |
| 37 testRunner.setPageVisibility('hidden'); |
| 38 return promise.then(() => { |
| 39 assert_false(device.opened); |
| 40 }); |
| 41 }); |
| 42 }, 'device connection is disallowed when it finishes while the tab is hidden'); |
| 43 |
| 44 usb_test(usb => { |
| 45 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 46 testRunner.setPageVisibility('visible'); |
| 47 return navigator.usb.getDevices().then(devices => { |
| 48 assert_equals(devices.length, 1); |
| 49 let device = devices[0]; |
| 50 return device.open().then(() => { |
| 51 testRunner.setPageVisibility('hidden'); |
| 52 return assertRejectsWithError( |
| 53 device.selectConfiguration(1), 'SecurityError', visibilityError); |
| 54 }).then(() => { |
| 55 assert_false(device.opened); |
| 56 }); |
| 57 }); |
| 58 }, 'device connection is closed when tab becomes hidden'); |
| 59 |
| 60 usb_test(usb => { |
| 61 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 62 testRunner.setPageVisibility('visible'); |
| 63 return navigator.usb.getDevices().then(devices => { |
| 64 assert_equals(devices.length, 1); |
| 65 let device = devices[0]; |
| 66 return device.open().then(() => { |
| 67 testRunner.setPageVisibility('hidden'); |
| 68 return assertRejectsWithError( |
| 69 device.selectConfiguration(0), 'SecurityError', visibilityError); |
| 70 }).then(() => { |
| 71 assert_false(device.opened); |
| 72 testRunner.setPageVisibility('visible'); |
| 73 return device.open() |
| 74 .then(() => device.selectConfiguration(1)) |
| 75 .then(() => device.close()); |
| 76 }); |
| 77 }); |
| 78 }, 'device can be reopened when the page is visible'); |
| 79 </script> |
| OLD | NEW |