@@ -64,20 +64,23 @@ class _MockXhr {
64
64
* An internal class used by [MockHttpBackend] .
65
65
*/
66
66
class MockHttpExpectation {
67
- final method;
68
- final url;
67
+ final String method;
68
+ final /*String or RegExp*/ url;
69
69
final data;
70
70
final headers;
71
+ final bool withCredentials;
71
72
72
73
var response;
73
74
74
- MockHttpExpectation (this .method, this .url, [this .data, this .headers]);
75
+ MockHttpExpectation (this .method, this .url, [this .data, this .headers, withCredentials]) :
76
+ this .withCredentials = withCredentials == true ;
75
77
76
- bool match (method, url, [data, headers]) {
78
+ bool match (method, url, [data, headers, withCredentials ]) {
77
79
if (method != method) return false ;
78
80
if (! matchUrl (url)) return false ;
79
81
if (data != null && ! matchData (data)) return false ;
80
82
if (headers != null && ! matchHeaders (headers)) return false ;
83
+ if (withCredentials != null && ! matchWithCredentials (withCredentials)) return false ;
81
84
return true ;
82
85
}
83
86
@@ -102,6 +105,8 @@ class MockHttpExpectation {
102
105
return JSON .encode (data) == JSON .encode (d);
103
106
}
104
107
108
+ bool matchWithCredentials (withCredentials) => this .withCredentials == withCredentials;
109
+
105
110
String toString () => "$method $url " ;
106
111
}
107
112
@@ -124,7 +129,7 @@ class MockHttpBackend implements HttpBackend {
124
129
* This function is called from [Http] and designed to mimic the Dart APIs.
125
130
*/
126
131
dart_async.Future request (String url,
127
- {String method, bool withCredentials, String responseType,
132
+ {String method, bool withCredentials: false , String responseType,
128
133
String mimeType, Map <String , String > requestHeaders, sendData,
129
134
void onProgress (ProgressEvent e)}) {
130
135
dart_async.Completer c = new dart_async.Completer ();
@@ -137,7 +142,7 @@ class MockHttpBackend implements HttpBackend {
137
142
}
138
143
};
139
144
call (method == null ? 'GET' : method, url, callback,
140
- data: sendData, headers: requestHeaders);
145
+ data: sendData, headers: requestHeaders, withCredentials : withCredentials );
141
146
return c.future;
142
147
}
143
148
@@ -163,7 +168,7 @@ class MockHttpBackend implements HttpBackend {
163
168
* A callback oriented API. This function takes a callback with
164
169
* will be called with (status, data, headers)
165
170
*/
166
- void call (method, url, callback, {data, headers, timeout}) {
171
+ void call (method, url, callback, {data, headers, timeout, withCredentials : false }) {
167
172
var xhr = new _MockXhr (),
168
173
expectation = expectations.isEmpty ? null : expectations[0 ],
169
174
wasExpected = false ;
@@ -206,6 +211,11 @@ class MockHttpBackend implements HttpBackend {
206
211
'EXPECTED: ${prettyPrint (expectation .headers )}\n '
207
212
'GOT: ${prettyPrint (headers )}' ];
208
213
214
+ if (! expectation.matchWithCredentials (withCredentials))
215
+ throw ['Expected $expectation with different withCredentials\n '
216
+ 'EXPECTED: ${prettyPrint (expectation .withCredentials )}\n '
217
+ 'GOT: ${prettyPrint (withCredentials )}' ];
218
+
209
219
expectations.removeAt (0 );
210
220
211
221
if (expectation.response != null ) {
@@ -216,7 +226,7 @@ class MockHttpBackend implements HttpBackend {
216
226
}
217
227
218
228
for (var definition in definitions) {
219
- if (definition.match (method, url, data, headers != null ? headers : {})) {
229
+ if (definition.match (method, url, data, headers != null ? headers : {}, withCredentials )) {
220
230
if (definition.response != null ) {
221
231
// if $browser specified, we do auto flush all requests
222
232
responses.add (wrapResponse (definition));
@@ -248,8 +258,8 @@ class MockHttpBackend implements HttpBackend {
248
258
* an array containing response status (number), response data (string) and response headers
249
259
* (Object).
250
260
*/
251
- _Chain when (method, [url, data, headers]) {
252
- var definition = new MockHttpExpectation (method, url, data, headers),
261
+ _Chain when (method, [url, data, headers, withCredentials = false ]) {
262
+ var definition = new MockHttpExpectation (method, url, data, headers, withCredentials ),
253
263
chain = new _Chain (respond: (status, data, headers) {
254
264
definition.response = _createResponse (status, data, headers);
255
265
});
@@ -364,8 +374,8 @@ class MockHttpBackend implements HttpBackend {
364
374
* an array containing response status (number), response data (string) and response headers
365
375
* (Object).
366
376
*/
367
- _Chain expect (method, [url, data, headers]) {
368
- var expectation = new MockHttpExpectation (method, url, data, headers);
377
+ _Chain expect (method, [url, data, headers, withCredentials = false ]) {
378
+ var expectation = new MockHttpExpectation (method, url, data, headers, withCredentials );
369
379
expectations.add (expectation);
370
380
return new _Chain (respond: (status, data, headers) {
371
381
expectation.response = _createResponse (status, data, headers);
@@ -385,7 +395,8 @@ class MockHttpBackend implements HttpBackend {
385
395
* @returns {requestHandler} Returns an object with `respond` method that control how a matched
386
396
* request is handled. See #expect for more info.
387
397
*/
388
- _Chain expectGET (url, [headers]) => expect ('GET' , url, null , headers);
398
+ _Chain expectGET (url, [headers, withCredentials = false ]) => expect ('GET' , url, null , headers,
399
+ withCredentials);
389
400
390
401
/**
391
402
* @ngdoc method
@@ -399,7 +410,8 @@ class MockHttpBackend implements HttpBackend {
399
410
* @returns {requestHandler} Returns an object with `respond` method that control how a matched
400
411
* request is handled.
401
412
*/
402
- _Chain expectDELETE (url, [headers]) => expect ('DELETE' , url, null , headers);
413
+ _Chain expectDELETE (url, [headers, withCredentials = false ]) => expect ('DELETE' , url, null ,
414
+ headers, withCredentials);
403
415
404
416
/**
405
417
* @ngdoc method
@@ -412,7 +424,8 @@ class MockHttpBackend implements HttpBackend {
412
424
* @returns {requestHandler} Returns an object with `respond` method that control how a matched
413
425
* request is handled.
414
426
*/
415
- _Chain expectJSONP (url, [headers]) => expect ('JSONP' , url, null , headers);
427
+ _Chain expectJSONP (url, [headers, withCredentials = false ]) => expect ('JSONP' , url, null , headers,
428
+ withCredentials);
416
429
417
430
/**
418
431
* @ngdoc method
@@ -427,7 +440,8 @@ class MockHttpBackend implements HttpBackend {
427
440
* @returns {requestHandler} Returns an object with `respond` method that control how a matched
428
441
* request is handled.
429
442
*/
430
- _Chain expectPUT (url, [data, headers]) => expect ('PUT' , url, data, headers);
443
+ _Chain expectPUT (url, [data, headers, withCredentials = false ]) => expect ('PUT' , url, data,
444
+ headers, withCredentials);
431
445
432
446
/**
433
447
* @ngdoc method
@@ -442,7 +456,8 @@ class MockHttpBackend implements HttpBackend {
442
456
* @returns {requestHandler} Returns an object with `respond` method that control how a matched
443
457
* request is handled.
444
458
*/
445
- _Chain expectPOST (url, [data, headers]) => expect ('POST' , url, data, headers);
459
+ _Chain expectPOST (url, [data, headers, withCredentials = false ]) => expect ('POST' , url, data,
460
+ headers, withCredentials);
446
461
447
462
/**
448
463
* @ngdoc method
@@ -457,7 +472,8 @@ class MockHttpBackend implements HttpBackend {
457
472
* @returns {requestHandler} Returns an object with `respond` method that control how a matched
458
473
* request is handled.
459
474
*/
460
- _Chain expectPATCH (url, [data, headers]) => expect ('PATCH' , url, data, headers);
475
+ _Chain expectPATCH (url, [data, headers, withCredentials = false ]) => expect ('PATCH' , url, data,
476
+ headers, withCredentials);
461
477
462
478
/**
463
479
* @ngdoc method
0 commit comments