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