@@ -112,16 +112,6 @@ describe('Google A4A utils', () => {
112112 } ) ;
113113
114114 describe ( '#ActiveView AmpAnalytics integration' , ( ) => {
115- let sandbox ;
116-
117- beforeEach ( ( ) => {
118- sandbox = sinon . sandbox ;
119- } ) ;
120-
121- afterEach ( ( ) => {
122- sandbox . restore ( ) ;
123- } ) ;
124-
125115 const builtConfig = {
126116 transport : { beacon : false , xhrpost : false } ,
127117 requests : {
@@ -194,7 +184,9 @@ describe('Google A4A utils', () => {
194184 } ) ;
195185
196186 it ( 'should add the correct CSI signals' , ( ) => {
197- sandbox . stub ( Services , 'documentInfoForDoc' ) . returns ( { pageViewId : 777 } ) ;
187+ window . sandbox
188+ . stub ( Services , 'documentInfoForDoc' )
189+ . returns ( { pageViewId : 777 } ) ;
198190 const mockElement = {
199191 getAttribute : function ( name ) {
200192 switch ( name ) {
@@ -315,16 +307,6 @@ describe('Google A4A utils', () => {
315307 } ) ;
316308
317309 describe ( '#googleAdUrl' , ( ) => {
318- let sandbox ;
319-
320- beforeEach ( ( ) => {
321- sandbox = sinon . sandbox ;
322- } ) ;
323-
324- afterEach ( ( ) => {
325- sandbox . restore ( ) ;
326- } ) ;
327-
328310 it ( 'should set ad position' , function ( ) {
329311 // When ran locally, this test tends to exceed 2000ms timeout.
330312 this . timeout ( 5000 ) ;
@@ -338,7 +320,7 @@ describe('Google A4A utils', () => {
338320 'height' : '50' ,
339321 } ) ;
340322 const impl = new MockA4AImpl ( elem ) ;
341- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
323+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
342324 return fixture . addElement ( elem ) . then ( ( ) => {
343325 return googleAdUrl ( impl , '' , 0 , [ ] , [ ] ) . then ( url1 => {
344326 expect ( url1 ) . to . match ( / a d y = 1 1 / ) ;
@@ -359,7 +341,7 @@ describe('Google A4A utils', () => {
359341 'height' : '50' ,
360342 } ) ;
361343 const impl = new MockA4AImpl ( elem ) ;
362- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
344+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
363345 const getRect = ( ) => {
364346 return { 'width' : 100 , 'height' : 200 } ;
365347 } ;
@@ -368,7 +350,7 @@ describe('Google A4A utils', () => {
368350 } ;
369351 const getScrollLeft = ( ) => 12 ;
370352 const getScrollTop = ( ) => 34 ;
371- const viewportStub = sandbox . stub ( Services , 'viewportForDoc' ) ;
353+ const viewportStub = window . sandbox . stub ( Services , 'viewportForDoc' ) ;
372354 viewportStub . returns ( { getRect, getSize, getScrollTop, getScrollLeft} ) ;
373355 return fixture . addElement ( elem ) . then ( ( ) => {
374356 return googleAdUrl ( impl , '' , 0 , { } , [ ] ) . then ( url1 => {
@@ -392,7 +374,7 @@ describe('Google A4A utils', () => {
392374 'data-experiment-id' : '123,456' ,
393375 } ) ;
394376 const impl = new MockA4AImpl ( elem ) ;
395- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
377+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
396378 return fixture . addElement ( elem ) . then ( ( ) => {
397379 return googleAdUrl ( impl , '' , 0 , { } , [ '789' , '098' ] ) . then ( url1 => {
398380 expect ( url1 ) . to . match ( / e i d = 1 2 3 % 2 C 4 5 6 % 2 C 7 8 9 % 2 C 0 9 8 / ) ;
@@ -412,7 +394,7 @@ describe('Google A4A utils', () => {
412394 'height' : '50' ,
413395 } ) ;
414396 const impl = new MockA4AImpl ( elem ) ;
415- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
397+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
416398 impl . win . AMP_CONFIG = { type : 'production' } ;
417399 impl . win . location . hash = 'foo,deid=123456,654321,bar' ;
418400 return fixture . addElement ( elem ) . then ( ( ) => {
@@ -434,7 +416,7 @@ describe('Google A4A utils', () => {
434416 'height' : '50' ,
435417 } ) ;
436418 const impl = new MockA4AImpl ( elem ) ;
437- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
419+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
438420 impl . win . gaGlobal = { cid : 'foo' , hid : 'bar' } ;
439421 return fixture . addElement ( elem ) . then ( ( ) => {
440422 return googleAdUrl ( impl , '' , 0 , [ ] , [ ] ) . then ( url => {
@@ -456,8 +438,8 @@ describe('Google A4A utils', () => {
456438 'height' : '50' ,
457439 } ) ;
458440 const impl = new MockA4AImpl ( elem ) ;
459- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
460- const createElementStub = sandbox . stub (
441+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
442+ const createElementStub = window . sandbox . stub (
461443 impl . win . document ,
462444 'createElement'
463445 ) ;
@@ -485,8 +467,8 @@ describe('Google A4A utils', () => {
485467 'height' : '50' ,
486468 } ) ;
487469 const impl = new MockA4AImpl ( elem ) ;
488- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
489- const createElementStub = sandbox . stub (
470+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
471+ const createElementStub = window . sandbox . stub (
490472 impl . win . document ,
491473 'createElement'
492474 ) ;
@@ -512,9 +494,9 @@ describe('Google A4A utils', () => {
512494 'height' : '50' ,
513495 } ) ;
514496 const impl = new MockA4AImpl ( elem ) ;
515- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
497+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
516498 impl . win . SVGElement = undefined ;
517- const createElementStub = sandbox . stub (
499+ const createElementStub = window . sandbox . stub (
518500 impl . win . document ,
519501 'createElement'
520502 ) ;
@@ -542,11 +524,11 @@ describe('Google A4A utils', () => {
542524 'height' : '50' ,
543525 } ) ;
544526 const impl = new MockA4AImpl ( elem ) ;
545- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
546- sandbox
527+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
528+ window . sandbox
547529 . stub ( Services . viewerForDoc ( impl . getAmpDoc ( ) ) , 'getReferrerUrl' )
548530 . returns ( new Promise ( ( ) => { } ) ) ;
549- const createElementStub = sandbox . stub (
531+ const createElementStub = window . sandbox . stub (
550532 impl . win . document ,
551533 'createElement'
552534 ) ;
@@ -571,7 +553,7 @@ describe('Google A4A utils', () => {
571553 doc . win = fixture . win ;
572554 const elem = createElementWithAttributes ( doc , 'amp-a4a' , { } ) ;
573555 const impl = new MockA4AImpl ( elem ) ;
574- noopMethods ( impl , fixture . ampdoc , sandbox ) ;
556+ noopMethods ( impl , fixture . ampdoc , window . sandbox ) ;
575557 return fixture . addElement ( elem ) . then ( ( ) => {
576558 return googleAdUrl ( impl , '' , Date . now ( ) , [ ] , [ ] ) . then ( url => {
577559 expect ( url ) . to . match ( / [ & ? ] b d t = [ 1 - 9 ] [ 0 - 9 ] * [ & $ ] / ) ;
@@ -663,11 +645,11 @@ describe('Google A4A utils', () => {
663645 } ) ;
664646 } ) ;
665647
666- describes . fakeWin ( '#getIdentityTokenRequestUrl' , { } , ( ) => {
648+ describes . fakeWin ( '#getIdentityTokenRequestUrl' , { } , env => {
667649 let doc ;
668650 let fakeWin ;
669651 beforeEach ( ( ) => {
670- const documentInfoStub = sandbox . stub ( Services , 'documentInfoForDoc' ) ;
652+ const documentInfoStub = env . sandbox . stub ( Services , 'documentInfoForDoc' ) ;
671653 doc = { } ;
672654 fakeWin = { location : { } } ;
673655 documentInfoStub
@@ -719,7 +701,7 @@ describe('Google A4A utils', () => {
719701 describes . fakeWin ( '#getIdentityToken' , { amp : true , mockFetch : true } , env => {
720702 beforeEach ( ( ) => {
721703 installXhrService ( env . win ) ;
722- const documentInfoStub = sandbox . stub ( Services , 'documentInfoForDoc' ) ;
704+ const documentInfoStub = env . sandbox . stub ( Services , 'documentInfoForDoc' ) ;
723705 documentInfoStub
724706 . withArgs ( env . ampdoc )
725707 . returns ( { canonicalUrl : 'http://f.blah.com?some_site' } ) ;
@@ -818,7 +800,7 @@ describe('Google A4A utils', () => {
818800 } ) ;
819801
820802 it ( 'should handle fetch error' , ( ) => {
821- sandbox
803+ env . sandbox
822804 . stub ( Services , 'xhrFor' )
823805 . returns ( { fetchJson : ( ) => Promise . reject ( 'some network failure' ) } ) ;
824806 return getIdentityToken ( env . win , env . ampdoc ) . then ( result =>
@@ -837,7 +819,7 @@ describe('Google A4A utils', () => {
837819 validLifetimeSecs : '5678' ,
838820 } )
839821 ) ;
840- sandbox . stub ( Services , 'consentPolicyServiceForDocOrNull' ) . returns (
822+ env . sandbox . stub ( Services , 'consentPolicyServiceForDocOrNull' ) . returns (
841823 Promise . resolve ( {
842824 whenPolicyResolved : ( ) => CONSENT_POLICY_STATE . SUFFICIENT ,
843825 } )
@@ -850,7 +832,7 @@ describe('Google A4A utils', () => {
850832 it . configure ( )
851833 . skipFirefox ( )
852834 . run ( 'should not fetch if INSUFFICIENT consent' , ( ) => {
853- sandbox . stub ( Services , 'consentPolicyServiceForDocOrNull' ) . returns (
835+ env . sandbox . stub ( Services , 'consentPolicyServiceForDocOrNull' ) . returns (
854836 Promise . resolve ( {
855837 whenPolicyResolved : ( ) => CONSENT_POLICY_STATE . INSUFFICIENT ,
856838 } )
@@ -863,7 +845,7 @@ describe('Google A4A utils', () => {
863845 it . configure ( )
864846 . skipFirefox ( )
865847 . run ( 'should not fetch if UNKNOWN consent' , ( ) => {
866- sandbox . stub ( Services , 'consentPolicyServiceForDocOrNull' ) . returns (
848+ env . sandbox . stub ( Services , 'consentPolicyServiceForDocOrNull' ) . returns (
867849 Promise . resolve ( {
868850 whenPolicyResolved : ( ) => CONSENT_POLICY_STATE . UNKNOWN ,
869851 } )
@@ -876,11 +858,9 @@ describe('Google A4A utils', () => {
876858
877859 describe ( 'variables for amp-analytics' , ( ) => {
878860 let a4a ;
879- let sandbox ;
880861 let ampdoc ;
881862
882863 beforeEach ( ( ) => {
883- sandbox = sinon . sandbox ;
884864 return createIframePromise ( ) . then ( fixture => {
885865 setupForAdTesting ( fixture ) ;
886866 const element = createElementWithAttributes ( fixture . doc , 'amp-a4a' , {
@@ -895,10 +875,6 @@ describe('Google A4A utils', () => {
895875 } ) ;
896876 } ) ;
897877
898- afterEach ( ( ) => {
899- sandbox . restore ( ) ;
900- } ) ;
901-
902878 it ( 'should include the correlator' , ( ) => {
903879 const vars = getCsiAmpAnalyticsVariables ( 'trigger' , a4a , null ) ;
904880 expect ( vars [ 'correlator' ] ) . not . to . be . undefined ;
@@ -934,7 +910,7 @@ describe('Google A4A utils', () => {
934910 } ) ;
935911
936912 it ( 'should include viewer lastVisibleTime' , ( ) => {
937- sandbox . stub ( ampdoc , 'getLastVisibleTime' ) . returns ( 300 ) ;
913+ window . sandbox . stub ( ampdoc , 'getLastVisibleTime' ) . returns ( 300 ) ;
938914
939915 const vars = getCsiAmpAnalyticsVariables ( 'trigger' , a4a , null ) ;
940916 expect ( vars [ 'viewerLastVisibleTime' ] ) . to . be . a ( 'number' ) ;
@@ -983,7 +959,7 @@ describe('Google A4A utils', () => {
983959
984960 it ( 'should calculate correlator from PVID and CID if possible' , ( ) => {
985961 const pageViewId = '818181' ;
986- sandbox . stub ( Services , 'documentInfoForDoc' ) . callsFake ( ( ) => {
962+ env . sandbox . stub ( Services , 'documentInfoForDoc' ) . callsFake ( ( ) => {
987963 return { pageViewId} ;
988964 } ) ;
989965 const cid = '12345678910' ;
@@ -1021,7 +997,7 @@ describes.realWin('#groupAmpAdsByType', {amp: true}, env => {
1021997 createResource ( { type : 'blah' } ) ,
1022998 createResource ( { } , 'amp-foo' ) ,
1023999 ] ;
1024- sandbox
1000+ env . sandbox
10251001 . stub ( IniLoad , 'getMeasuredResources' )
10261002 . callsFake ( ( doc , win , fn ) => Promise . resolve ( resources . filter ( fn ) ) ) ;
10271003 return groupAmpAdsByType ( ampdoc , 'doubleclick' , ( ) => 'foo' ) . then (
@@ -1051,7 +1027,7 @@ describes.realWin('#groupAmpAdsByType', {amp: true}, env => {
10511027 stickyResource . element
10521028 ) ;
10531029 ampAdResource . element . createdCallback = true ;
1054- sandbox
1030+ env . sandbox
10551031 . stub ( IniLoad , 'getMeasuredResources' )
10561032 . callsFake ( ( doc , win , fn ) => Promise . resolve ( resources . filter ( fn ) ) ) ;
10571033 return groupAmpAdsByType ( win , 'doubleclick' , ( ) => 'foo' ) . then ( result => {
@@ -1082,7 +1058,7 @@ describes.realWin('#groupAmpAdsByType', {amp: true}, env => {
10821058 stickyResource . element
10831059 ) ;
10841060 ampAdResource . element . createdCallback = true ;
1085- sandbox
1061+ env . sandbox
10861062 . stub ( IniLoad , 'getMeasuredResources' )
10871063 . callsFake ( ( doc , win , fn ) => Promise . resolve ( resources . filter ( fn ) ) ) ;
10881064 return groupAmpAdsByType ( win , 'doubleclick' , element =>
0 commit comments