OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE HTML> |
| 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <script> |
| 5 function testImageBitmap(source) |
| 6 { |
| 7 return createImageBitmap(source, 0, 0, 0x8000, 0x8000, {imageOrientation: "f
lipY", premultiplyAlpha: "none"}).then(function() { |
| 8 assert_true(false, "Promise should be rejected if the cropRect is too bi
g."); |
| 9 }, function() { |
| 10 return createImageBitmap(source, 5, 5, 10, 10, {resizeWidth: 0x8000, res
izeHeight: 0x8000}).then(function() { |
| 11 assert_true(false, "Promise should be rejected if the resizeWidth or
resizeHeight is too big."); |
| 12 }, function() { |
| 13 }); |
| 14 }); |
| 15 } |
| 16 |
| 17 function initializeTestCanvas() |
| 18 { |
| 19 var testCanvas = document.createElement("canvas"); |
| 20 testCanvas.width = 20; |
| 21 testCanvas.height = 20; |
| 22 var testCtx = testCanvas.getContext("2d"); |
| 23 testCtx.fillStyle = "rgb(255, 0, 0)"; |
| 24 testCtx.fillRect(0, 0, 10, 10); |
| 25 testCtx.fillStyle = "rgb(0, 255, 0)"; |
| 26 testCtx.fillRect(10, 0, 10, 10); |
| 27 testCtx.fillStyle = "rgb(0, 0, 255)"; |
| 28 testCtx.fillRect(0, 10, 10, 10); |
| 29 testCtx.fillStyle = "rgb(0, 0, 0)"; |
| 30 testCtx.fillRect(10, 10, 10, 10); |
| 31 return testCanvas; |
| 32 } |
| 33 |
| 34 function getBlobWithXhr(url) |
| 35 { |
| 36 return new Promise((resolve, reject) => { |
| 37 var xhr = new XMLHttpRequest(); |
| 38 xhr.open("GET", url); |
| 39 xhr.responseType = 'blob'; |
| 40 xhr.send(); |
| 41 xhr.onload = function() { |
| 42 resolve(xhr.response); |
| 43 }; |
| 44 }); |
| 45 } |
| 46 |
| 47 function loadImage(url) |
| 48 { |
| 49 return new Promise((resolve, reject) => { |
| 50 var image = new Image(); |
| 51 image.onload = function() { |
| 52 resolve(image); |
| 53 } |
| 54 image.src = url; |
| 55 }); |
| 56 } |
| 57 |
| 58 function loadVideo(url) |
| 59 { |
| 60 return new Promise((resolve, reject) => { |
| 61 var video = document.createElement("video"); |
| 62 video.oncanplaythrough = function() { |
| 63 resolve(video); |
| 64 }; |
| 65 video.src = url; |
| 66 }); |
| 67 } |
| 68 |
| 69 // Blob |
| 70 promise_test(function() { |
| 71 return getBlobWithXhr('resources/pattern.png').then(testImageBitmap); |
| 72 }, 'createImageBitmap from a Blob with a big cropRect.'); |
| 73 |
| 74 // HTMLCanvasElement |
| 75 promise_test(function() { |
| 76 var testCanvas = initializeTestCanvas(); |
| 77 return testImageBitmap(testCanvas); |
| 78 }, 'createImageBitmap from a HTMLCanvasElement with a big cropRect.'); |
| 79 |
| 80 // HTMLImageElement |
| 81 promise_test(function() { |
| 82 return loadImage('resources/pattern.png').then(testImageBitmap); |
| 83 }, 'createImageBitmap from a HTMLImageElement with a big cropRect.'); |
| 84 |
| 85 // ImageBitmap |
| 86 promise_test(function() { |
| 87 var testCanvas = initializeTestCanvas(); |
| 88 return createImageBitmap(testCanvas).then(testImageBitmap); |
| 89 }, 'createImageBitmap from an ImageBitmap with a big cropRect.'); |
| 90 |
| 91 // ImageData |
| 92 promise_test(function() { |
| 93 var canvas = initializeTestCanvas(); |
| 94 var ctx = canvas.getContext("2d"); |
| 95 var data = ctx.getImageData(0, 0, 20, 20); |
| 96 return testImageBitmap(data); |
| 97 }, 'createImageBitmap from an ImageData with a big cropRect.'); |
| 98 |
| 99 // HTMLVideoElement |
| 100 promise_test(function() { |
| 101 return loadVideo('../../compositing/resources/video.ogv').then(testImageBitm
ap); |
| 102 }, 'createImageBitmap from a HTMLVideoElement with resize option.'); |
| 103 </script> |
OLD | NEW |