| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #import("dart:io"); | 5 #import("dart:io"); |
| 6 #import("dart:isolate"); | 6 #import("dart:isolate"); |
| 7 | 7 |
| 8 class ExpectedDataOutputStream implements OutputStream { | 8 class ExpectedDataOutputStream implements OutputStream { |
| 9 ExpectedDataOutputStream(List<int> this._data, | 9 ExpectedDataOutputStream(List<int> this._data, |
| 10 int this._cutoff, | 10 int this._cutoff, |
| 11 bool this._closeAsError, | 11 bool this._closeAsError, |
| 12 SocketMock this._socket); | 12 SocketMock this._socket); |
| 13 | 13 |
| 14 void set onNoPendingWrites(void callback()) { | 14 void set onNoPendingWrites(void callback()) { |
| 15 _onNoPendingWrites = callback; | 15 _onNoPendingWrites = callback; |
| 16 } | 16 } |
| 17 | 17 |
| 18 void set onError(void callback(e)) { |
| 19 _onError = callback; |
| 20 } |
| 21 |
| 18 bool write(List data, [bool copyBuffer = true]) { | 22 bool write(List data, [bool copyBuffer = true]) { |
| 19 _onData(data); | 23 _onData(data); |
| 20 return true; | 24 return true; |
| 21 } | 25 } |
| 22 | 26 |
| 23 bool writeFrom(List data, [int offset = 0, int len]) { | 27 bool writeFrom(List data, [int offset = 0, int len]) { |
| 24 if (len === null) len = data.length - offset; | 28 if (len === null) len = data.length - offset; |
| 25 _onData(data.getRange(offset, len)); | 29 _onData(data.getRange(offset, len)); |
| 26 return true; | 30 return true; |
| 27 } | 31 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 Expect.listEquals(data, _data.getRange(0, data.length)); | 42 Expect.listEquals(data, _data.getRange(0, data.length)); |
| 39 _data = _data.getRange(data.length, _data.length - data.length); | 43 _data = _data.getRange(data.length, _data.length - data.length); |
| 40 _written += data.length; | 44 _written += data.length; |
| 41 if (_written >= _cutoff) { | 45 if (_written >= _cutoff) { |
| 42 // Tell HttpServer that the socket have closed. | 46 // Tell HttpServer that the socket have closed. |
| 43 _socket._closeInternal(_closeAsError); | 47 _socket._closeInternal(_closeAsError); |
| 44 } | 48 } |
| 45 } | 49 } |
| 46 | 50 |
| 47 Function _onNoPendingWrites; | 51 Function _onNoPendingWrites; |
| 52 Function _onError; |
| 48 List<int> _data; | 53 List<int> _data; |
| 49 int _written = 0; | 54 int _written = 0; |
| 50 int _cutoff; | 55 int _cutoff; |
| 51 bool _closeAsError; | 56 bool _closeAsError; |
| 52 SocketMock _socket; | 57 SocketMock _socket; |
| 53 } | 58 } |
| 54 | 59 |
| 55 class SocketMock implements Socket { | 60 class SocketMock implements Socket { |
| 56 SocketMock(List<int> this._data, | 61 SocketMock(List<int> this._data, |
| 57 List<int> expected, | 62 List<int> expected, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 95 } |
| 91 | 96 |
| 92 void set onData(void callback()) { | 97 void set onData(void callback()) { |
| 93 _onData = callback; | 98 _onData = callback; |
| 94 } | 99 } |
| 95 | 100 |
| 96 void set onClosed(void callback()) { | 101 void set onClosed(void callback()) { |
| 97 _onClosed = callback; | 102 _onClosed = callback; |
| 98 } | 103 } |
| 99 | 104 |
| 100 void set onError(void callback(Exception error)) { | 105 void set onError(void callback(e)) { |
| 101 _onError = callback; | 106 _onError = callback; |
| 102 } | 107 } |
| 103 | 108 |
| 104 OutputStream get outputStream() => _outputStream; | 109 OutputStream get outputStream() => _outputStream; |
| 105 | 110 |
| 106 int hashCode() => _hashCode; | 111 int hashCode() => _hashCode; |
| 107 | 112 |
| 108 List<int> _read; | 113 List<int> _read; |
| 109 bool _closed = false; | 114 bool _closed = false; |
| 110 int _hashCode; | 115 int _hashCode; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 140 } | 145 } |
| 141 | 146 |
| 142 void close() { | 147 void close() { |
| 143 Expect.fail("Don't close the connection, we attach to this socket"); | 148 Expect.fail("Don't close the connection, we attach to this socket"); |
| 144 } | 149 } |
| 145 | 150 |
| 146 void set onConnection(void callback(Socket connection)) { | 151 void set onConnection(void callback(Socket connection)) { |
| 147 _onConnection = callback; | 152 _onConnection = callback; |
| 148 } | 153 } |
| 149 | 154 |
| 150 void set onError(void callback(Exception)) { | 155 void set onError(void callback(e)) { |
| 151 _onError = callback; | 156 _onError = callback; |
| 152 } | 157 } |
| 153 | 158 |
| 154 int get port() => _port; | 159 int get port() => _port; |
| 155 | 160 |
| 156 int _port; | 161 int _port; |
| 157 Function _onConnection; | 162 Function _onConnection; |
| 158 Function _onError; | 163 Function _onError; |
| 159 Set<Socket> _sockets; | 164 Set<Socket> _sockets; |
| 160 } | 165 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 "GET / HTTP/1.1\r\nKeep-Alive: False\r\n\r\n", | 210 "GET / HTTP/1.1\r\nKeep-Alive: False\r\n\r\n", |
| 206 "HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\nconnection: close" + | 211 "HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\nconnection: close" + |
| 207 "\r\n\r\n0\r\n\r\n"); | 212 "\r\n\r\n0\r\n\r\n"); |
| 208 | 213 |
| 209 server.close(); | 214 server.close(); |
| 210 } | 215 } |
| 211 | 216 |
| 212 void main() { | 217 void main() { |
| 213 testSocketClose(); | 218 testSocketClose(); |
| 214 } | 219 } |
| OLD | NEW |