| OLD | NEW |
| 1 library angular.playback.playback_http; | 1 library angular.playback.playback_http; |
| 2 | 2 |
| 3 import 'dart:async'; | 3 import 'dart:async'; |
| 4 import 'dart:convert' show JSON; | 4 import 'dart:convert' show JSON; |
| 5 import 'dart:html'; | 5 import 'dart:html'; |
| 6 | 6 |
| 7 import 'package:angular/core_dom/module.dart'; | 7 import 'package:angular/core_dom/module.dart'; |
| 8 import 'package:angular/core/service.dart'; | 8 import 'package:angular/core/service.dart'; |
| 9 import 'package:angular/mock/module.dart' as mock; | 9 import 'package:angular/mock/module.dart' as mock; |
| 10 | 10 |
| 11 import 'package:angular/playback/playback_data.dart' as playback_data; | 11 import 'package:angular/playback/playback_data.dart' as playback_data; |
| 12 | 12 |
| 13 @NgInjectableService() | 13 @NgInjectableService() |
| 14 class PlaybackHttpBackendConfig { | 14 class PlaybackHttpBackendConfig { |
| 15 requestKey(String url, | 15 requestKey(String url, |
| 16 {String method, bool withCredentials, String responseType, | 16 {String method, bool withCredentials, String responseType, |
| 17 String mimeType, Map<String, String> requestHeaders, sendData, | 17 String mimeType, Map<String, String> requestHeaders, sendData, |
| 18 void onProgress(ProgressEvent e)}) { | 18 void onProgress(ProgressEvent e)}) { |
| 19 return JSON.encode({ | 19 return JSON.encode({ |
| 20 "url": url, | 20 "url": url, |
| 21 "method": method, | 21 "method": method, |
| 22 "requestHeaders": requestHeaders, | 22 "requestHeaders": requestHeaders, |
| 23 "data": sendData | 23 "data": sendData |
| 24 }); | 24 }); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 // HELP! The DI system is getting in the way. We want | 28 // HELP! The DI system is getting in the way. We want |
| 29 // the HttpBackend, but it will be implemented by ourselves. | 29 // the HttpBackend, but it will be implemented by ourselves. |
| 30 class HttpBackendWrapper { | 30 class HttpBackendWrapper { |
| 31 HttpBackend backend; | 31 HttpBackend backend; |
| 32 HttpBackendWrapper(this.backend); | 32 HttpBackendWrapper(HttpBackend this.backend); |
| 33 } | 33 } |
| 34 | 34 |
| 35 class RecordingHttpBackend implements HttpBackend { | 35 class RecordingHttpBackend implements HttpBackend { |
| 36 | 36 |
| 37 HttpBackend _prodBackend; | 37 HttpBackend _prodBackend; |
| 38 PlaybackHttpBackendConfig _config; | 38 PlaybackHttpBackendConfig _config; |
| 39 | 39 |
| 40 RecordingHttpBackend(HttpBackendWrapper wrapper, this._config) | 40 RecordingHttpBackend(HttpBackendWrapper wrapper, this._config) { |
| 41 : _prodBackend = wrapper.backend; | 41 this._prodBackend = wrapper.backend; |
| 42 } |
| 42 | 43 |
| 43 Future request(String url, | 44 Future request(String url, |
| 44 {String method, bool withCredentials, String responseType, | 45 {String method, bool withCredentials, String responseType, |
| 45 String mimeType, Map<String, String> requestHeaders, sendData, | 46 String mimeType, Map<String, String> requestHeaders, sendData, |
| 46 void onProgress(ProgressEvent e)}) { | 47 void onProgress(ProgressEvent e)}) { |
| 47 return _prodBackend.request(url, | 48 return _prodBackend.request(url, |
| 48 method: method, | 49 method: method, |
| 49 withCredentials: withCredentials, | 50 withCredentials: withCredentials, |
| 50 responseType: responseType, | 51 responseType: responseType, |
| 51 mimeType: mimeType, | 52 mimeType: mimeType, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 void onProgress(ProgressEvent e)}) { | 90 void onProgress(ProgressEvent e)}) { |
| 90 var key = _config.requestKey(url, | 91 var key = _config.requestKey(url, |
| 91 method: method, | 92 method: method, |
| 92 withCredentials: withCredentials, | 93 withCredentials: withCredentials, |
| 93 responseType: responseType, | 94 responseType: responseType, |
| 94 mimeType: mimeType, | 95 mimeType: mimeType, |
| 95 requestHeaders: requestHeaders, | 96 requestHeaders: requestHeaders, |
| 96 sendData: sendData, | 97 sendData: sendData, |
| 97 onProgress: onProgress); | 98 onProgress: onProgress); |
| 98 | 99 |
| 99 if (!data.containsKey(key)) throw ["Request is not recorded $key"]; | 100 if (!data.containsKey(key)) { |
| 101 throw ["Request is not recorded $key"]; |
| 102 } |
| 100 var playback = data[key]; | 103 var playback = data[key]; |
| 101 return new Future.value( | 104 return new Future.value( |
| 102 new mock.MockHttpRequest( | 105 new mock.MockHttpRequest( |
| 103 playback['status'], | 106 playback['status'], |
| 104 playback['data'], | 107 playback['data'], |
| 105 playback['headers'])); | 108 playback['headers'])); |
| 106 } | 109 } |
| 107 } | 110 } |
| OLD | NEW |