@@ -17,7 +17,7 @@ describe('Application', () => {
17
17
const application = new Application ( ) ;
18
18
19
19
const oldDocument = global . document ;
20
- global . document = { referrer : 'http://localhost:8080' , createElement : document . createElement . bind ( document ) } ;
20
+ global . document = { referrer : 'http://localhost:8080' , createElement : document . createElement . bind ( document ) , body : { addEventListener : ( ) => console . log ( 'mock addEventListener' ) } } ;
21
21
application . init ( { acls, secret, onReady} ) ;
22
22
global . document = oldDocument ;
23
23
@@ -27,7 +27,7 @@ describe('Application', () => {
27
27
28
28
it ( "doesn't set activeACL to document referrer if not in ACL" , ( ) => {
29
29
const insecureApp = new Application ( ) ;
30
- global . document = { referrer : 'http://evilsite.com' , createElement : document . createElement . bind ( document ) } ;
30
+ global . document = { referrer : 'http://evilsite.com' , createElement : document . createElement . bind ( document ) , body : { addEventListener : ( ) => console . log ( 'mock addEventListener' ) } } ;
31
31
insecureApp . init ( { acls, secret, onReady} ) ;
32
32
global . document = oldDocument ;
33
33
@@ -49,6 +49,11 @@ describe('Application', () => {
49
49
it ( "sets application's JSONRPC" , ( ) => {
50
50
expect ( application . JSONRPC ) . to . be . an . instanceof ( JSONRPC ) ;
51
51
} ) ;
52
+
53
+ it ( "calls addEventListener" , sinon . test ( function ( ) {
54
+ sinon . spy ( document . body , 'addEventListener' ) ;
55
+ expect ( document . body . addEventListener . calledOnce ) ;
56
+ } ) ) ;
52
57
53
58
describe ( '#trigger(event, detail)' , ( ) => {
54
59
it ( "calls this.JSONRPC.notification of 'event' with event and detail" , sinon . test ( function ( ) {
@@ -262,6 +267,50 @@ describe('Application', () => {
262
267
} ) ;
263
268
} ) ;
264
269
270
+ describe ( '#imageRequestResize(event)' , ( ) => {
271
+ const application = new Application ( ) ;
272
+ it ( "calls requestResize for an image" , sinon . test ( function ( ) {
273
+ const requestResize = this . stub ( application , 'requestResize' ) ;
274
+ application . resizeConfig = { }
275
+ const event = {
276
+ target : {
277
+ tagName : "IMG" ,
278
+ hasAttribute : ( attr ) => { attr === 'height' }
279
+ }
280
+ } ;
281
+ application . imageRequestResize ( event ) ;
282
+
283
+ sinon . assert . called ( requestResize ) ;
284
+ } ) ) ;
285
+
286
+ it ( "does not call requestResize for an image with height" , sinon . test ( function ( ) {
287
+ const requestResize = this . stub ( application , 'requestResize' ) ;
288
+ application . resizeConfig = { }
289
+
290
+ let event = {
291
+ target : {
292
+ tagName : "IMG" ,
293
+ hasAttribute : ( attr ) => { return [ 'width' , 'height' ] . includes ( attr ) } ,
294
+ }
295
+ } ;
296
+ application . imageRequestResize ( event ) ;
297
+
298
+ sinon . assert . notCalled ( requestResize ) ;
299
+ } ) ) ;
300
+ } ) ;
301
+
302
+ describe ( '#requestResize()' , ( ) => {
303
+ it ( "does not resize when resizeConfig is null" , sinon . test ( function ( ) {
304
+ const application = new Application ( ) ;
305
+ application . init ( { acls : [ '*' ] } ) ;
306
+ const notification = this . stub ( application . JSONRPC , 'notification' ) ;
307
+ application . resizeConfig = null ;
308
+ application . requestResize ( ) ;
309
+
310
+ sinon . assert . notCalled ( notification ) ;
311
+ } ) ) ;
312
+ } ) ;
313
+
265
314
describe ( '#launch()' , ( ) => {
266
315
describe ( 'if window.self === window.top' , ( ) => {
267
316
const tests = [
0 commit comments