From 17b70670f8ea78a19c193b9db84cf04c5d11c3bf Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Mar 2017 13:47:31 -0800 Subject: [PATCH] Add initial NativeImage.addRepresentation specs --- spec/api-native-image-spec.js | 27 +++++++++++++++++++++++++++ spec/fixtures/assets/2x2.jpg | Bin 0 -> 3176 bytes spec/fixtures/assets/3x3.png | Bin 0 -> 507 bytes 3 files changed, 27 insertions(+) create mode 100644 spec/fixtures/assets/2x2.jpg create mode 100644 spec/fixtures/assets/3x3.png diff --git a/spec/api-native-image-spec.js b/spec/api-native-image-spec.js index 22fe187b2d74..d9fb31a81ecb 100644 --- a/spec/api-native-image-spec.js +++ b/spec/api-native-image-spec.js @@ -249,4 +249,31 @@ describe('nativeImage module', () => { assert.equal(nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png')).getAspectRatio(), 2.8315789699554443) }) }) + + describe('addRepresentation()', () => { + it('supports adding a representation for a scale factor', () => { + const image = nativeImage.createEmpty() + image.addRepresentation({ + scaleFactor: 1.0, + buffer: nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', '1x1.png')).toPNG() + }) + image.addRepresentation({ + scaleFactor: 2.0, + buffer: nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', '2x2.jpg')).toPNG() + }) + image.addRepresentation({ + scaleFactor: 3.0, + buffer: nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', '3x3.png')).toPNG() + }) + image.addRepresentation({ + scaleFactor: 4.0, + buffer: 'invalid' + }) + + assert.equal(image.toDataURL({scaleFactor: 1.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=') + assert.equal(image.toDataURL({scaleFactor: 2.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFUlEQVQYlWP8////fwYGBgYmBigAAD34BABBrq9BAAAAAElFTkSuQmCC') + assert.equal(image.toDataURL({scaleFactor: 3.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAADElEQVQYlWNgIAoAAAAnAAGZWEMnAAAAAElFTkSuQmCC') + assert.equal(image.toDataURL({scaleFactor: 4.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAADElEQVQYlWNgIAoAAAAnAAGZWEMnAAAAAElFTkSuQmCC') + }) + }) }) diff --git a/spec/fixtures/assets/2x2.jpg b/spec/fixtures/assets/2x2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d96fdb313314c5f328e461727e7a992cdb6474a8 GIT binary patch literal 3176 zcmeHJSxgf_82)Du+M*;B0k0UB1r$x_mI6u}3*i(FinqSu4aP*gH5$bejb@!)YDs)DzS?g#GvDs~$9(_n!!O^LA3=!5f@H11H&iT!z8O!K^&VXLr`~ zBIDreJYFmN?(8|1@wlw)!fcz-<}2jgp3)XSU)3^ap0lOiX?C%Bxy&rdA~pCLc+t*C z4NJTMi)3Zh;1N0*=**FCeCC^#}?^AX0%y1tJxQR3K7;NCp1C3XF6+ycf4PLEOuL{1$R5+=3_s+=7qEG#DYL zpv*=o4H$;XQ&k#!ds2JfM(Czqtp9sX8bbmG`?<0qs}nVL3jdRF#~nK@=lVNr3(?9#IGs(JGlEUaEs<8<-0b#Bk% zfY`J&C^fgNTD@lNy7e2{Hf`Rrb=&sN9XogL*}HH5frEz*cON}={KUyqr_Wrtc1%j$KE3bjg{O?-LyU-sr@Xtbx=)MVhMY z?}WAfld`a|5nT_U5C|0{fp3W<@l8<}w1!ro(P~s^Lx@%}NP!fMCu_Ae*W0qmPX2bzW}+TK9c|d literal 0 HcmV?d00001 diff --git a/spec/fixtures/assets/3x3.png b/spec/fixtures/assets/3x3.png new file mode 100644 index 0000000000000000000000000000000000000000..b1c1d9d688c59194fbad1431f6c2fffc7eaa1bf1 GIT binary patch literal 507 zcmeAS@N?(olHy`uVBq!ia0vp^%plCc1|-8Yw(bW~Ea{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8X6a5n0T@z%2~Ij105p zNH8!kMrMXYltlRYSS9D@>LsS+C#C9DVstT4fPE4;bsH1+JHo@{EISEfi{E8 zw==W>t3(ll+GC>+vK+}V5TAlYfnK%aveAbJn;nB3GS( TF(Rpo5fsFpu6{1-oD!M