detection-ImageBitmap-closed.https.window.js (1341B)
1 'use strict'; 2 3 async function createClosedImageBitmap(t) { 4 const img = new Image(); 5 const imgWatcher = new EventWatcher(t, img, ['load', 'error']); 6 img.src = '/images/green-16x16.png'; 7 await imgWatcher.wait_for('load'); 8 const imageBitmap = await createImageBitmap(img); 9 imageBitmap.close(); 10 return imageBitmap; 11 } 12 13 promise_test(async (t) => { 14 const imageBitmap = await createClosedImageBitmap(t); 15 const detector = new FaceDetector(); 16 try { 17 await detector.detect(imageBitmap); 18 assert_unreached(); 19 } catch (e) { 20 assert_equals(e.code, DOMException.INVALID_STATE_ERR); 21 } 22 }, 'FaceDetector.detect() rejects on a closed ImageBitmap'); 23 24 promise_test(async (t) => { 25 const imageBitmap = await createClosedImageBitmap(t); 26 const detector = new BarcodeDetector(); 27 try { 28 await detector.detect(imageBitmap); 29 assert_unreached(); 30 } catch (e) { 31 assert_equals(e.code, DOMException.INVALID_STATE_ERR); 32 } 33 }, 'BarcodeDetector.detect() rejects on a closed ImageBitmap'); 34 35 promise_test(async (t) => { 36 const imageBitmap = await createClosedImageBitmap(t); 37 const detector = new TextDetector(); 38 try { 39 await detector.detect(imageBitmap); 40 assert_unreached(); 41 } catch (e) { 42 assert_equals(e.code, DOMException.INVALID_STATE_ERR); 43 } 44 }, 'TextDetector.detect() rejects on a closed ImageBitmap');