Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(805)

Unified Diff: content/test/data/media/image_capture_test.html

Issue 2193213003: ImageCapture: Queue up requests while device not ready (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/test/data/media/image_capture_test.html
diff --git a/content/test/data/media/image_capture_test.html b/content/test/data/media/image_capture_test.html
index 6b8b6461ccef696d6ab651dbdd94aab8736cca93..5714c34685f1e84af376604c8123bcffca829686 100644
--- a/content/test/data/media/image_capture_test.html
+++ b/content/test/data/media/image_capture_test.html
@@ -7,24 +7,34 @@
<script type="text/javascript" src="webrtc_test_utilities.js"></script>
<script>
-// Runs an ImageCapture.getPhotoCapabilities().
-function testCreateAndGetCapabilities() {
- var hasVideoInputDevice = false;
- navigator.mediaDevices.enumerateDevices()
- .then(devices => {
- devices.forEach(function(device) {
- if (device.kind === "videoinput")
- hasVideoInputDevice = true;
+// Returns a Promise that is resolved if there is at least one video device or
+// rejected otherwise.
+function checkForVideoDevices() {
+ return new Promise((resolve, reject) => {
+ navigator.mediaDevices.enumerateDevices()
+ .then(devices => {
+ devices.forEach(function(device) {
+ if (device.kind === "videoinput")
+ return resolve();
+ });
+ return reject(new Error('no video devices'));
+ })
+ .catch(err => {
+ return reject(new Error('enumerating devices: ' + err.toString()));
});
+ });
+}
- if (!hasVideoInputDevice)
- return Promise.reject("no video devices");
- })
+// Runs an ImageCapture.getPhotoCapabilities().
+function testCreateAndGetCapabilities() {
+ checkForVideoDevices()
.catch(err => {
- return failTest('Error enumerating devices: ' + err.toString());
- });
-
- navigator.mediaDevices.getUserMedia({"video" : true})
+ console.log('no video devices found, skipping test');
+ reportTestSuccess();
+ })
+ .then(() => {
+ return navigator.mediaDevices.getUserMedia({"video" : true});
+ })
.then(stream => {
assertEquals('video', stream.getVideoTracks()[0].kind);
return new ImageCapture(stream.getVideoTracks()[0]);
@@ -50,6 +60,34 @@ function testCreateAndGetCapabilities() {
});
}
+// Runs an ImageCapture.takePhoto().
+function testCreateAndTakePhoto() {
+ checkForVideoDevices()
+ .catch(err => {
+ console.log('no video devices found, skipping test');
+ reportTestSuccess();
+ })
+ .then(() => {
+ return navigator.mediaDevices.getUserMedia({"video" : true});
+ })
+ .then(stream => {
+ assertEquals('video', stream.getVideoTracks()[0].kind);
+ return new ImageCapture(stream.getVideoTracks()[0]);
+ })
+ .then(capturer => {
+ return capturer.takePhoto();
+ })
+ .then(blob => {
+ assertTrue(blob.type != undefined);
+ assertNotEquals(0, blob.size);
+
emircan 2016/08/03 21:55:54 Remove empty line.
mcasas 2016/08/03 22:19:36 Done.
+ reportTestSuccess();
+ })
+ .catch(err => {
+ return failTest(err.toString());
+ });
+}
+
</script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698