| OLD | NEW |
| 1 B<!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <!-- Image Capture Browser Test --> | 4 <!-- Image Capture Browser Test --> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <script type="text/javascript" src="webrtc_test_utilities.js"></script> | 7 <script type="text/javascript" src="webrtc_test_utilities.js"></script> |
| 8 <script> | 8 <script> |
| 9 | 9 |
| 10 // Returns a Promise that is resolved if there is at least one video device or | |
| 11 // rejected otherwise. | |
| 12 function checkForVideoDevices() { | |
| 13 return new Promise((resolve, reject) => { | |
| 14 navigator.mediaDevices.enumerateDevices() | |
| 15 .then(devices => { | |
| 16 devices.forEach(function(device) { | |
| 17 if (device.kind === "videoinput") | |
| 18 return resolve(); | |
| 19 }); | |
| 20 return reject(new Error('no video devices')); | |
| 21 }) | |
| 22 .catch(err => { | |
| 23 return reject(new Error('enumerating devices: ' + err.toString())); | |
| 24 }); | |
| 25 }); | |
| 26 } | |
| 27 | |
| 28 // Runs an ImageCapture.getPhotoCapabilities(). | 10 // Runs an ImageCapture.getPhotoCapabilities(). |
| 29 function testCreateAndGetCapabilities() { | 11 function testCreateAndGetCapabilities() { |
| 30 checkForVideoDevices() | 12 var hasVideoInputDevice = false; |
| 13 navigator.mediaDevices.enumerateDevices() |
| 14 .then(devices => { |
| 15 devices.forEach(function(device) { |
| 16 if (device.kind === "videoinput") |
| 17 hasVideoInputDevice = true; |
| 18 }); |
| 19 |
| 20 if (!hasVideoInputDevice) |
| 21 return Promise.reject("no video devices"); |
| 22 }) |
| 31 .catch(err => { | 23 .catch(err => { |
| 32 console.log('no video devices found, skipping test'); | 24 return failTest('Error enumerating devices: ' + err.toString()); |
| 33 reportTestSuccess(); | 25 }); |
| 34 }) | 26 |
| 35 .then(() => { | 27 navigator.mediaDevices.getUserMedia({"video" : true}) |
| 36 const constraints = { mandatory: { maxHeight: 180, maxWidth: 320 } }; | |
| 37 return navigator.mediaDevices.getUserMedia({"video" : constraints}); | |
| 38 }) | |
| 39 .then(stream => { | 28 .then(stream => { |
| 40 assertEquals('video', stream.getVideoTracks()[0].kind); | 29 assertEquals('video', stream.getVideoTracks()[0].kind); |
| 41 return new ImageCapture(stream.getVideoTracks()[0]); | 30 return new ImageCapture(stream.getVideoTracks()[0]); |
| 42 }) | 31 }) |
| 43 .then(capturer => { | 32 .then(capturer => { |
| 44 return capturer.getPhotoCapabilities(); | 33 return capturer.getPhotoCapabilities(); |
| 45 }) | 34 }) |
| 46 .then(capabilities => { | 35 .then(capabilities => { |
| 47 assertNotEquals(0, capabilities.imageHeight.min); | 36 assertNotEquals(0, capabilities.imageHeight.min); |
| 48 assertNotEquals(0, capabilities.imageHeight.current); | 37 assertNotEquals(0, capabilities.imageHeight.current); |
| 49 assertNotEquals(0, capabilities.imageHeight.max); | 38 assertNotEquals(0, capabilities.imageHeight.max); |
| 50 assertNotEquals(0, capabilities.imageWidth.min); | 39 assertNotEquals(0, capabilities.imageWidth.min); |
| 51 assertNotEquals(0, capabilities.imageWidth.current); | 40 assertNotEquals(0, capabilities.imageWidth.current); |
| 52 assertNotEquals(0, capabilities.imageWidth.max); | 41 assertNotEquals(0, capabilities.imageWidth.max); |
| 53 assertNotEquals(0, capabilities.zoom.min); | 42 assertNotEquals(0, capabilities.zoom.min); |
| 54 assertNotEquals(0, capabilities.zoom.current); | 43 assertNotEquals(0, capabilities.zoom.current); |
| 55 assertNotEquals(0, capabilities.zoom.max); | 44 assertNotEquals(0, capabilities.zoom.max); |
| 56 | 45 |
| 57 reportTestSuccess(); | 46 reportTestSuccess(); |
| 58 }) | 47 }) |
| 59 .catch(err => { | 48 .catch(err => { |
| 60 return failTest(err.toString()); | 49 return failTest(err.toString()); |
| 61 }); | 50 }); |
| 62 } | 51 } |
| 63 | 52 |
| 64 // Runs an ImageCapture.takePhoto(). | |
| 65 function testCreateAndTakePhoto() { | |
| 66 checkForVideoDevices() | |
| 67 .catch(err => { | |
| 68 console.log('no video devices found, skipping test'); | |
| 69 reportTestSuccess(); | |
| 70 }) | |
| 71 .then(() => { | |
| 72 const constraints = { mandatory: { maxHeight: 180, maxWidth: 320 } }; | |
| 73 return navigator.mediaDevices.getUserMedia({"video" : constraints}); | |
| 74 }) | |
| 75 .then(stream => { | |
| 76 assertEquals('video', stream.getVideoTracks()[0].kind); | |
| 77 return new ImageCapture(stream.getVideoTracks()[0]); | |
| 78 }) | |
| 79 .then(capturer => { | |
| 80 return capturer.takePhoto(); | |
| 81 }) | |
| 82 .then(blob => { | |
| 83 assertTrue(blob.type != undefined); | |
| 84 assertNotEquals(0, blob.size); | |
| 85 | |
| 86 reportTestSuccess(); | |
| 87 }) | |
| 88 .catch(err => { | |
| 89 return failTest(err.toString()); | |
| 90 }); | |
| 91 } | |
| 92 | |
| 93 </script> | 53 </script> |
| 94 </body> | 54 </body> |
| 95 </html> | 55 </html> |
| OLD | NEW |