Skip to content

Commit d1cb9e1

Browse files
committed
Test: Loading an image from a File object.
1 parent d311ff6 commit d1cb9e1

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

test/test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
canCreateBlob: !!window.dataURLtoBlob
2020
}
2121

22-
// black 60x40 GIF
22+
// black+white 60x40 GIF
2323
// Image data layout (B=black, F=white), scaled to 3x2:
2424
// BFF
2525
// BBB
@@ -29,6 +29,12 @@
2929
'stpXsLv9gr2q8UZshnDTjTUbWH7TqvS6/Y7P6/f8vv9vVwAAOw=='
3030
var imageUrlGIF = 'data:image/gif;base64,' + b64DataGIF
3131
var blobGIF = browser.canCreateBlob && window.dataURLtoBlob(imageUrlGIF)
32+
var fileGIF
33+
try {
34+
fileGIF = new File([blobGIF], 'image.gif')
35+
} catch (_) {
36+
// No File constructor support
37+
}
3238

3339
// black 3x2 GIF
3440
// Image data layout (B=black, F=white):
@@ -206,7 +212,22 @@
206212
).to.be.ok
207213
})
208214

209-
describe('Object URL revoke', function () {
215+
describe('File', function () {
216+
if (!fileGIF) return
217+
218+
it('Load image file as img element', function (done) {
219+
expect(
220+
loadImage(fileGIF, function (img) {
221+
expect(img.nodeName.toLowerCase()).to.equal('img')
222+
expect(img.width).to.equal(60)
223+
expect(img.height).to.equal(40)
224+
done()
225+
})
226+
).to.be.ok
227+
})
228+
})
229+
230+
describe('Object URL', function () {
210231
// Using XMLHttpRequest via the request helper function to test Object
211232
// URLs to work around Edge Legacy and IE caching image URLs.
212233
if (!window.XMLHttpRequest) return

0 commit comments

Comments
 (0)