[WRTjs] Enable WRTjs
[platform/framework/web/chromium-efl.git] / electron / spec / api-native-image-spec.ts
1 import { expect } from 'chai';
2 import { nativeImage } from 'electron/common';
3 import { ifdescribe, ifit } from './lib/spec-helpers';
4 import * as path from 'node:path';
5
6 describe('nativeImage module', () => {
7   const fixturesPath = path.join(__dirname, 'fixtures');
8
9   const imageLogo = {
10     path: path.join(fixturesPath, 'assets', 'logo.png'),
11     width: 538,
12     height: 190
13   };
14   const image1x1 = {
15     dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=',
16     path: path.join(fixturesPath, 'assets', '1x1.png'),
17     height: 1,
18     width: 1
19   };
20   const image2x2 = {
21     dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVQYlWP8//8/AwMDEwMDAwMDAwAkBgMBBMzldwAAAABJRU5ErkJggg==',
22     path: path.join(fixturesPath, 'assets', '2x2.jpg'),
23     height: 2,
24     width: 2
25   };
26   const image3x3 = {
27     dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAADElEQVQYlWNgIAoAAAAnAAGZWEMnAAAAAElFTkSuQmCC',
28     path: path.join(fixturesPath, 'assets', '3x3.png'),
29     height: 3,
30     width: 3
31   };
32
33   const dataUrlImages = [
34     image1x1,
35     image2x2,
36     image3x3
37   ];
38
39   ifdescribe(process.platform === 'darwin')('isMacTemplateImage state', () => {
40     describe('with properties', () => {
41       it('correctly recognizes a template image', () => {
42         const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
43         expect(image.isMacTemplateImage).to.be.false();
44
45         const templateImage = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo_Template.png'));
46         expect(templateImage.isMacTemplateImage).to.be.true();
47       });
48
49       it('sets a template image', function () {
50         const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
51         expect(image.isMacTemplateImage).to.be.false();
52
53         image.isMacTemplateImage = true;
54         expect(image.isMacTemplateImage).to.be.true();
55       });
56     });
57
58     describe('with functions', () => {
59       it('correctly recognizes a template image', () => {
60         const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
61         expect(image.isTemplateImage()).to.be.false();
62
63         const templateImage = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo_Template.png'));
64         expect(templateImage.isTemplateImage()).to.be.true();
65       });
66
67       it('sets a template image', function () {
68         const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
69         expect(image.isTemplateImage()).to.be.false();
70
71         image.setTemplateImage(true);
72         expect(image.isTemplateImage()).to.be.true();
73       });
74     });
75   });
76
77   describe('createEmpty()', () => {
78     it('returns an empty image', () => {
79       const empty = nativeImage.createEmpty();
80       expect(empty.isEmpty()).to.be.true();
81       expect(empty.getAspectRatio()).to.equal(1);
82       expect(empty.toDataURL()).to.equal('data:image/png;base64,');
83       expect(empty.toDataURL({ scaleFactor: 2.0 })).to.equal('data:image/png;base64,');
84       expect(empty.getSize()).to.deep.equal({ width: 0, height: 0 });
85       expect(empty.getBitmap()).to.be.empty();
86       expect(empty.getBitmap({ scaleFactor: 2.0 })).to.be.empty();
87       expect(empty.toBitmap()).to.be.empty();
88       expect(empty.toBitmap({ scaleFactor: 2.0 })).to.be.empty();
89       expect(empty.toJPEG(100)).to.be.empty();
90       expect(empty.toPNG()).to.be.empty();
91       expect(empty.toPNG({ scaleFactor: 2.0 })).to.be.empty();
92
93       if (process.platform === 'darwin') {
94         expect(empty.getNativeHandle()).to.be.empty();
95       }
96     });
97   });
98
99   describe('createFromBitmap(buffer, options)', () => {
100     it('returns an empty image when the buffer is empty', () => {
101       expect(nativeImage.createFromBitmap(Buffer.from([]), { width: 0, height: 0 }).isEmpty()).to.be.true();
102     });
103
104     it('returns an image created from the given buffer', () => {
105       const imageA = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
106
107       const imageB = nativeImage.createFromBitmap(imageA.toBitmap(), imageA.getSize());
108       expect(imageB.getSize()).to.deep.equal({ width: 538, height: 190 });
109
110       const imageC = nativeImage.createFromBuffer(imageA.toBitmap(), { ...imageA.getSize(), scaleFactor: 2.0 });
111       expect(imageC.getSize()).to.deep.equal({ width: 269, height: 95 });
112     });
113
114     it('throws on invalid arguments', () => {
115       expect(() => nativeImage.createFromBitmap(null as any, {} as any)).to.throw('buffer must be a node Buffer');
116       expect(() => nativeImage.createFromBitmap([12, 14, 124, 12] as any, {} as any)).to.throw('buffer must be a node Buffer');
117       expect(() => nativeImage.createFromBitmap(Buffer.from([]), {} as any)).to.throw('width is required');
118       expect(() => nativeImage.createFromBitmap(Buffer.from([]), { width: 1 } as any)).to.throw('height is required');
119       expect(() => nativeImage.createFromBitmap(Buffer.from([]), { width: 1, height: 1 })).to.throw('invalid buffer size');
120     });
121   });
122
123   describe('createFromBuffer(buffer, options)', () => {
124     it('returns an empty image when the buffer is empty', () => {
125       expect(nativeImage.createFromBuffer(Buffer.from([])).isEmpty()).to.be.true();
126     });
127
128     it('returns an empty image when the buffer is too small', () => {
129       const image = nativeImage.createFromBuffer(Buffer.from([1, 2, 3, 4]), { width: 100, height: 100 });
130       expect(image.isEmpty()).to.be.true();
131     });
132
133     it('returns an image created from the given buffer', () => {
134       const imageA = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
135
136       const imageB = nativeImage.createFromBuffer(imageA.toPNG());
137       expect(imageB.getSize()).to.deep.equal({ width: 538, height: 190 });
138       expect(imageA.toBitmap().equals(imageB.toBitmap())).to.be.true();
139
140       const imageC = nativeImage.createFromBuffer(imageA.toJPEG(100));
141       expect(imageC.getSize()).to.deep.equal({ width: 538, height: 190 });
142
143       const imageD = nativeImage.createFromBuffer(imageA.toBitmap(),
144         { width: 538, height: 190 });
145       expect(imageD.getSize()).to.deep.equal({ width: 538, height: 190 });
146
147       const imageE = nativeImage.createFromBuffer(imageA.toBitmap(),
148         { width: 100, height: 200 });
149       expect(imageE.getSize()).to.deep.equal({ width: 100, height: 200 });
150
151       const imageF = nativeImage.createFromBuffer(imageA.toBitmap());
152       expect(imageF.isEmpty()).to.be.true();
153
154       const imageG = nativeImage.createFromBuffer(imageA.toPNG(),
155         { width: 100, height: 200 });
156       expect(imageG.getSize()).to.deep.equal({ width: 538, height: 190 });
157
158       const imageH = nativeImage.createFromBuffer(imageA.toJPEG(100),
159         { width: 100, height: 200 });
160       expect(imageH.getSize()).to.deep.equal({ width: 538, height: 190 });
161
162       const imageI = nativeImage.createFromBuffer(imageA.toBitmap(),
163         { width: 538, height: 190, scaleFactor: 2.0 });
164       expect(imageI.getSize()).to.deep.equal({ width: 269, height: 95 });
165     });
166
167     it('throws on invalid arguments', () => {
168       expect(() => nativeImage.createFromBuffer(null as any)).to.throw('buffer must be a node Buffer');
169       expect(() => nativeImage.createFromBuffer([12, 14, 124, 12] as any)).to.throw('buffer must be a node Buffer');
170     });
171   });
172
173   describe('createFromDataURL(dataURL)', () => {
174     it('returns an empty image from the empty string', () => {
175       expect(nativeImage.createFromDataURL('').isEmpty()).to.be.true();
176     });
177
178     it('returns an image created from the given string', () => {
179       for (const imageData of dataUrlImages) {
180         const imageFromPath = nativeImage.createFromPath(imageData.path);
181         const imageFromDataUrl = nativeImage.createFromDataURL(imageData.dataUrl!);
182
183         expect(imageFromDataUrl.isEmpty()).to.be.false();
184         expect(imageFromDataUrl.getSize()).to.deep.equal(imageFromPath.getSize());
185         expect(imageFromDataUrl.toBitmap()).to.satisfy(
186           (bitmap: any) => imageFromPath.toBitmap().equals(bitmap));
187         expect(imageFromDataUrl.toDataURL()).to.equal(imageFromPath.toDataURL());
188       }
189     });
190   });
191
192   describe('toDataURL()', () => {
193     it('returns a PNG data URL', () => {
194       for (const imageData of dataUrlImages) {
195         const imageFromPath = nativeImage.createFromPath(imageData.path!);
196
197         const scaleFactors = [1.0, 2.0];
198         for (const scaleFactor of scaleFactors) {
199           expect(imageFromPath.toDataURL({ scaleFactor })).to.equal(imageData.dataUrl);
200         }
201       }
202     });
203
204     it('returns a data URL at 1x scale factor by default', () => {
205       const imageData = imageLogo;
206       const image = nativeImage.createFromPath(imageData.path);
207
208       const imageOne = nativeImage.createFromBuffer(image.toPNG(), {
209         width: image.getSize().width,
210         height: image.getSize().height,
211         scaleFactor: 2.0
212       });
213       expect(imageOne.getSize()).to.deep.equal(
214         { width: imageData.width / 2, height: imageData.height / 2 });
215
216       const imageTwo = nativeImage.createFromDataURL(imageOne.toDataURL());
217       expect(imageTwo.getSize()).to.deep.equal(
218         { width: imageData.width, height: imageData.height });
219
220       expect(imageOne.toBitmap().equals(imageTwo.toBitmap())).to.be.true();
221     });
222
223     it('supports a scale factor', () => {
224       const imageData = imageLogo;
225       const image = nativeImage.createFromPath(imageData.path);
226       const expectedSize = { width: imageData.width, height: imageData.height };
227
228       const imageFromDataUrlOne = nativeImage.createFromDataURL(
229         image.toDataURL({ scaleFactor: 1.0 }));
230       expect(imageFromDataUrlOne.getSize()).to.deep.equal(expectedSize);
231
232       const imageFromDataUrlTwo = nativeImage.createFromDataURL(
233         image.toDataURL({ scaleFactor: 2.0 }));
234       expect(imageFromDataUrlTwo.getSize()).to.deep.equal(expectedSize);
235     });
236   });
237
238   describe('toPNG()', () => {
239     it('returns a buffer at 1x scale factor by default', () => {
240       const imageData = imageLogo;
241       const imageA = nativeImage.createFromPath(imageData.path);
242
243       const imageB = nativeImage.createFromBuffer(imageA.toPNG(), {
244         width: imageA.getSize().width,
245         height: imageA.getSize().height,
246         scaleFactor: 2.0
247       });
248       expect(imageB.getSize()).to.deep.equal(
249         { width: imageData.width / 2, height: imageData.height / 2 });
250
251       const imageC = nativeImage.createFromBuffer(imageB.toPNG());
252       expect(imageC.getSize()).to.deep.equal(
253         { width: imageData.width, height: imageData.height });
254
255       expect(imageB.toBitmap().equals(imageC.toBitmap())).to.be.true();
256     });
257
258     it('supports a scale factor', () => {
259       const imageData = imageLogo;
260       const image = nativeImage.createFromPath(imageData.path);
261
262       const imageFromBufferOne = nativeImage.createFromBuffer(
263         image.toPNG({ scaleFactor: 1.0 }));
264       expect(imageFromBufferOne.getSize()).to.deep.equal(
265         { width: imageData.width, height: imageData.height });
266
267       const imageFromBufferTwo = nativeImage.createFromBuffer(
268         image.toPNG({ scaleFactor: 2.0 }), { scaleFactor: 2.0 });
269       expect(imageFromBufferTwo.getSize()).to.deep.equal(
270         { width: imageData.width / 2, height: imageData.height / 2 });
271     });
272   });
273
274   describe('createFromPath(path)', () => {
275     it('returns an empty image for invalid paths', () => {
276       expect(nativeImage.createFromPath('').isEmpty()).to.be.true();
277       expect(nativeImage.createFromPath('does-not-exist.png').isEmpty()).to.be.true();
278       expect(nativeImage.createFromPath('does-not-exist.ico').isEmpty()).to.be.true();
279       expect(nativeImage.createFromPath(__dirname).isEmpty()).to.be.true();
280       expect(nativeImage.createFromPath(__filename).isEmpty()).to.be.true();
281     });
282
283     it('loads images from paths relative to the current working directory', () => {
284       const imagePath = path.relative('.', path.join(fixturesPath, 'assets', 'logo.png'));
285       const image = nativeImage.createFromPath(imagePath);
286       expect(image.isEmpty()).to.be.false();
287       expect(image.getSize()).to.deep.equal({ width: 538, height: 190 });
288     });
289
290     it('loads images from paths with `.` segments', () => {
291       const imagePath = `${path.join(fixturesPath)}${path.sep}.${path.sep}${path.join('assets', 'logo.png')}`;
292       const image = nativeImage.createFromPath(imagePath);
293       expect(image.isEmpty()).to.be.false();
294       expect(image.getSize()).to.deep.equal({ width: 538, height: 190 });
295     });
296
297     it('loads images from paths with `..` segments', () => {
298       const imagePath = `${path.join(fixturesPath, 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`;
299       const image = nativeImage.createFromPath(imagePath);
300       expect(image.isEmpty()).to.be.false();
301       expect(image.getSize()).to.deep.equal({ width: 538, height: 190 });
302     });
303
304     ifit(process.platform === 'darwin')('Gets an NSImage pointer on macOS', function () {
305       const imagePath = `${path.join(fixturesPath, 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`;
306       const image = nativeImage.createFromPath(imagePath);
307       const nsimage = image.getNativeHandle();
308
309       expect(nsimage).to.have.lengthOf(8);
310
311       // If all bytes are null, that's Bad
312       const allBytesAreNotNull = nsimage.reduce((acc, x) => acc || (x !== 0), false);
313       expect(allBytesAreNotNull);
314     });
315
316     ifit(process.platform === 'win32')('loads images from .ico files on Windows', function () {
317       const imagePath = path.join(fixturesPath, 'assets', 'icon.ico');
318       const image = nativeImage.createFromPath(imagePath);
319       expect(image.isEmpty()).to.be.false();
320       expect(image.getSize()).to.deep.equal({ width: 256, height: 256 });
321     });
322   });
323
324   describe('createFromNamedImage(name)', () => {
325     it('returns empty for invalid options', () => {
326       const image = nativeImage.createFromNamedImage('totally_not_real');
327       expect(image.isEmpty()).to.be.true();
328     });
329
330     ifit(process.platform !== 'darwin')('returns empty on non-darwin platforms', function () {
331       const image = nativeImage.createFromNamedImage('NSActionTemplate');
332       expect(image.isEmpty()).to.be.true();
333     });
334
335     ifit(process.platform === 'darwin')('returns a valid image on darwin', function () {
336       const image = nativeImage.createFromNamedImage('NSActionTemplate');
337       expect(image.isEmpty()).to.be.false();
338     });
339
340     ifit(process.platform === 'darwin')('returns allows an HSL shift for a valid image on darwin', function () {
341       const image = nativeImage.createFromNamedImage('NSActionTemplate', [0.5, 0.2, 0.8]);
342       expect(image.isEmpty()).to.be.false();
343     });
344   });
345
346   describe('resize(options)', () => {
347     it('returns a resized image', () => {
348       const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
349       for (const [resizeTo, expectedSize] of new Map([
350         [{}, { width: 538, height: 190 }],
351         [{ width: 269 }, { width: 269, height: 95 }],
352         [{ width: 600 }, { width: 600, height: 212 }],
353         [{ height: 95 }, { width: 269, height: 95 }],
354         [{ height: 200 }, { width: 566, height: 200 }],
355         [{ width: 80, height: 65 }, { width: 80, height: 65 }],
356         [{ width: 600, height: 200 }, { width: 600, height: 200 }],
357         [{ width: 0, height: 0 }, { width: 0, height: 0 }],
358         [{ width: -1, height: -1 }, { width: 0, height: 0 }]
359       ])) {
360         const actualSize = image.resize(resizeTo).getSize();
361         expect(actualSize).to.deep.equal(expectedSize);
362       }
363     });
364
365     it('returns an empty image when called on an empty image', () => {
366       expect(nativeImage.createEmpty().resize({ width: 1, height: 1 }).isEmpty()).to.be.true();
367       expect(nativeImage.createEmpty().resize({ width: 0, height: 0 }).isEmpty()).to.be.true();
368     });
369
370     it('supports a quality option', () => {
371       const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
372       const good = image.resize({ width: 100, height: 100, quality: 'good' });
373       const better = image.resize({ width: 100, height: 100, quality: 'better' });
374       const best = image.resize({ width: 100, height: 100, quality: 'best' });
375
376       expect(good.toPNG()).to.have.lengthOf.at.most(better.toPNG().length);
377       expect(better.toPNG()).to.have.lengthOf.below(best.toPNG().length);
378     });
379   });
380
381   describe('crop(bounds)', () => {
382     it('returns an empty image when called on an empty image', () => {
383       expect(nativeImage.createEmpty().crop({ width: 1, height: 2, x: 0, y: 0 }).isEmpty()).to.be.true();
384       expect(nativeImage.createEmpty().crop({ width: 0, height: 0, x: 0, y: 0 }).isEmpty()).to.be.true();
385     });
386
387     it('returns an empty image when the bounds are invalid', () => {
388       const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
389       expect(image.crop({ width: 0, height: 0, x: 0, y: 0 }).isEmpty()).to.be.true();
390       expect(image.crop({ width: -1, height: 10, x: 0, y: 0 }).isEmpty()).to.be.true();
391       expect(image.crop({ width: 10, height: -35, x: 0, y: 0 }).isEmpty()).to.be.true();
392       expect(image.crop({ width: 100, height: 100, x: 1000, y: 1000 }).isEmpty()).to.be.true();
393     });
394
395     it('returns a cropped image', () => {
396       const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
397       const cropA = image.crop({ width: 25, height: 64, x: 0, y: 0 });
398       const cropB = image.crop({ width: 25, height: 64, x: 30, y: 40 });
399       expect(cropA.getSize()).to.deep.equal({ width: 25, height: 64 });
400       expect(cropB.getSize()).to.deep.equal({ width: 25, height: 64 });
401       expect(cropA.toPNG().equals(cropB.toPNG())).to.be.false();
402     });
403
404     it('toBitmap() returns a buffer of the right size', () => {
405       const image = nativeImage.createFromPath(path.join(fixturesPath, 'assets', 'logo.png'));
406       const crop = image.crop({ width: 25, height: 64, x: 0, y: 0 });
407       expect(crop.toBitmap().length).to.equal(25 * 64 * 4);
408     });
409   });
410
411   describe('getAspectRatio()', () => {
412     it('returns an aspect ratio of an empty image', () => {
413       expect(nativeImage.createEmpty().getAspectRatio()).to.equal(1.0);
414     });
415
416     it('returns an aspect ratio of an image', () => {
417       const imageData = imageLogo;
418       // imageData.width / imageData.height = 2.831578947368421
419       const expectedAspectRatio = 2.8315789699554443;
420
421       const image = nativeImage.createFromPath(imageData.path);
422       expect(image.getAspectRatio()).to.equal(expectedAspectRatio);
423     });
424   });
425
426   ifdescribe(process.platform !== 'linux')('createThumbnailFromPath(path, size)', () => {
427     it('throws when invalid size is passed', async () => {
428       const badSize = { width: -1, height: -1 };
429
430       await expect(
431         nativeImage.createThumbnailFromPath('path', badSize)
432       ).to.eventually.be.rejectedWith('size must not be empty');
433     });
434
435     it('throws when a bad path is passed', async () => {
436       const badPath = process.platform === 'win32' ? '\\hey\\hi\\hello' : '/hey/hi/hello';
437       const goodSize = { width: 100, height: 100 };
438
439       await expect(
440         nativeImage.createThumbnailFromPath(badPath, goodSize)
441       ).to.eventually.be.rejected();
442     });
443
444     it('returns native image given valid params', async () => {
445       const goodPath = path.join(fixturesPath, 'assets', 'logo.png');
446       const goodSize = { width: 100, height: 100 };
447       const result = await nativeImage.createThumbnailFromPath(goodPath, goodSize);
448       expect(result.isEmpty()).to.equal(false);
449     });
450
451     it('returns the correct size if larger than the initial image', async () => {
452       // capybara.png is a 128x128 image.
453       const imgPath = path.join(fixturesPath, 'assets', 'capybara.png');
454       const size = { width: 256, height: 256 };
455       const result = await nativeImage.createThumbnailFromPath(imgPath, size);
456       expect(result.getSize()).to.deep.equal(size);
457     });
458
459     it('returns the correct size if is the same as the initial image', async () => {
460       // capybara.png is a 128x128 image.
461       const imgPath = path.join(fixturesPath, 'assets', 'capybara.png');
462       const size = { width: 128, height: 128 };
463       const result = await nativeImage.createThumbnailFromPath(imgPath, size);
464       expect(result.getSize()).to.deep.equal(size);
465     });
466
467     it('returns the correct size if smaller than the initial image', async () => {
468       // capybara.png is a 128x128 image.
469       const imgPath = path.join(fixturesPath, 'assets', 'capybara.png');
470       const maxSize = { width: 64, height: 64 };
471       const result = await nativeImage.createThumbnailFromPath(imgPath, maxSize);
472       expect(result.getSize()).to.deep.equal(maxSize);
473     });
474   });
475
476   describe('addRepresentation()', () => {
477     it('does not add representation when the buffer is too small', () => {
478       const image = nativeImage.createEmpty();
479
480       image.addRepresentation({
481         buffer: Buffer.from([1, 2, 3, 4]),
482         width: 100,
483         height: 100
484       });
485
486       expect(image.isEmpty()).to.be.true();
487     });
488
489     it('supports adding a buffer representation for a scale factor', () => {
490       const image = nativeImage.createEmpty();
491
492       const imageDataOne = image1x1;
493       image.addRepresentation({
494         scaleFactor: 1.0,
495         buffer: nativeImage.createFromPath(imageDataOne.path).toPNG()
496       });
497
498       expect(image.getScaleFactors()).to.deep.equal([1]);
499
500       const imageDataTwo = image2x2;
501       image.addRepresentation({
502         scaleFactor: 2.0,
503         buffer: nativeImage.createFromPath(imageDataTwo.path).toPNG()
504       });
505
506       expect(image.getScaleFactors()).to.deep.equal([1, 2]);
507
508       const imageDataThree = image3x3;
509       image.addRepresentation({
510         scaleFactor: 3.0,
511         buffer: nativeImage.createFromPath(imageDataThree.path).toPNG()
512       });
513
514       expect(image.getScaleFactors()).to.deep.equal([1, 2, 3]);
515
516       image.addRepresentation({
517         scaleFactor: 4.0,
518         buffer: 'invalid' as any
519       });
520
521       // this one failed, so it shouldn't show up in the scale factors
522       expect(image.getScaleFactors()).to.deep.equal([1, 2, 3]);
523
524       expect(image.isEmpty()).to.be.false();
525       expect(image.getSize()).to.deep.equal({ width: 1, height: 1 });
526
527       expect(image.toDataURL({ scaleFactor: 1.0 })).to.equal(imageDataOne.dataUrl);
528       expect(image.toDataURL({ scaleFactor: 2.0 })).to.equal(imageDataTwo.dataUrl);
529       expect(image.toDataURL({ scaleFactor: 3.0 })).to.equal(imageDataThree.dataUrl);
530       expect(image.toDataURL({ scaleFactor: 4.0 })).to.equal(imageDataThree.dataUrl);
531     });
532
533     it('supports adding a data URL representation for a scale factor', () => {
534       const image = nativeImage.createEmpty();
535
536       const imageDataOne = image1x1;
537       image.addRepresentation({
538         scaleFactor: 1.0,
539         dataURL: imageDataOne.dataUrl
540       });
541
542       const imageDataTwo = image2x2;
543       image.addRepresentation({
544         scaleFactor: 2.0,
545         dataURL: imageDataTwo.dataUrl
546       });
547
548       const imageDataThree = image3x3;
549       image.addRepresentation({
550         scaleFactor: 3.0,
551         dataURL: imageDataThree.dataUrl
552       });
553
554       image.addRepresentation({
555         scaleFactor: 4.0,
556         dataURL: 'invalid'
557       });
558
559       expect(image.isEmpty()).to.be.false();
560       expect(image.getSize()).to.deep.equal({ width: 1, height: 1 });
561
562       expect(image.toDataURL({ scaleFactor: 1.0 })).to.equal(imageDataOne.dataUrl);
563       expect(image.toDataURL({ scaleFactor: 2.0 })).to.equal(imageDataTwo.dataUrl);
564       expect(image.toDataURL({ scaleFactor: 3.0 })).to.equal(imageDataThree.dataUrl);
565       expect(image.toDataURL({ scaleFactor: 4.0 })).to.equal(imageDataThree.dataUrl);
566     });
567
568     it('supports adding a representation to an existing image', () => {
569       const imageDataOne = image1x1;
570       const image = nativeImage.createFromPath(imageDataOne.path);
571
572       const imageDataTwo = image2x2;
573       image.addRepresentation({
574         scaleFactor: 2.0,
575         dataURL: imageDataTwo.dataUrl
576       });
577
578       const imageDataThree = image3x3;
579       image.addRepresentation({
580         scaleFactor: 2.0,
581         dataURL: imageDataThree.dataUrl
582       });
583
584       expect(image.toDataURL({ scaleFactor: 1.0 })).to.equal(imageDataOne.dataUrl);
585       expect(image.toDataURL({ scaleFactor: 2.0 })).to.equal(imageDataTwo.dataUrl);
586     });
587   });
588 });