Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../../resources/js-test.js"></script> | 2 <script src="../../resources/js-test.js"></script> |
| 3 <script> | 3 <script> |
| 4 jsTestIsAsync = true; | 4 jsTestIsAsync = true; |
| 5 var worker = new Worker('./resources/worker-onmessage-noop.js'); | 5 var worker = new Worker('./resources/worker-onmessage-noop.js'); |
| 6 | 6 |
| 7 description("Tests that the close method of ImageBitmap does dispose the image d ata"); | 7 description("Tests that the close method of ImageBitmap does dispose the image d ata"); |
| 8 | 8 |
| 9 var imgHeight = 10; | 9 var imgHeight = 10; |
| 10 var imgWidth = 10; | 10 var imgWidth = 10; |
| 11 var imageData = new ImageData(10, 10); | 11 var imageData = new ImageData(10, 10); |
| 12 var bitmap; | 12 var bitmap; |
| 13 createImageBitmap(imageData).then(imageBitmap => { | 13 createImageBitmap(imageData).then(imageBitmap => { |
| 14 bitmap = imageBitmap; | 14 bitmap = imageBitmap; |
| 15 shouldBe("bitmap.width", "imgWidth"); | 15 shouldBe("bitmap.width", "imgWidth"); |
| 16 shouldBe("bitmap.height", "imgHeight"); | 16 shouldBe("bitmap.height", "imgHeight"); |
| 17 | 17 |
| 18 // Apply structured clone to the bitmap, nothing should be changed | 18 // Apply structured clone to the bitmap, nothing should be changed |
| 19 worker.postMessage({data: bitmap}); | 19 worker.postMessage({data: bitmap}); |
| 20 shouldBe("bitmap.width", "imgWidth"); | 20 shouldBe("bitmap.width", "imgWidth"); |
| 21 shouldBe("bitmap.height", "imgHeight"); | 21 shouldBe("bitmap.height", "imgHeight"); |
| 22 | 22 |
| 23 // After calling close, the image data associated with the bitmap should no longer exist | 23 // After calling close, the image data associated with the bitmap should no longer exist |
| 24 bitmap.close(); | 24 bitmap.close(); |
| 25 shouldBe("bitmap.width", "0"); | 25 shouldBe("bitmap.width", "0"); |
| 26 shouldBe("bitmap.height", "0"); | 26 shouldBe("bitmap.height", "0"); |
| 27 | 27 |
| 28 var canvas = document.createElement("canvas"); | |
| 29 canvas.width = imgWidth; | |
| 30 canvas.height = imgHeight; | |
| 31 var ctx = canvas.getContext("2d"); | |
| 32 try { | |
|
Justin Novosad
2016/04/21 20:45:19
In tests that include js-test.js, you might as wel
xidachen
2016/04/22 01:58:13
Done.
| |
| 33 ctx.drawImage(bitmap, 0, 0); | |
| 34 testFailed("Drawing a closed ImageBitmap passed unexpectedly"); | |
| 35 } catch(ex) { | |
| 36 testPassed("Drawing a closed ImageBitmap throws: " + ex); | |
| 37 } | |
| 38 | |
| 28 // Try to apply structured clone to an already closed bitmap | 39 // Try to apply structured clone to an already closed bitmap |
| 29 try { | 40 try { |
| 30 worker.postMessage({data: bitmap}); | 41 worker.postMessage({data: bitmap}); |
| 31 testFailed("Apply structured clone to an already closed bitmap passed un expectedly"); | 42 testFailed("Apply structured clone to an already closed bitmap passed un expectedly"); |
| 32 } catch(ex) { | 43 } catch(ex) { |
| 33 testPassed("Apply structured clone to an already closed bitmap is reject ed as expected: " + ex); | 44 testPassed("Apply structured clone to an already closed bitmap is reject ed as expected: " + ex); |
| 34 } | 45 } |
| 35 | 46 |
| 36 // Try to apply transfering to an already closed bitmap | 47 // Try to apply transfering to an already closed bitmap |
| 37 try { | 48 try { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 68 | 79 |
| 69 // Calling close to a neutered bitmap should be noop. | 80 // Calling close to a neutered bitmap should be noop. |
| 70 bitmap.close(); | 81 bitmap.close(); |
| 71 shouldBe("bitmap.width", "0"); | 82 shouldBe("bitmap.width", "0"); |
| 72 shouldBe("bitmap.height", "0"); | 83 shouldBe("bitmap.height", "0"); |
| 73 }); | 84 }); |
| 74 }).catch(function(ex) { | 85 }).catch(function(ex) { |
| 75 testFailed("Unexpected failure: " + ex); | 86 testFailed("Unexpected failure: " + ex); |
| 76 }).then(() => { finishJSTest(); }); | 87 }).then(() => { finishJSTest(); }); |
| 77 </script> | 88 </script> |
| OLD | NEW |