@@ -26,6 +26,7 @@ it('should work', async({context, page, server}) => {
2626 } ] ) ;
2727 expect ( await page . evaluate ( ( ) => document . cookie ) ) . toEqual ( 'password=123456' ) ;
2828} ) ;
29+
2930it ( 'should roundtrip cookie' , async ( { context, page, server} ) => {
3031 await page . goto ( server . EMPTY_PAGE ) ;
3132 // @see https://en.wikipedia.org/wiki/Year_2038_problem
@@ -42,6 +43,7 @@ it('should roundtrip cookie', async({context, page, server}) => {
4243 await context . addCookies ( cookies ) ;
4344 expect ( await context . cookies ( ) ) . toEqual ( cookies ) ;
4445} ) ;
46+
4547it ( 'should send cookie header' , async ( { server, context} ) => {
4648 let cookie = '' ;
4749 server . setRoute ( '/empty.html' , ( req , res ) => {
@@ -53,6 +55,7 @@ it('should send cookie header', async({server, context}) => {
5355 await page . goto ( server . EMPTY_PAGE ) ;
5456 expect ( cookie ) . toBe ( 'cookie=value' ) ;
5557} ) ;
58+
5659it ( 'should isolate cookies in browser contexts' , async ( { context, server, browser} ) => {
5760 const anotherContext = await browser . newContext ( ) ;
5861 await context . addCookies ( [ { url : server . EMPTY_PAGE , name : 'isolatecookie' , value : 'page1value' } ] ) ;
@@ -68,6 +71,7 @@ it('should isolate cookies in browser contexts', async({context, server, browser
6871 expect ( cookies2 [ 0 ] . value ) . toBe ( 'page2value' ) ;
6972 await anotherContext . close ( ) ;
7073} ) ;
74+
7175it ( 'should isolate session cookies' , async ( { context, server, browser} ) => {
7276 server . setRoute ( '/setcookie.html' , ( req , res ) => {
7377 res . setHeader ( 'Set-Cookie' , 'session=value' ) ;
@@ -93,6 +97,7 @@ it('should isolate session cookies', async({context, server, browser}) => {
9397 await context2 . close ( ) ;
9498 }
9599} ) ;
100+
96101it ( 'should isolate persistent cookies' , async ( { context, server, browser} ) => {
97102 server . setRoute ( '/setcookie.html' , ( req , res ) => {
98103 res . setHeader ( 'Set-Cookie' , 'persistent=persistent-value; max-age=3600' ) ;
@@ -112,6 +117,7 @@ it('should isolate persistent cookies', async({context, server, browser}) => {
112117 expect ( cookies2 . length ) . toBe ( 0 ) ;
113118 await context2 . close ( ) ;
114119} ) ;
120+
115121it ( 'should isolate send cookie header' , async ( { server, context, browser} ) => {
116122 let cookie = [ ] ;
117123 server . setRoute ( '/empty.html' , ( req , res ) => {
@@ -132,6 +138,7 @@ it('should isolate send cookie header', async({server, context, browser}) => {
132138 await context . close ( ) ;
133139 }
134140} ) ;
141+
135142it . slow ( ) ( 'should isolate cookies between launches' , async ( { browserType, server, defaultBrowserOptions} ) => {
136143 const browser1 = await browserType . launch ( defaultBrowserOptions ) ;
137144 const context1 = await browser1 . newContext ( ) ;
@@ -144,6 +151,7 @@ it.slow()('should isolate cookies between launches', async({browserType, server,
144151 expect ( cookies . length ) . toBe ( 0 ) ;
145152 await browser2 . close ( ) ;
146153} ) ;
154+
147155it ( 'should set multiple cookies' , async ( { context, page, server} ) => {
148156 await page . goto ( server . EMPTY_PAGE ) ;
149157 await context . addCookies ( [ {
@@ -163,6 +171,7 @@ it('should set multiple cookies', async({context, page, server}) => {
163171 'multiple-2=bar' ,
164172 ] ) ;
165173} ) ;
174+
166175it ( 'should have |expires| set to |-1| for session cookies' , async ( { context, server} ) => {
167176 await context . addCookies ( [ {
168177 url : server . EMPTY_PAGE ,
@@ -172,6 +181,7 @@ it('should have |expires| set to |-1| for session cookies', async({context, serv
172181 const cookies = await context . cookies ( ) ;
173182 expect ( cookies [ 0 ] . expires ) . toBe ( - 1 ) ;
174183} ) ;
184+
175185it ( 'should set cookie with reasonable defaults' , async ( { context, server} ) => {
176186 await context . addCookies ( [ {
177187 url : server . EMPTY_PAGE ,
@@ -190,6 +200,7 @@ it('should set cookie with reasonable defaults', async({context, server}) => {
190200 sameSite : 'None' ,
191201 } ] ) ;
192202} ) ;
203+
193204it ( 'should set a cookie with a path' , async ( { context, page, server} ) => {
194205 await page . goto ( server . PREFIX + '/grid.html' ) ;
195206 await context . addCookies ( [ {
@@ -214,6 +225,7 @@ it('should set a cookie with a path', async({context, page, server}) => {
214225 await page . goto ( server . PREFIX + '/grid.html' ) ;
215226 expect ( await page . evaluate ( 'document.cookie' ) ) . toBe ( 'gridcookie=GRID' ) ;
216227} ) ;
228+
217229it ( 'should not set a cookie with blank page URL' , async function ( { context, server} ) {
218230 let error = null ;
219231 try {
@@ -228,6 +240,7 @@ it('should not set a cookie with blank page URL', async function({context, serve
228240 `Blank page can not have cookie "example-cookie-blank"`
229241 ) ;
230242} ) ;
243+
231244it ( 'should not set a cookie on a data URL page' , async function ( { context} ) {
232245 let error = null ;
233246 try {
@@ -237,6 +250,7 @@ it('should not set a cookie on a data URL page', async function({context}) {
237250 }
238251 expect ( error . message ) . toContain ( 'Data URL page can not have cookie "example-cookie"' ) ;
239252} ) ;
253+
240254it ( 'should default to setting secure cookie for HTTPS websites' , async ( { context, page, server} ) => {
241255 await page . goto ( server . EMPTY_PAGE ) ;
242256 const SECURE_URL = 'https://example.com' ;
@@ -248,6 +262,7 @@ it('should default to setting secure cookie for HTTPS websites', async({context,
248262 const [ cookie ] = await context . cookies ( SECURE_URL ) ;
249263 expect ( cookie . secure ) . toBe ( true ) ;
250264} ) ;
265+
251266it ( 'should be able to set unsecure cookie for HTTP website' , async ( { context, page, server} ) => {
252267 await page . goto ( server . EMPTY_PAGE ) ;
253268 const HTTP_URL = 'http://example.com' ;
@@ -259,6 +274,7 @@ it('should be able to set unsecure cookie for HTTP website', async({context, pag
259274 const [ cookie ] = await context . cookies ( HTTP_URL ) ;
260275 expect ( cookie . secure ) . toBe ( false ) ;
261276} ) ;
277+
262278it ( 'should set a cookie on a different domain' , async ( { context, page, server} ) => {
263279 await page . goto ( server . EMPTY_PAGE ) ;
264280 await context . addCookies ( [ {
@@ -278,6 +294,7 @@ it('should set a cookie on a different domain', async({context, page, server}) =
278294 sameSite : 'None' ,
279295 } ] ) ;
280296} ) ;
297+
281298it ( 'should set cookies for a frame' , async ( { context, page, server} ) => {
282299 await page . goto ( server . EMPTY_PAGE ) ;
283300 await context . addCookies ( [
@@ -295,6 +312,7 @@ it('should set cookies for a frame', async({context, page, server}) => {
295312
296313 expect ( await page . frames ( ) [ 1 ] . evaluate ( 'document.cookie' ) ) . toBe ( 'frame-cookie=value' ) ;
297314} ) ;
315+
298316it ( 'should(not) block third party cookies' , async ( { context, page, server} ) => {
299317 await page . goto ( server . EMPTY_PAGE ) ;
300318 await page . evaluate ( src => {
0 commit comments