Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: pkg/webdriver/lib/webdriver.dart

Issue 14997015: trim() does not remove the trailing null characters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for webdriver.dart Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:json' as json; 9 import 'dart:json' as json;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (params != null) { 278 if (params != null) {
279 var body = json.stringify(params); 279 var body = json.stringify(params);
280 req.write(body); 280 req.write(body);
281 } 281 }
282 req.close().then((rsp) { 282 req.close().then((rsp) {
283 List<int> body = new List<int>(); 283 List<int> body = new List<int>();
284 rsp.listen(body.addAll, onDone: () { 284 rsp.listen(body.addAll, onDone: () {
285 var value = null; 285 var value = null;
286 // For some reason we get a bunch of NULs on the end 286 // For some reason we get a bunch of NULs on the end
287 // of the text and the json.parse blows up on these, so 287 // of the text and the json.parse blows up on these, so
288 // strip them with trim(). 288 // strip them.
289 // These NULs can be seen in the TCP packet, so it is not 289 // These NULs can be seen in the TCP packet, so it is not
290 // an issue with character encoding; it seems to be a bug 290 // an issue with character encoding; it seems to be a bug
291 // in WebDriver stack. 291 // in WebDriver stack.
292 results = new String.fromCharCodes(body).trim(); 292 results = new String.fromCharCodes(body)
293 .replaceAll(new RegExp('\u{0}*\$'), '');
293 if (!successCodes.contains(rsp.statusCode)) { 294 if (!successCodes.contains(rsp.statusCode)) {
294 _failRequest(completer, 295 _failRequest(completer,
295 'Unexpected response ${rsp.statusCode}; $results'); 296 'Unexpected response ${rsp.statusCode}; $results');
296 completer = null; 297 completer = null;
297 return; 298 return;
298 } 299 }
299 if (status == 0 && results.length > 0) { 300 if (status == 0 && results.length > 0) {
300 // 4xx responses send plain text; others send JSON. 301 // 4xx responses send plain text; others send JSON.
301 if (rsp.statusCode < 400) { 302 if (rsp.statusCode < 400) {
302 results = json.parse(results); 303 results = json.parse(results);
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 Future<String> getElementWithFocus() => _post('element/active'); 876 Future<String> getElementWithFocus() => _post('element/active');
876 877
877 /** 878 /**
878 * Search for an element on the page, starting from element with id [id]. 879 * Search for an element on the page, starting from element with id [id].
879 * The located element will be returned as WebElement JSON objects. See 880 * The located element will be returned as WebElement JSON objects. See
880 * [findElement] for the locator strategies that each server supports. 881 * [findElement] for the locator strategies that each server supports.
881 * 882 *
882 * Potential Errors: NoSuchWindow, XPathLookupError. 883 * Potential Errors: NoSuchWindow, XPathLookupError.
883 */ 884 */
884 Future<String> 885 Future<String>
885 findElementFromId(String id, String strategy, String searchValue) { 886 findElementFromId(String id, String strategy, String searchValue) =>
886 _post('element/$id/element', { 'using': strategy, 'value' : searchValue }); 887 _post('element/$id/element',
887 } 888 { 'using': strategy, 'value' : searchValue });
888 889
889 /** 890 /**
890 * Search for multiple elements on the page, starting from the element with 891 * Search for multiple elements on the page, starting from the element with
891 * id [id].The located elements will be returned as WebElement JSON objects. 892 * id [id].The located elements will be returned as WebElement JSON objects.
892 * See [findElement] for the locator strategies that each server supports. 893 * See [findElement] for the locator strategies that each server supports.
893 * Elements are be returned in the order located in the DOM. 894 * Elements are be returned in the order located in the DOM.
894 * 895 *
895 * Potential Errors: NoSuchWindow, XPathLookupError. 896 * Potential Errors: NoSuchWindow, XPathLookupError.
896 */ 897 */
897 Future<List<String>> 898 Future<List<String>>
898 findElementsFromId(String id, String strategy, String searchValue) => 899 findElementsFromId(String id, String strategy, String searchValue) =>
899 _post('element/$id/elements', 900 _post('element/$id/elements',
900 params: { 'using': strategy, 'value' : searchValue }); 901 { 'using': strategy, 'value' : searchValue });
901 902
902 /** 903 /**
903 * Click on an element specified by [id]. 904 * Click on an element specified by [id].
904 * 905 *
905 * Potential Errors: NoSuchWindow, StaleElementReference, ElementNotVisible 906 * Potential Errors: NoSuchWindow, StaleElementReference, ElementNotVisible
906 * (if the referenced element is not visible on the page, either hidden 907 * (if the referenced element is not visible on the page, either hidden
907 * by CSS, or has 0-width or 0-height). 908 * by CSS, or has 0-width or 0-height).
908 */ 909 */
909 Future clickElement(String id) => _post('element/$id/click'); 910 Future clickElement(String id) => _post('element/$id/click');
910 911
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 * 1461 *
1461 * 'timestamp' (int) - The timestamp of the entry. 1462 * 'timestamp' (int) - The timestamp of the entry.
1462 * 'level' (String) - The log level of the entry, for example, "INFO". 1463 * 'level' (String) - The log level of the entry, for example, "INFO".
1463 * 'message' (String) - The log message. 1464 * 'message' (String) - The log message.
1464 * 1465 *
1465 * This works with Firefox but Chrome returns a 500 response due to a 1466 * This works with Firefox but Chrome returns a 500 response due to a
1466 * bad cast. 1467 * bad cast.
1467 */ 1468 */
1468 Future<List<Map>> getLogs(String type) => _post('log', { 'type': type }); 1469 Future<List<Map>> getLogs(String type) => _post('log', { 'type': type });
1469 } 1470 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698