-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathhttp_request_data_test.dart
More file actions
95 lines (84 loc) · 2.72 KB
/
http_request_data_test.dart
File metadata and controls
95 lines (84 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import 'package:devtools_app/src/shared/http/http_request_data.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('responseBytes', () {
Map<String, Object?> baseJson(Map<String, Object?> responseHeaders) {
return {
'isolateId': 'isolate-1',
'id': 'request-1',
'method': 'GET',
'uri': 'https://example.com',
'events': <Object?>[],
'startTime': DateTime.now().microsecondsSinceEpoch,
'endTime': DateTime.now().microsecondsSinceEpoch,
'request': {
'headers': <String, Object?>{},
'connectionInfo': null,
'contentLength': null,
'cookies': <Object?>[],
'followRedirects': true,
'maxRedirects': 5,
'persistentConnection': true,
},
'response': {
'headers': responseHeaders,
'connectionInfo': null,
'contentLength': null,
'cookies': <Object?>[],
'compressionState': 'ResponseBodyCompressionState.notCompressed',
'isRedirect': false,
'persistentConnection': true,
'reasonPhrase': 'OK',
'redirects': <Map<String, dynamic>>[],
'statusCode': 200,
'startTime': DateTime.now().microsecondsSinceEpoch,
},
};
}
// Verifies parsing when content-length is a string value.
test('parses content-length from string', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({'content-length': '1234'}),
null,
null,
);
expect(request.responseBytes, 1234);
});
// Verifies parsing when content-length is a list of strings.
test('parses content-length from list of strings', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({
'content-length': ['5678'],
}),
null,
null,
);
expect(request.responseBytes, 5678);
});
// Ensures integer values inside a list are handled correctly.
test('handles integer in list', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({
'content-length': [91011],
}),
null,
null,
);
expect(request.responseBytes, 91011);
});
// Returns null when header is missing.
test('returns null for missing header', () {
final request = DartIOHttpRequestData.fromJson(baseJson({}), null, null);
expect(request.responseBytes, null);
});
// Returns null when parsing fails.
test('returns null for invalid value', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({'content-length': 'invalid'}),
null,
null,
);
expect(request.responseBytes, null);
});
});
}