| OLD | NEW |
| 1 <!DOCTYPE html> | 1 B<!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 |
| 10 // Runs an ImageCapture.getPhotoCapabilities(). | 28 // Runs an ImageCapture.getPhotoCapabilities(). |
| 11 function testCreateAndGetCapabilities() { | 29 function testCreateAndGetCapabilities() { |
| 12 var hasVideoInputDevice = false; | 30 checkForVideoDevices() |
| 13 navigator.mediaDevices.enumerateDevices() | 31 .catch(err => { |
| 14 .then(devices => { | 32 console.log('no video devices found, skipping test'); |
| 15 devices.forEach(function(device) { | 33 reportTestSuccess(); |
| 16 if (device.kind === "videoinput") | |
| 17 hasVideoInputDevice = true; | |
| 18 }); | |
| 19 | |
| 20 if (!hasVideoInputDevice) | |
| 21 return Promise.reject("no video devices"); | |
| 22 }) | 34 }) |
| 23 .catch(err => { | 35 .then(() => { |
| 24 return failTest('Error enumerating devices: ' + err.toString()); | 36 const constraints = { mandatory: { maxHeight: 180, maxWidth: 320 } }; |
| 25 }); | 37 return navigator.mediaDevices.getUserMedia({"video" : constraints}); |
| 26 | 38 }) |
| 27 navigator.mediaDevices.getUserMedia({"video" : true}) | |
| 28 .then(stream => { | 39 .then(stream => { |
| 29 assertEquals('video', stream.getVideoTracks()[0].kind); | 40 assertEquals('video', stream.getVideoTracks()[0].kind); |
| 30 return new ImageCapture(stream.getVideoTracks()[0]); | 41 return new ImageCapture(stream.getVideoTracks()[0]); |
| 31 }) | 42 }) |
| 32 .then(capturer => { | 43 .then(capturer => { |
| 33 return capturer.getPhotoCapabilities(); | 44 return capturer.getPhotoCapabilities(); |
| 34 }) | 45 }) |
| 35 .then(capabilities => { | 46 .then(capabilities => { |
| 36 assertNotEquals(0, capabilities.imageHeight.min); | 47 assertNotEquals(0, capabilities.imageHeight.min); |
| 37 assertNotEquals(0, capabilities.imageHeight.current); | 48 assertNotEquals(0, capabilities.imageHeight.current); |
| 38 assertNotEquals(0, capabilities.imageHeight.max); | 49 assertNotEquals(0, capabilities.imageHeight.max); |
| 39 assertNotEquals(0, capabilities.imageWidth.min); | 50 assertNotEquals(0, capabilities.imageWidth.min); |
| 40 assertNotEquals(0, capabilities.imageWidth.current); | 51 assertNotEquals(0, capabilities.imageWidth.current); |
| 41 assertNotEquals(0, capabilities.imageWidth.max); | 52 assertNotEquals(0, capabilities.imageWidth.max); |
| 42 assertNotEquals(0, capabilities.zoom.min); | 53 assertNotEquals(0, capabilities.zoom.min); |
| 43 assertNotEquals(0, capabilities.zoom.current); | 54 assertNotEquals(0, capabilities.zoom.current); |
| 44 assertNotEquals(0, capabilities.zoom.max); | 55 assertNotEquals(0, capabilities.zoom.max); |
| 45 | 56 |
| 46 reportTestSuccess(); | 57 reportTestSuccess(); |
| 47 }) | 58 }) |
| 48 .catch(err => { | 59 .catch(err => { |
| 49 return failTest(err.toString()); | 60 return failTest(err.toString()); |
| 50 }); | 61 }); |
| 51 } | 62 } |
| 52 | 63 |
| 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 |
| 53 </script> | 93 </script> |
| 54 </body> | 94 </body> |
| 55 </html> | 95 </html> |
| OLD | NEW |