diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/html/reftests/toblob-todataurl/blob.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/html/reftests/toblob-todataurl/blob.js')
-rw-r--r-- | dom/html/reftests/toblob-todataurl/blob.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/dom/html/reftests/toblob-todataurl/blob.js b/dom/html/reftests/toblob-todataurl/blob.js new file mode 100644 index 000000000..4ed9fdb37 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/blob.js @@ -0,0 +1,68 @@ +function init() { + function end() { + document.documentElement.className = ''; + } + + function next() { + compressAndDisplay(original, end); + } + + var original = getImageFromDataUrl(sample); + setImgLoadListener(original, next); +} + +function compressAndDisplay(image, next) { + var canvas = document.createElement('canvas'); + canvas.width = image.naturalWidth; + canvas.height = image.naturalHeight; + var ctx = canvas.getContext('2d'); + ctx.drawImage(image, 0, 0); + + function gotBlob(blob) { + var img = getImageFromBlob(blob); + setImgLoadListener(img, next); + document.body.appendChild(img); + } + + // I want to test passing 'undefined' as quality as well + if ('quality' in window) { + canvas.toBlob(gotBlob, 'image/jpeg', quality); + } else { + canvas.toBlob(gotBlob, 'image/jpeg'); + } +} + +function setImgLoadListener(img, func) { + if (img.complete) { + func.call(img, { target: img}); + } else { + img.addEventListener('load', func); + } +} + +function naturalDimensionsHandler(e) { + var img = e.target; + img.width = img.naturalWidth; + img.height = img.naturalHeight; +} + +function getImageFromBlob(blob) { + var img = document.createElement('img'); + img.src = window.URL.createObjectURL(blob); + setImgLoadListener(img, naturalDimensionsHandler); + setImgLoadListener(img, function(e) { + window.URL.revokeObjectURL(e.target.src); + }); + + return img; +} + +function getImageFromDataUrl(url) { + var img = document.createElement('img'); + img.src = url; + setImgLoadListener(img, naturalDimensionsHandler); + + return img; +} + +init(); |