|
68 | 68 | }
|
69 | 69 | }
|
70 | 70 |
|
| 71 | + /** |
| 72 | + * Request helper function. |
| 73 | + * |
| 74 | + * @param {string} url URL to request |
| 75 | + * @param {Function} callback Request callback |
| 76 | + */ |
| 77 | + function request(url, callback) { |
| 78 | + var xhr = new XMLHttpRequest() |
| 79 | + xhr.onload = callback |
| 80 | + xhr.onerror = callback |
| 81 | + try { |
| 82 | + xhr.open('GET', url, true) |
| 83 | + } catch (e) { |
| 84 | + callback.call(xhr, e) |
| 85 | + return |
| 86 | + } |
| 87 | + xhr.send() |
| 88 | + } |
| 89 | + |
71 | 90 | describe('Loading', function () {
|
72 | 91 | it('Return an object with onload and onerror methods', function () {
|
73 | 92 | var img = loadImage(blobGIF, function () {})
|
|
116 | 135 | ).to.be.ok
|
117 | 136 | })
|
118 | 137 |
|
119 |
| - it('Keep object URL if noRevoke is true', function (done) { |
120 |
| - expect( |
121 |
| - loadImage( |
122 |
| - blobGIF, |
123 |
| - function (img) { |
124 |
| - loadImage(img.src, function (img2) { |
125 |
| - expect(img.width).to.equal(img2.width) |
126 |
| - expect(img.height).to.equal(img2.height) |
| 138 | + describe('ObjectURL revoke', function () { |
| 139 | + // Using XMLHttpRequest via the request helper function to test Object |
| 140 | + // URLs to work around Edge Legacy and IE caching image URLs. |
| 141 | + if (!window.XMLHttpRequest) return |
| 142 | + |
| 143 | + it('Keep object URL if noRevoke is set to true', function (done) { |
| 144 | + expect( |
| 145 | + loadImage( |
| 146 | + blobGIF, |
| 147 | + function (img) { |
| 148 | + request(img.src, function (event) { |
| 149 | + expect(event.type).to.equal('load') |
| 150 | + done() |
| 151 | + }) |
| 152 | + }, |
| 153 | + { noRevoke: true } |
| 154 | + ) |
| 155 | + ).to.be.ok |
| 156 | + }) |
| 157 | + |
| 158 | + it('Discard object URL if noRevoke is not set', function (done) { |
| 159 | + expect( |
| 160 | + loadImage(blobGIF, function (img) { |
| 161 | + request(img.src, function (event) { |
| 162 | + // IE throws an error that has no type property: |
| 163 | + expect(event.type).to.be.oneOf(['error', undefined]) |
127 | 164 | done()
|
128 | 165 | })
|
129 |
| - }, |
130 |
| - { noRevoke: true } |
131 |
| - ) |
132 |
| - ).to.be.ok |
133 |
| - }) |
134 |
| - |
135 |
| - it('Discard object URL if noRevoke is undefined/false', function (done) { |
136 |
| - expect( |
137 |
| - loadImage(blobGIF, function (img) { |
138 |
| - loadImage(img.src, function (img2) { |
139 |
| - expect(img2).to.be.an.instanceOf(window.Event) |
140 |
| - expect(img2.type).to.equal('error') |
141 |
| - done() |
142 | 166 | })
|
143 |
| - }) |
144 |
| - ).to.be.ok |
| 167 | + ).to.be.ok |
| 168 | + }) |
145 | 169 | })
|
146 | 170 | })
|
147 | 171 |
|
|
1232 | 1256 | it('Should fetch image URL as blob if meta option is true', function (done) {
|
1233 | 1257 | expect(
|
1234 | 1258 | loadImage(
|
1235 |
| - // IE11 does not allow XMLHttpRequest access to data URLs, |
| 1259 | + // IE does not allow XMLHttpRequest access to data URLs, |
1236 | 1260 | // so we use an ObjectURL instead of imageUrlJPEG directly:
|
1237 | 1261 | loadImage.createObjectURL(blobJPEG),
|
1238 | 1262 | function (img, data) {
|
|
0 commit comments