Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 library http_mock; | 1 library http_mock; |
| 2 | 2 |
| 3 import 'dart:async'; | 3 import 'dart:async'; |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'dart:convert'; | 5 import 'dart:convert'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 class MockHttpHeaders implements HttpHeaders { | 8 class MockHttpHeaders implements HttpHeaders { |
| 9 final Map<String, List<String>> _headers = | 9 final Map<String, List<String>> _headers = |
| 10 new HashMap<String, List<String>>(); | 10 new HashMap<String, List<String>>(); |
| 11 | 11 |
| 12 operator[](key) => _headers[key]; | |
| 12 | 13 |
| 13 DateTime get ifModifiedSince { | 14 DateTime get ifModifiedSince { |
| 14 List<String> values = _headers[HttpHeaders.IF_MODIFIED_SINCE]; | 15 List<String> values = _headers[HttpHeaders.IF_MODIFIED_SINCE]; |
| 15 if (values != null) { | 16 if (values != null) { |
| 16 try { | 17 try { |
| 17 return HttpDate.parse(values[0]); | 18 return HttpDate.parse(values[0]); |
| 18 } on Exception catch (e) { | 19 } on Exception catch (e) { |
| 19 return null; | 20 return null; |
| 20 } | 21 } |
| 21 } | 22 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 assert(name == name.toLowerCase()); | 91 assert(name == name.toLowerCase()); |
| 91 List<String> values = new List<String>(); | 92 List<String> values = new List<String>(); |
| 92 _headers[name] = values; | 93 _headers[name] = values; |
| 93 values.add(value); | 94 values.add(value); |
| 94 } | 95 } |
| 95 | 96 |
| 96 /* | 97 /* |
| 97 * Implemented to remove editor warnings | 98 * Implemented to remove editor warnings |
| 98 */ | 99 */ |
| 99 dynamic noSuchMethod(Invocation invocation) { | 100 dynamic noSuchMethod(Invocation invocation) { |
| 100 print([invocation.memberName, invocation.isGetter, invocation.isSetter, invo cation.isMethod, invocation.isAccessor]); | 101 print([invocation.memberName, invocation.isGetter, invocation.isSetter, invo cation.isMethod, invocation.isAccessor]); |
|
kustermann
2014/11/14 13:25:27
long line
Søren Gjesse
2014/11/14 15:27:29
Done.
| |
| 101 return super.noSuchMethod(invocation); | 102 return super.noSuchMethod(invocation); |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 class MockHttpRequest implements HttpRequest { | 106 class MockHttpRequest implements HttpRequest { |
| 106 final Uri uri; | 107 final Uri uri; |
| 107 final MockHttpResponse response = new MockHttpResponse(); | 108 final MockHttpResponse response = new MockHttpResponse(); |
| 108 final HttpHeaders headers = new MockHttpHeaders(); | 109 final HttpHeaders headers = new MockHttpHeaders(); |
| 109 final String method = 'GET'; | 110 final String method = 'GET'; |
| 110 final bool followRedirects; | 111 final bool followRedirects; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 } | 176 } |
| 176 | 177 |
| 177 /* | 178 /* |
| 178 * Implemented to remove editor warnings | 179 * Implemented to remove editor warnings |
| 179 */ | 180 */ |
| 180 dynamic noSuchMethod(Invocation invocation) => | 181 dynamic noSuchMethod(Invocation invocation) => |
| 181 super.noSuchMethod(invocation); | 182 super.noSuchMethod(invocation); |
| 182 | 183 |
| 183 String get mockContent => UTF8.decode(_buffer); | 184 String get mockContent => UTF8.decode(_buffer); |
| 184 | 185 |
| 186 String get mockContentBinary => _buffer; | |
|
kustermann
2014/11/14 13:25:27
That seems wrong. [_buffer] is of type List<int>
Søren Gjesse
2014/11/14 15:27:29
Fixed. The beauty of ignoring the analyzer.
| |
| 187 | |
| 185 bool get mockDone => _isDone; | 188 bool get mockDone => _isDone; |
| 186 | 189 |
| 187 // Copied from SDK http_impl.dart @ 845 on 2014-01-05 | 190 // Copied from SDK http_impl.dart @ 845 on 2014-01-05 |
| 188 // TODO: file an SDK bug to expose this on HttpStatus in some way | 191 // TODO: file an SDK bug to expose this on HttpStatus in some way |
| 189 String _findReasonPhrase(int statusCode) { | 192 String _findReasonPhrase(int statusCode) { |
| 190 if (_reasonPhrase != null) { | 193 if (_reasonPhrase != null) { |
| 191 return _reasonPhrase; | 194 return _reasonPhrase; |
| 192 } | 195 } |
| 193 | 196 |
| 194 switch (statusCode) { | 197 switch (statusCode) { |
| 195 case HttpStatus.NOT_FOUND: return "Not Found"; | 198 case HttpStatus.NOT_FOUND: return "Not Found"; |
| 196 default: return "Status $statusCode"; | 199 default: return "Status $statusCode"; |
| 197 } | 200 } |
| 198 } | 201 } |
| 199 } | 202 } |
| OLD | NEW |