@@ -163,6 +163,9 @@ function forceEssentialCampaign() {
163163 }
164164}
165165
166+ const existingMarketingParams =
167+ 'utm_source=newsletter&utm_medium=email&utm_campaign=existing' ;
168+
166169test . describe ( 'marketing download attribution' , ( ) => {
167170 test ( 'has expected cookie values' , async ( { page, browserName } ) => {
168171 await page . addInitScript ( mockGetGtagClientID ) ;
@@ -271,7 +274,7 @@ test.describe('marketing download attribution', () => {
271274 ( ) => {
272275 const url = '/en-US/?geo=us' ;
273276
274- test ( 'on cookie created' , async ( { page, browserName } ) => {
277+ test ( 'cookie created' , async ( { page, browserName } ) => {
275278 await page . addInitScript ( mockGetGtagClientID ) ;
276279
277280 const capture = { params : null } ;
@@ -462,6 +465,63 @@ test.describe('marketing download attribution', () => {
462465 }
463466 ) ;
464467 } ) ;
468+
469+ test . describe (
470+ 'user action grants consent' ,
471+ {
472+ tag : '@firefox'
473+ } ,
474+ ( ) => {
475+ test ( 'cookie created' , async ( { page, browserName } ) => {
476+ await page . addInitScript ( interceptInitMarketing ) ;
477+ await page . addInitScript ( mockGetGtagClientID ) ;
478+ await openPage (
479+ `/fr/?geo=fr&mozcb=y&${ existingMarketingParams } ` ,
480+ page ,
481+ browserName
482+ ) ;
483+
484+ // confirm there's no existing cookie
485+ await page . waitForLoadState ( 'networkidle' ) ;
486+
487+ const initMarketingCalled = await page . evaluate (
488+ ( ) => window . __initMarketingCalled
489+ ) ;
490+ expect ( initMarketingCalled ) . toBe ( false ) ;
491+
492+ const existingMarketingCookies = await page . context ( ) . cookies ( ) ;
493+ const existingMarketingCookie = existingMarketingCookies . find (
494+ ( c ) => c . name === 'moz-download-attribution-marketing-raw'
495+ ) ;
496+ expect ( existingMarketingCookie ) . toBeUndefined ( ) ;
497+
498+ // change consent status
499+ const acceptButton = page . getByTestId (
500+ 'consent-banner-accept-button'
501+ ) ;
502+ acceptButton . click ( ) ;
503+
504+ // check marketing cookie was added
505+ await page . waitForFunction ( ( ) => {
506+ return document . cookie
507+ . split ( ';' )
508+ . some ( ( c ) =>
509+ c
510+ . trim ( )
511+ . startsWith (
512+ 'moz-download-attribution-marketing-raw='
513+ )
514+ ) ;
515+ } ) ;
516+
517+ const cookies = await page . context ( ) . cookies ( ) ;
518+ const marketingCookie = cookies . find (
519+ ( c ) => c . name === 'moz-download-attribution-marketing-raw'
520+ ) ;
521+ expect ( marketingCookie ) . toBeDefined ( ) ;
522+ } ) ;
523+ }
524+ ) ;
465525} ) ;
466526
467527test . describe ( 'essential download attribution' , ( ) => {
0 commit comments