@@ -66,7 +66,7 @@ function setupForAdTesting(fixture) {
6666// functions.
6767function noopMethods (
6868 impl ,
69- doc ,
69+ ampdoc ,
7070 sandbox ,
7171 pageLayoutBox = {
7272 top : 11 ,
@@ -81,7 +81,7 @@ function noopMethods(
8181 impl . element . build = noop ;
8282 impl . element . getPlaceholder = noop ;
8383 impl . element . createPlaceholder = noop ;
84- sandbox . stub ( impl , 'getAmpDoc' ) . returns ( doc ) ;
84+ sandbox . stub ( impl , 'getAmpDoc' ) . returns ( ampdoc ) ;
8585 sandbox . stub ( impl , 'getPageLayoutBox' ) . returns ( pageLayoutBox ) ;
8686}
8787
@@ -331,7 +331,7 @@ describe('Google A4A utils', () => {
331331 'height' : '50' ,
332332 } ) ;
333333 const impl = new MockA4AImpl ( elem ) ;
334- noopMethods ( impl , doc , sandbox ) ;
334+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
335335 return fixture . addElement ( elem ) . then ( ( ) => {
336336 return googleAdUrl ( impl , '' , 0 , [ ] , [ ] ) . then ( url1 => {
337337 expect ( url1 ) . to . match ( / a d y = 1 1 / ) ;
@@ -352,7 +352,7 @@ describe('Google A4A utils', () => {
352352 'height' : '50' ,
353353 } ) ;
354354 const impl = new MockA4AImpl ( elem ) ;
355- noopMethods ( impl , doc , sandbox ) ;
355+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
356356 const getRect = ( ) => {
357357 return { 'width' : 100 , 'height' : 200 } ;
358358 } ;
@@ -385,7 +385,7 @@ describe('Google A4A utils', () => {
385385 'data-experiment-id' : '123,456' ,
386386 } ) ;
387387 const impl = new MockA4AImpl ( elem ) ;
388- noopMethods ( impl , doc , sandbox ) ;
388+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
389389 return fixture . addElement ( elem ) . then ( ( ) => {
390390 return googleAdUrl ( impl , '' , 0 , { } , [ '789' , '098' ] ) . then ( url1 => {
391391 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 / ) ;
@@ -405,7 +405,7 @@ describe('Google A4A utils', () => {
405405 'height' : '50' ,
406406 } ) ;
407407 const impl = new MockA4AImpl ( elem ) ;
408- noopMethods ( impl , doc , sandbox ) ;
408+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
409409 impl . win . AMP_CONFIG = { type : 'production' } ;
410410 impl . win . location . hash = 'foo,deid=123456,654321,bar' ;
411411 return fixture . addElement ( elem ) . then ( ( ) => {
@@ -427,7 +427,7 @@ describe('Google A4A utils', () => {
427427 'height' : '50' ,
428428 } ) ;
429429 const impl = new MockA4AImpl ( elem ) ;
430- noopMethods ( impl , doc , sandbox ) ;
430+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
431431 impl . win . gaGlobal = { cid : 'foo' , hid : 'bar' } ;
432432 return fixture . addElement ( elem ) . then ( ( ) => {
433433 return googleAdUrl ( impl , '' , 0 , [ ] , [ ] ) . then ( url => {
@@ -449,7 +449,7 @@ describe('Google A4A utils', () => {
449449 'height' : '50' ,
450450 } ) ;
451451 const impl = new MockA4AImpl ( elem ) ;
452- noopMethods ( impl , doc , sandbox ) ;
452+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
453453 const createElementStub = sandbox . stub (
454454 impl . win . document ,
455455 'createElement'
@@ -478,7 +478,7 @@ describe('Google A4A utils', () => {
478478 'height' : '50' ,
479479 } ) ;
480480 const impl = new MockA4AImpl ( elem ) ;
481- noopMethods ( impl , doc , sandbox ) ;
481+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
482482 const createElementStub = sandbox . stub (
483483 impl . win . document ,
484484 'createElement'
@@ -505,7 +505,7 @@ describe('Google A4A utils', () => {
505505 'height' : '50' ,
506506 } ) ;
507507 const impl = new MockA4AImpl ( elem ) ;
508- noopMethods ( impl , doc , sandbox ) ;
508+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
509509 impl . win . SVGElement = undefined ;
510510 const createElementStub = sandbox . stub (
511511 impl . win . document ,
@@ -535,7 +535,7 @@ describe('Google A4A utils', () => {
535535 'height' : '50' ,
536536 } ) ;
537537 const impl = new MockA4AImpl ( elem ) ;
538- noopMethods ( impl , doc , sandbox ) ;
538+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
539539 sandbox
540540 . stub ( Services . viewerForDoc ( impl . getAmpDoc ( ) ) , 'getReferrerUrl' )
541541 . returns ( new Promise ( ( ) => { } ) ) ;
@@ -564,7 +564,7 @@ describe('Google A4A utils', () => {
564564 doc . win = fixture . win ;
565565 const elem = createElementWithAttributes ( doc , 'amp-a4a' , { } ) ;
566566 const impl = new MockA4AImpl ( elem ) ;
567- noopMethods ( impl , doc , sandbox ) ;
567+ noopMethods ( impl , fixture . ampdoc , sandbox ) ;
568568 return fixture . addElement ( elem ) . then ( ( ) => {
569569 return googleAdUrl ( impl , '' , Date . now ( ) , [ ] , [ ] ) . then ( url => {
570570 expect ( url ) . to . match ( / [ & ? ] b d t = [ 1 - 9 ] [ 0 - 9 ] * [ & $ ] / ) ;
@@ -580,7 +580,7 @@ describe('Google A4A utils', () => {
580580 doc . win = fixture . win ;
581581 const elem = createElementWithAttributes ( doc , 'amp-a4a' , { } ) ;
582582 const impl = new MockA4AImpl ( elem ) ;
583- noopMethods ( impl , doc , sandbox , {
583+ noopMethods ( impl , fixture . ampdoc , sandbox , {
584584 top : 0 ,
585585 left : 0 ,
586586 right : 0 ,
@@ -902,6 +902,7 @@ describe('Google A4A utils', () => {
902902 describe ( 'variables for amp-analytics' , ( ) => {
903903 let a4a ;
904904 let sandbox ;
905+ let ampdoc ;
905906
906907 beforeEach ( ( ) => {
907908 sandbox = sinon . sandbox ;
@@ -913,7 +914,8 @@ describe('Google A4A utils', () => {
913914 'type' : 'adsense' ,
914915 'data-amp-slot-index' : '4' ,
915916 } ) ;
916- element . getAmpDoc = ( ) => fixture . doc ;
917+ ampdoc = fixture . ampdoc ;
918+ element . getAmpDoc = ( ) => ampdoc ;
917919 a4a = new MockA4AImpl ( element ) ;
918920 } ) ;
919921 } ) ;
@@ -957,9 +959,7 @@ describe('Google A4A utils', () => {
957959 } ) ;
958960
959961 it ( 'should include viewer lastVisibleTime' , ( ) => {
960- const getLastVisibleTime = ( ) => 300 ;
961- const viewerStub = sandbox . stub ( Services , 'viewerForDoc' ) ;
962- viewerStub . returns ( { getLastVisibleTime} ) ;
962+ sandbox . stub ( ampdoc , 'getLastVisibleTime' ) . returns ( 300 ) ;
963963
964964 const vars = getCsiAmpAnalyticsVariables ( 'trigger' , a4a , null ) ;
965965 expect ( vars [ 'viewerLastVisibleTime' ] ) . to . be . a ( 'number' ) ;
0 commit comments