2020-03-20 20:28:31 +00:00
|
|
|
'use strict';
|
2016-03-04 22:54:12 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const { expect } = require('chai');
|
|
|
|
const { nativeImage } = require('electron');
|
|
|
|
const { ifdescribe, ifit } = require('./spec-helpers');
|
|
|
|
const path = require('path');
|
2016-03-04 20:03:13 +00:00
|
|
|
|
2016-03-04 22:54:12 +00:00
|
|
|
describe('nativeImage module', () => {
|
2017-10-31 16:57:31 +00:00
|
|
|
const ImageFormat = {
|
|
|
|
PNG: 'png',
|
|
|
|
JPEG: 'jpeg'
|
2020-03-20 20:28:31 +00:00
|
|
|
};
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
const images = [
|
|
|
|
{
|
|
|
|
filename: 'logo.png',
|
|
|
|
format: ImageFormat.PNG,
|
|
|
|
hasAlphaChannel: true,
|
|
|
|
hasDataUrl: false,
|
|
|
|
width: 538,
|
|
|
|
height: 190
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=',
|
|
|
|
filename: '1x1.png',
|
|
|
|
format: ImageFormat.PNG,
|
|
|
|
hasAlphaChannel: true,
|
|
|
|
hasDataUrl: true,
|
|
|
|
height: 1,
|
|
|
|
width: 1
|
|
|
|
},
|
|
|
|
{
|
2017-11-30 16:56:32 +00:00
|
|
|
dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVQYlWP8//8/AwMDEwMDAwMDAwAkBgMBBMzldwAAAABJRU5ErkJggg==',
|
2017-10-31 16:57:31 +00:00
|
|
|
filename: '2x2.jpg',
|
|
|
|
format: ImageFormat.JPEG,
|
|
|
|
hasAlphaChannel: false,
|
|
|
|
hasDataUrl: true,
|
|
|
|
height: 2,
|
|
|
|
width: 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAADElEQVQYlWNgIAoAAAAnAAGZWEMnAAAAAElFTkSuQmCC',
|
|
|
|
filename: '3x3.png',
|
|
|
|
format: ImageFormat.PNG,
|
|
|
|
hasAlphaChannel: true,
|
|
|
|
hasDataUrl: true,
|
|
|
|
height: 3,
|
|
|
|
width: 3
|
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
];
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?string} filename
|
|
|
|
* @returns {?string} Full path.
|
|
|
|
*/
|
|
|
|
const getImagePathFromFilename = (filename) => {
|
|
|
|
return (filename === null) ? null
|
2020-03-20 20:28:31 +00:00
|
|
|
: path.join(__dirname, 'fixtures', 'assets', filename);
|
|
|
|
};
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {!Object} image
|
|
|
|
* @param {Object} filters
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
const imageMatchesTheFilters = (image, filters = null) => {
|
|
|
|
if (filters === null) {
|
2020-03-20 20:28:31 +00:00
|
|
|
return true;
|
2017-10-31 16:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Object.entries(filters)
|
2020-03-20 20:28:31 +00:00
|
|
|
.every(([key, value]) => image[key] === value);
|
|
|
|
};
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {!Object} filters
|
|
|
|
* @returns {!Array} A matching images list.
|
|
|
|
*/
|
|
|
|
const getImages = (filters) => {
|
|
|
|
const matchingImages = images
|
2020-03-20 20:28:31 +00:00
|
|
|
.filter(i => imageMatchesTheFilters(i, filters));
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
// Add `.path` property to every image.
|
|
|
|
matchingImages
|
2020-03-20 20:28:31 +00:00
|
|
|
.forEach(i => { i.path = getImagePathFromFilename(i.filename); });
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
return matchingImages;
|
|
|
|
};
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {!Object} filters
|
|
|
|
* @returns {Object} A matching image if any.
|
|
|
|
*/
|
|
|
|
const getImage = (filters) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const matchingImages = getImages(filters);
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
let matchingImage = null;
|
2017-10-31 16:57:31 +00:00
|
|
|
if (matchingImages.length > 0) {
|
2020-03-20 20:28:31 +00:00
|
|
|
matchingImage = matchingImages[0];
|
2017-10-31 16:57:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
return matchingImage;
|
|
|
|
};
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-18 01:06:52 +00:00
|
|
|
ifdescribe(process.platform === 'darwin')('isMacTemplateImage state', () => {
|
|
|
|
describe('with properties', () => {
|
|
|
|
it('correctly recognizes a template image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
|
|
|
expect(image.isMacTemplateImage).to.be.false();
|
2019-05-07 13:52:07 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const templateImage = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo_Template.png'));
|
|
|
|
expect(templateImage.isMacTemplateImage).to.be.true();
|
|
|
|
});
|
2019-05-07 13:52:07 +00:00
|
|
|
|
2020-03-18 01:06:52 +00:00
|
|
|
it('sets a template image', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
|
|
|
expect(image.isMacTemplateImage).to.be.false();
|
2019-05-07 13:52:07 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
image.isMacTemplateImage = true;
|
|
|
|
expect(image.isMacTemplateImage).to.be.true();
|
|
|
|
});
|
|
|
|
});
|
2019-05-07 13:52:07 +00:00
|
|
|
|
2020-03-18 01:06:52 +00:00
|
|
|
describe('with functions', () => {
|
|
|
|
it('correctly recognizes a template image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
|
|
|
expect(image.isTemplateImage()).to.be.false();
|
2020-03-18 01:06:52 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const templateImage = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo_Template.png'));
|
|
|
|
expect(templateImage.isTemplateImage()).to.be.true();
|
|
|
|
});
|
2019-05-07 13:52:07 +00:00
|
|
|
|
2020-03-18 01:06:52 +00:00
|
|
|
it('sets a template image', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
|
|
|
expect(image.isTemplateImage()).to.be.false();
|
2019-05-07 13:52:07 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
image.setTemplateImage(true);
|
|
|
|
expect(image.isTemplateImage()).to.be.true();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-05-07 13:52:07 +00:00
|
|
|
|
2016-10-04 18:05:07 +00:00
|
|
|
describe('createEmpty()', () => {
|
|
|
|
it('returns an empty image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const empty = nativeImage.createEmpty();
|
|
|
|
expect(empty.isEmpty()).to.be.true();
|
|
|
|
expect(empty.getAspectRatio()).to.equal(1);
|
|
|
|
expect(empty.toDataURL()).to.equal('data:image/png;base64,');
|
|
|
|
expect(empty.toDataURL({ scaleFactor: 2.0 })).to.equal('data:image/png;base64,');
|
|
|
|
expect(empty.getSize()).to.deep.equal({ width: 0, height: 0 });
|
|
|
|
expect(empty.getBitmap()).to.be.empty();
|
|
|
|
expect(empty.getBitmap({ scaleFactor: 2.0 })).to.be.empty();
|
|
|
|
expect(empty.toBitmap()).to.be.empty();
|
|
|
|
expect(empty.toBitmap({ scaleFactor: 2.0 })).to.be.empty();
|
|
|
|
expect(empty.toJPEG(100)).to.be.empty();
|
|
|
|
expect(empty.toPNG()).to.be.empty();
|
|
|
|
expect(empty.toPNG({ scaleFactor: 2.0 })).to.be.empty();
|
2017-01-25 21:52:18 +00:00
|
|
|
|
|
|
|
if (process.platform === 'darwin') {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(empty.getNativeHandle()).to.be.empty();
|
2017-01-25 21:52:18 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
2016-10-04 18:05:07 +00:00
|
|
|
|
2019-03-14 18:00:38 +00:00
|
|
|
describe('createFromBitmap(buffer, options)', () => {
|
|
|
|
it('returns an empty image when the buffer is empty', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeImage.createFromBitmap(Buffer.from([]), { width: 0, height: 0 }).isEmpty()).to.be.true();
|
|
|
|
});
|
2019-03-14 18:00:38 +00:00
|
|
|
|
|
|
|
it('returns an image created from the given buffer', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageA = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
2019-03-14 18:00:38 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageB = nativeImage.createFromBitmap(imageA.toBitmap(), imageA.getSize());
|
|
|
|
expect(imageB.getSize()).to.deep.equal({ width: 538, height: 190 });
|
2019-03-14 18:00:38 +00:00
|
|
|
|
2020-08-24 16:58:55 +00:00
|
|
|
let imageC;
|
|
|
|
// TODO fix nativeImage.createFromBuffer from bitmaps on WOA. See https://github.com/electron/electron/issues/25069
|
|
|
|
if (process.platform === 'win32' && process.arch === 'arm64') {
|
|
|
|
imageC = nativeImage.createFromBuffer(imageA.toPNG(), { ...imageA.getSize(), scaleFactor: 2.0 });
|
|
|
|
} else {
|
|
|
|
imageC = nativeImage.createFromBuffer(imageA.toBitmap(), { ...imageA.getSize(), scaleFactor: 2.0 });
|
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(imageC.getSize()).to.deep.equal({ width: 269, height: 95 });
|
|
|
|
});
|
2019-03-14 18:00:38 +00:00
|
|
|
|
|
|
|
it('throws on invalid arguments', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(() => nativeImage.createFromBitmap(null, {})).to.throw('buffer must be a node Buffer');
|
|
|
|
expect(() => nativeImage.createFromBitmap([12, 14, 124, 12], {})).to.throw('buffer must be a node Buffer');
|
|
|
|
expect(() => nativeImage.createFromBitmap(Buffer.from([]), {})).to.throw('width is required');
|
|
|
|
expect(() => nativeImage.createFromBitmap(Buffer.from([]), { width: 1 })).to.throw('height is required');
|
|
|
|
expect(() => nativeImage.createFromBitmap(Buffer.from([]), { width: 1, height: 1 })).to.throw('invalid buffer size');
|
|
|
|
});
|
|
|
|
});
|
2019-03-14 18:00:38 +00:00
|
|
|
|
2020-08-24 16:58:55 +00:00
|
|
|
// TODO fix nativeImage.createFromBuffer on WOA. See https://github.com/electron/electron/issues/25069
|
|
|
|
ifdescribe(!(process.platform === 'win32' && process.arch === 'arm64'))('createFromBuffer(buffer, options)', () => {
|
2016-10-04 18:05:07 +00:00
|
|
|
it('returns an empty image when the buffer is empty', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeImage.createFromBuffer(Buffer.from([])).isEmpty()).to.be.true();
|
|
|
|
});
|
2016-10-04 18:05:07 +00:00
|
|
|
|
2019-03-26 01:13:39 +00:00
|
|
|
it('returns an empty image when the buffer is too small', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromBuffer(Buffer.from([1, 2, 3, 4]), { width: 100, height: 100 });
|
|
|
|
expect(image.isEmpty()).to.be.true();
|
|
|
|
});
|
2019-03-26 01:13:39 +00:00
|
|
|
|
2016-10-04 18:05:07 +00:00
|
|
|
it('returns an image created from the given buffer', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageA = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
2016-10-04 18:05:07 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageB = nativeImage.createFromBuffer(imageA.toPNG());
|
|
|
|
expect(imageB.getSize()).to.deep.equal({ width: 538, height: 190 });
|
|
|
|
expect(imageA.toBitmap().equals(imageB.toBitmap())).to.be.true();
|
2016-10-04 18:05:07 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageC = nativeImage.createFromBuffer(imageA.toJPEG(100));
|
|
|
|
expect(imageC.getSize()).to.deep.equal({ width: 538, height: 190 });
|
2016-12-09 23:12:36 +00:00
|
|
|
|
2016-12-13 20:30:45 +00:00
|
|
|
const imageD = nativeImage.createFromBuffer(imageA.toBitmap(),
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: 538, height: 190 });
|
|
|
|
expect(imageD.getSize()).to.deep.equal({ width: 538, height: 190 });
|
2016-12-13 23:18:24 +00:00
|
|
|
|
|
|
|
const imageE = nativeImage.createFromBuffer(imageA.toBitmap(),
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: 100, height: 200 });
|
|
|
|
expect(imageE.getSize()).to.deep.equal({ width: 100, height: 200 });
|
2016-12-13 23:18:24 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageF = nativeImage.createFromBuffer(imageA.toBitmap());
|
|
|
|
expect(imageF.isEmpty()).to.be.true();
|
2016-12-13 23:18:24 +00:00
|
|
|
|
2016-12-13 23:24:57 +00:00
|
|
|
const imageG = nativeImage.createFromBuffer(imageA.toPNG(),
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: 100, height: 200 });
|
|
|
|
expect(imageG.getSize()).to.deep.equal({ width: 538, height: 190 });
|
2016-12-13 23:24:57 +00:00
|
|
|
|
|
|
|
const imageH = nativeImage.createFromBuffer(imageA.toJPEG(100),
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: 100, height: 200 });
|
|
|
|
expect(imageH.getSize()).to.deep.equal({ width: 538, height: 190 });
|
2016-12-14 18:18:01 +00:00
|
|
|
|
|
|
|
const imageI = nativeImage.createFromBuffer(imageA.toBitmap(),
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: 538, height: 190, scaleFactor: 2.0 });
|
|
|
|
expect(imageI.getSize()).to.deep.equal({ width: 269, height: 95 });
|
|
|
|
});
|
2019-03-13 15:26:11 +00:00
|
|
|
|
|
|
|
it('throws on invalid arguments', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(() => nativeImage.createFromBuffer(null)).to.throw('buffer must be a node Buffer');
|
|
|
|
expect(() => nativeImage.createFromBuffer([12, 14, 124, 12])).to.throw('buffer must be a node Buffer');
|
|
|
|
});
|
|
|
|
});
|
2016-10-04 18:05:07 +00:00
|
|
|
|
|
|
|
describe('createFromDataURL(dataURL)', () => {
|
2017-10-31 16:57:31 +00:00
|
|
|
it('returns an empty image from the empty string', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeImage.createFromDataURL('').isEmpty()).to.be.true();
|
|
|
|
});
|
2016-10-04 18:05:07 +00:00
|
|
|
|
2017-10-31 16:57:31 +00:00
|
|
|
it('returns an image created from the given string', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imagesData = getImages({ hasDataUrl: true });
|
2017-10-31 16:57:31 +00:00
|
|
|
for (const imageData of imagesData) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageFromPath = nativeImage.createFromPath(imageData.path);
|
|
|
|
const imageFromDataUrl = nativeImage.createFromDataURL(imageData.dataUrl);
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(imageFromDataUrl.isEmpty()).to.be.false();
|
|
|
|
expect(imageFromDataUrl.getSize()).to.deep.equal(imageFromPath.getSize());
|
2017-11-16 13:00:11 +00:00
|
|
|
expect(imageFromDataUrl.toBitmap()).to.satisfy(
|
2020-03-20 20:28:31 +00:00
|
|
|
bitmap => imageFromPath.toBitmap().equals(bitmap));
|
|
|
|
expect(imageFromDataUrl.toDataURL()).to.equal(imageFromPath.toDataURL());
|
2017-10-31 16:57:31 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
2016-10-04 18:05:07 +00:00
|
|
|
|
2017-03-06 21:15:07 +00:00
|
|
|
describe('toDataURL()', () => {
|
2017-03-06 21:22:55 +00:00
|
|
|
it('returns a PNG data URL', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imagesData = getImages({ hasDataUrl: true });
|
2017-10-31 16:57:31 +00:00
|
|
|
for (const imageData of imagesData) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageFromPath = nativeImage.createFromPath(imageData.path);
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const scaleFactors = [1.0, 2.0];
|
2017-11-30 16:50:51 +00:00
|
|
|
for (const scaleFactor of scaleFactors) {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(imageFromPath.toDataURL({ scaleFactor })).to.equal(imageData.dataUrl);
|
2017-11-30 16:50:51 +00:00
|
|
|
}
|
2017-10-31 16:57:31 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-03-06 21:22:55 +00:00
|
|
|
|
2017-03-07 20:34:31 +00:00
|
|
|
it('returns a data URL at 1x scale factor by default', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageData = getImage({ filename: 'logo.png' });
|
|
|
|
const image = nativeImage.createFromPath(imageData.path);
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
const imageOne = nativeImage.createFromBuffer(image.toPNG(), {
|
|
|
|
width: image.getSize().width,
|
|
|
|
height: image.getSize().height,
|
2017-03-06 21:15:07 +00:00
|
|
|
scaleFactor: 2.0
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-11-16 13:00:11 +00:00
|
|
|
expect(imageOne.getSize()).to.deep.equal(
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: imageData.width / 2, height: imageData.height / 2 });
|
2017-03-06 21:15:07 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageTwo = nativeImage.createFromDataURL(imageOne.toDataURL());
|
2017-11-16 13:00:11 +00:00
|
|
|
expect(imageTwo.getSize()).to.deep.equal(
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: imageData.width, height: imageData.height });
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(imageOne.toBitmap().equals(imageTwo.toBitmap())).to.be.true();
|
|
|
|
});
|
2017-03-07 00:19:16 +00:00
|
|
|
|
|
|
|
it('supports a scale factor', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageData = getImage({ filename: 'logo.png' });
|
|
|
|
const image = nativeImage.createFromPath(imageData.path);
|
|
|
|
const expectedSize = { width: imageData.width, height: imageData.height };
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
const imageFromDataUrlOne = nativeImage.createFromDataURL(
|
2020-03-20 20:28:31 +00:00
|
|
|
image.toDataURL({ scaleFactor: 1.0 }));
|
|
|
|
expect(imageFromDataUrlOne.getSize()).to.deep.equal(expectedSize);
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
const imageFromDataUrlTwo = nativeImage.createFromDataURL(
|
2020-03-20 20:28:31 +00:00
|
|
|
image.toDataURL({ scaleFactor: 2.0 }));
|
|
|
|
expect(imageFromDataUrlTwo.getSize()).to.deep.equal(expectedSize);
|
|
|
|
});
|
|
|
|
});
|
2017-03-06 21:15:07 +00:00
|
|
|
|
2017-03-06 21:47:19 +00:00
|
|
|
describe('toPNG()', () => {
|
2017-03-07 20:34:31 +00:00
|
|
|
it('returns a buffer at 1x scale factor by default', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageData = getImage({ filename: 'logo.png' });
|
|
|
|
const imageA = nativeImage.createFromPath(imageData.path);
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2017-03-06 21:47:19 +00:00
|
|
|
const imageB = nativeImage.createFromBuffer(imageA.toPNG(), {
|
|
|
|
width: imageA.getSize().width,
|
|
|
|
height: imageA.getSize().height,
|
|
|
|
scaleFactor: 2.0
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-11-16 13:00:11 +00:00
|
|
|
expect(imageB.getSize()).to.deep.equal(
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: imageData.width / 2, height: imageData.height / 2 });
|
2017-03-06 21:47:19 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageC = nativeImage.createFromBuffer(imageB.toPNG());
|
2017-11-16 13:00:11 +00:00
|
|
|
expect(imageC.getSize()).to.deep.equal(
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: imageData.width, height: imageData.height });
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(imageB.toBitmap().equals(imageC.toBitmap())).to.be.true();
|
|
|
|
});
|
2017-03-07 20:34:31 +00:00
|
|
|
|
|
|
|
it('supports a scale factor', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageData = getImage({ filename: 'logo.png' });
|
|
|
|
const image = nativeImage.createFromPath(imageData.path);
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
const imageFromBufferOne = nativeImage.createFromBuffer(
|
2020-03-20 20:28:31 +00:00
|
|
|
image.toPNG({ scaleFactor: 1.0 }));
|
2017-11-16 13:00:11 +00:00
|
|
|
expect(imageFromBufferOne.getSize()).to.deep.equal(
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: imageData.width, height: imageData.height });
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
const imageFromBufferTwo = nativeImage.createFromBuffer(
|
2020-03-20 20:28:31 +00:00
|
|
|
image.toPNG({ scaleFactor: 2.0 }), { scaleFactor: 2.0 });
|
2017-11-16 13:00:11 +00:00
|
|
|
expect(imageFromBufferTwo.getSize()).to.deep.equal(
|
2020-03-20 20:28:31 +00:00
|
|
|
{ width: imageData.width / 2, height: imageData.height / 2 });
|
|
|
|
});
|
|
|
|
});
|
2017-03-06 21:47:19 +00:00
|
|
|
|
2016-03-04 22:54:12 +00:00
|
|
|
describe('createFromPath(path)', () => {
|
2020-08-24 16:58:55 +00:00
|
|
|
// TODO fix nativeImage.createFromPath on WOA. See https://github.com/electron/electron/issues/25069
|
|
|
|
ifit(!(process.platform === 'win32' && process.arch === 'arm64'))('returns an empty image for invalid paths', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeImage.createFromPath('').isEmpty()).to.be.true();
|
|
|
|
expect(nativeImage.createFromPath('does-not-exist.png').isEmpty()).to.be.true();
|
|
|
|
expect(nativeImage.createFromPath('does-not-exist.ico').isEmpty()).to.be.true();
|
|
|
|
expect(nativeImage.createFromPath(__dirname).isEmpty()).to.be.true();
|
|
|
|
expect(nativeImage.createFromPath(__filename).isEmpty()).to.be.true();
|
|
|
|
});
|
2016-03-07 22:19:24 +00:00
|
|
|
|
|
|
|
it('loads images from paths relative to the current working directory', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imagePath = path.relative('.', path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
|
|
|
const image = nativeImage.createFromPath(imagePath);
|
|
|
|
expect(image.isEmpty()).to.be.false();
|
|
|
|
expect(image.getSize()).to.deep.equal({ width: 538, height: 190 });
|
|
|
|
});
|
2016-03-07 22:19:24 +00:00
|
|
|
|
|
|
|
it('loads images from paths with `.` segments', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imagePath = `${path.join(__dirname, 'fixtures')}${path.sep}.${path.sep}${path.join('assets', 'logo.png')}`;
|
|
|
|
const image = nativeImage.createFromPath(imagePath);
|
|
|
|
expect(image.isEmpty()).to.be.false();
|
|
|
|
expect(image.getSize()).to.deep.equal({ width: 538, height: 190 });
|
|
|
|
});
|
2016-03-07 22:19:24 +00:00
|
|
|
|
2016-03-07 22:22:55 +00:00
|
|
|
it('loads images from paths with `..` segments', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`;
|
|
|
|
const image = nativeImage.createFromPath(imagePath);
|
|
|
|
expect(image.isEmpty()).to.be.false();
|
|
|
|
expect(image.getSize()).to.deep.equal({ width: 538, height: 190 });
|
|
|
|
});
|
2016-03-14 03:25:49 +00:00
|
|
|
|
2020-08-24 16:58:55 +00:00
|
|
|
ifit(process.platform === 'darwin')('Gets an NSImage pointer on macOS', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`;
|
|
|
|
const image = nativeImage.createFromPath(imagePath);
|
|
|
|
const nsimage = image.getNativeHandle();
|
2016-03-14 03:25:49 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nsimage).to.have.lengthOf(8);
|
2016-03-14 03:25:49 +00:00
|
|
|
|
|
|
|
// If all bytes are null, that's Bad
|
2020-03-20 20:28:31 +00:00
|
|
|
const allBytesAreNotNull = nsimage.reduce((acc, x) => acc || (x !== 0), false);
|
|
|
|
expect(allBytesAreNotNull);
|
|
|
|
});
|
2016-06-28 18:58:34 +00:00
|
|
|
|
2020-08-24 16:58:55 +00:00
|
|
|
ifit(process.platform === 'win32')('loads images from .ico files on Windows', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imagePath = path.join(__dirname, 'fixtures', 'assets', 'icon.ico');
|
|
|
|
const image = nativeImage.createFromPath(imagePath);
|
|
|
|
expect(image.isEmpty()).to.be.false();
|
|
|
|
expect(image.getSize()).to.deep.equal({ width: 256, height: 256 });
|
|
|
|
});
|
|
|
|
});
|
2016-10-04 17:50:33 +00:00
|
|
|
|
2017-10-10 06:30:27 +00:00
|
|
|
describe('createFromNamedImage(name)', () => {
|
|
|
|
it('returns empty for invalid options', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromNamedImage('totally_not_real');
|
|
|
|
expect(image.isEmpty()).to.be.true();
|
|
|
|
});
|
2017-10-10 06:30:27 +00:00
|
|
|
|
2020-08-24 16:58:55 +00:00
|
|
|
ifit(process.platform !== 'darwin')('returns empty on non-darwin platforms', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromNamedImage('NSActionTemplate');
|
|
|
|
expect(image.isEmpty()).to.be.true();
|
|
|
|
});
|
2017-10-10 06:30:27 +00:00
|
|
|
|
2020-08-24 16:58:55 +00:00
|
|
|
ifit(process.platform === 'darwin')('returns a valid image on darwin', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromNamedImage('NSActionTemplate');
|
|
|
|
expect(image.isEmpty()).to.be.false();
|
|
|
|
});
|
2017-10-10 06:30:27 +00:00
|
|
|
|
2020-08-24 16:58:55 +00:00
|
|
|
ifit(process.platform === 'darwin')('returns allows an HSL shift for a valid image on darwin', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromNamedImage('NSActionTemplate', [0.5, 0.2, 0.8]);
|
|
|
|
expect(image.isEmpty()).to.be.false();
|
|
|
|
});
|
|
|
|
});
|
2017-10-10 06:30:27 +00:00
|
|
|
|
2016-10-04 17:50:33 +00:00
|
|
|
describe('resize(options)', () => {
|
|
|
|
it('returns a resized image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
2017-11-16 13:00:11 +00:00
|
|
|
for (const [resizeTo, expectedSize] of new Map([
|
2018-09-13 16:10:51 +00:00
|
|
|
[{}, { width: 538, height: 190 }],
|
|
|
|
[{ width: 269 }, { width: 269, height: 95 }],
|
|
|
|
[{ width: 600 }, { width: 600, height: 212 }],
|
|
|
|
[{ height: 95 }, { width: 269, height: 95 }],
|
|
|
|
[{ height: 200 }, { width: 566, height: 200 }],
|
|
|
|
[{ width: 80, height: 65 }, { width: 80, height: 65 }],
|
|
|
|
[{ width: 600, height: 200 }, { width: 600, height: 200 }],
|
|
|
|
[{ width: 0, height: 0 }, { width: 0, height: 0 }],
|
|
|
|
[{ width: -1, height: -1 }, { width: 0, height: 0 }]
|
2017-11-16 13:00:11 +00:00
|
|
|
])) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const actualSize = image.resize(resizeTo).getSize();
|
|
|
|
expect(actualSize).to.deep.equal(expectedSize);
|
2017-11-16 13:00:11 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-10-04 19:50:20 +00:00
|
|
|
|
|
|
|
it('returns an empty image when called on an empty image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeImage.createEmpty().resize({ width: 1, height: 1 }).isEmpty()).to.be.true();
|
|
|
|
expect(nativeImage.createEmpty().resize({ width: 0, height: 0 }).isEmpty()).to.be.true();
|
|
|
|
});
|
2016-10-04 17:50:33 +00:00
|
|
|
|
|
|
|
it('supports a quality option', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
|
|
|
const good = image.resize({ width: 100, height: 100, quality: 'good' });
|
|
|
|
const better = image.resize({ width: 100, height: 100, quality: 'better' });
|
|
|
|
const best = image.resize({ width: 100, height: 100, quality: 'best' });
|
2017-11-16 13:00:11 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(good.toPNG()).to.have.lengthOf.at.most(better.toPNG().length);
|
|
|
|
expect(better.toPNG()).to.have.lengthOf.below(best.toPNG().length);
|
|
|
|
});
|
|
|
|
});
|
2016-10-04 18:28:47 +00:00
|
|
|
|
|
|
|
describe('crop(bounds)', () => {
|
2016-10-04 19:50:20 +00:00
|
|
|
it('returns an empty image when called on an empty image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeImage.createEmpty().crop({ width: 1, height: 2, x: 0, y: 0 }).isEmpty()).to.be.true();
|
|
|
|
expect(nativeImage.createEmpty().crop({ width: 0, height: 0, x: 0, y: 0 }).isEmpty()).to.be.true();
|
|
|
|
});
|
2016-10-04 19:50:20 +00:00
|
|
|
|
2016-10-04 18:28:47 +00:00
|
|
|
it('returns an empty image when the bounds are invalid', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
|
|
|
expect(image.crop({ width: 0, height: 0, x: 0, y: 0 }).isEmpty()).to.be.true();
|
|
|
|
expect(image.crop({ width: -1, height: 10, x: 0, y: 0 }).isEmpty()).to.be.true();
|
|
|
|
expect(image.crop({ width: 10, height: -35, x: 0, y: 0 }).isEmpty()).to.be.true();
|
|
|
|
expect(image.crop({ width: 100, height: 100, x: 1000, y: 1000 }).isEmpty()).to.be.true();
|
|
|
|
});
|
2016-10-04 18:28:47 +00:00
|
|
|
|
|
|
|
it('returns a cropped image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'));
|
|
|
|
const cropA = image.crop({ width: 25, height: 64, x: 0, y: 0 });
|
|
|
|
const cropB = image.crop({ width: 25, height: 64, x: 30, y: 40 });
|
|
|
|
expect(cropA.getSize()).to.deep.equal({ width: 25, height: 64 });
|
|
|
|
expect(cropB.getSize()).to.deep.equal({ width: 25, height: 64 });
|
|
|
|
expect(cropA.toPNG().equals(cropB.toPNG())).to.be.false();
|
|
|
|
});
|
|
|
|
});
|
2016-10-05 16:21:28 +00:00
|
|
|
|
|
|
|
describe('getAspectRatio()', () => {
|
2017-10-31 16:57:31 +00:00
|
|
|
it('returns an aspect ratio of an empty image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeImage.createEmpty().getAspectRatio()).to.equal(1.0);
|
|
|
|
});
|
2017-10-31 16:57:31 +00:00
|
|
|
|
|
|
|
it('returns an aspect ratio of an image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageData = getImage({ filename: 'logo.png' });
|
2017-10-31 16:57:31 +00:00
|
|
|
// imageData.width / imageData.height = 2.831578947368421
|
2020-03-20 20:28:31 +00:00
|
|
|
const expectedAspectRatio = 2.8315789699554443;
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createFromPath(imageData.path);
|
|
|
|
expect(image.getAspectRatio()).to.equal(expectedAspectRatio);
|
|
|
|
});
|
|
|
|
});
|
2017-03-07 21:47:31 +00:00
|
|
|
|
2020-08-24 16:36:13 +00:00
|
|
|
ifdescribe(process.platform !== 'linux')('createThumbnailFromPath(path, size)', () => {
|
|
|
|
it('throws when invalid size is passed', async () => {
|
|
|
|
const badSize = { width: -1, height: -1 };
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
nativeImage.createThumbnailFromPath('path', badSize)
|
|
|
|
).to.eventually.be.rejectedWith('size must not be empty');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws when a bad path is passed', async () => {
|
|
|
|
const badPath = process.platform === 'win32' ? '\\hey\\hi\\hello' : '/hey/hi/hello';
|
|
|
|
const goodSize = { width: 100, height: 100 };
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
nativeImage.createThumbnailFromPath(badPath, goodSize)
|
|
|
|
).to.eventually.be.rejected();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns native image given valid params', async () => {
|
|
|
|
const goodPath = path.join(__dirname, 'fixtures', 'assets', 'logo.png');
|
|
|
|
const goodSize = { width: 100, height: 100 };
|
|
|
|
const result = await nativeImage.createThumbnailFromPath(goodPath, goodSize);
|
|
|
|
expect(result.isEmpty()).to.equal(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-25 11:58:33 +00:00
|
|
|
describe('addRepresentation()', () => {
|
2020-08-24 16:58:55 +00:00
|
|
|
// TODO fix nativeImage.createFromBuffer on WOA. See https://github.com/electron/electron/issues/25069
|
|
|
|
ifit(!(process.platform === 'win32' && process.arch === 'arm64'))('does not add representation when the buffer is too small', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createEmpty();
|
2019-03-26 01:13:39 +00:00
|
|
|
|
|
|
|
image.addRepresentation({
|
|
|
|
buffer: Buffer.from([1, 2, 3, 4]),
|
|
|
|
width: 100,
|
|
|
|
height: 100
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-03-26 01:13:39 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(image.isEmpty()).to.be.true();
|
|
|
|
});
|
2019-03-26 01:13:39 +00:00
|
|
|
|
2017-03-07 22:24:37 +00:00
|
|
|
it('supports adding a buffer representation for a scale factor', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createEmpty();
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataOne = getImage({ width: 1, height: 1 });
|
2017-03-07 21:47:31 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 1.0,
|
2017-10-31 16:57:31 +00:00
|
|
|
buffer: nativeImage.createFromPath(imageDataOne.path).toPNG()
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataTwo = getImage({ width: 2, height: 2 });
|
2017-03-07 21:47:31 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 2.0,
|
2017-10-31 16:57:31 +00:00
|
|
|
buffer: nativeImage.createFromPath(imageDataTwo.path).toPNG()
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataThree = getImage({ width: 3, height: 3 });
|
2017-03-07 21:47:31 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 3.0,
|
2017-10-31 16:57:31 +00:00
|
|
|
buffer: nativeImage.createFromPath(imageDataThree.path).toPNG()
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2017-03-07 21:47:31 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 4.0,
|
|
|
|
buffer: 'invalid'
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-03-07 21:47:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(image.isEmpty()).to.be.false();
|
|
|
|
expect(image.getSize()).to.deep.equal({ width: 1, height: 1 });
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(image.toDataURL({ scaleFactor: 1.0 })).to.equal(imageDataOne.dataUrl);
|
|
|
|
expect(image.toDataURL({ scaleFactor: 2.0 })).to.equal(imageDataTwo.dataUrl);
|
|
|
|
expect(image.toDataURL({ scaleFactor: 3.0 })).to.equal(imageDataThree.dataUrl);
|
|
|
|
expect(image.toDataURL({ scaleFactor: 4.0 })).to.equal(imageDataThree.dataUrl);
|
|
|
|
});
|
2017-03-07 22:24:37 +00:00
|
|
|
|
|
|
|
it('supports adding a data URL representation for a scale factor', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const image = nativeImage.createEmpty();
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataOne = getImage({ width: 1, height: 1 });
|
2017-03-07 22:24:37 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 1.0,
|
2017-10-31 16:57:31 +00:00
|
|
|
dataURL: imageDataOne.dataUrl
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataTwo = getImage({ width: 2, height: 2 });
|
2017-03-07 22:24:37 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 2.0,
|
2017-10-31 16:57:31 +00:00
|
|
|
dataURL: imageDataTwo.dataUrl
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataThree = getImage({ width: 3, height: 3 });
|
2017-03-07 22:24:37 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 3.0,
|
2017-10-31 16:57:31 +00:00
|
|
|
dataURL: imageDataThree.dataUrl
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2017-03-07 22:24:37 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 4.0,
|
|
|
|
dataURL: 'invalid'
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-03-07 22:24:37 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(image.isEmpty()).to.be.false();
|
|
|
|
expect(image.getSize()).to.deep.equal({ width: 1, height: 1 });
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(image.toDataURL({ scaleFactor: 1.0 })).to.equal(imageDataOne.dataUrl);
|
|
|
|
expect(image.toDataURL({ scaleFactor: 2.0 })).to.equal(imageDataTwo.dataUrl);
|
|
|
|
expect(image.toDataURL({ scaleFactor: 3.0 })).to.equal(imageDataThree.dataUrl);
|
|
|
|
expect(image.toDataURL({ scaleFactor: 4.0 })).to.equal(imageDataThree.dataUrl);
|
|
|
|
});
|
2017-03-08 22:53:08 +00:00
|
|
|
|
|
|
|
it('supports adding a representation to an existing image', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataOne = getImage({ width: 1, height: 1 });
|
|
|
|
const image = nativeImage.createFromPath(imageDataOne.path);
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataTwo = getImage({ width: 2, height: 2 });
|
2017-03-08 22:53:08 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 2.0,
|
2017-10-31 16:57:31 +00:00
|
|
|
dataURL: imageDataTwo.dataUrl
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-10-31 16:57:31 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const imageDataThree = getImage({ width: 3, height: 3 });
|
2017-03-08 22:53:08 +00:00
|
|
|
image.addRepresentation({
|
|
|
|
scaleFactor: 2.0,
|
2017-10-31 16:57:31 +00:00
|
|
|
dataURL: imageDataThree.dataUrl
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-03-08 22:53:08 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(image.toDataURL({ scaleFactor: 1.0 })).to.equal(imageDataOne.dataUrl);
|
|
|
|
expect(image.toDataURL({ scaleFactor: 2.0 })).to.equal(imageDataTwo.dataUrl);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|