@@ -72,6 +72,42 @@ it('should get a non-session cookie', async ({ context, page, server, defaultSam
7272 expect ( cookies [ 0 ] . expires ) . toBeGreaterThan ( ( Date . now ( ) + FOUR_HUNDRED_DAYS - FIVE_MINUTES ) / 1000 ) ;
7373} ) ;
7474
75+ it ( 'should allow adding cookies with >400 days expiration' , {
76+ annotation : { type : 'issue' , description : 'https://github.com/microsoft/playwright/issues/37903' }
77+ } , async ( { context, server, browserName, channel } ) => {
78+ it . fixme ( browserName === 'firefox' && ! channel ?. startsWith ( 'moz-firefox' ) , 'Firefox fails to add cookies with >400 days expiration' ) ;
79+
80+ // Browsers start to cap cookies with 400 days max expires value.
81+ // See https://github.com/httpwg/http-extensions/pull/1732
82+ // Chromium patch: https://chromium.googlesource.com/chromium/src/+/aaa5d2b55478eac2ee642653dcd77a50ac3faff6
83+ const expire = Date . now ( ) / 1000 + 401 * 24 * 3600 ;
84+ await context . addCookies ( [
85+ {
86+ name : 'username' ,
87+ value : 'John Doe' ,
88+ domain : server . HOSTNAME ,
89+ path : '/' ,
90+ expires : expire ,
91+ httpOnly : false ,
92+ secure : false ,
93+ sameSite : 'Lax' ,
94+ }
95+ ] ) ;
96+
97+ const cookies = await context . cookies ( ) ;
98+ expect ( cookies . length ) . toBe ( 1 ) ;
99+ expect ( cookies [ 0 ] ) . toEqual ( {
100+ name : 'username' ,
101+ value : 'John Doe' ,
102+ domain : server . HOSTNAME ,
103+ path : '/' ,
104+ expires : expect . anything ( ) ,
105+ httpOnly : false ,
106+ secure : false ,
107+ sameSite : 'Lax' ,
108+ } ) ;
109+ } ) ;
110+
75111it ( 'should properly report httpOnly cookie' , async ( { context, page, server } ) => {
76112 server . setRoute ( '/empty.html' , ( req , res ) => {
77113 res . setHeader ( 'Set-Cookie' , 'name=value;HttpOnly; Path=/' ) ;
0 commit comments