@@ -283,3 +283,64 @@ suite('Atomic HTTP redirect handling', function() {
283
283
} )
284
284
} )
285
285
} )
286
+
287
+ // https://fetch.spec.whatwg.org/#concept-request-credentials-mode
288
+ suite ( 'credentials mode' , function ( ) {
289
+ var omitSupported = ! self . fetch . polyfill
290
+
291
+ ; ( omitSupported ? suite : suite . skip ) ( 'omit' , function ( ) {
292
+ test ( 'request credentials defaults to omit' , function ( ) {
293
+ var request = new Request ( '' )
294
+ assert . equal ( request . credentials , 'omit' )
295
+ } )
296
+
297
+ test ( 'does not send cookies with implicit omit credentials' , function ( ) {
298
+ return fetch ( '/cookie?name=foo&value=bar' ) . then ( function ( ) {
299
+ return fetch ( '/cookie?name=foo' ) ;
300
+ } ) . then ( function ( response ) {
301
+ return response . text ( )
302
+ } ) . then ( function ( data ) {
303
+ assert . equal ( data , '' )
304
+ } )
305
+ } )
306
+
307
+ test ( 'does not send cookies with omit credentials' , function ( ) {
308
+ return fetch ( '/cookie?name=foo&value=bar' ) . then ( function ( ) {
309
+ return fetch ( '/cookie?name=foo' , { credentials : 'omit' } )
310
+ } ) . then ( function ( response ) {
311
+ return response . text ( )
312
+ } ) . then ( function ( data ) {
313
+ assert . equal ( data , '' )
314
+ } )
315
+ } )
316
+ } )
317
+
318
+ suite ( 'same-origin' , function ( ) {
319
+ test ( 'request credentials uses inits member' , function ( ) {
320
+ var request = new Request ( '' , { credentials : 'same-origin' } )
321
+ assert . equal ( request . credentials , 'same-origin' )
322
+ } )
323
+
324
+ test ( 'send cookies with same-origin credentials' , function ( ) {
325
+ return fetch ( '/cookie?name=foo&value=bar' ) . then ( function ( ) {
326
+ return fetch ( '/cookie?name=foo' , { credentials : 'same-origin' } )
327
+ } ) . then ( function ( response ) {
328
+ return response . text ( )
329
+ } ) . then ( function ( data ) {
330
+ assert . equal ( data , 'bar' )
331
+ } )
332
+ } )
333
+ } )
334
+
335
+ suite ( 'include' , function ( ) {
336
+ test ( 'send cookies with include credentials' , function ( ) {
337
+ return fetch ( '/cookie?name=foo&value=bar' ) . then ( function ( ) {
338
+ return fetch ( '/cookie?name=foo' , { credentials : 'include' } )
339
+ } ) . then ( function ( response ) {
340
+ return response . text ( )
341
+ } ) . then ( function ( data ) {
342
+ assert . equal ( data , 'bar' )
343
+ } )
344
+ } )
345
+ } )
346
+ } )
0 commit comments