@@ -12,6 +12,10 @@ var mouseEvent = require('../assets/mouse_event');
1212var jsLogo = 'https://images.plot.ly/language-icons/api-home/js-logo.png' ;
1313var pythonLogo = 'https://images.plot.ly/language-icons/api-home/python-logo.png' ;
1414
15+ // Single red pixel png generated with http://png-pixel.com/
16+ var dataUriImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfF' +
17+ 'cSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==' ;
18+
1519describe ( 'Layout images' , function ( ) {
1620 describe ( 'supplyLayoutDefaults' , function ( ) {
1721 var layoutIn ,
@@ -290,6 +294,31 @@ describe('Layout images', function() {
290294
291295 afterEach ( destroyGraphDiv ) ;
292296
297+ it ( 'should only create canvas if url image' , function ( done ) {
298+ var originalCreateElement = document . createElement ;
299+ var newCanvasElement ;
300+ spyOn ( document , 'createElement' ) . and . callFake ( function ( elementType ) {
301+ var element = originalCreateElement . call ( document , elementType ) ;
302+ if ( elementType === 'canvas' ) {
303+ newCanvasElement = element ;
304+ spyOn ( newCanvasElement , 'toDataURL' ) ;
305+ }
306+ return element ;
307+ } ) ;
308+
309+ Plotly . relayout ( gd , 'images[0].source' , dataUriImage ) . then ( function ( ) {
310+ setTimeout ( function ( ) {
311+ expect ( newCanvasElement ) . toBeUndefined ( ) ;
312+ Plotly . relayout ( gd , 'images[0].source' , pythonLogo ) . then ( function ( ) {
313+ expect ( newCanvasElement ) . eventually . toBeDefined ( ) ;
314+ expect ( newCanvasElement . toDataURL ) . toHaveBeenCalledTimes ( 1 ) ;
315+ } ) ;
316+
317+ done ( ) ;
318+ } , 500 ) ;
319+ } ) ;
320+ } ) ;
321+
293322 it ( 'should update the image if changed' , function ( done ) {
294323 var img = Plotly . d3 . select ( 'image' ) ;
295324 var url = img . attr ( 'xlink:href' ) ;
0 commit comments