Bug 1482346 [wpt PR 12401] - Upstream image_capture tests to WPT, a=testonly

Automatic update from web-platform-testsUpstream image_capture tests to WPT

Moved the layout tests under third_party/WebKit/LayoutTests/imagecapture/ to
third_party/WebKit/LayoutTests/external/wpt/mediacapture-image/

Moved the layout tests under fast/imagecapture to wpt and suffixed some file names with
-fast.html to avoid name collision.
ImageCapture-creation.html was renamed to
ImageCapture-creation.https.html as it needed to be served over https

Moved third_party/WebKit/LayoutTests/imagecapture/resources/imagecapture-helpers.js to
third_party/WebKit/LayoutTests/external/wpt/mediacapture-image/resources/imagecapture-helpers.js
and extended it by adding a wrapper promise test, image_capture_test.

Copy the auto generated image_capture.mojom.js to wpt/resources/chromium/mock-imagecapture.js
used a flag called "scramble_message_ids = false" to the mojom compiler.

Used the testharness from wpt/

No new tests have been added.

BUG=706434

Cq-Include-Trybots: luci.chromium.try​:linux-blink-gen-property-trees;luci.chromium.try​:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I7de5b87b60396da841dda490da02bce800fcb793
Reviewed-on: https://chromium-review.googlesource.com/1165355
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Miguel Casas <mcasas@chromium.org>
Commit-Queue: Rijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Cr-Commit-Position: refs/heads/master@{#587144}

--

wpt-commits: ebd78777bf11e9764204ca293c8565c2e51bb1ab
wpt-pr: 12401
This commit is contained in:
Rijubrata Bhaumik 2018-09-04 18:33:25 +00:00 коммит произвёл moz-wptsync-bot
Родитель 03af923f9b
Коммит 29be14102b
24 изменённых файлов: 2942 добавлений и 1 удалений

Просмотреть файл

@ -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"

Просмотреть файл

@ -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

Просмотреть файл

@ -0,0 +1,25 @@
<!DOCTYPE HTML>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// Tests that getSupportedConstraints() returns what it should.
test(function() {
supported_constraints = navigator.mediaDevices.getSupportedConstraints();
assert_true(supported_constraints.whiteBalanceMode);
assert_true(supported_constraints.exposureMode);
assert_true(supported_constraints.focusMode);
assert_true(supported_constraints.pointsOfInterest);
assert_true(supported_constraints.exposureCompensation);
assert_true(supported_constraints.colorTemperature);
assert_true(supported_constraints.iso);
assert_true(supported_constraints.brightness);
assert_true(supported_constraints.contrast);
assert_true(supported_constraints.saturation);
assert_true(supported_constraints.sharpness);
assert_true(supported_constraints.zoom);
assert_true(supported_constraints.torch);
}, 'Image Capture supported constraints');
</script>

Просмотреть файл

@ -0,0 +1,76 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// This test verifies that ImageCapture can be created (or not) with different
// Media Stream Track types (audio, video).
function makeAsyncTest(modifyTrack, message) {
async_test(function(test) {
const gotStream = test.step_func(function(stream) {
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
var videoTrack = stream.getVideoTracks()[0];
assert_equals(videoTrack.readyState, 'live');
assert_true(videoTrack.enabled);
assert_false(videoTrack.muted);
var capturer = new ImageCapture(videoTrack);
assert_equals(capturer.track, videoTrack);
modifyTrack(videoTrack);
promise_rejects(test,
'InvalidStateError',
capturer.grabFrame(),
'Should throw InvalidStateError.')
.then(() => test.done());
});
const onError = test.unreached_func('Error creating MediaStream.');
navigator.mediaDevices.getUserMedia({video: true})
.then(gotStream)
.catch(onError);
}, message);
}
var disableTrack = function(videoTrack) {
// grabFrame() is rejected if the associated video track is disabled.
videoTrack.enabled = false;
};
var stopTrack = function(videoTrack) {
// grabFrame() is rejected if the associated video track is ended.
videoTrack.stop();
assert_equals(videoTrack.readyState, 'ended');
};
// Create the rejection tests. Note that grabFrame() would also be rejected if
// the video Track was muted but that's a read-only property of the Track.
makeAsyncTest(disableTrack, 'grabFrame() of a disabled Track');
makeAsyncTest(stopTrack, 'grabFrame() of an ended Track');
var testAudio = async_test(function() {
navigator.mediaDevices.getUserMedia({audio:true})
.then(
this.step_func(function(stream) {
assert_equals(stream.getAudioTracks().length, 1);
assert_equals(stream.getVideoTracks().length, 0);
assert_throws("NotSupportedError",
function() {
var capturer = new ImageCapture(stream.getAudioTracks()[0]);
},
'an ImageCapturer can only be created from a video track');
this.done();
}))
.catch(
this.unreached_func('Error creating MediaStream.'));
}, 'verifies that an ImageCapture cannot be created out of an Audio Track');
</script>

Просмотреть файл

@ -0,0 +1,46 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<canvas id='canvas0' width=10 height=10/>
<canvas id='canvas1' width=10 height=10/>
</body>
<script>
// This test verifies that ImageCapture can grabFrame()s.
var test = async_test(function() {
var canvas0 = document.getElementById('canvas0');
var context0 = canvas0.getContext("2d");
context0.fillStyle = "red";
context0.fillRect(0, 0, 10, 10);
var stream = canvas0.captureStream();
var capturer = new ImageCapture(stream.getVideoTracks()[0]);
capturer.grabFrame()
.then(bitmap => {
assert_equals(canvas0.width, bitmap.width);
assert_equals(canvas0.height, bitmap.height);
var context1 = document.getElementById('canvas1').getContext("2d");
context1.drawImage(bitmap, 0, 0);
var imageData0 = context0.getImageData(0, 0, 10, 10);
var imageData1 = context1.getImageData(0, 0, 10, 10);
assert_equals(imageData0.width, imageData1.width);
assert_equals(imageData0.height, imageData1.height);
assert_equals(imageData0.data.length, imageData1.data.length);
for (var i = 0; i < imageData0.data.length; i++)
assert_approx_equals(imageData0.data[i], imageData1.data[i], 5);
this.done();
})
.catch(error => {
assert_unreached('Error during grabFrame(): '+ error);
});
}, 'exercises the ImageCapture API creation and grabFrame().');
</script>

Просмотреть файл

@ -0,0 +1,85 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
// This test verifies that MediaStreamTrack.applyConstraints() exists and that,
// when called with no parameters, returns a Promise that is resolved. This
// might not make sense: https://github.com/w3c/mediacapture-main/issues/438 .
// Other tests go deeper.
promise_test(function(t) {
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
var stream = canvas.captureStream();
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
var videoTrack = stream.getVideoTracks()[0];
return videoTrack.applyConstraints();
}, 'MediaStreamTrack.applyConstraints()');
// This test verifies that MediaStreamTrack.applyConstraints() exists and that,
// when called with an empty advanced constraint set, returns a Promise that is
// resolved.
promise_test(function(t) {
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
var stream = canvas.captureStream();
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
var videoTrack = stream.getVideoTracks()[0];
return videoTrack.applyConstraints({advanced: []});
}, 'MediaStreamTrack.applyConstraints({advanced: []})');
// This test verifies that applyConstraints() rejects the returned Promise if
// passed a non-supported image-capture constraint (https://crbug.com/711694).
promise_test(function(t) {
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
var stream = canvas.captureStream();
var videoTrack = stream.getVideoTracks()[0];
var expectedError =
new DOMException('Unsupported constraint(s)', 'NotSupportedError');
// Use e.g. |torch| as an example of unsupported constraint.
assert_false("torch" in videoTrack.getCapabilities());
return promise_rejects(
t, expectedError,
videoTrack.applyConstraints({advanced : [ {torch : true} ]}));
}, 'MediaStreamTrack.applyConstraints() with unsupported constraint');
// This test verifies that applyConstraints() rejects the returned Promise if
// passed mixed ImageCapture and non-ImageCapture constraints.
// TODO(mcasas): remove entirely after https://crbug.com/338503.
promise_test(function(t) {
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
var stream = canvas.captureStream();
var videoTrack = stream.getVideoTracks()[0];
var expectedError = new OverconstrainedError(
'', 'Mixing ImageCapture and non-ImageCapture constraints is not currently supported');
return promise_rejects(
t, expectedError,
videoTrack.applyConstraints({advanced : [ {width : 640, torch: true} ]}));
}, 'MediaStreamTrack.applyConstraints() with non Image-Capture constraint');
</script>

Просмотреть файл

@ -0,0 +1,91 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
// This test verifies that the |constraints| configured in the mock Mojo
// service implementation, are returned by MediaStreamTrack.getSettings().
image_capture_test(async t => {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
const constraints = { advanced : [{ whiteBalanceMode : 'single-shot',
exposureMode : 'continuous',
focusMode : 'single-shot',
pointsOfInterest : [{x : 0.1, y : 0.2},
{x : 0.3, y : 0.4}],
exposureCompensation : 133.77,
colorTemperature : 6000,
iso : 120.0,
brightness : 3,
contrast : 4,
saturation : 5,
sharpness : 6,
zoom : 3.141592,
torch : true
}]};
let stream = canvas.captureStream();
let videoTrack = stream.getVideoTracks()[0];
// |videoTrack|'s capabilities gathering, just like the actual capture, is
// a process kicked off right after creation, we introduce a small delay
// to allow for those to be collected, since they are needed to understand
// which constraints are supported in applyConstraints().
// TODO(mcasas): this shouldn't be needed, https://crbug.com/711524.
await new Promise(resolve => step_timeout(resolve, 100));
try {
await videoTrack.applyConstraints(constraints);
} catch (error) {
assert_unreached('Error applying constraints: ' + error.message);
}
let settings = videoTrack.getSettings();
assert_equals(typeof settings, 'object');
assert_equals(constraints.advanced[0].whiteBalanceMode,
settings.whiteBalanceMode, 'whiteBalanceMode');
assert_equals(constraints.advanced[0].exposureMode, settings.exposureMode,
'exposureMode');
assert_equals(constraints.advanced[0].focusMode, settings.focusMode,
'focusMode');
assert_point2d_array_approx_equals(
constraints.advanced[0].pointsOfInterest, settings.pointsOfInterest,
0.01);
assert_equals(constraints.advanced[0].exposureCompensation,
settings.exposureCompensation, 'exposureCompensation');
assert_equals(constraints.advanced[0].colorTemperature,
settings.colorTemperature, 'colorTemperature');
assert_equals(constraints.advanced[0].iso, settings.iso, 'iso');
assert_equals(constraints.advanced[0].brightness, settings.brightness,
'brightness');
assert_equals(constraints.advanced[0].contrast, settings.contrast,
'contrast');
assert_equals(constraints.advanced[0].saturation, settings.saturation,
'saturation');
assert_equals(constraints.advanced[0].sharpness, settings.sharpness,
'sharpness');
assert_equals(constraints.advanced[0].zoom, settings.zoom, 'zoom');
assert_equals(constraints.advanced[0].torch, settings.torch, 'torch');
}, 'exercises an applyConstraints() - getSettings() cycle');
</script>

Просмотреть файл

@ -0,0 +1,84 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
// This test verifies that MediaStreamTrack.applyConstraints() rejects if any
// passed constraint is unsupported or outside its allowed range.
var makePromiseTest = function(getConstraint) {
image_capture_test(async (t, imageCaptureTest) => {
imageCaptureTest.mockImageCapture().state().supportsTorch = false;
let stream = canvas.captureStream();
let videoTrack = stream.getVideoTracks()[0];
// |videoTrack|'s capabilities gathering, just like the actual capture,
// is a process kicked off right after creation, we introduce a small
// delay to allow for those to be collected, since they are needed to
// understand which constraints are supported in applyConstraints().
// TODO(mcasas): this shouldn't be needed, https://crbug.com/711524.
await new Promise(resolve => step_timeout(resolve, 100));
try {
const constraints = {
advanced : [ getConstraint(imageCaptureTest.mockImageCapture().state()) ]
};
await videoTrack.applyConstraints(constraints);
assert_unreached('expected applyConstraints to reject');
} catch (error) {
assert_equals(error.name, 'NotSupportedError');
}
});
};
const constraintGenerators = [
capabilities => ({ whiteBalanceMode: 'manual' }),
capabilities => ({ exposureMode: 'manual' }),
capabilities => ({ focusMode: 'continuous' }),
capabilities => ({
exposureCompensation: capabilities.exposureCompensation.max + 1
}),
capabilities => ({
exposureCompensation: capabilities.exposureCompensation.min - 1
}),
capabilities => ({
colorTemperature: capabilities.colorTemperature.max + 1
}),
capabilities => ({
colorTemperature: capabilities.colorTemperature.min - 1
}),
capabilities => ({ iso: capabilities.iso.max + 1 }),
capabilities => ({ iso: capabilities.iso.min - 1 }),
capabilities => ({ brightness: capabilities.brightness.max + 1 }),
capabilities => ({ brightness: capabilities.brightness.min - 1 }),
capabilities => ({ contrast: capabilities.contrast.max + 1 }),
capabilities => ({ contrast: capabilities.contrast.min - 1 }),
capabilities => ({ saturation: capabilities.saturation.max + 1 }),
capabilities => ({ saturation: capabilities.saturation.min - 1 }),
capabilities => ({ sharpness: capabilities.sharpness.max + 1 }),
capabilities => ({ sharpness: capabilities.sharpness.min - 1 }),
capabilities => ({ zoom: capabilities.zoom.max + 1 }),
capabilities => ({ zoom: capabilities.zoom.min - 1 }),
capabilities => ({ torch: true }),
];
for (key in constraintGenerators) {
generate_tests(
makePromiseTest, [[
'MediaStreamTrack.applyConstraints(constraints) rejects with bad' +
' constraints, #' + key,
constraintGenerators[key]
]]);
}
</script>

Просмотреть файл

@ -0,0 +1,109 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
const meteringModeNames = ['none', 'manual', 'single-shot', 'continuous'];
// This test verifies that we can all MediaStreamTrack.applyConstraints(), with
// a mock Mojo service implementation.
image_capture_test(async (t, imageCaptureTest) => {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
const constraints = { advanced : [{ whiteBalanceMode : 'single-shot',
exposureMode : 'continuous',
focusMode : 'single-shot',
pointsOfInterest : [{x : 0.1, y : 0.2},
{x : 0.3, y : 0.4}],
exposureCompensation : 133.77,
colorTemperature : 6000,
iso : 120.0,
brightness : 3,
contrast : 4,
saturation : 5,
sharpness : 6,
zoom : 3.141592,
torch : true
}]};
let stream = canvas.captureStream();
let videoTrack = stream.getVideoTracks()[0];
// |videoTrack|'s capabilities gathering, just like the actual capture, is
// a process kicked off right after creation, we introduce a small delay
// to allow for those to be collected, since they are needed to understand
// which constraints are supported in applyConstraints().
// TODO(mcasas): this shouldn't be needed, https://crbug.com/711524.
await new Promise(resolve => step_timeout(resolve, 100));
try {
await videoTrack.applyConstraints(constraints);
} catch (error) {
assert_unreached('applyConstraints(): ' + error.message);
}
const constraintsDict = constraints.advanced[0];
let appliedConstraints = videoTrack.getConstraints();
const appliedConstraintsDict = appliedConstraints.advanced[0];
// Check that |appliedConstraints| and |constraints| are equal.
assert_equals(constraintsDict.length, appliedConstraintsDict.length);
Object.keys(appliedConstraintsDict).forEach((key, value) => {
assert_not_equals(constraintsDict[key], undefined, 'key ' + key);
if (key != 'pointsOfInterest') {
assert_equals(constraintsDict[key], appliedConstraintsDict[key], key);
} else {
assert_point2d_array_approx_equals(constraintsDict[key],
appliedConstraintsDict[key], 0.01);
}
});
let theMock = imageCaptureTest.mockImageCapture();
assert_equals(constraintsDict.whiteBalanceMode,
meteringModeNames[theMock.options().whiteBalanceMode],
'whiteBalanceMode');
assert_equals(constraintsDict.exposureMode,
meteringModeNames[theMock.options().exposureMode],
'exposureMode');
assert_equals(constraintsDict.focusMode,
meteringModeNames[theMock.options().focusMode],
'focusMode');
assert_point2d_array_approx_equals(constraintsDict.pointsOfInterest,
theMock.options().pointsOfInterest,
0.01);
assert_equals(constraintsDict.exposureCompensation,
theMock.options().exposureCompensation,
'exposureCompensation');
assert_equals(constraintsDict.colorTemperature,
theMock.options().colorTemperature, 'colorTemperature');
assert_equals(constraintsDict.iso, theMock.options().iso, 'iso');
assert_equals(constraintsDict.brightness, theMock.options().brightness,
'brightness');
assert_equals(constraintsDict.contrast, theMock.options().contrast,
'constrast');
assert_equals(constraintsDict.saturation, theMock.options().saturation,
'saturation');
assert_equals(constraintsDict.sharpness, theMock.options().sharpness,
'sharpness');
assert_equals(constraintsDict.torch, theMock.options().torch, 'torch');
}, 'exercises MediaStreamTrack.applyConstraints(constraints)');
</script>

Просмотреть файл

@ -0,0 +1,29 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
// This test verifies that MediaStreamTrack.getCapabilities() exists and that it
// returns something. Other tests go deeper.
test(function() {
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
var stream = canvas.captureStream();
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
var videoTrack = stream.getVideoTracks()[0];
assert_equals(typeof videoTrack.getCapabilities, 'function');
capabilities = videoTrack.getCapabilities();
assert_equals(typeof capabilities, 'object');
}, 'MediaStreamTrack.getCapabilities()');
</script>

Просмотреть файл

@ -0,0 +1,137 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
const meteringModeNames = ['none', 'manual', 'single-shot', 'continuous'];
// This test verifies that MediaTrackCapabilities are returned upon
// MediaStreamTrack.getCapabilities(), with a mock Mojo service implementation.
image_capture_test(async (t, imageCaptureTest) => {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
let mockCapabilities = imageCaptureTest.mockImageCapture().state();
// |stream| must be created _after_ |mock| is constructed to give the
// latter time to override the bindings.
let stream = canvas.captureStream();
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
let videoTrack = stream.getVideoTracks()[0];
assert_equals(typeof videoTrack.getCapabilities, 'function');
// |videoTrack|'s capabilities gathering, just like the actual capture, is
// a process kicked off right after creation, we introduce a small delay
// to allow for those to be collected.
// TODO(mcasas): this shouldn't be needed, https://crbug.com/711524.
await new Promise(resolve => step_timeout(resolve, 100));
let capabilities = videoTrack.getCapabilities();
assert_equals(typeof capabilities, 'object');
assert_equals(capabilities.whiteBalanceMode.length,
mockCapabilities.supportedWhiteBalanceModes.length,
'whiteBalanceMode');
for (i = 0; i < capabilities.whiteBalanceMode.length; ++i) {
assert_equals(
capabilities.whiteBalanceMode[i],
meteringModeNames[mockCapabilities
.supportedWhiteBalanceModes[i]],
'whiteBalanceMode');
}
assert_equals(capabilities.exposureMode.length,
mockCapabilities.supportedExposureModes.length,
'exposureMode');
for (i = 0; i < capabilities.exposureMode.length; ++i) {
assert_equals(
capabilities.exposureMode[i],
meteringModeNames[mockCapabilities.supportedExposureModes[i]],
'exposureMode');
}
assert_equals(capabilities.focusMode.length,
mockCapabilities.supportedFocusModes.length,
'focusMode');
for (i = 0; i < capabilities.focusMode.length; ++i) {
assert_equals(
capabilities.focusMode[i],
meteringModeNames[mockCapabilities.supportedFocusModes[i]],
'focusMode');
}
assert_true(capabilities.exposureCompensation instanceof
MediaSettingsRange);
assert_equals(capabilities.exposureCompensation.max,
mockCapabilities.exposureCompensation.max);
assert_equals(capabilities.exposureCompensation.min,
mockCapabilities.exposureCompensation.min);
assert_equals(capabilities.exposureCompensation.step,
mockCapabilities.exposureCompensation.step);
assert_true(capabilities.colorTemperature instanceof
MediaSettingsRange);
assert_equals(capabilities.colorTemperature.max,
mockCapabilities.colorTemperature.max);
assert_equals(capabilities.colorTemperature.min,
mockCapabilities.colorTemperature.min);
assert_equals(capabilities.colorTemperature.step,
mockCapabilities.colorTemperature.step);
assert_true(capabilities.iso instanceof MediaSettingsRange);
assert_equals(capabilities.iso.max, mockCapabilities.iso.max);
assert_equals(capabilities.iso.min, mockCapabilities.iso.min);
assert_equals(capabilities.iso.step, mockCapabilities.iso.step);
assert_true(capabilities.brightness instanceof MediaSettingsRange);
assert_equals(capabilities.brightness.max,
mockCapabilities.brightness.max);
assert_equals(capabilities.brightness.min,
mockCapabilities.brightness.min);
assert_equals(capabilities.brightness.step,
mockCapabilities.brightness.step);
assert_true(capabilities.contrast instanceof MediaSettingsRange);
assert_equals(capabilities.contrast.max,
mockCapabilities.contrast.max);
assert_equals(capabilities.contrast.min,
mockCapabilities.contrast.min);
assert_equals(capabilities.contrast.step,
mockCapabilities.contrast.step);
assert_true(capabilities.saturation instanceof MediaSettingsRange);
assert_equals(capabilities.saturation.max,
mockCapabilities.saturation.max);
assert_equals(capabilities.saturation.min,
mockCapabilities.saturation.min);
assert_equals(capabilities.saturation.step,
mockCapabilities.saturation.step);
assert_true(capabilities.sharpness instanceof MediaSettingsRange);
assert_equals(capabilities.sharpness.max,
mockCapabilities.sharpness.max);
assert_equals(capabilities.sharpness.min,
mockCapabilities.sharpness.min);
assert_equals(capabilities.sharpness.step,
mockCapabilities.sharpness.step);
assert_true(capabilities.zoom instanceof MediaSettingsRange);
assert_equals(capabilities.zoom.max, mockCapabilities.zoom.max);
assert_equals(capabilities.zoom.min, mockCapabilities.zoom.min);
assert_equals(capabilities.zoom.step, mockCapabilities.zoom.step);
assert_equals(capabilities.torch, mockCapabilities.supportsTorch,
'torch');
}, 'exercises MediaStreamTrack.getCapabilities()');
</script>

Просмотреть файл

@ -0,0 +1,74 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
const constraints = { whiteBalanceMode : "manual",
exposureMode : "continuous",
focusMode : "single-shot",
exposureCompensation : 133.77,
colorTemperature : 6000,
iso : 120.0,
brightness : 3,
contrast : 4,
saturation : 5,
sharpness : 6,
zoom : 3.141592
// TODO: torch https://crbug.com/700607.
};
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
// These tests verify that MediaStreamTrack.getConstraints() exists and that,
// returns the constraints passed beforehand with applyConstraints.
var makeAsyncTest = function(c) {
async_test(function(t) {
var stream = canvas.captureStream();
var videoTrack = stream.getVideoTracks()[0];
const constraintsIn = { advanced : [ c ]};
// Method applyConstraints() will fail since there is no Image Capture
// service in this Layout Test, but |constraintsIn| should be cached.
videoTrack.applyConstraints(constraintsIn)
.then(() => { /* ignore */ })
.catch((e) => { /* ignore */ })
.then(() => {
const constraintsOut = videoTrack.getConstraints();
assert_object_equals(constraintsOut, constraintsIn, "constraints");
t.done();
});
// Clear constraints by sending an empty constraint set.
videoTrack.applyConstraints({})
.then(() => {
const constraintsOut = videoTrack.getConstraints();
assert_object_equals(constraintsOut, {}, "constraints");
t.done();
});
});
};
// Send each line of |constraints| in turn and then the whole dictionary.
for (key in constraints) {
var one_constraint = {};
one_constraint[key] = constraints[key];
generate_tests(
makeAsyncTest,
[[ 'MediaStreamTrack.getConstraints(), key: ' + key, one_constraint ]]);
}
generate_tests(makeAsyncTest, [[
'MediaStreamTrack.getConstraints(), complete ', constraints
]]);
</script>

Просмотреть файл

@ -0,0 +1,29 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
// This test verifies that MediaStreamTrack.getSettings() exists and that it
// returns something. Other tests go deeper.
test(function() {
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
var stream = canvas.captureStream();
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
var videoTrack = stream.getVideoTracks()[0];
assert_equals(typeof videoTrack.getSettings, 'function');
settings = videoTrack.getSettings();
assert_equals(typeof settings, 'object');
}, 'MediaStreamTrack.getSettings()');
</script>

Просмотреть файл

@ -0,0 +1,67 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
const meteringModeNames = ['none', 'manual', 'single-shot', 'continuous'];
// This test verifies that the settings defined in the mock Mojo service
// implementation are the same as those returned by the corresponding
// MediaStreamTrack.getSettings().
image_capture_test(async (t, imageCaptureTest) => {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
let mockSettings = imageCaptureTest.mockImageCapture().state();
// |stream| must be created _after_ |mock| is constructed to give the
// latter time to override the bindings.
let stream = canvas.captureStream();
let videoTrack = stream.getVideoTracks()[0];
// |videoTrack|s settings retrieval, just like the actual capture, is a
// process kicked right after creation, we introduce a small delay to
// allow for those to be collected.
await new Promise(resolve => step_timeout(resolve, 100));
let settings = videoTrack.getSettings();
assert_equals(typeof settings, 'object');
assert_equals(settings.whiteBalanceMode,
meteringModeNames[mockSettings.currentWhiteBalanceMode],
'whiteBalanceMode');
assert_equals(settings.exposureMode,
meteringModeNames[mockSettings.currentExposureMode],
'exposureMode;');
assert_equals(settings.focusMode,
meteringModeNames[mockSettings.currentFocusMode],
'focusMode');
assert_point2d_array_approx_equals(
settings.pointsOfInterest, mockSettings.pointsOfInterest, 0.01);
assert_equals(settings.exposureCompensation,
mockSettings.exposureCompensation.current);
assert_equals(settings.colorTemperature,
mockSettings.colorTemperature.current);
assert_equals(settings.iso, mockSettings.iso.current);
assert_equals(settings.brightness, mockSettings.brightness.current);
assert_equals(settings.contrast, mockSettings.contrast.current);
assert_equals(settings.saturation, mockSettings.saturation.current);
assert_equals(settings.sharpness, mockSettings.sharpness.current);
assert_equals(settings.zoom, mockSettings.zoom.current);
assert_equals(settings.torch, mockSettings.torch, 'torch');
}, 'exercises MediaStreamTrack.getSettings()');
</script>

Просмотреть файл

@ -0,0 +1,26 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
async_test(t => {
let iframe = document.createElement('iframe');
let html = "<canvas id='canvas' width=10 height=10 />";
iframe.srcdoc = html;
iframe.onload = t.step_func_done(() => {
// This detaches the frame while retaining a reference to an
// HTMLCanvasElement from it.
let canvas = iframe.contentWindow.document.getElementById('canvas');
document.body.removeChild(iframe);
// Creation of the ImageCapture object (as part of the MediaStreamTrack)
// should be safe even if the frame is detached.
canvas.captureStream();
});
document.body.appendChild(iframe);
}, 'MediaStreamTrack can be obtained from a detached frame');
</script>
</body>

Просмотреть файл

@ -0,0 +1,45 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
// This test verifies that ImageCapture can get PhotoCapabilities(), with a mock
// Mojo interface implementation.
image_capture_test(async (t, imageCaptureTest) => {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
let stream = canvas.captureStream();
let mockCapabilities = imageCaptureTest.mockImageCapture().state();
let capturer = new ImageCapture(stream.getVideoTracks()[0]);
assert_true(typeof capturer.getPhotoCapabilities == 'function');
let capabilities = await capturer.getPhotoCapabilities();
assert_true(capabilities instanceof PhotoCapabilities);
assert_equals(capabilities.redEyeReduction, 'controllable',
'redEyeReduction');
assert_true(capabilities.imageHeight instanceof MediaSettingsRange);
assert_equals(capabilities.imageHeight.max, mockCapabilities.height.max);
assert_equals(capabilities.imageHeight.min, mockCapabilities.height.min);
assert_equals(capabilities.imageHeight.step, mockCapabilities.height.step);
assert_true(capabilities.imageWidth instanceof MediaSettingsRange);
assert_equals(capabilities.imageWidth.max, mockCapabilities.width.max);
assert_equals(capabilities.imageWidth.min, mockCapabilities.width.min);
assert_equals(capabilities.imageWidth.step, mockCapabilities.width.step);
assert_array_equals(capabilities.fillLightMode, [ 'auto', 'flash' ],
'fillLightMode');
}, 'exercises ImageCapture.getPhotoCapabilities()');
</script>

Просмотреть файл

@ -0,0 +1,30 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
const fillLightModeNames = ['off', 'auto', 'flash'];
// This test verifies that ImageCapture can call getPhotoSettings(), with a
// mock Mojo interface implementation.
image_capture_test(async (t, imageCaptureTest) => {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
let stream = canvas.captureStream();
let mockState = imageCaptureTest.mockImageCapture().state();
let capturer = new ImageCapture(stream.getVideoTracks()[0]);
let settings = await capturer.getPhotoSettings();
assert_equals(settings.imageWidth, mockState.width.current, 'width');
assert_equals(settings.imageHeight, mockState.height.current, 'height');
// TODO(mcasas): check the remaining two entries https://crbug.com/732521.
}, 'exercises ImageCapture.getPhotoSettings()');
</script>

Просмотреть файл

@ -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');
}
}

Просмотреть файл

@ -0,0 +1,51 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
// This test verifies that ImageCapture.takePhoto() rejects if any passed
// option is unsupported or outside its allowed range.
function makePromiseTest(getOption) {
image_capture_test(async (t, imageCaptureTest) => {
imageCaptureTest.mockImageCapture().state().redEyeReduction = 0;
let stream = canvas.captureStream();
let capturer = new ImageCapture(stream.getVideoTracks()[0]);
await capturer.getPhotoCapabilities();
const options = getOption(imageCaptureTest.mockImageCapture().state());
try {
await capturer.takePhoto(options);
assert_unreached('expected takePhoto to reject');
} catch (error) {
assert_equals(error.name, 'NotSupportedError');
}
});
}
const optionsGenerators = [
capabilities => ({ redEyeReduction: true }),
capabilities => ({ imageHeight: capabilities.height.max + 1 }),
capabilities => ({ imageHeight: capabilities.height.min - 1 }),
capabilities => ({ imageWidth: capabilities.width.max + 1 }),
capabilities => ({ imageWidth: capabilities.width.min - 1 }),
capabilities => ({ fillLightMode: 'off' }),
];
for (key in optionsGenerators) {
generate_tests(
makePromiseTest,
[[ 'ImageCapture.takePhoto(options) rejects with bad options, #' + key,
optionsGenerators[key] ]]);
}
</script>

Просмотреть файл

@ -0,0 +1,63 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
const fillLightModeNames = ['off', 'auto', 'flash'];
// This test verifies that ImageCapture can call takePhoto with a PhotoSettings
// argument, with a mock Mojo interface implementation.
image_capture_test(async (t, imageCaptureTest) => {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
let stream = canvas.captureStream();
const optionsDict = { imageWidth : 1080,
imageHeight : 100,
redEyeReduction : true,
fillLightMode : 'flash'
};
let capturer = new ImageCapture(stream.getVideoTracks()[0]);
let blob = await capturer.takePhoto(optionsDict);
// JS Blob is almost-opaque, can only check |type| and |size|.
assert_equals(blob.type, 'image/cat');
assert_equals(blob.size, 2);
assert_equals(true, imageCaptureTest.mockImageCapture().options().hasWidth,
'hasWidth');
assert_equals(optionsDict.imageWidth,
imageCaptureTest.mockImageCapture().options().width,'width');
assert_equals(true, imageCaptureTest.mockImageCapture().options().hasHeight,
'hasHeight');
assert_equals(optionsDict.imageHeight,
imageCaptureTest.mockImageCapture().options().height,
'height');
// Depending on how mojo boolean packing in integers is arranged, this can
// be a number instead of a boolean, compare directly.
// TODO(mcasas): Revert to assert_equals() when yzshen@ has sorted it out.
assert_true(
optionsDict.redEyeReduction == imageCaptureTest.mockImageCapture().
options().redEyeReduction, 'redEyeReduction');
assert_equals(true,
imageCaptureTest.mockImageCapture().options().hasFillLightMode,
'hasFillLightMode');
assert_equals(optionsDict.fillLightMode,
fillLightModeNames[
imageCaptureTest.mockImageCapture().options().fillLightMode],
'fillLightMode');
}, 'exercises ImageCapture.takePhoto(PhotoSettings dictionary)');
</script>

Просмотреть файл

@ -0,0 +1,29 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<script>
// This test verifies that ImageCapture can takePhoto()s, with a mock Mojo
// interface implementation.
image_capture_test(async t => {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 10, 10);
let stream = canvas.captureStream();
let capturer = new ImageCapture(stream.getVideoTracks()[0]);
let blob = await capturer.takePhoto();
// JS Blob is almost-opaque, can only check |type| and |size|.
assert_equals(blob.type, 'image/cat');
assert_equals(blob.size, 2);
}, 'exercises ImageCapture.takePhoto()');
</script>

Просмотреть файл

@ -0,0 +1 @@
Content-Type: text/javascript; charset=utf-8

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -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;
})();