Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!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 | |
| 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 return navigator.mediaDevices.getUserMedia({"video" : true}); |
| 25 }); | 37 }) |
| 26 | |
| 27 navigator.mediaDevices.getUserMedia({"video" : true}) | |
| 28 .then(stream => { | 38 .then(stream => { |
| 29 assertEquals('video', stream.getVideoTracks()[0].kind); | 39 assertEquals('video', stream.getVideoTracks()[0].kind); |
| 30 return new ImageCapture(stream.getVideoTracks()[0]); | 40 return new ImageCapture(stream.getVideoTracks()[0]); |
| 31 }) | 41 }) |
| 32 .then(capturer => { | 42 .then(capturer => { |
| 33 return capturer.getPhotoCapabilities(); | 43 return capturer.getPhotoCapabilities(); |
| 34 }) | 44 }) |
| 35 .then(capabilities => { | 45 .then(capabilities => { |
| 36 assertNotEquals(0, capabilities.imageHeight.min); | 46 assertNotEquals(0, capabilities.imageHeight.min); |
| 37 assertNotEquals(0, capabilities.imageHeight.current); | 47 assertNotEquals(0, capabilities.imageHeight.current); |
| 38 assertNotEquals(0, capabilities.imageHeight.max); | 48 assertNotEquals(0, capabilities.imageHeight.max); |
| 39 assertNotEquals(0, capabilities.imageWidth.min); | 49 assertNotEquals(0, capabilities.imageWidth.min); |
| 40 assertNotEquals(0, capabilities.imageWidth.current); | 50 assertNotEquals(0, capabilities.imageWidth.current); |
| 41 assertNotEquals(0, capabilities.imageWidth.max); | 51 assertNotEquals(0, capabilities.imageWidth.max); |
| 42 assertNotEquals(0, capabilities.zoom.min); | 52 assertNotEquals(0, capabilities.zoom.min); |
| 43 assertNotEquals(0, capabilities.zoom.current); | 53 assertNotEquals(0, capabilities.zoom.current); |
| 44 assertNotEquals(0, capabilities.zoom.max); | 54 assertNotEquals(0, capabilities.zoom.max); |
| 45 | 55 |
| 46 reportTestSuccess(); | 56 reportTestSuccess(); |
| 47 }) | 57 }) |
| 48 .catch(err => { | 58 .catch(err => { |
| 49 return failTest(err.toString()); | 59 return failTest(err.toString()); |
| 50 }); | 60 }); |
| 51 } | 61 } |
| 52 | 62 |
| 63 // Runs an ImageCapture.takePhoto(). | |
| 64 function testCreateAndTakePhoto() { | |
| 65 checkForVideoDevices() | |
| 66 .catch(err => { | |
| 67 console.log('no video devices found, skipping test'); | |
| 68 reportTestSuccess(); | |
| 69 }) | |
| 70 .then(() => { | |
| 71 return navigator.mediaDevices.getUserMedia({"video" : true}); | |
| 72 }) | |
| 73 .then(stream => { | |
| 74 assertEquals('video', stream.getVideoTracks()[0].kind); | |
| 75 return new ImageCapture(stream.getVideoTracks()[0]); | |
| 76 }) | |
| 77 .then(capturer => { | |
| 78 return capturer.takePhoto(); | |
| 79 }) | |
| 80 .then(blob => { | |
| 81 assertTrue(blob.type != undefined); | |
| 82 assertNotEquals(0, blob.size); | |
| 83 | |
|
emircan
2016/08/03 21:55:54
Remove empty line.
mcasas
2016/08/03 22:19:36
Done.
| |
| 84 reportTestSuccess(); | |
| 85 }) | |
| 86 .catch(err => { | |
| 87 return failTest(err.toString()); | |
| 88 }); | |
| 89 } | |
| 90 | |
| 53 </script> | 91 </script> |
| 54 </body> | 92 </body> |
| 55 </html> | 93 </html> |
| OLD | NEW |