From f5545d7309c8ed77a714e2495023401ca7ad42ea Mon Sep 17 00:00:00 2001 From: Khoi Doan Date: Wed, 6 Mar 2024 23:20:24 +0000 Subject: [PATCH 1/4] Check for consent before writing ADCID. --- extensions/amp-a4a/0.1/amp-a4a.js | 16 ++++++++++++++-- .../0.1/amp-ad-network-doubleclick-impl.js | 16 +++++++++------- .../0.1/amp-ad-network-smartadserver-impl.js | 16 +++++++++------- .../0.1/amp-ad-network-valueimpression-impl.js | 12 ++++++++++-- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/extensions/amp-a4a/0.1/amp-a4a.js b/extensions/amp-a4a/0.1/amp-a4a.js index 6a8b6bc4659c..4e8c78ee93ca 100644 --- a/extensions/amp-a4a/0.1/amp-a4a.js +++ b/extensions/amp-a4a/0.1/amp-a4a.js @@ -787,6 +787,9 @@ export class AmpA4A extends AMP.BaseElement { const consentStringType = consentMetadata ? consentMetadata['consentStringType'] : consentMetadata; + const purposeOne = consentMetadata + ? consentMetadata['purposeOne'] + : consentMetadata; return /** @type {!Promise} */ ( this.getServeNpaSignal().then((npaSignal) => @@ -798,6 +801,7 @@ export class AmpA4A extends AMP.BaseElement { gdprApplies, additionalConsent, consentSharedData, + purposeOne, }, this.tryExecuteRealTimeConfig_( consentState, @@ -2399,6 +2403,13 @@ export class AmpA4A extends AMP.BaseElement { * @return {Promise>|undefined} */ tryExecuteRealTimeConfig_(consentState, consentString, consentMetadata) { + const hasStorageConsent = + consentState != CONSENT_POLICY_STATE.UNKNOWN && + consentState != CONSENT_POLICY_STATE.INSUFFICIENT && + ((consentMetadata.gdprApplies && + consentString && + consentMetadata.purposeOne) || + !consentMetadata.gdprApplies); if (this.element.getAttribute('rtc-config')) { installRealTimeConfigServiceForDoc(this.getAmpDoc()); return this.getBlockRtc_().then((shouldBlock) => @@ -2408,7 +2419,7 @@ export class AmpA4A extends AMP.BaseElement { (realTimeConfig) => realTimeConfig.maybeExecuteRealTimeConfig( this.element, - this.getCustomRealTimeConfigMacros_(), + this.getCustomRealTimeConfigMacros_(hasStorageConsent), consentState, consentString, consentMetadata, @@ -2422,10 +2433,11 @@ export class AmpA4A extends AMP.BaseElement { /** * To be overriden by network impl. Should return a mapping of macro keys * to values for substitution in publisher-specified URLs for RTC. + * @param {?boolean} unusedHasStorageConsent * @return {!Object} */ - getCustomRealTimeConfigMacros_() { + getCustomRealTimeConfigMacros_(unusedHasStorageConsent) { return {}; } diff --git a/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js b/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js index a8e1d58e5364..1b91288a726f 100644 --- a/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js +++ b/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js @@ -943,7 +943,7 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A { } /** @override */ - getCustomRealTimeConfigMacros_() { + getCustomRealTimeConfigMacros_(hasStorageConsent) { /** * This lists allowed attributes on the amp-ad element to be used as * macros for constructing the RTC URL. Add attributes here, in lowercase, @@ -971,12 +971,14 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A { (tryParseJson(this.element.getAttribute('json')) || {})['targeting'] ), ADCID: (opt_timeout) => - getOrCreateAdCid( - this.getAmpDoc(), - 'AMP_ECID_GOOGLE', - '_ga', - parseInt(opt_timeout, 10) - ), + hasStorageConsent + ? getOrCreateAdCid( + this.getAmpDoc(), + 'AMP_ECID_GOOGLE', + '_ga', + parseInt(opt_timeout, 10) + ) + : undefined, ATTR: (name) => { if (!allowlist[name.toLowerCase()]) { dev().warn(TAG, `Invalid attribute ${name}`); diff --git a/extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js b/extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js index e8740669ad3a..49382f2fe041 100644 --- a/extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js +++ b/extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js @@ -133,7 +133,7 @@ export class AmpAdNetworkSmartadserverImpl extends AmpA4A { } /** @override */ - getCustomRealTimeConfigMacros_() { + getCustomRealTimeConfigMacros_(hasStorageConsent) { const allowed = { 'width': true, 'height': true, @@ -156,12 +156,14 @@ export class AmpAdNetworkSmartadserverImpl extends AmpA4A { (tryParseJson(this.element.getAttribute('json')) || {})['targeting'] ), ADCID: (opt_timeout) => - getOrCreateAdCid( - this.getAmpDoc(), - 'AMP_ECID_GOOGLE', - '_ga', - parseInt(opt_timeout, 10) - ), + hasStorageConsent + ? getOrCreateAdCid( + this.getAmpDoc(), + 'AMP_ECID_GOOGLE', + '_ga', + parseInt(opt_timeout, 10) + ) + : undefined, ATTR: (name) => { if (!allowed[name]) { dev().warn(TAG, `Invalid attribute ${name}`); diff --git a/extensions/amp-ad-network-valueimpression-impl/0.1/amp-ad-network-valueimpression-impl.js b/extensions/amp-ad-network-valueimpression-impl/0.1/amp-ad-network-valueimpression-impl.js index d2a379ff9c64..2c1dd12b3adc 100644 --- a/extensions/amp-ad-network-valueimpression-impl/0.1/amp-ad-network-valueimpression-impl.js +++ b/extensions/amp-ad-network-valueimpression-impl/0.1/amp-ad-network-valueimpression-impl.js @@ -1,4 +1,5 @@ import '#service/real-time-config/real-time-config-impl'; +import {CONSENT_POLICY_STATE} from '#core/constants/consent-state'; import {Deferred} from '#core/data-structures/promise'; import {domFingerprintPlain} from '#core/dom/fingerprint'; import {getPageLayoutBoxBlocking} from '#core/dom/layout/page-layout-box'; @@ -191,7 +192,7 @@ export class AmpAdNetworkValueimpressionImpl extends AmpA4A { /** @override */ getAdUrl(opt_consentTuple, opt_rtcResponsesPromise, opt_serveNpaSignal) { const consentTuple = opt_consentTuple || {}; - const {consentString, gdprApplies} = consentTuple; + const {consentState, consentString, gdprApplies, purposeOne} = consentTuple; const {win} = this; const ampDoc = this.getAmpDoc(); @@ -229,10 +230,17 @@ export class AmpAdNetworkValueimpressionImpl extends AmpA4A { }); const startTime = Date.now(); + const hasStorageConsent = + consentState != CONSENT_POLICY_STATE.UNKNOWN && + consentState != CONSENT_POLICY_STATE.INSUFFICIENT && + ((gdprApplies && consentString && purposeOne) || !gdprApplies); + Promise.all([ rtcParamsPromise, referrerPromise, - getOrCreateAdCid(ampDoc, 'AMP_ECID_GOOGLE', '_ga'), + hasStorageConsent + ? getOrCreateAdCid(ampDoc, 'AMP_ECID_GOOGLE', '_ga') + : Promise.resolve(undefined), ]).then((results) => { const clientId = results[2]; const referrer = results[1]; From e6658bbf7d7c5c47aa9f58e279e1b89ac9316041 Mon Sep 17 00:00:00 2001 From: Khoi Doan Date: Wed, 3 Apr 2024 19:21:26 +0000 Subject: [PATCH 2/4] Add unit tests and fix some errors in code --- extensions/amp-a4a/0.1/amp-a4a.js | 6 +- extensions/amp-a4a/0.1/test/test-amp-a4a.js | 75 ++++++++++++++++++- .../0.1/amp-ad-network-doubleclick-impl.js | 2 +- .../0.1/test/test-doubleclick-rtc.js | 41 +++++++--- .../0.1/amp-ad-network-smartadserver-impl.js | 2 +- .../test-amp-ad-network-smartadserver-impl.js | 12 ++- 6 files changed, 119 insertions(+), 19 deletions(-) diff --git a/extensions/amp-a4a/0.1/amp-a4a.js b/extensions/amp-a4a/0.1/amp-a4a.js index 4e8c78ee93ca..86141034fe6e 100644 --- a/extensions/amp-a4a/0.1/amp-a4a.js +++ b/extensions/amp-a4a/0.1/amp-a4a.js @@ -2406,10 +2406,10 @@ export class AmpA4A extends AMP.BaseElement { const hasStorageConsent = consentState != CONSENT_POLICY_STATE.UNKNOWN && consentState != CONSENT_POLICY_STATE.INSUFFICIENT && - ((consentMetadata.gdprApplies && + ((consentMetadata?.gdprApplies && consentString && - consentMetadata.purposeOne) || - !consentMetadata.gdprApplies); + consentMetadata?.purposeOne) || + !consentMetadata?.gdprApplies); if (this.element.getAttribute('rtc-config')) { installRealTimeConfigServiceForDoc(this.getAmpDoc()); return this.getBlockRtc_().then((shouldBlock) => diff --git a/extensions/amp-a4a/0.1/test/test-amp-a4a.js b/extensions/amp-a4a/0.1/test/test-amp-a4a.js index eef8d09ec89e..b6730b8d6ab7 100644 --- a/extensions/amp-a4a/0.1/test/test-amp-a4a.js +++ b/extensions/amp-a4a/0.1/test/test-amp-a4a.js @@ -2811,6 +2811,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => { gdprApplies, 'consentStringType': 1, 'additionalConsent': 'abc123', + purposeOne: true, }; consentSharedData = { 'doubleclick-tfcd': 1, @@ -2857,6 +2858,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => { consentStringType: consentMetadata['consentStringType'], additionalConsent: consentMetadata['additionalConsent'], consentSharedData, + purposeOne: consentMetadata['purposeOne'], }) ).calledOnce; expect( @@ -2913,6 +2915,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => { consentStringType: consentMetadata['consentStringType'], additionalConsent: consentMetadata['additionalConsent'], consentSharedData, + purposeOne: consentMetadata['purposeOne'], }) ).calledOnce; expect( @@ -2963,6 +2966,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => { gdprApplies: null, additionalConsent: null, consentSharedData: null, + purposeOne: null, }) ).calledOnce; expect( @@ -3533,9 +3537,78 @@ describes.realWin('AmpA4a-RTC', {amp: true}, (env) => { }); }); + describe('#tryExecuteRealTimeConfig storage consent test', () => { + let getCustomRealTimeConfigMacrosSpy; + + beforeEach(() => { + element.setAttribute('rtc-config', true); + getCustomRealTimeConfigMacrosSpy = env.sandbox.spy(a4a, 'getCustomRealTimeConfigMacros_'); + }); + + for (const {consentState, gdprApplies, consentString, purposeOne, hasStorageConsent} of [ + // Unknown consent + { + consentState: CONSENT_POLICY_STATE.UNKNOWN, + gdprApplies: true, + consentString: 'string', + purposeOne: true, + hasStorageConsent: false, + }, + // Insufficient consent + { + consentState: CONSENT_POLICY_STATE.INSUFFICIENT, + gdprApplies: true, + consentString: 'string', + purposeOne: true, + hasStorageConsent: false, + }, + // Insufficient consent + { + consentState: CONSENT_POLICY_STATE.SUFFICIENT, + gdprApplies: false, + consentString: '', + purposeOne: false, + hasStorageConsent: true, + }, + // No consent string + { + consentState: CONSENT_POLICY_STATE.SUFFICIENT, + gdprApplies: true, + consentString: '', + purposeOne: true, + hasStorageConsent: false, + }, + // no purpose one consent + { + consentState: CONSENT_POLICY_STATE.SUFFICIENT, + gdprApplies: true, + consentString: 'string', + purposeOne: false, + hasStorageConsent: false, + }, + // GDPR applies and all prerequisite satisfied + { + consentState: CONSENT_POLICY_STATE.SUFFICIENT, + gdprApplies: true, + consentString: 'string', + purposeOne: true, + hasStorageConsent: true, + }, + ]) { + it(`storageConsent test - consentState=${consentState}, ` + + `consentString=${consentString}, gdprApplies=${gdprApplies},` + + `purposeOne=${purposeOne} -> hasStorageConsent=${hasStorageConsent}`, + () => { + return a4a.tryExecuteRealTimeConfig_(consentState, consentString, {gdprApplies, purposeOne}).then(() => { + expect(getCustomRealTimeConfigMacrosSpy).to.be.calledWith(hasStorageConsent); + }); + }); + } + }); + describe('#getCustomRealTimeConfigMacros_', () => { it('should return empty object', () => { - expect(a4a.getCustomRealTimeConfigMacros_()).to.deep.equal({}); + expect(a4a.getCustomRealTimeConfigMacros_(true)).to.deep.equal({}); }); }); diff --git a/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js b/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js index 1b91288a726f..6010cf93845d 100644 --- a/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js +++ b/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js @@ -978,7 +978,7 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A { '_ga', parseInt(opt_timeout, 10) ) - : undefined, + : Promise.resolve(undefined), ATTR: (name) => { if (!allowlist[name.toLowerCase()]) { dev().warn(TAG, `Invalid attribute ${name}`); diff --git a/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-doubleclick-rtc.js b/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-doubleclick-rtc.js index 0ecbd59fae08..e24ed0a14983 100644 --- a/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-doubleclick-rtc.js +++ b/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-doubleclick-rtc.js @@ -392,8 +392,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { }); describe('getCustomRealTimeConfigMacros', () => { - // TODO(bradfrizzell, #18574): Fix failing referrer check and re-enable. - it.skip('should return correct macros', () => { + it('should return correct macros', () => { const macros = { 'data-slot': '5678', 'height': '50', @@ -419,18 +418,19 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { 'json': JSON.stringify(json), }); env.win.document.body.appendChild(element); - env.sandbox.defineProperty(env.win.document, 'referrer', { - value: 'https://www.google.com/', - }); + // TODO(bradfrizzell, #18574): Fix failing referrer check and re-enable. + //env.sandbox.defineProperty(env.win.document, 'referrer', { + // value: 'https://www.google.com/', + //}); const docInfo = Services.documentInfoForDoc(element); impl = new AmpAdNetworkDoubleclickImpl( element, env.win.document, env.win ); - const docViewport = Services.viewportForDoc(this.getAmpDoc()); + const docViewport = Services.viewportForDoc(impl.getAmpDoc()); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(); + const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); expect(customMacros.PAGEVIEWID()).to.equal(docInfo.pageViewId); expect(customMacros.PAGEVIEWID_64()).to.equal(docInfo.pageViewId64); expect(customMacros.HREF()).to.equal(env.win.location.href); @@ -443,7 +443,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { docViewport.getScrollHeight() ); expect(customMacros.BKG_STATE()).to.equal( - this.getAmpDoc().isVisible() ? 'visible' : 'hidden' + impl.getAmpDoc().isVisible() ? 'visible' : 'hidden' ); Object.keys(macros).forEach((macro) => { expect(customMacros.ATTR(macro)).to.equal(macros[macro]); @@ -469,7 +469,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { env.win ); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(); + const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); let adcid; return customMacros.ADCID().then((adcid1) => { adcid = adcid1; @@ -480,6 +480,23 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { }); }); + it('should not set adcid if no storage consent', () => { + element = createElementWithAttributes(env.win.document, 'amp-ad', { + type: 'doubleclick', + }); + env.win.document.body.appendChild(element); + impl = new AmpAdNetworkDoubleclickImpl( + element, + env.win.document, + env.win + ); + impl.populateAdUrlState(); + const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/false); + return customMacros.ADCID().then((adcid) => { + expect(adcid).to.be.undefined; + }); + }); + it('should respect timeout for adcid', () => { element = createElementWithAttributes(env.win.document, 'amp-ad', { type: 'doubleclick', @@ -491,7 +508,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { env.win ); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(); + const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); return customMacros.ADCID(0).then((adcid) => { expect(adcid).to.be.undefined; }); @@ -510,7 +527,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { impl.populateAdUrlState(); const viewer = Services.viewerForDoc(impl.getAmpDoc()); env.sandbox.stub(viewer, 'getReferrerUrl').returns(new Promise(() => {})); - const customMacros = impl.getCustomRealTimeConfigMacros_(); + const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); return expect(customMacros.REFERRER(0)).to.eventually.be.undefined; }); @@ -528,7 +545,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { env.win ); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(); + const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); expect(customMacros.TGT()).to.equal(JSON.stringify(json['targeting'])); }); }); diff --git a/extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js b/extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js index 49382f2fe041..e078b82ed7a5 100644 --- a/extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js +++ b/extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js @@ -163,7 +163,7 @@ export class AmpAdNetworkSmartadserverImpl extends AmpA4A { '_ga', parseInt(opt_timeout, 10) ) - : undefined, + : Promise.resolve(undefined), ATTR: (name) => { if (!allowed[name]) { dev().warn(TAG, `Invalid attribute ${name}`); diff --git a/extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js b/extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js index df574c62a670..1911ce984f37 100644 --- a/extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js +++ b/extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js @@ -113,7 +113,7 @@ describes.realWin('amp-ad-network-smartadserver-impl', realWinConfig, (env) => { impl = new AmpAdNetworkSmartadserverImpl(element, env.win.doc, win); const docInfo = Services.documentInfoForDoc(element); - const customMacros = impl.getCustomRealTimeConfigMacros_(); + const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/false); expect(customMacros.PAGEVIEWID()).to.equal(docInfo.pageViewId); expect(customMacros.PAGEVIEWID_64()).to.equal(docInfo.pageViewId64); @@ -157,6 +157,16 @@ describes.realWin('amp-ad-network-smartadserver-impl', realWinConfig, (env) => { ); expect(customMacros.ATTR('not-allowed')).to.equal(''); }); + + it('should not set adcid if no storage consent', () => { + element = createElementWithAttributes(doc, 'amp-ad'); + impl = new AmpAdNetworkSmartadserverImpl(element); + const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/false); + + return customMacros.ADCID().then((adcid) => { + expect(adcid).to.be.undefined; + }); + }); }); describe('getAdUrl', () => { From 6e98c1c391bb86440e7747eba44d1ad1e645b214 Mon Sep 17 00:00:00 2001 From: Khoi Doan Date: Wed, 3 Apr 2024 19:28:10 +0000 Subject: [PATCH 3/4] Fix comment in test --- extensions/amp-a4a/0.1/test/test-amp-a4a.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/amp-a4a/0.1/test/test-amp-a4a.js b/extensions/amp-a4a/0.1/test/test-amp-a4a.js index 27550714ec79..050f515a1ce8 100644 --- a/extensions/amp-a4a/0.1/test/test-amp-a4a.js +++ b/extensions/amp-a4a/0.1/test/test-amp-a4a.js @@ -3566,7 +3566,7 @@ describes.realWin('AmpA4a-RTC', {amp: true}, (env) => { purposeOne: true, hasStorageConsent: false, }, - // Insufficient consent + // GDPR doesn't apply { consentState: CONSENT_POLICY_STATE.SUFFICIENT, gdprApplies: false, From 98e38550c2c0ed4781f8894cc0a5112ec82b4c34 Mon Sep 17 00:00:00 2001 From: Khoi Doan Date: Tue, 9 Apr 2024 14:43:27 +0000 Subject: [PATCH 4/4] Lint fixes --- extensions/amp-a4a/0.1/test/test-amp-a4a.js | 132 ++++++++++-------- .../0.1/test/test-doubleclick-rtc.js | 24 +++- .../test-amp-ad-network-smartadserver-impl.js | 8 +- 3 files changed, 99 insertions(+), 65 deletions(-) diff --git a/extensions/amp-a4a/0.1/test/test-amp-a4a.js b/extensions/amp-a4a/0.1/test/test-amp-a4a.js index 050f515a1ce8..30791a4e45c5 100644 --- a/extensions/amp-a4a/0.1/test/test-amp-a4a.js +++ b/extensions/amp-a4a/0.1/test/test-amp-a4a.js @@ -3546,67 +3546,85 @@ describes.realWin('AmpA4a-RTC', {amp: true}, (env) => { beforeEach(() => { element.setAttribute('rtc-config', true); - getCustomRealTimeConfigMacrosSpy = env.sandbox.spy(a4a, 'getCustomRealTimeConfigMacros_'); - }); - - for (const {consentState, gdprApplies, consentString, purposeOne, hasStorageConsent} of [ - // Unknown consent - { - consentState: CONSENT_POLICY_STATE.UNKNOWN, - gdprApplies: true, - consentString: 'string', - purposeOne: true, - hasStorageConsent: false, - }, - // Insufficient consent - { - consentState: CONSENT_POLICY_STATE.INSUFFICIENT, - gdprApplies: true, - consentString: 'string', - purposeOne: true, - hasStorageConsent: false, - }, - // GDPR doesn't apply - { - consentState: CONSENT_POLICY_STATE.SUFFICIENT, - gdprApplies: false, - consentString: '', - purposeOne: false, - hasStorageConsent: true, - }, - // No consent string - { - consentState: CONSENT_POLICY_STATE.SUFFICIENT, - gdprApplies: true, - consentString: '', - purposeOne: true, - hasStorageConsent: false, - }, - // no purpose one consent - { - consentState: CONSENT_POLICY_STATE.SUFFICIENT, - gdprApplies: true, - consentString: 'string', - purposeOne: false, - hasStorageConsent: false, - }, - // GDPR applies and all prerequisite satisfied - { - consentState: CONSENT_POLICY_STATE.SUFFICIENT, - gdprApplies: true, - consentString: 'string', - purposeOne: true, - hasStorageConsent: true, - }, + getCustomRealTimeConfigMacrosSpy = env.sandbox.spy( + a4a, + 'getCustomRealTimeConfigMacros_' + ); + }); + + for (const { + consentState, + consentString, + gdprApplies, + hasStorageConsent, + purposeOne, + } of [ + // Unknown consent + { + consentState: CONSENT_POLICY_STATE.UNKNOWN, + gdprApplies: true, + consentString: 'string', + purposeOne: true, + hasStorageConsent: false, + }, + // Insufficient consent + { + consentState: CONSENT_POLICY_STATE.INSUFFICIENT, + gdprApplies: true, + consentString: 'string', + purposeOne: true, + hasStorageConsent: false, + }, + // GDPR doesn't apply + { + consentState: CONSENT_POLICY_STATE.SUFFICIENT, + gdprApplies: false, + consentString: '', + purposeOne: false, + hasStorageConsent: true, + }, + // No consent string + { + consentState: CONSENT_POLICY_STATE.SUFFICIENT, + gdprApplies: true, + consentString: '', + purposeOne: true, + hasStorageConsent: false, + }, + // no purpose one consent + { + consentState: CONSENT_POLICY_STATE.SUFFICIENT, + gdprApplies: true, + consentString: 'string', + purposeOne: false, + hasStorageConsent: false, + }, + // GDPR applies and all prerequisite satisfied + { + consentState: CONSENT_POLICY_STATE.SUFFICIENT, + gdprApplies: true, + consentString: 'string', + purposeOne: true, + hasStorageConsent: true, + }, ]) { - it(`storageConsent test - consentState=${consentState}, ` + + it( + `storageConsent test - consentState=${consentState}, ` + `consentString=${consentString}, gdprApplies=${gdprApplies},` + `purposeOne=${purposeOne} -> hasStorageConsent=${hasStorageConsent}`, - () => { - return a4a.tryExecuteRealTimeConfig_(consentState, consentString, {gdprApplies, purposeOne}).then(() => { - expect(getCustomRealTimeConfigMacrosSpy).to.be.calledWith(hasStorageConsent); + () => { + return a4a + .tryExecuteRealTimeConfig_(consentState, consentString, { + gdprApplies, + purposeOne, + }) + .then(() => { + expect(getCustomRealTimeConfigMacrosSpy).to.be.calledWith( + hasStorageConsent + ); }); - }); + } + ); } }); diff --git a/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-doubleclick-rtc.js b/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-doubleclick-rtc.js index e24ed0a14983..3f1f370d2a10 100644 --- a/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-doubleclick-rtc.js +++ b/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-doubleclick-rtc.js @@ -430,7 +430,9 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { ); const docViewport = Services.viewportForDoc(impl.getAmpDoc()); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); + const customMacros = impl.getCustomRealTimeConfigMacros_( + /*hasStorageConsent=*/ true + ); expect(customMacros.PAGEVIEWID()).to.equal(docInfo.pageViewId); expect(customMacros.PAGEVIEWID_64()).to.equal(docInfo.pageViewId64); expect(customMacros.HREF()).to.equal(env.win.location.href); @@ -469,7 +471,9 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { env.win ); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); + const customMacros = impl.getCustomRealTimeConfigMacros_( + /*hasStorageConsent=*/ true + ); let adcid; return customMacros.ADCID().then((adcid1) => { adcid = adcid1; @@ -491,7 +495,9 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { env.win ); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/false); + const customMacros = impl.getCustomRealTimeConfigMacros_( + /*hasStorageConsent=*/ false + ); return customMacros.ADCID().then((adcid) => { expect(adcid).to.be.undefined; }); @@ -508,7 +514,9 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { env.win ); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); + const customMacros = impl.getCustomRealTimeConfigMacros_( + /*hasStorageConsent=*/ true + ); return customMacros.ADCID(0).then((adcid) => { expect(adcid).to.be.undefined; }); @@ -527,7 +535,9 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { impl.populateAdUrlState(); const viewer = Services.viewerForDoc(impl.getAmpDoc()); env.sandbox.stub(viewer, 'getReferrerUrl').returns(new Promise(() => {})); - const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); + const customMacros = impl.getCustomRealTimeConfigMacros_( + /*hasStorageConsent=*/ true + ); return expect(customMacros.REFERRER(0)).to.eventually.be.undefined; }); @@ -545,7 +555,9 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => { env.win ); impl.populateAdUrlState(); - const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/true); + const customMacros = impl.getCustomRealTimeConfigMacros_( + /*hasStorageConsent=*/ true + ); expect(customMacros.TGT()).to.equal(JSON.stringify(json['targeting'])); }); }); diff --git a/extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js b/extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js index 1911ce984f37..046af00a339b 100644 --- a/extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js +++ b/extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js @@ -113,7 +113,9 @@ describes.realWin('amp-ad-network-smartadserver-impl', realWinConfig, (env) => { impl = new AmpAdNetworkSmartadserverImpl(element, env.win.doc, win); const docInfo = Services.documentInfoForDoc(element); - const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/false); + const customMacros = impl.getCustomRealTimeConfigMacros_( + /*hasStorageConsent=*/ false + ); expect(customMacros.PAGEVIEWID()).to.equal(docInfo.pageViewId); expect(customMacros.PAGEVIEWID_64()).to.equal(docInfo.pageViewId64); @@ -161,7 +163,9 @@ describes.realWin('amp-ad-network-smartadserver-impl', realWinConfig, (env) => { it('should not set adcid if no storage consent', () => { element = createElementWithAttributes(doc, 'amp-ad'); impl = new AmpAdNetworkSmartadserverImpl(element); - const customMacros = impl.getCustomRealTimeConfigMacros_(/*hasStorageConsent=*/false); + const customMacros = impl.getCustomRealTimeConfigMacros_( + /*hasStorageConsent=*/ false + ); return customMacros.ADCID().then((adcid) => { expect(adcid).to.be.undefined;