diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 42c12dc6cb74..4bcefb1cf772 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -291458,6 +291458,11 @@ {} ] ], + "mediacapture-image/resources/imagecapture-helpers.js": [ + [ + {} + ] + ], "mediacapture-record/META.yml": [ [ {} @@ -295908,6 +295913,21 @@ {} ] ], + "resources/chromium/image_capture-mojom.js.headers": [ + [ + {} + ] + ], + "resources/chromium/image_capture.mojom.js": [ + [ + {} + ] + ], + "resources/chromium/mock-imagecapture.js": [ + [ + {} + ] + ], "resources/chromium/mojo_bindings.js": [ [ {} @@ -368296,12 +368316,120 @@ {} ] ], + "mediacapture-image/ImageCapture-MediaTrackSupportedConstraints.html": [ + [ + "/mediacapture-image/ImageCapture-MediaTrackSupportedConstraints.html", + {} + ] + ], + "mediacapture-image/ImageCapture-creation.https.html": [ + [ + "/mediacapture-image/ImageCapture-creation.https.html", + {} + ] + ], + "mediacapture-image/ImageCapture-grabFrame.html": [ + [ + "/mediacapture-image/ImageCapture-grabFrame.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-applyConstraints-fast.html": [ + [ + "/mediacapture-image/MediaStreamTrack-applyConstraints-fast.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-applyConstraints-getSettings.html": [ + [ + "/mediacapture-image/MediaStreamTrack-applyConstraints-getSettings.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-applyConstraints-reject.html": [ + [ + "/mediacapture-image/MediaStreamTrack-applyConstraints-reject.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-applyConstraints.html": [ + [ + "/mediacapture-image/MediaStreamTrack-applyConstraints.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-getCapabilities-fast.html": [ + [ + "/mediacapture-image/MediaStreamTrack-getCapabilities-fast.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-getCapabilities.html": [ + [ + "/mediacapture-image/MediaStreamTrack-getCapabilities.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-getConstraints-fast.html": [ + [ + "/mediacapture-image/MediaStreamTrack-getConstraints-fast.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-getSettings-fast.html": [ + [ + "/mediacapture-image/MediaStreamTrack-getSettings-fast.html", + {} + ] + ], + "mediacapture-image/MediaStreamTrack-getSettings.html": [ + [ + "/mediacapture-image/MediaStreamTrack-getSettings.html", + {} + ] + ], + "mediacapture-image/detached-HTMLCanvasElement.html": [ + [ + "/mediacapture-image/detached-HTMLCanvasElement.html", + {} + ] + ], + "mediacapture-image/getPhotoCapabilities.html": [ + [ + "/mediacapture-image/getPhotoCapabilities.html", + {} + ] + ], + "mediacapture-image/getPhotoSettings.html": [ + [ + "/mediacapture-image/getPhotoSettings.html", + {} + ] + ], "mediacapture-image/idlharness.window.js": [ [ "/mediacapture-image/idlharness.window.html", {} ] ], + "mediacapture-image/setOptions-reject.html": [ + [ + "/mediacapture-image/setOptions-reject.html", + {} + ] + ], + "mediacapture-image/takePhoto-with-PhotoSettings.html": [ + [ + "/mediacapture-image/takePhoto-with-PhotoSettings.html", + {} + ] + ], + "mediacapture-image/takePhoto.html": [ + [ + "/mediacapture-image/takePhoto.html", + {} + ] + ], "mediacapture-record/BlobEvent-constructor.html": [ [ "/mediacapture-record/BlobEvent-constructor.html", @@ -611194,7 +611322,7 @@ "support" ], "lint.whitelist": [ - "92bb4b5bcc96e4ff84ce077c391ce7efa3952ee4", + "7d579b6b343a23e6c039f309f362354c5aa5ba62", "support" ], "longtask-timing/META.yml": [ @@ -612405,14 +612533,90 @@ "c58e63ff12acefc73fc3cfa2f35836778696c827", "testharness" ], + "mediacapture-image/ImageCapture-MediaTrackSupportedConstraints.html": [ + "aae75b7e8c91b76d163404d6cc319382606e4e2e", + "testharness" + ], + "mediacapture-image/ImageCapture-creation.https.html": [ + "9e8b5feeeb5cdf5686c36e3972fc9a1a8961de95", + "testharness" + ], + "mediacapture-image/ImageCapture-grabFrame.html": [ + "bf5e9400a038f2432ce1bee3a3b345f3c82e5ea5", + "testharness" + ], "mediacapture-image/META.yml": [ "1b4fef5e5a19ed3d7e61320bfa752a19da1f595a", "support" ], + "mediacapture-image/MediaStreamTrack-applyConstraints-fast.html": [ + "75ed17a9e3302b0cb2b388846ad73d55c6d9c166", + "testharness" + ], + "mediacapture-image/MediaStreamTrack-applyConstraints-getSettings.html": [ + "6241d599dc325d9b567eb6900c3daafaded92af3", + "testharness" + ], + "mediacapture-image/MediaStreamTrack-applyConstraints-reject.html": [ + "8f08d250fd1a569d84ecd4ce36fe5ffa29f583f7", + "testharness" + ], + "mediacapture-image/MediaStreamTrack-applyConstraints.html": [ + "431646eb53f030dce81f15a0130ea660142ce2ce", + "testharness" + ], + "mediacapture-image/MediaStreamTrack-getCapabilities-fast.html": [ + "55272d1499517a6fda0b7e06068928b4e1127b27", + "testharness" + ], + "mediacapture-image/MediaStreamTrack-getCapabilities.html": [ + "452b223a1b0bf3bad06d956e16b0eff22c8b6507", + "testharness" + ], + "mediacapture-image/MediaStreamTrack-getConstraints-fast.html": [ + "8cae4331318cb32c30e1c89339fdb37fee97a5db", + "testharness" + ], + "mediacapture-image/MediaStreamTrack-getSettings-fast.html": [ + "a4ecbe61181640f7f993f7f5c9cd3fd4e992f72c", + "testharness" + ], + "mediacapture-image/MediaStreamTrack-getSettings.html": [ + "04fbfbfb6137cf61ee6491e2bef5786f202b43e3", + "testharness" + ], + "mediacapture-image/detached-HTMLCanvasElement.html": [ + "e27950fc5edfea8357344f91198f0105775fef2c", + "testharness" + ], + "mediacapture-image/getPhotoCapabilities.html": [ + "83329fcac4ad37bea6dd13930103c2fd689a77fd", + "testharness" + ], + "mediacapture-image/getPhotoSettings.html": [ + "6a6184f17cb2f92c01d7bf784047ae17b1e8be66", + "testharness" + ], "mediacapture-image/idlharness.window.js": [ "9d8f7eefb84dcc16534f1311c3b3c3d68e84572d", "testharness" ], + "mediacapture-image/resources/imagecapture-helpers.js": [ + "6d5ffa1695d807a05edeb75a21d472856bdda252", + "support" + ], + "mediacapture-image/setOptions-reject.html": [ + "4deee97d7bc77859602aa25d51e547bd0290409b", + "testharness" + ], + "mediacapture-image/takePhoto-with-PhotoSettings.html": [ + "58708612456fc669c5a445b76ad110fcbb0bb27d", + "testharness" + ], + "mediacapture-image/takePhoto.html": [ + "49926db1cde6ee6b3e703e920e0812232eac0835", + "testharness" + ], "mediacapture-record/BlobEvent-constructor.html": [ "3bcf4296e68aea1a7b167e570c0dcec148cc95e4", "testharness" @@ -631185,6 +631389,18 @@ "6805c323df5a975231648b830e33ce183c3cbbd3", "support" ], + "resources/chromium/image_capture-mojom.js.headers": [ + "6c61a34a4ec2e75096db0eb9f7748b142f0db7bb", + "support" + ], + "resources/chromium/image_capture.mojom.js": [ + "1d01581e023e4655ec9d5c634aa9c8bbdf79d40b", + "support" + ], + "resources/chromium/mock-imagecapture.js": [ + "a700bc97b3e055a66c80aca7cac33cfac3a2334f", + "support" + ], "resources/chromium/mojo_bindings.js": [ "67d6a8828551c1f703ef29831592f2e4d8a42485", "support" diff --git a/testing/web-platform/tests/lint.whitelist b/testing/web-platform/tests/lint.whitelist index 92bb4b5bcc96..7d579b6b343a 100644 --- a/testing/web-platform/tests/lint.whitelist +++ b/testing/web-platform/tests/lint.whitelist @@ -265,6 +265,9 @@ GENERATE_TESTS: dom/traversal/TreeWalker.html GENERATE_TESTS: domparsing/createContextualFragment.html GENERATE_TESTS: domxpath/001.html GENERATE_TESTS: domxpath/002.html +GENERATE_TESTS: mediacapture-image/MediaStreamTrack-applyConstraints-reject.html +GENERATE_TESTS: mediacapture-image/MediaStreamTrack-getConstraints-fast.html +GENERATE_TESTS: mediacapture-image/setOptions-reject.html GENERATE_TESTS: html/semantics/scripting-1/the-template-element/template-element/template-as-a-descendant.html GENERATE_TESTS: html/syntax/parsing/Document.getElementsByTagName-foreign-01.html GENERATE_TESTS: html/syntax/parsing/template/clearing-the-stack-back-to-a-given-context/clearing-stack-back-to-a-table-body-context.html diff --git a/testing/web-platform/tests/mediacapture-image/ImageCapture-MediaTrackSupportedConstraints.html b/testing/web-platform/tests/mediacapture-image/ImageCapture-MediaTrackSupportedConstraints.html new file mode 100644 index 000000000000..aae75b7e8c91 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/ImageCapture-MediaTrackSupportedConstraints.html @@ -0,0 +1,25 @@ + + + + diff --git a/testing/web-platform/tests/mediacapture-image/ImageCapture-creation.https.html b/testing/web-platform/tests/mediacapture-image/ImageCapture-creation.https.html new file mode 100644 index 000000000000..9e8b5feeeb5c --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/ImageCapture-creation.https.html @@ -0,0 +1,76 @@ + + + + diff --git a/testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html b/testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html new file mode 100644 index 000000000000..bf5e9400a038 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html @@ -0,0 +1,46 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-fast.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-fast.html new file mode 100644 index 000000000000..75ed17a9e330 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-fast.html @@ -0,0 +1,85 @@ + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-getSettings.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-getSettings.html new file mode 100644 index 000000000000..6241d599dc32 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-getSettings.html @@ -0,0 +1,91 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-reject.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-reject.html new file mode 100644 index 000000000000..8f08d250fd1a --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints-reject.html @@ -0,0 +1,84 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints.html new file mode 100644 index 000000000000..431646eb53f0 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-applyConstraints.html @@ -0,0 +1,109 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getCapabilities-fast.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getCapabilities-fast.html new file mode 100644 index 000000000000..55272d149951 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getCapabilities-fast.html @@ -0,0 +1,29 @@ + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getCapabilities.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getCapabilities.html new file mode 100644 index 000000000000..452b223a1b0b --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getCapabilities.html @@ -0,0 +1,137 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getConstraints-fast.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getConstraints-fast.html new file mode 100644 index 000000000000..8cae4331318c --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getConstraints-fast.html @@ -0,0 +1,74 @@ + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getSettings-fast.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getSettings-fast.html new file mode 100644 index 000000000000..a4ecbe611816 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getSettings-fast.html @@ -0,0 +1,29 @@ + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getSettings.html b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getSettings.html new file mode 100644 index 000000000000..04fbfbfb6137 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getSettings.html @@ -0,0 +1,67 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/detached-HTMLCanvasElement.html b/testing/web-platform/tests/mediacapture-image/detached-HTMLCanvasElement.html new file mode 100644 index 000000000000..e27950fc5edf --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/detached-HTMLCanvasElement.html @@ -0,0 +1,26 @@ + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/getPhotoCapabilities.html b/testing/web-platform/tests/mediacapture-image/getPhotoCapabilities.html new file mode 100644 index 000000000000..83329fcac4ad --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/getPhotoCapabilities.html @@ -0,0 +1,45 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/getPhotoSettings.html b/testing/web-platform/tests/mediacapture-image/getPhotoSettings.html new file mode 100644 index 000000000000..6a6184f17cb2 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/getPhotoSettings.html @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/resources/imagecapture-helpers.js b/testing/web-platform/tests/mediacapture-image/resources/imagecapture-helpers.js new file mode 100644 index 000000000000..6d5ffa1695d8 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/resources/imagecapture-helpers.js @@ -0,0 +1,69 @@ +'use strict'; + +// These tests rely on the User Agent providing an implementation of +// platform image capture backends. +// +// In Chromium-based browsers this implementation is provided by a polyfill +// in order to reduce the amount of test-only code shipped to users. To enable +// these tests the browser must be run with these options: +// +// --enable-blink-features=MojoJS,MojoJSTest + +let loadChromiumResources = Promise.resolve().then(() => { + if (!MojoInterfaceInterceptor) { + // Do nothing on non-Chromium-based browsers or when the Mojo bindings are + // not present in the global namespace. + return; + } + + let chain = Promise.resolve(); + [ + '/resources/chromium/mojo_bindings.js', + '/resources/chromium/image_capture.mojom.js', + '/resources/chromium/mock-imagecapture.js', + ].forEach(path => { + // Use importScripts for workers. + if (typeof document === 'undefined') { + chain = chain.then(() => importScripts(path)); + return; + } + let script = document.createElement('script'); + script.src = path; + script.async = false; + chain = chain.then(() => new Promise(resolve => { + script.onload = () => resolve(); + })); + document.head.appendChild(script); + }); + + return chain; +}); + +async function initialize_image_capture_tests() { + if (typeof ImageCaptureTest === 'undefined') { + await loadChromiumResources; + } + assert_true(typeof ImageCaptureTest !== 'undefined'); + let imageCaptureTest = new ImageCaptureTest(); + await imageCaptureTest.initialize(); + return imageCaptureTest; +} + +function image_capture_test(func, name, properties) { + promise_test(async (t) => { + let imageCaptureTest = await initialize_image_capture_tests(); + try { + await func(t, imageCaptureTest); + } finally { + await imageCaptureTest.reset(); + }; + }, name, properties); +} + +function assert_point2d_array_approx_equals(actual, expected, epsilon) { + assert_equals(actual.length, expected.length, 'length'); + for (var i = 0; i < actual.length; ++i) { + assert_approx_equals(actual[i].x, expected[i].x, epsilon, 'x'); + assert_approx_equals(actual[i].y, expected[i].y, epsilon, 'y'); + } +} diff --git a/testing/web-platform/tests/mediacapture-image/setOptions-reject.html b/testing/web-platform/tests/mediacapture-image/setOptions-reject.html new file mode 100644 index 000000000000..4deee97d7bc7 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/setOptions-reject.html @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/takePhoto-with-PhotoSettings.html b/testing/web-platform/tests/mediacapture-image/takePhoto-with-PhotoSettings.html new file mode 100644 index 000000000000..58708612456f --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/takePhoto-with-PhotoSettings.html @@ -0,0 +1,63 @@ + + + + + + + + diff --git a/testing/web-platform/tests/mediacapture-image/takePhoto.html b/testing/web-platform/tests/mediacapture-image/takePhoto.html new file mode 100644 index 000000000000..49926db1cde6 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-image/takePhoto.html @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/testing/web-platform/tests/resources/chromium/image_capture-mojom.js.headers b/testing/web-platform/tests/resources/chromium/image_capture-mojom.js.headers new file mode 100644 index 000000000000..6c61a34a4ec2 --- /dev/null +++ b/testing/web-platform/tests/resources/chromium/image_capture-mojom.js.headers @@ -0,0 +1 @@ +Content-Type: text/javascript; charset=utf-8 \ No newline at end of file diff --git a/testing/web-platform/tests/resources/chromium/image_capture.mojom.js b/testing/web-platform/tests/resources/chromium/image_capture.mojom.js new file mode 100644 index 000000000000..1d01581e023e --- /dev/null +++ b/testing/web-platform/tests/resources/chromium/image_capture.mojom.js @@ -0,0 +1,1329 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +'use strict'; + +(function() { + var mojomId = 'media/capture/mojom/image_capture.mojom'; + if (mojo.internal.isMojomLoaded(mojomId)) { + console.warn('The following mojom is loaded multiple times: ' + mojomId); + return; + } + mojo.internal.markMojomLoaded(mojomId); + var bindings = mojo; + var associatedBindings = mojo; + var codec = mojo.internal; + var validator = mojo.internal; + + var exports = mojo.internal.exposeNamespace('media.mojom'); + + + var MeteringMode = {}; + MeteringMode.NONE = 0; + MeteringMode.MANUAL = MeteringMode.NONE + 1; + MeteringMode.SINGLE_SHOT = MeteringMode.MANUAL + 1; + MeteringMode.CONTINUOUS = MeteringMode.SINGLE_SHOT + 1; + + MeteringMode.isKnownEnumValue = function(value) { + switch (value) { + case 0: + case 1: + case 2: + case 3: + return true; + } + return false; + }; + + MeteringMode.validate = function(enumValue) { + var isExtensible = false; + if (isExtensible || this.isKnownEnumValue(enumValue)) + return validator.validationError.NONE; + + return validator.validationError.UNKNOWN_ENUM_VALUE; + }; + var RedEyeReduction = {}; + RedEyeReduction.NEVER = 0; + RedEyeReduction.ALWAYS = RedEyeReduction.NEVER + 1; + RedEyeReduction.CONTROLLABLE = RedEyeReduction.ALWAYS + 1; + + RedEyeReduction.isKnownEnumValue = function(value) { + switch (value) { + case 0: + case 1: + case 2: + return true; + } + return false; + }; + + RedEyeReduction.validate = function(enumValue) { + var isExtensible = false; + if (isExtensible || this.isKnownEnumValue(enumValue)) + return validator.validationError.NONE; + + return validator.validationError.UNKNOWN_ENUM_VALUE; + }; + var FillLightMode = {}; + FillLightMode.OFF = 0; + FillLightMode.AUTO = FillLightMode.OFF + 1; + FillLightMode.FLASH = FillLightMode.AUTO + 1; + + FillLightMode.isKnownEnumValue = function(value) { + switch (value) { + case 0: + case 1: + case 2: + return true; + } + return false; + }; + + FillLightMode.validate = function(enumValue) { + var isExtensible = false; + if (isExtensible || this.isKnownEnumValue(enumValue)) + return validator.validationError.NONE; + + return validator.validationError.UNKNOWN_ENUM_VALUE; + }; + + function Range(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + Range.prototype.initDefaults_ = function() { + this.max = 0; + this.min = 0; + this.current = 0; + this.step = 0; + }; + Range.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + Range.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 40} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + + + + return validator.validationError.NONE; + }; + + Range.encodedSize = codec.kStructHeaderSize + 32; + + Range.decode = function(decoder) { + var packed; + var val = new Range(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.max = decoder.decodeStruct(codec.Double); + val.min = decoder.decodeStruct(codec.Double); + val.current = decoder.decodeStruct(codec.Double); + val.step = decoder.decodeStruct(codec.Double); + return val; + }; + + Range.encode = function(encoder, val) { + var packed; + encoder.writeUint32(Range.encodedSize); + encoder.writeUint32(0); + encoder.encodeStruct(codec.Double, val.max); + encoder.encodeStruct(codec.Double, val.min); + encoder.encodeStruct(codec.Double, val.current); + encoder.encodeStruct(codec.Double, val.step); + }; + function PhotoState(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + PhotoState.prototype.initDefaults_ = function() { + this.supportedWhiteBalanceModes = null; + this.currentWhiteBalanceMode = 0; + this.currentExposureMode = 0; + this.supportedExposureModes = null; + this.supportedFocusModes = null; + this.currentFocusMode = 0; + this.supportsTorch = false; + this.torch = false; + this.pointsOfInterest = null; + this.exposureCompensation = null; + this.colorTemperature = null; + this.iso = null; + this.brightness = null; + this.contrast = null; + this.saturation = null; + this.sharpness = null; + this.zoom = null; + this.redEyeReduction = 0; + this.height = null; + this.width = null; + this.fillLightMode = null; + }; + PhotoState.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + PhotoState.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 152} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.supportedWhiteBalanceModes + err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize + 0, 4, new codec.Enum(MeteringMode), false, [0], 0); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.currentWhiteBalanceMode + err = messageValidator.validateEnum(offset + codec.kStructHeaderSize + 8, MeteringMode); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.supportedExposureModes + err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize + 16, 4, new codec.Enum(MeteringMode), false, [0], 0); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.currentExposureMode + err = messageValidator.validateEnum(offset + codec.kStructHeaderSize + 12, MeteringMode); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.supportedFocusModes + err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize + 24, 4, new codec.Enum(MeteringMode), false, [0], 0); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.currentFocusMode + err = messageValidator.validateEnum(offset + codec.kStructHeaderSize + 32, MeteringMode); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.pointsOfInterest + err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize + 40, 8, new codec.PointerTo(Point2D), false, [0], 0); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.exposureCompensation + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 48, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.colorTemperature + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 56, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.iso + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 64, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.brightness + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 72, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.contrast + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 80, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.saturation + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 88, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.sharpness + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 96, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.zoom + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 104, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + + + // validate PhotoState.redEyeReduction + err = messageValidator.validateEnum(offset + codec.kStructHeaderSize + 112, RedEyeReduction); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.height + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 120, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.width + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 128, Range, false); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoState.fillLightMode + err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize + 136, 4, new codec.Enum(FillLightMode), false, [0], 0); + if (err !== validator.validationError.NONE) + return err; + + return validator.validationError.NONE; + }; + + PhotoState.encodedSize = codec.kStructHeaderSize + 144; + + PhotoState.decode = function(decoder) { + var packed; + var val = new PhotoState(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.supportedWhiteBalanceModes = decoder.decodeArrayPointer(new codec.Enum(MeteringMode)); + val.currentWhiteBalanceMode = decoder.decodeStruct(codec.Int32); + val.currentExposureMode = decoder.decodeStruct(codec.Int32); + val.supportedExposureModes = decoder.decodeArrayPointer(new codec.Enum(MeteringMode)); + val.supportedFocusModes = decoder.decodeArrayPointer(new codec.Enum(MeteringMode)); + val.currentFocusMode = decoder.decodeStruct(codec.Int32); + packed = decoder.readUint8(); + val.supportsTorch = (packed >> 0) & 1 ? true : false; + val.torch = (packed >> 1) & 1 ? true : false; + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + val.pointsOfInterest = decoder.decodeArrayPointer(new codec.PointerTo(Point2D)); + val.exposureCompensation = decoder.decodeStructPointer(Range); + val.colorTemperature = decoder.decodeStructPointer(Range); + val.iso = decoder.decodeStructPointer(Range); + val.brightness = decoder.decodeStructPointer(Range); + val.contrast = decoder.decodeStructPointer(Range); + val.saturation = decoder.decodeStructPointer(Range); + val.sharpness = decoder.decodeStructPointer(Range); + val.zoom = decoder.decodeStructPointer(Range); + val.redEyeReduction = decoder.decodeStruct(codec.Int32); + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + val.height = decoder.decodeStructPointer(Range); + val.width = decoder.decodeStructPointer(Range); + val.fillLightMode = decoder.decodeArrayPointer(new codec.Enum(FillLightMode)); + return val; + }; + + PhotoState.encode = function(encoder, val) { + var packed; + encoder.writeUint32(PhotoState.encodedSize); + encoder.writeUint32(0); + encoder.encodeArrayPointer(new codec.Enum(MeteringMode), val.supportedWhiteBalanceModes); + encoder.encodeStruct(codec.Int32, val.currentWhiteBalanceMode); + encoder.encodeStruct(codec.Int32, val.currentExposureMode); + encoder.encodeArrayPointer(new codec.Enum(MeteringMode), val.supportedExposureModes); + encoder.encodeArrayPointer(new codec.Enum(MeteringMode), val.supportedFocusModes); + encoder.encodeStruct(codec.Int32, val.currentFocusMode); + packed = 0; + packed |= (val.supportsTorch & 1) << 0 + packed |= (val.torch & 1) << 1 + encoder.writeUint8(packed); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.encodeArrayPointer(new codec.PointerTo(Point2D), val.pointsOfInterest); + encoder.encodeStructPointer(Range, val.exposureCompensation); + encoder.encodeStructPointer(Range, val.colorTemperature); + encoder.encodeStructPointer(Range, val.iso); + encoder.encodeStructPointer(Range, val.brightness); + encoder.encodeStructPointer(Range, val.contrast); + encoder.encodeStructPointer(Range, val.saturation); + encoder.encodeStructPointer(Range, val.sharpness); + encoder.encodeStructPointer(Range, val.zoom); + encoder.encodeStruct(codec.Int32, val.redEyeReduction); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.encodeStructPointer(Range, val.height); + encoder.encodeStructPointer(Range, val.width); + encoder.encodeArrayPointer(new codec.Enum(FillLightMode), val.fillLightMode); + }; + function Point2D(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + Point2D.prototype.initDefaults_ = function() { + this.x = 0; + this.y = 0; + }; + Point2D.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + Point2D.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 16} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + + return validator.validationError.NONE; + }; + + Point2D.encodedSize = codec.kStructHeaderSize + 8; + + Point2D.decode = function(decoder) { + var packed; + var val = new Point2D(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.x = decoder.decodeStruct(codec.Float); + val.y = decoder.decodeStruct(codec.Float); + return val; + }; + + Point2D.encode = function(encoder, val) { + var packed; + encoder.writeUint32(Point2D.encodedSize); + encoder.writeUint32(0); + encoder.encodeStruct(codec.Float, val.x); + encoder.encodeStruct(codec.Float, val.y); + }; + function PhotoSettings(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + PhotoSettings.prototype.initDefaults_ = function() { + this.hasWhiteBalanceMode = false; + this.hasExposureMode = false; + this.hasFocusMode = false; + this.hasExposureCompensation = false; + this.hasColorTemperature = false; + this.hasIso = false; + this.hasBrightness = false; + this.hasContrast = false; + this.hasSaturation = false; + this.hasSharpness = false; + this.hasZoom = false; + this.hasTorch = false; + this.torch = false; + this.hasFillLightMode = false; + this.hasWidth = false; + this.hasHeight = false; + this.hasRedEyeReduction = false; + this.redEyeReduction = false; + this.whiteBalanceMode = 0; + this.exposureMode = 0; + this.focusMode = 0; + this.pointsOfInterest = null; + this.exposureCompensation = 0; + this.colorTemperature = 0; + this.iso = 0; + this.brightness = 0; + this.contrast = 0; + this.saturation = 0; + this.sharpness = 0; + this.zoom = 0; + this.fillLightMode = 0; + this.width = 0; + this.height = 0; + }; + PhotoSettings.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + PhotoSettings.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 120} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + + // validate PhotoSettings.whiteBalanceMode + err = messageValidator.validateEnum(offset + codec.kStructHeaderSize + 4, MeteringMode); + if (err !== validator.validationError.NONE) + return err; + + + + // validate PhotoSettings.exposureMode + err = messageValidator.validateEnum(offset + codec.kStructHeaderSize + 8, MeteringMode); + if (err !== validator.validationError.NONE) + return err; + + + + // validate PhotoSettings.focusMode + err = messageValidator.validateEnum(offset + codec.kStructHeaderSize + 12, MeteringMode); + if (err !== validator.validationError.NONE) + return err; + + + // validate PhotoSettings.pointsOfInterest + err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize + 16, 8, new codec.PointerTo(Point2D), false, [0], 0); + if (err !== validator.validationError.NONE) + return err; + + + + + + + + + + + + + + + + + + + + + + // validate PhotoSettings.fillLightMode + err = messageValidator.validateEnum(offset + codec.kStructHeaderSize + 88, FillLightMode); + if (err !== validator.validationError.NONE) + return err; + + + + + + + + return validator.validationError.NONE; + }; + + PhotoSettings.encodedSize = codec.kStructHeaderSize + 112; + + PhotoSettings.decode = function(decoder) { + var packed; + var val = new PhotoSettings(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + packed = decoder.readUint8(); + val.hasWhiteBalanceMode = (packed >> 0) & 1 ? true : false; + val.hasExposureMode = (packed >> 1) & 1 ? true : false; + val.hasFocusMode = (packed >> 2) & 1 ? true : false; + val.hasExposureCompensation = (packed >> 3) & 1 ? true : false; + val.hasColorTemperature = (packed >> 4) & 1 ? true : false; + val.hasIso = (packed >> 5) & 1 ? true : false; + val.hasBrightness = (packed >> 6) & 1 ? true : false; + val.hasContrast = (packed >> 7) & 1 ? true : false; + packed = decoder.readUint8(); + val.hasSaturation = (packed >> 0) & 1 ? true : false; + val.hasSharpness = (packed >> 1) & 1 ? true : false; + val.hasZoom = (packed >> 2) & 1 ? true : false; + val.hasTorch = (packed >> 3) & 1 ? true : false; + val.torch = (packed >> 4) & 1 ? true : false; + val.hasFillLightMode = (packed >> 5) & 1 ? true : false; + val.hasWidth = (packed >> 6) & 1 ? true : false; + val.hasHeight = (packed >> 7) & 1 ? true : false; + packed = decoder.readUint8(); + val.hasRedEyeReduction = (packed >> 0) & 1 ? true : false; + val.redEyeReduction = (packed >> 1) & 1 ? true : false; + decoder.skip(1); + val.whiteBalanceMode = decoder.decodeStruct(codec.Int32); + val.exposureMode = decoder.decodeStruct(codec.Int32); + val.focusMode = decoder.decodeStruct(codec.Int32); + val.pointsOfInterest = decoder.decodeArrayPointer(new codec.PointerTo(Point2D)); + val.exposureCompensation = decoder.decodeStruct(codec.Double); + val.colorTemperature = decoder.decodeStruct(codec.Double); + val.iso = decoder.decodeStruct(codec.Double); + val.brightness = decoder.decodeStruct(codec.Double); + val.contrast = decoder.decodeStruct(codec.Double); + val.saturation = decoder.decodeStruct(codec.Double); + val.sharpness = decoder.decodeStruct(codec.Double); + val.zoom = decoder.decodeStruct(codec.Double); + val.fillLightMode = decoder.decodeStruct(codec.Int32); + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + val.width = decoder.decodeStruct(codec.Double); + val.height = decoder.decodeStruct(codec.Double); + return val; + }; + + PhotoSettings.encode = function(encoder, val) { + var packed; + encoder.writeUint32(PhotoSettings.encodedSize); + encoder.writeUint32(0); + packed = 0; + packed |= (val.hasWhiteBalanceMode & 1) << 0 + packed |= (val.hasExposureMode & 1) << 1 + packed |= (val.hasFocusMode & 1) << 2 + packed |= (val.hasExposureCompensation & 1) << 3 + packed |= (val.hasColorTemperature & 1) << 4 + packed |= (val.hasIso & 1) << 5 + packed |= (val.hasBrightness & 1) << 6 + packed |= (val.hasContrast & 1) << 7 + encoder.writeUint8(packed); + packed = 0; + packed |= (val.hasSaturation & 1) << 0 + packed |= (val.hasSharpness & 1) << 1 + packed |= (val.hasZoom & 1) << 2 + packed |= (val.hasTorch & 1) << 3 + packed |= (val.torch & 1) << 4 + packed |= (val.hasFillLightMode & 1) << 5 + packed |= (val.hasWidth & 1) << 6 + packed |= (val.hasHeight & 1) << 7 + encoder.writeUint8(packed); + packed = 0; + packed |= (val.hasRedEyeReduction & 1) << 0 + packed |= (val.redEyeReduction & 1) << 1 + encoder.writeUint8(packed); + encoder.skip(1); + encoder.encodeStruct(codec.Int32, val.whiteBalanceMode); + encoder.encodeStruct(codec.Int32, val.exposureMode); + encoder.encodeStruct(codec.Int32, val.focusMode); + encoder.encodeArrayPointer(new codec.PointerTo(Point2D), val.pointsOfInterest); + encoder.encodeStruct(codec.Double, val.exposureCompensation); + encoder.encodeStruct(codec.Double, val.colorTemperature); + encoder.encodeStruct(codec.Double, val.iso); + encoder.encodeStruct(codec.Double, val.brightness); + encoder.encodeStruct(codec.Double, val.contrast); + encoder.encodeStruct(codec.Double, val.saturation); + encoder.encodeStruct(codec.Double, val.sharpness); + encoder.encodeStruct(codec.Double, val.zoom); + encoder.encodeStruct(codec.Int32, val.fillLightMode); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.encodeStruct(codec.Double, val.width); + encoder.encodeStruct(codec.Double, val.height); + }; + function Blob(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + Blob.prototype.initDefaults_ = function() { + this.mimeType = null; + this.data = null; + }; + Blob.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + Blob.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 24} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + // validate Blob.mimeType + err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 0, false) + if (err !== validator.validationError.NONE) + return err; + + + // validate Blob.data + err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize + 8, 1, codec.Uint8, false, [0], 0); + if (err !== validator.validationError.NONE) + return err; + + return validator.validationError.NONE; + }; + + Blob.encodedSize = codec.kStructHeaderSize + 16; + + Blob.decode = function(decoder) { + var packed; + var val = new Blob(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.mimeType = decoder.decodeStruct(codec.String); + val.data = decoder.decodeArrayPointer(codec.Uint8); + return val; + }; + + Blob.encode = function(encoder, val) { + var packed; + encoder.writeUint32(Blob.encodedSize); + encoder.writeUint32(0); + encoder.encodeStruct(codec.String, val.mimeType); + encoder.encodeArrayPointer(codec.Uint8, val.data); + }; + function ImageCapture_GetPhotoState_Params(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + ImageCapture_GetPhotoState_Params.prototype.initDefaults_ = function() { + this.sourceId = null; + }; + ImageCapture_GetPhotoState_Params.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + ImageCapture_GetPhotoState_Params.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 16} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + // validate ImageCapture_GetPhotoState_Params.sourceId + err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 0, false) + if (err !== validator.validationError.NONE) + return err; + + return validator.validationError.NONE; + }; + + ImageCapture_GetPhotoState_Params.encodedSize = codec.kStructHeaderSize + 8; + + ImageCapture_GetPhotoState_Params.decode = function(decoder) { + var packed; + var val = new ImageCapture_GetPhotoState_Params(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.sourceId = decoder.decodeStruct(codec.String); + return val; + }; + + ImageCapture_GetPhotoState_Params.encode = function(encoder, val) { + var packed; + encoder.writeUint32(ImageCapture_GetPhotoState_Params.encodedSize); + encoder.writeUint32(0); + encoder.encodeStruct(codec.String, val.sourceId); + }; + function ImageCapture_GetPhotoState_ResponseParams(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + ImageCapture_GetPhotoState_ResponseParams.prototype.initDefaults_ = function() { + this.state = null; + }; + ImageCapture_GetPhotoState_ResponseParams.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + ImageCapture_GetPhotoState_ResponseParams.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 16} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + // validate ImageCapture_GetPhotoState_ResponseParams.state + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 0, PhotoState, false); + if (err !== validator.validationError.NONE) + return err; + + return validator.validationError.NONE; + }; + + ImageCapture_GetPhotoState_ResponseParams.encodedSize = codec.kStructHeaderSize + 8; + + ImageCapture_GetPhotoState_ResponseParams.decode = function(decoder) { + var packed; + var val = new ImageCapture_GetPhotoState_ResponseParams(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.state = decoder.decodeStructPointer(PhotoState); + return val; + }; + + ImageCapture_GetPhotoState_ResponseParams.encode = function(encoder, val) { + var packed; + encoder.writeUint32(ImageCapture_GetPhotoState_ResponseParams.encodedSize); + encoder.writeUint32(0); + encoder.encodeStructPointer(PhotoState, val.state); + }; + function ImageCapture_SetOptions_Params(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + ImageCapture_SetOptions_Params.prototype.initDefaults_ = function() { + this.sourceId = null; + this.settings = null; + }; + ImageCapture_SetOptions_Params.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + ImageCapture_SetOptions_Params.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 24} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + // validate ImageCapture_SetOptions_Params.sourceId + err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 0, false) + if (err !== validator.validationError.NONE) + return err; + + + // validate ImageCapture_SetOptions_Params.settings + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 8, PhotoSettings, false); + if (err !== validator.validationError.NONE) + return err; + + return validator.validationError.NONE; + }; + + ImageCapture_SetOptions_Params.encodedSize = codec.kStructHeaderSize + 16; + + ImageCapture_SetOptions_Params.decode = function(decoder) { + var packed; + var val = new ImageCapture_SetOptions_Params(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.sourceId = decoder.decodeStruct(codec.String); + val.settings = decoder.decodeStructPointer(PhotoSettings); + return val; + }; + + ImageCapture_SetOptions_Params.encode = function(encoder, val) { + var packed; + encoder.writeUint32(ImageCapture_SetOptions_Params.encodedSize); + encoder.writeUint32(0); + encoder.encodeStruct(codec.String, val.sourceId); + encoder.encodeStructPointer(PhotoSettings, val.settings); + }; + function ImageCapture_SetOptions_ResponseParams(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + ImageCapture_SetOptions_ResponseParams.prototype.initDefaults_ = function() { + this.success = false; + }; + ImageCapture_SetOptions_ResponseParams.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + ImageCapture_SetOptions_ResponseParams.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 16} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + return validator.validationError.NONE; + }; + + ImageCapture_SetOptions_ResponseParams.encodedSize = codec.kStructHeaderSize + 8; + + ImageCapture_SetOptions_ResponseParams.decode = function(decoder) { + var packed; + var val = new ImageCapture_SetOptions_ResponseParams(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + packed = decoder.readUint8(); + val.success = (packed >> 0) & 1 ? true : false; + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + decoder.skip(1); + return val; + }; + + ImageCapture_SetOptions_ResponseParams.encode = function(encoder, val) { + var packed; + encoder.writeUint32(ImageCapture_SetOptions_ResponseParams.encodedSize); + encoder.writeUint32(0); + packed = 0; + packed |= (val.success & 1) << 0 + encoder.writeUint8(packed); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + encoder.skip(1); + }; + function ImageCapture_TakePhoto_Params(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + ImageCapture_TakePhoto_Params.prototype.initDefaults_ = function() { + this.sourceId = null; + }; + ImageCapture_TakePhoto_Params.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + ImageCapture_TakePhoto_Params.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 16} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + // validate ImageCapture_TakePhoto_Params.sourceId + err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 0, false) + if (err !== validator.validationError.NONE) + return err; + + return validator.validationError.NONE; + }; + + ImageCapture_TakePhoto_Params.encodedSize = codec.kStructHeaderSize + 8; + + ImageCapture_TakePhoto_Params.decode = function(decoder) { + var packed; + var val = new ImageCapture_TakePhoto_Params(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.sourceId = decoder.decodeStruct(codec.String); + return val; + }; + + ImageCapture_TakePhoto_Params.encode = function(encoder, val) { + var packed; + encoder.writeUint32(ImageCapture_TakePhoto_Params.encodedSize); + encoder.writeUint32(0); + encoder.encodeStruct(codec.String, val.sourceId); + }; + function ImageCapture_TakePhoto_ResponseParams(values) { + this.initDefaults_(); + this.initFields_(values); + } + + + ImageCapture_TakePhoto_ResponseParams.prototype.initDefaults_ = function() { + this.blob = null; + }; + ImageCapture_TakePhoto_ResponseParams.prototype.initFields_ = function(fields) { + for(var field in fields) { + if (this.hasOwnProperty(field)) + this[field] = fields[field]; + } + }; + + ImageCapture_TakePhoto_ResponseParams.validate = function(messageValidator, offset) { + var err; + err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize); + if (err !== validator.validationError.NONE) + return err; + + var kVersionSizes = [ + {version: 0, numBytes: 16} + ]; + err = messageValidator.validateStructVersion(offset, kVersionSizes); + if (err !== validator.validationError.NONE) + return err; + + + // validate ImageCapture_TakePhoto_ResponseParams.blob + err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 0, Blob, false); + if (err !== validator.validationError.NONE) + return err; + + return validator.validationError.NONE; + }; + + ImageCapture_TakePhoto_ResponseParams.encodedSize = codec.kStructHeaderSize + 8; + + ImageCapture_TakePhoto_ResponseParams.decode = function(decoder) { + var packed; + var val = new ImageCapture_TakePhoto_ResponseParams(); + var numberOfBytes = decoder.readUint32(); + var version = decoder.readUint32(); + val.blob = decoder.decodeStructPointer(Blob); + return val; + }; + + ImageCapture_TakePhoto_ResponseParams.encode = function(encoder, val) { + var packed; + encoder.writeUint32(ImageCapture_TakePhoto_ResponseParams.encodedSize); + encoder.writeUint32(0); + encoder.encodeStructPointer(Blob, val.blob); + }; + var kImageCapture_GetPhotoState_Name = 0; + var kImageCapture_SetOptions_Name = 1; + var kImageCapture_TakePhoto_Name = 2; + + function ImageCapturePtr(handleOrPtrInfo) { + this.ptr = new bindings.InterfacePtrController(ImageCapture, + handleOrPtrInfo); + } + + function ImageCaptureAssociatedPtr(associatedInterfacePtrInfo) { + this.ptr = new associatedBindings.AssociatedInterfacePtrController( + ImageCapture, associatedInterfacePtrInfo); + } + + ImageCaptureAssociatedPtr.prototype = + Object.create(ImageCapturePtr.prototype); + ImageCaptureAssociatedPtr.prototype.constructor = + ImageCaptureAssociatedPtr; + + function ImageCaptureProxy(receiver) { + this.receiver_ = receiver; + } + ImageCapturePtr.prototype.getPhotoState = function() { + return ImageCaptureProxy.prototype.getPhotoState + .apply(this.ptr.getProxy(), arguments); + }; + + ImageCaptureProxy.prototype.getPhotoState = function(sourceId) { + var params_ = new ImageCapture_GetPhotoState_Params(); + params_.sourceId = sourceId; + return new Promise(function(resolve, reject) { + var builder = new codec.MessageV1Builder( + kImageCapture_GetPhotoState_Name, + codec.align(ImageCapture_GetPhotoState_Params.encodedSize), + codec.kMessageExpectsResponse, 0); + builder.encodeStruct(ImageCapture_GetPhotoState_Params, params_); + var message = builder.finish(); + this.receiver_.acceptAndExpectResponse(message).then(function(message) { + var reader = new codec.MessageReader(message); + var responseParams = + reader.decodeStruct(ImageCapture_GetPhotoState_ResponseParams); + resolve(responseParams); + }).catch(function(result) { + reject(Error("Connection error: " + result)); + }); + }.bind(this)); + }; + ImageCapturePtr.prototype.setOptions = function() { + return ImageCaptureProxy.prototype.setOptions + .apply(this.ptr.getProxy(), arguments); + }; + + ImageCaptureProxy.prototype.setOptions = function(sourceId, settings) { + var params_ = new ImageCapture_SetOptions_Params(); + params_.sourceId = sourceId; + params_.settings = settings; + return new Promise(function(resolve, reject) { + var builder = new codec.MessageV1Builder( + kImageCapture_SetOptions_Name, + codec.align(ImageCapture_SetOptions_Params.encodedSize), + codec.kMessageExpectsResponse, 0); + builder.encodeStruct(ImageCapture_SetOptions_Params, params_); + var message = builder.finish(); + this.receiver_.acceptAndExpectResponse(message).then(function(message) { + var reader = new codec.MessageReader(message); + var responseParams = + reader.decodeStruct(ImageCapture_SetOptions_ResponseParams); + resolve(responseParams); + }).catch(function(result) { + reject(Error("Connection error: " + result)); + }); + }.bind(this)); + }; + ImageCapturePtr.prototype.takePhoto = function() { + return ImageCaptureProxy.prototype.takePhoto + .apply(this.ptr.getProxy(), arguments); + }; + + ImageCaptureProxy.prototype.takePhoto = function(sourceId) { + var params_ = new ImageCapture_TakePhoto_Params(); + params_.sourceId = sourceId; + return new Promise(function(resolve, reject) { + var builder = new codec.MessageV1Builder( + kImageCapture_TakePhoto_Name, + codec.align(ImageCapture_TakePhoto_Params.encodedSize), + codec.kMessageExpectsResponse, 0); + builder.encodeStruct(ImageCapture_TakePhoto_Params, params_); + var message = builder.finish(); + this.receiver_.acceptAndExpectResponse(message).then(function(message) { + var reader = new codec.MessageReader(message); + var responseParams = + reader.decodeStruct(ImageCapture_TakePhoto_ResponseParams); + resolve(responseParams); + }).catch(function(result) { + reject(Error("Connection error: " + result)); + }); + }.bind(this)); + }; + + function ImageCaptureStub(delegate) { + this.delegate_ = delegate; + } + ImageCaptureStub.prototype.getPhotoState = function(sourceId) { + return this.delegate_ && this.delegate_.getPhotoState && this.delegate_.getPhotoState(sourceId); + } + ImageCaptureStub.prototype.setOptions = function(sourceId, settings) { + return this.delegate_ && this.delegate_.setOptions && this.delegate_.setOptions(sourceId, settings); + } + ImageCaptureStub.prototype.takePhoto = function(sourceId) { + return this.delegate_ && this.delegate_.takePhoto && this.delegate_.takePhoto(sourceId); + } + + ImageCaptureStub.prototype.accept = function(message) { + var reader = new codec.MessageReader(message); + switch (reader.messageName) { + default: + return false; + } + }; + + ImageCaptureStub.prototype.acceptWithResponder = + function(message, responder) { + var reader = new codec.MessageReader(message); + switch (reader.messageName) { + case kImageCapture_GetPhotoState_Name: + var params = reader.decodeStruct(ImageCapture_GetPhotoState_Params); + this.getPhotoState(params.sourceId).then(function(response) { + var responseParams = + new ImageCapture_GetPhotoState_ResponseParams(); + responseParams.state = response.state; + var builder = new codec.MessageV1Builder( + kImageCapture_GetPhotoState_Name, + codec.align(ImageCapture_GetPhotoState_ResponseParams.encodedSize), + codec.kMessageIsResponse, reader.requestID); + builder.encodeStruct(ImageCapture_GetPhotoState_ResponseParams, + responseParams); + var message = builder.finish(); + responder.accept(message); + }); + return true; + case kImageCapture_SetOptions_Name: + var params = reader.decodeStruct(ImageCapture_SetOptions_Params); + this.setOptions(params.sourceId, params.settings).then(function(response) { + var responseParams = + new ImageCapture_SetOptions_ResponseParams(); + responseParams.success = response.success; + var builder = new codec.MessageV1Builder( + kImageCapture_SetOptions_Name, + codec.align(ImageCapture_SetOptions_ResponseParams.encodedSize), + codec.kMessageIsResponse, reader.requestID); + builder.encodeStruct(ImageCapture_SetOptions_ResponseParams, + responseParams); + var message = builder.finish(); + responder.accept(message); + }); + return true; + case kImageCapture_TakePhoto_Name: + var params = reader.decodeStruct(ImageCapture_TakePhoto_Params); + this.takePhoto(params.sourceId).then(function(response) { + var responseParams = + new ImageCapture_TakePhoto_ResponseParams(); + responseParams.blob = response.blob; + var builder = new codec.MessageV1Builder( + kImageCapture_TakePhoto_Name, + codec.align(ImageCapture_TakePhoto_ResponseParams.encodedSize), + codec.kMessageIsResponse, reader.requestID); + builder.encodeStruct(ImageCapture_TakePhoto_ResponseParams, + responseParams); + var message = builder.finish(); + responder.accept(message); + }); + return true; + default: + return false; + } + }; + + function validateImageCaptureRequest(messageValidator) { + var message = messageValidator.message; + var paramsClass = null; + switch (message.getName()) { + case kImageCapture_GetPhotoState_Name: + if (message.expectsResponse()) + paramsClass = ImageCapture_GetPhotoState_Params; + break; + case kImageCapture_SetOptions_Name: + if (message.expectsResponse()) + paramsClass = ImageCapture_SetOptions_Params; + break; + case kImageCapture_TakePhoto_Name: + if (message.expectsResponse()) + paramsClass = ImageCapture_TakePhoto_Params; + break; + } + if (paramsClass === null) + return validator.validationError.NONE; + return paramsClass.validate(messageValidator, messageValidator.message.getHeaderNumBytes()); + } + + function validateImageCaptureResponse(messageValidator) { + var message = messageValidator.message; + var paramsClass = null; + switch (message.getName()) { + case kImageCapture_GetPhotoState_Name: + if (message.isResponse()) + paramsClass = ImageCapture_GetPhotoState_ResponseParams; + break; + case kImageCapture_SetOptions_Name: + if (message.isResponse()) + paramsClass = ImageCapture_SetOptions_ResponseParams; + break; + case kImageCapture_TakePhoto_Name: + if (message.isResponse()) + paramsClass = ImageCapture_TakePhoto_ResponseParams; + break; + } + if (paramsClass === null) + return validator.validationError.NONE; + return paramsClass.validate(messageValidator, messageValidator.message.getHeaderNumBytes()); + } + + var ImageCapture = { + name: 'media.mojom.ImageCapture', + kVersion: 0, + ptrClass: ImageCapturePtr, + proxyClass: ImageCaptureProxy, + stubClass: ImageCaptureStub, + validateRequest: validateImageCaptureRequest, + validateResponse: validateImageCaptureResponse, + }; + ImageCaptureStub.prototype.validator = validateImageCaptureRequest; + ImageCaptureProxy.prototype.validator = validateImageCaptureResponse; + exports.MeteringMode = MeteringMode; + exports.RedEyeReduction = RedEyeReduction; + exports.FillLightMode = FillLightMode; + exports.Range = Range; + exports.PhotoState = PhotoState; + exports.Point2D = Point2D; + exports.PhotoSettings = PhotoSettings; + exports.Blob = Blob; + exports.ImageCapture = ImageCapture; + exports.ImageCapturePtr = ImageCapturePtr; + exports.ImageCaptureAssociatedPtr = ImageCaptureAssociatedPtr; +})(); \ No newline at end of file diff --git a/testing/web-platform/tests/resources/chromium/mock-imagecapture.js b/testing/web-platform/tests/resources/chromium/mock-imagecapture.js new file mode 100644 index 000000000000..a700bc97b3e0 --- /dev/null +++ b/testing/web-platform/tests/resources/chromium/mock-imagecapture.js @@ -0,0 +1,227 @@ +"use strict"; + +var ImageCaptureTest = (() => { + // Class that mocks ImageCapture interface defined in + // https://cs.chromium.org/chromium/src/media/capture/mojom/image_capture.mojom + class MockImageCapture { + constructor() { + this.interceptor_ = new MojoInterfaceInterceptor( + media.mojom.ImageCapture.name); + this.interceptor_.oninterfacerequest = + e => this.bindingSet_.addBinding(this, e.handle); + this.interceptor_.start(); + + this.state_ = { + state: { + supportedWhiteBalanceModes: [ + media.mojom.MeteringMode.SINGLE_SHOT, + media.mojom.MeteringMode.CONTINUOUS + ], + currentWhiteBalanceMode: media.mojom.MeteringMode.CONTINUOUS, + supportedExposureModes: [ + media.mojom.MeteringMode.SINGLE_SHOT, + media.mojom.MeteringMode.CONTINUOUS + ], + currentExposureMode: media.mojom.MeteringMode.SINGLE_SHOT, + supportedFocusModes: [ + media.mojom.MeteringMode.MANUAL, + media.mojom.MeteringMode.SINGLE_SHOT + ], + currentFocusMode: media.mojom.MeteringMode.MANUAL, + pointsOfInterest: [{ + x: 0.4, + y: 0.6 + }], + + exposureCompensation: { + min: -200.0, + max: 200.0, + current: 33.0, + step: 33.0 + }, + colorTemperature: { + min: 2500.0, + max: 6500.0, + current: 6000.0, + step: 1000.0 + }, + iso: { + min: 100.0, + max: 12000.0, + current: 400.0, + step: 1.0 + }, + + brightness: { + min: 1.0, + max: 10.0, + current: 5.0, + step: 1.0 + }, + contrast: { + min: 2.0, + max: 9.0, + current: 5.0, + step: 1.0 + }, + saturation: { + min: 3.0, + max: 8.0, + current: 6.0, + step: 1.0 + }, + sharpness: { + min: 4.0, + max: 7.0, + current: 7.0, + step: 1.0 + }, + + zoom: { + min: 0.0, + max: 10.0, + current: 5.0, + step: 5.0 + }, + + supportsTorch: true, + torch: false, + + redEyeReduction: media.mojom.RedEyeReduction.CONTROLLABLE, + height: { + min: 240.0, + max: 2448.0, + current: 240.0, + step: 2.0 + }, + width: { + min: 320.0, + max: 3264.0, + current: 320.0, + step: 3.0 + }, + fillLightMode: [ + media.mojom.FillLightMode.AUTO, media.mojom.FillLightMode.FLASH + ], + } + }; + this.settings_ = null; + this.bindingSet_ = new mojo.BindingSet(media.mojom.ImageCapture); + } + + reset() { + this.bindingSet_.closeAllBindings(); + this.interceptor_.stop(); + } + + getPhotoState(source_id) { + return Promise.resolve(this.state_); + } + + setOptions(source_id, settings) { + this.settings_ = settings; + if (settings.hasIso) + this.state_.state.iso.current = settings.iso; + if (settings.hasHeight) + this.state_.state.height.current = settings.height; + if (settings.hasWidth) + this.state_.state.width.current = settings.width; + if (settings.hasZoom) + this.state_.state.zoom.current = settings.zoom; + if (settings.hasFocusMode) + this.state_.state.currentFocusMode = settings.focusMode; + + if (settings.pointsOfInterest.length > 0) { + this.state_.state.pointsOfInterest = + settings.pointsOfInterest; + } + + if (settings.hasExposureMode) + this.state_.state.currentExposureMode = settings.exposureMode; + + if (settings.hasExposureCompensation) { + this.state_.state.exposureCompensation.current = + settings.exposureCompensation; + } + if (settings.hasWhiteBalanceMode) { + this.state_.state.currentWhiteBalanceMode = + settings.whiteBalanceMode; + } + if (settings.hasFillLightMode) + this.state_.state.fillLightMode = [settings.fillLightMode]; + if (settings.hasRedEyeReduction) + this.state_.state.redEyeReduction = settings.redEyeReduction; + if (settings.hasColorTemperature) { + this.state_.state.colorTemperature.current = + settings.colorTemperature; + } + if (settings.hasBrightness) + this.state_.state.brightness.current = settings.brightness; + if (settings.hasContrast) + this.state_.state.contrast.current = settings.contrast; + if (settings.hasSaturation) + this.state_.state.saturation.current = settings.saturation; + if (settings.hasSharpness) + this.state_.state.sharpness.current = settings.sharpness; + + if (settings.hasTorch) + this.state_.state.torch = settings.torch; + + return Promise.resolve({ + success: true + }); + } + + takePhoto(source_id) { + return Promise.resolve({ + blob: { + mimeType: 'image/cat', + data: new Array(2) + } + }); + } + + state() { + return this.state_.state; + } + + options() { + return this.settings_; + } + } + + let testInternal = { + initialized: false, + mockImageCapture: null + } + + class ImageCaptureTestChromium { + + constructor() { + Object.freeze(this); // Make it immutable. + } + + initialize() { + if (testInternal.initialized) + throw new Error('Call reset() before initialize().'); + + testInternal.mockImageCapture = new MockImageCapture; + testInternal.initialized = true; + } + // Resets state of image capture mocks between test runs. + async reset() { + if (!testInternal.initialized) + throw new Error('Call initialize() before reset().'); + testInternal.mockImageCapture.reset(); + testInternal.mockImageCapture = null; + testInternal.initialized = false; + + await new Promise(resolve => setTimeout(resolve, 0)); + } + mockImageCapture() { + return testInternal.mockImageCapture; + } + } + + return ImageCaptureTestChromium; +})(); \ No newline at end of file