OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 library webdriver; | 5 library webdriver; |
6 | 6 |
7 import 'dart:json' as json; | 7 import 'dart:json' as json; |
8 import 'dart:uri'; | 8 import 'dart:uri'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 var data = s.read(); | 275 var data = s.read(); |
276 if (data != null) { | 276 if (data != null) { |
277 sbuf.add(data); | 277 sbuf.add(data); |
278 } | 278 } |
279 }; | 279 }; |
280 s.onClosed = () { | 280 s.onClosed = () { |
281 var value = null; | 281 var value = null; |
282 results = sbuf.toString().trim(); | 282 results = sbuf.toString().trim(); |
283 // For some reason we get a bunch of NULs on the end | 283 // For some reason we get a bunch of NULs on the end |
284 // of the text and the json.parse blows up on these, so | 284 // of the text and the json.parse blows up on these, so |
285 // strip them. We have to do this the hard way as | 285 // strip them. |
286 // replaceAll('\0', '') does not work. | |
287 // These NULs can be seen in the TCP packet, so it is not | 286 // These NULs can be seen in the TCP packet, so it is not |
288 // an issue with character encoding; it seems to be a bug | 287 // an issue with character encoding; it seems to be a bug |
289 // in WebDriver stack. | 288 // in WebDriver stack. |
290 for (var i = results.length; --i >= 0;) { | 289 for (var i = results.length; --i >= 0;) { |
291 var code = results.charCodeAt(i); | 290 var code = results.codeUnitAt(i); |
292 if (code != 0) { | 291 if (code != 0) { |
293 results = results.substring(0, i+1); | 292 results = results.substring(0, i + 1); |
294 break; | 293 break; |
295 } | 294 } |
296 } | 295 } |
297 if (successCodes.indexOf(r.statusCode) < 0) { | 296 if (successCodes.indexOf(r.statusCode) < 0) { |
298 throw 'Unexpected response ${r.statusCode}'; | 297 throw 'Unexpected response ${r.statusCode}'; |
299 } | 298 } |
300 if (status == 0 && results.length > 0) { | 299 if (status == 0 && results.length > 0) { |
301 // 4xx responses send plain text; others send JSON. | 300 // 4xx responses send plain text; others send JSON. |
302 if (r.statusCode < 400) { | 301 if (r.statusCode < 400) { |
303 results = json.parse(results); | 302 results = json.parse(results); |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 * Get the log for a given log type. Log buffer is reset after each request. | 1355 * Get the log for a given log type. Log buffer is reset after each request. |
1357 * Each log entry is a [Map] with these fields: | 1356 * Each log entry is a [Map] with these fields: |
1358 * | 1357 * |
1359 * 'timestamp' (int) - The timestamp of the entry. | 1358 * 'timestamp' (int) - The timestamp of the entry. |
1360 * 'level' (String) - The log level of the entry, for example, "INFO". | 1359 * 'level' (String) - The log level of the entry, for example, "INFO". |
1361 * 'message' (String) - The log message. | 1360 * 'message' (String) - The log message. |
1362 */ | 1361 */ |
1363 Future<List<Map>> getLogs(String type) => | 1362 Future<List<Map>> getLogs(String type) => |
1364 _post('log', params: { 'type': type }); | 1363 _post('log', params: { 'type': type }); |
1365 } | 1364 } |
OLD | NEW |