test_imageDecoder_desiredSize.html (1533B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title></title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <script> 10 // Bug 1924775 - ESLint doesn't yet know about `ImageDecoder`. 11 /* globals ImageDecoder:false */ 12 13 async function test(desiredWidth, desiredHeight, expectedWidth, expectedHeight) { 14 const imgResponse = await fetch("green.png"); 15 const decoder = new ImageDecoder({ 16 data: imgResponse.body, 17 type: "image/png", 18 desiredWidth, 19 desiredHeight, 20 }); 21 22 // Should download all the data and decode metadata just fine. 23 await decoder.completed; 24 await decoder.tracks.ready; 25 is(decoder.tracks.length, 1, "Should have one track"); 26 is(decoder.tracks[0].frameCount, 1, "Should have a single frame"); 27 28 try { 29 const result = await decoder.decode(); 30 ok(result.complete, "Should have complete image"); 31 is(result.image.codedWidth, expectedWidth, "Should have expected width"); 32 is(result.image.codedHeight, expectedHeight, "Should have expected height"); 33 } catch (e) { 34 ok(false, "Decode image failed with " + e) 35 } 36 37 return Promise.resolve(); 38 } 39 40 async function initTest() { 41 SimpleTest.waitForExplicitFinish(); 42 try { 43 await test(10, 20, 10, 20); 44 await test(100, 300, 100, 100); 45 await test(500, 40, 100, 100); 46 await test(500, 300, 100, 100); 47 } catch (e) { 48 ok(false, "Unexpected error " + e); 49 } finally { 50 SimpleTest.finish(); 51 } 52 } 53 54 initTest(); 55 </script> 56 </body> 57 </html>