From ad4519c2a98d1a92bd7d82c9e39636af6787bfaa Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 8 Dec 2016 15:24:27 -0600 Subject: [PATCH] test(img): allow datauris --- src/components/img/img.ts | 10 ++++++++-- src/components/img/test/basic/main.html | 14 ++++++++++++++ src/components/img/test/img.spec.ts | 8 ++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/components/img/img.ts b/src/components/img/img.ts index 808d925f66..dc1b3b697e 100644 --- a/src/components/img/img.ts +++ b/src/components/img/img.ts @@ -189,8 +189,14 @@ export class Img implements OnDestroy { // update to the new src this._src = newSrc; - // reset any existing datauri we might be holding onto - this._tmpDataUri = null; + if (newSrc.indexOf('data:') === 0) { + // they're using an actual datauri already + this._tmpDataUri = newSrc; + + } else { + // reset any existing datauri we might be holding onto + this._tmpDataUri = null; + } // run update to kick off requests or render if everything is good this.update(); diff --git a/src/components/img/test/basic/main.html b/src/components/img/test/basic/main.html index 8c971d6e8d..116e10eaa3 100644 --- a/src/components/img/test/basic/main.html +++ b/src/components/img/test/basic/main.html @@ -51,6 +51,20 @@ + + + + + + + Datauri + + + + + + + diff --git a/src/components/img/test/img.spec.ts b/src/components/img/test/img.spec.ts index e4a6945a09..2223fe6d82 100644 --- a/src/components/img/test/img.spec.ts +++ b/src/components/img/test/img.spec.ts @@ -42,6 +42,14 @@ describe('Img', () => { expect(img._tmpDataUri).toEqual(null); }); + it('should set datauri src', () => { + spyOn(img, 'update'); + img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw=='; + expect(img.src).toEqual('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw=='); + expect(img._tmpDataUri).toEqual(`data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==`); + expect(img.update).toHaveBeenCalled(); + }); + it('should set src', () => { spyOn(img, 'update'); img.src = 'image.jpg';