@@ -106,10 +106,9 @@ it('should get multiple cookies', async ({context, page, server}) => {
106
106
document . cookie = 'password=1234' ;
107
107
return document . cookie . split ( '; ' ) . sort ( ) . join ( '; ' ) ;
108
108
} ) ;
109
- const cookies = await context . cookies ( ) ;
110
- cookies . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
109
+ const cookies = new Set ( await context . cookies ( ) ) ;
111
110
expect ( documentCookie ) . toBe ( 'password=1234; username=John Doe' ) ;
112
- expect ( cookies ) . toEqual ( [
111
+ expect ( cookies ) . toEqual ( new Set ( [
113
112
{
114
113
name : 'password' ,
115
114
value : '1234' ,
@@ -130,7 +129,7 @@ it('should get multiple cookies', async ({context, page, server}) => {
130
129
secure : false ,
131
130
sameSite : 'None' ,
132
131
} ,
133
- ] ) ;
132
+ ] ) ) ;
134
133
} ) ;
135
134
136
135
it ( 'should get cookies from multiple urls' , async ( { context} ) => {
@@ -147,9 +146,8 @@ it('should get cookies from multiple urls', async ({context}) => {
147
146
name : 'birdo' ,
148
147
value : 'tweets' ,
149
148
} ] ) ;
150
- const cookies = await context . cookies ( [ 'https://foo.com' , 'https://baz.com' ] ) ;
151
- cookies . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
152
- expect ( cookies ) . toEqual ( [ {
149
+ const cookies = new Set ( await context . cookies ( [ 'https://foo.com' , 'https://baz.com' ] ) ) ;
150
+ expect ( cookies ) . toEqual ( new Set ( [ {
153
151
name : 'birdo' ,
154
152
value : 'tweets' ,
155
153
domain : 'baz.com' ,
@@ -167,7 +165,7 @@ it('should get cookies from multiple urls', async ({context}) => {
167
165
httpOnly : false ,
168
166
secure : true ,
169
167
sameSite : 'None' ,
170
- } ] ) ;
168
+ } ] ) ) ;
171
169
} ) ;
172
170
173
171
it ( 'should work with subdomain cookie' , async ( { context, page, server} ) => {
@@ -210,3 +208,46 @@ it('should not return cookies with empty value', async ({context, page, server})
210
208
expect ( cookies . length ) . toBe ( 0 ) ;
211
209
} ) ;
212
210
211
+ it ( 'should return secure cookies based on HTTP(S) protocol' , async ( { context} ) => {
212
+ await context . addCookies ( [ {
213
+ url : 'https://foo.com' ,
214
+ name : 'doggo' ,
215
+ value : 'woofs' ,
216
+ secure : true
217
+ } , {
218
+ url : 'http://foo.com' ,
219
+ name : 'catto' ,
220
+ value : 'purrs' ,
221
+ secure : false
222
+ } ] ) ;
223
+ const cookies = new Set ( await context . cookies ( 'https://foo.com' ) ) ;
224
+ expect ( cookies ) . toEqual ( new Set ( [ {
225
+ name : 'catto' ,
226
+ value : 'purrs' ,
227
+ domain : 'foo.com' ,
228
+ path : '/' ,
229
+ expires : - 1 ,
230
+ httpOnly : false ,
231
+ secure : false ,
232
+ sameSite : 'None' ,
233
+ } , {
234
+ name : 'doggo' ,
235
+ value : 'woofs' ,
236
+ domain : 'foo.com' ,
237
+ path : '/' ,
238
+ expires : - 1 ,
239
+ httpOnly : false ,
240
+ secure : true ,
241
+ sameSite : 'None' ,
242
+ } ] ) ) ;
243
+ expect ( await context . cookies ( 'http://foo.com/' ) ) . toEqual ( [ {
244
+ name : 'catto' ,
245
+ value : 'purrs' ,
246
+ domain : 'foo.com' ,
247
+ path : '/' ,
248
+ expires : - 1 ,
249
+ httpOnly : false ,
250
+ secure : false ,
251
+ sameSite : 'None' ,
252
+ } ] ) ;
253
+ } ) ;
0 commit comments