// Check if the callback returns even no JS reference on it.
async function gcTest(track) {
const repeat = 100;
const promises = [];
for (let i = 0; i < repeat; ++i) {
const imageCapture = new ImageCapture(track);
promises.push(new Promise((resolve, reject) => {
imageCapture.onphoto = resolve;
imageCapture.onerror = () =>
reject(new Error(`takePhoto gcTest failure for capture ${i}`));
}));
imageCapture.takePhoto();
}
info("Call gc ");
SpecialPowers.gc();
await Promise.all(promises);
}
// Continue calling takePhoto() in rapid succession.
async function rapidTest(track) {
const repeat = 100;
const imageCapture = new ImageCapture(track);
// "error" can fire synchronously in `takePhoto`
const errorPromise = new Promise(r => imageCapture.onerror = r);
for (let i = 0; i < repeat; ++i) {
imageCapture.takePhoto();
}
for (let i = 0; i < repeat; ++i) {
await Promise.race([
new Promise(r => imageCapture.onphoto = r),
errorPromise.then(() => Promise.reject(new Error("Capture failed"))),
]);
}
}
// Check if the blob is decodable.
async function blobTest(track) {
const imageCapture = new ImageCapture(track);
// "error" can fire synchronously in `takePhoto`
const errorPromise = new Promise(r => imageCapture.onerror = r);
imageCapture.takePhoto();
const blob = await Promise.race([
new Promise(r => imageCapture.onphoto = r),
errorPromise.then(() => Promise.reject(new Error("Capture failed"))),
]);
// It should return an error event after disabling videotrack.
async function trackTest(track) {
const imageCapture = new ImageCapture(track); track.enabled = false;
try {
const errorPromise = new Promise(r => imageCapture.onerror = r);
imageCapture.takePhoto();
const error = await Promise.race([
errorPromise,
new Promise(r => imageCapture.onphoto = r).then(
() => Promise.reject(new Error("Disabled video track should fail"))),
]);
is(error.imageCaptureError.code, error.imageCaptureError.PHOTO_ERROR, "Expected error code")
} finally { track.enabled = true;
}
}
async function init() {
// Use loopback camera if available, otherwise fake.
// MediaTrackGraph will be the backend of ImageCapture.
await setupGetUserMediaTestPrefs();
let stream = await navigator.mediaDevices.getUserMedia({video: true});
return stream.getVideoTracks()[0];
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.