fix safari test

Apparently my approach to use wss didn't work to exercise the error codepath. This change makes us excersize errors. After testing this in Safari though, I coudln't reproduce the issue, so I remove the note about this being a regression test for the original issue.

Review URL: https://codereview.chromium.org/1513363003 .
This commit is contained in:
Sigmund Cherem 2015-12-10 16:02:27 -08:00
parent f38b810d33
commit e6f6ce9743
2 changed files with 11 additions and 22 deletions

View file

@ -39,28 +39,11 @@ main() {
});
});
test('regression for 19137', () {
// The server supports ws, but not wss, this will yield an error that we
// expect to catch below.
var socket = new WebSocket('wss://${window.location.host}/ws');
socket.onOpen.first.then((_) => socket.send('hello!'));
test('error handling', () {
var socket = new WebSocket('ws://${window.location.host}/ws');
socket.onOpen.first.then((_) => socket.send('close-with-error'));
return socket.onError.first.then((e) {
// This test is modeled after a comment in issue #19137. We haven't
// verified that this is the casue, but the theory is that on Safari
// we will reach this point correctly, we then try to get an
// interceptor for `e` to call `.toString` on it, but our
// get-interceptor logic crashes. This is because the process of
// finding the interceptor may ask to extract the constructor name,
// and that code assumes that the name matches a specific regular
// expression. Apparently that regular expression doesn't match on
// Safari 7 and the line below would ends up throwing and error of the
// form:
//
// TypeError: null is not an object (evaluating
// 'String(a.constructor).match(/^\s*function\s*([\w$]*)\s*\(/)')
// at ...
//
print('$e was caught');
print('$e was caught, yay!');
socket.close();
});
});

View file

@ -260,7 +260,13 @@ class TestingServers {
websocket.done.catchError((_) {});
websocket.listen((data) {
websocket.add(data);
websocket.close();
if (data == 'close-with-error') {
// Note: according to the web-sockets spec, a reason longer than 123
// bytes will produce a SyntaxError on the client.
websocket.close(WebSocketStatus.UNSUPPORTED_DATA, 'X' * 124);
} else {
websocket.close();
}
}, onError: (e) {
DebugLogger.warning('HttpServer: error while echoing to WebSocket', e);
});