diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /dom/html/reftests/toblob-todataurl | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/html/reftests/toblob-todataurl')
32 files changed, 306 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 0000000000..4ed9fdb372 --- /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(); diff --git a/dom/html/reftests/toblob-todataurl/dataurl.js b/dom/html/reftests/toblob-todataurl/dataurl.js new file mode 100644 index 0000000000..8ffba1fa8e --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/dataurl.js @@ -0,0 +1,56 @@ +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); + + var dataUrl; + // I want to test passing undefined as well + if ('quality' in window) { + dataUrl = canvas.toDataURL('image/jpeg', quality); + } else { + dataUrl = canvas.toDataURL('image/jpeg'); + } + + var img = getImageFromDataUrl(dataUrl); + setImgLoadListener(img, next); + document.body.appendChild(img); +} + +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 getImageFromDataUrl(url) { + var img = document.createElement('img'); + img.src = url; + setImgLoadListener(img, naturalDimensionsHandler); + + return img; +} + +init(); diff --git a/dom/html/reftests/toblob-todataurl/images/original.png b/dom/html/reftests/toblob-todataurl/images/original.png Binary files differnew file mode 100644 index 0000000000..c2da5b3597 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/images/original.png diff --git a/dom/html/reftests/toblob-todataurl/images/q0.jpg b/dom/html/reftests/toblob-todataurl/images/q0.jpg Binary files differnew file mode 100644 index 0000000000..eb41ad3e93 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/images/q0.jpg diff --git a/dom/html/reftests/toblob-todataurl/images/q100.jpg b/dom/html/reftests/toblob-todataurl/images/q100.jpg Binary files differnew file mode 100644 index 0000000000..aaa79f2d31 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/images/q100.jpg diff --git a/dom/html/reftests/toblob-todataurl/images/q25.jpg b/dom/html/reftests/toblob-todataurl/images/q25.jpg Binary files differnew file mode 100644 index 0000000000..d8b1c9bfb2 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/images/q25.jpg diff --git a/dom/html/reftests/toblob-todataurl/images/q50.jpg b/dom/html/reftests/toblob-todataurl/images/q50.jpg Binary files differnew file mode 100644 index 0000000000..f93356ef22 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/images/q50.jpg diff --git a/dom/html/reftests/toblob-todataurl/images/q75.jpg b/dom/html/reftests/toblob-todataurl/images/q75.jpg Binary files differnew file mode 100644 index 0000000000..6c25c55a1a --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/images/q75.jpg diff --git a/dom/html/reftests/toblob-todataurl/images/q92.jpg b/dom/html/reftests/toblob-todataurl/images/q92.jpg Binary files differnew file mode 100644 index 0000000000..1de242a171 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/images/q92.jpg diff --git a/dom/html/reftests/toblob-todataurl/quality-0-ref.html b/dom/html/reftests/toblob-todataurl/quality-0-ref.html new file mode 100644 index 0000000000..3d6923fd39 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/quality-0-ref.html @@ -0,0 +1,2 @@ +<!doctype html> +<html><body><img src='images/q0.jpg'/></table></body></html> diff --git a/dom/html/reftests/toblob-todataurl/quality-100-ref.html b/dom/html/reftests/toblob-todataurl/quality-100-ref.html new file mode 100644 index 0000000000..8b157d0ab3 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/quality-100-ref.html @@ -0,0 +1,2 @@ +<!doctype html> +<html><body><img src='images/q100.jpg'/></table></body></html> diff --git a/dom/html/reftests/toblob-todataurl/quality-25-ref.html b/dom/html/reftests/toblob-todataurl/quality-25-ref.html new file mode 100644 index 0000000000..385f2ab356 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/quality-25-ref.html @@ -0,0 +1,2 @@ +<!doctype html> +<html><body><img src='images/q25.jpg'/></table></body></html> diff --git a/dom/html/reftests/toblob-todataurl/quality-50-ref.html b/dom/html/reftests/toblob-todataurl/quality-50-ref.html new file mode 100644 index 0000000000..68b91f43f6 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/quality-50-ref.html @@ -0,0 +1,2 @@ +<!doctype html> +<html><body><img src='images/q50.jpg'/></table></body></html> diff --git a/dom/html/reftests/toblob-todataurl/quality-75-ref.html b/dom/html/reftests/toblob-todataurl/quality-75-ref.html new file mode 100644 index 0000000000..7e610d231b --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/quality-75-ref.html @@ -0,0 +1,2 @@ +<!doctype html> +<html><body><img src='images/q75.jpg'/></table></body></html> diff --git a/dom/html/reftests/toblob-todataurl/quality-92-ref.html b/dom/html/reftests/toblob-todataurl/quality-92-ref.html new file mode 100644 index 0000000000..15a930c942 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/quality-92-ref.html @@ -0,0 +1,2 @@ +<!doctype html> +<html><body><img src='images/q92.jpg'/></table></body></html> diff --git a/dom/html/reftests/toblob-todataurl/reftest.list b/dom/html/reftests/toblob-todataurl/reftest.list new file mode 100644 index 0000000000..efe5a3e7f6 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/reftest.list @@ -0,0 +1,16 @@ +fuzzy-if(Android,0-105,0-482) == toblob-quality-0.html quality-0-ref.html +fuzzy-if(Android,0-38,0-2024) == toblob-quality-25.html quality-25-ref.html +fuzzy-if(Android,0-29,0-2336) == toblob-quality-50.html quality-50-ref.html +fuzzy-if(Android,0-23,0-3533) == toblob-quality-75.html quality-75-ref.html +fuzzy-if(Android,0-16,0-4199) == toblob-quality-92.html quality-92-ref.html +fuzzy-if(Android,0-8,0-2461) == toblob-quality-100.html quality-100-ref.html +fuzzy-if(Android,0-16,0-4199) == toblob-quality-undefined.html quality-92-ref.html +fuzzy-if(Android,0-16,0-4199) == toblob-quality-default.html quality-92-ref.html +fuzzy-if(Android,0-105,0-482) == todataurl-quality-0.html quality-0-ref.html +fuzzy-if(Android,0-38,0-2024) == todataurl-quality-25.html quality-25-ref.html +fuzzy-if(Android,0-29,0-2336) == todataurl-quality-50.html quality-50-ref.html +fuzzy-if(Android,0-23,0-3533) == todataurl-quality-75.html quality-75-ref.html +fuzzy-if(Android,0-16,0-4199) == todataurl-quality-92.html quality-92-ref.html +fuzzy-if(Android,0-8,0-2461) == todataurl-quality-100.html quality-100-ref.html +fuzzy-if(Android,0-16,0-4199) == todataurl-quality-undefined.html quality-92-ref.html +fuzzy-if(Android,0-16,0-4199) == todataurl-quality-default.html quality-92-ref.html
\ No newline at end of file diff --git a/dom/html/reftests/toblob-todataurl/toblob-quality-0.html b/dom/html/reftests/toblob-todataurl/toblob-quality-0.html new file mode 100644 index 0000000000..7e7298cb6b --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/toblob-quality-0.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0; + </script> + <script src='sample.js'></script> + <script src='blob.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/toblob-quality-100.html b/dom/html/reftests/toblob-todataurl/toblob-quality-100.html new file mode 100644 index 0000000000..34f318e11f --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/toblob-quality-100.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 1; + </script> + <script src='sample.js'></script> + <script src='blob.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/toblob-quality-25.html b/dom/html/reftests/toblob-todataurl/toblob-quality-25.html new file mode 100644 index 0000000000..ed4350e6eb --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/toblob-quality-25.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0.25; + </script> + <script src='sample.js'></script> + <script src='blob.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/toblob-quality-50.html b/dom/html/reftests/toblob-todataurl/toblob-quality-50.html new file mode 100644 index 0000000000..47e3b684fa --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/toblob-quality-50.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0.50; + </script> + <script src='sample.js'></script> + <script src='blob.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/toblob-quality-75.html b/dom/html/reftests/toblob-todataurl/toblob-quality-75.html new file mode 100644 index 0000000000..45ccfe1fe0 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/toblob-quality-75.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0.75; + </script> + <script src='sample.js'></script> + <script src='blob.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/toblob-quality-92.html b/dom/html/reftests/toblob-todataurl/toblob-quality-92.html new file mode 100644 index 0000000000..6a7f8788fb --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/toblob-quality-92.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0.92; + </script> + <script src='sample.js'></script> + <script src='blob.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/toblob-quality-default.html b/dom/html/reftests/toblob-todataurl/toblob-quality-default.html new file mode 100644 index 0000000000..c5b404744c --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/toblob-quality-default.html @@ -0,0 +1,7 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script src='sample.js'></script> + <script src='blob.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/toblob-quality-undefined.html b/dom/html/reftests/toblob-todataurl/toblob-quality-undefined.html new file mode 100644 index 0000000000..3252900200 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/toblob-quality-undefined.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = undefined; + </script> + <script src='sample.js'></script> + <script src='blob.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/todataurl-quality-0.html b/dom/html/reftests/toblob-todataurl/todataurl-quality-0.html new file mode 100644 index 0000000000..1d4eb9b7f1 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/todataurl-quality-0.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0; + </script> + <script src='sample.js'></script> + <script src='dataurl.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/todataurl-quality-100.html b/dom/html/reftests/toblob-todataurl/todataurl-quality-100.html new file mode 100644 index 0000000000..66b627c13e --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/todataurl-quality-100.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 1; + </script> + <script src='sample.js'></script> + <script src='dataurl.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/todataurl-quality-25.html b/dom/html/reftests/toblob-todataurl/todataurl-quality-25.html new file mode 100644 index 0000000000..15237cea8b --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/todataurl-quality-25.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0.25; + </script> + <script src='sample.js'></script> + <script src='dataurl.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/todataurl-quality-50.html b/dom/html/reftests/toblob-todataurl/todataurl-quality-50.html new file mode 100644 index 0000000000..93e820e68b --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/todataurl-quality-50.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0.50; + </script> + <script src='sample.js'></script> + <script src='dataurl.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/todataurl-quality-75.html b/dom/html/reftests/toblob-todataurl/todataurl-quality-75.html new file mode 100644 index 0000000000..acdc7416f8 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/todataurl-quality-75.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0.75; + </script> + <script src='sample.js'></script> + <script src='dataurl.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/todataurl-quality-92.html b/dom/html/reftests/toblob-todataurl/todataurl-quality-92.html new file mode 100644 index 0000000000..ca3de4ee0b --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/todataurl-quality-92.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = 0.92; + </script> + <script src='sample.js'></script> + <script src='dataurl.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/todataurl-quality-default.html b/dom/html/reftests/toblob-todataurl/todataurl-quality-default.html new file mode 100644 index 0000000000..cc7771dbf0 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/todataurl-quality-default.html @@ -0,0 +1,7 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script src='sample.js'></script> + <script src='dataurl.js'></script> + </body> +</html> diff --git a/dom/html/reftests/toblob-todataurl/todataurl-quality-undefined.html b/dom/html/reftests/toblob-todataurl/todataurl-quality-undefined.html new file mode 100644 index 0000000000..16801e4829 --- /dev/null +++ b/dom/html/reftests/toblob-todataurl/todataurl-quality-undefined.html @@ -0,0 +1,10 @@ +<!doctype html> +<html class='reftest-wait'> + <body> + <script> + var quality = undefined; + </script> + <script src='sample.js'></script> + <script src='dataurl.js'></script> + </body> +</html> |