Merge pull request #11255 from electron/fix-11245
Enable nativeImage module addRepresentation() tests
This commit is contained in:
commit
aab35073ee
2 changed files with 21 additions and 7 deletions
|
@ -17,6 +17,8 @@
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "net/base/data_url.h"
|
#include "net/base/data_url.h"
|
||||||
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
|
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||||
#include "third_party/skia/include/core/SkPixelRef.h"
|
#include "third_party/skia/include/core/SkPixelRef.h"
|
||||||
#include "ui/base/layout.h"
|
#include "ui/base/layout.h"
|
||||||
#include "ui/base/webui/web_ui_util.h"
|
#include "ui/base/webui/web_ui_util.h"
|
||||||
|
@ -93,9 +95,20 @@ bool AddImageSkiaRep(gfx::ImageSkia* image,
|
||||||
std::unique_ptr<SkBitmap> decoded(new SkBitmap());
|
std::unique_ptr<SkBitmap> decoded(new SkBitmap());
|
||||||
|
|
||||||
// Try PNG first.
|
// Try PNG first.
|
||||||
if (!gfx::PNGCodec::Decode(data, size, decoded.get()))
|
if (!gfx::PNGCodec::Decode(data, size, decoded.get())) {
|
||||||
// Try JPEG.
|
// Try JPEG.
|
||||||
decoded = gfx::JPEGCodec::Decode(data, size);
|
decoded = gfx::JPEGCodec::Decode(data, size);
|
||||||
|
if (decoded) {
|
||||||
|
// `JPEGCodec::Decode()` doesn't tell `SkBitmap` instance it creates
|
||||||
|
// that all of its pixels are opaque, that's why the bitmap gets
|
||||||
|
// an alpha type `kPremul_SkAlphaType` instead of `kOpaque_SkAlphaType`.
|
||||||
|
// Let's fix it here.
|
||||||
|
// TODO(alexeykuzmin): This workaround should be removed
|
||||||
|
// when the `JPEGCodec::Decode()` code is fixed.
|
||||||
|
// See https://github.com/electron/electron/issues/11294.
|
||||||
|
decoded->setAlphaType(SkAlphaType::kOpaque_SkAlphaType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!decoded) {
|
if (!decoded) {
|
||||||
// Try Bitmap
|
// Try Bitmap
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe('nativeImage module', () => {
|
||||||
width: 1
|
width: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFUlEQVQYlWP8////fwYGBgYmBigAAD34BABBrq9BAAAAAElFTkSuQmCC',
|
dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVQYlWP8//8/AwMDEwMDAwMDAwAkBgMBBMzldwAAAABJRU5ErkJggg==',
|
||||||
filename: '2x2.jpg',
|
filename: '2x2.jpg',
|
||||||
format: ImageFormat.JPEG,
|
format: ImageFormat.JPEG,
|
||||||
hasAlphaChannel: false,
|
hasAlphaChannel: false,
|
||||||
|
@ -183,6 +183,7 @@ describe('nativeImage module', () => {
|
||||||
expect(imageFromDataUrl.getSize()).to.deep.equal(imageFromPath.getSize())
|
expect(imageFromDataUrl.getSize()).to.deep.equal(imageFromPath.getSize())
|
||||||
expect(imageFromDataUrl.toBitmap()).to.satisfy(
|
expect(imageFromDataUrl.toBitmap()).to.satisfy(
|
||||||
bitmap => imageFromPath.toBitmap().equals(bitmap))
|
bitmap => imageFromPath.toBitmap().equals(bitmap))
|
||||||
|
expect(imageFromDataUrl.toDataURL()).to.equal(imageFromPath.toDataURL())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -193,8 +194,10 @@ describe('nativeImage module', () => {
|
||||||
for (const imageData of imagesData) {
|
for (const imageData of imagesData) {
|
||||||
const imageFromPath = nativeImage.createFromPath(imageData.path)
|
const imageFromPath = nativeImage.createFromPath(imageData.path)
|
||||||
|
|
||||||
expect(imageFromPath.toDataURL()).to.equal(imageData.dataUrl)
|
const scaleFactors = [1.0, 2.0]
|
||||||
expect(imageFromPath.toDataURL({scaleFactor: 2.0})).to.equal(imageData.dataUrl)
|
for (const scaleFactor of scaleFactors) {
|
||||||
|
expect(imageFromPath.toDataURL({scaleFactor})).to.equal(imageData.dataUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -444,9 +447,7 @@ describe('nativeImage module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO(alexeykuzmin): Disabled during Chromium 61 upgrade.
|
describe('addRepresentation()', () => {
|
||||||
// Fix them and enable.
|
|
||||||
xdescribe('addRepresentation()', () => {
|
|
||||||
it('supports adding a buffer representation for a scale factor', () => {
|
it('supports adding a buffer representation for a scale factor', () => {
|
||||||
const image = nativeImage.createEmpty()
|
const image = nativeImage.createEmpty()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue