Fixing more tests

This commit is contained in:
Joakim Erdfelt 2012-07-06 13:49:47 -07:00
parent 071f15e0c9
commit b39a6a6f59
3 changed files with 42 additions and 9 deletions

View File

@ -129,17 +129,24 @@ public class WebSocketEventDriver implements Parser.Listener
{ {
case CLOSE: case CLOSE:
{ {
if (events.onClose != null) if (events.onClose == null)
{ {
// not interested in close events
return;
}
byte payload[] = frame.getPayloadData(); byte payload[] = frame.getPayloadData();
int statusCode = CloseUtil.getStatusCode(payload); int statusCode = CloseUtil.getStatusCode(payload);
String reason = CloseUtil.getReason(payload); String reason = CloseUtil.getReason(payload);
events.onClose.call(websocket,connection,statusCode,reason); events.onClose.call(websocket,connection,statusCode,reason);
}
return; return;
} }
case BINARY: case BINARY:
{ {
if (events.onBinary == null)
{
// not interested in binary events
return;
}
if (events.onBinary.isStreaming()) if (events.onBinary.isStreaming())
{ {
boolean needsNotification = false; boolean needsNotification = false;
@ -205,6 +212,11 @@ public class WebSocketEventDriver implements Parser.Listener
} }
case TEXT: case TEXT:
{ {
if (events.onText == null)
{
// not interested in text events
return;
}
if (events.onText.isStreaming()) if (events.onText.isStreaming())
{ {
boolean needsNotification = false; boolean needsNotification = false;

View File

@ -316,4 +316,25 @@ public class WebSocketFrame implements Frame
{ {
this.rsv3 = rsv3; this.rsv3 = rsv3;
} }
@Override
public String toString()
{
StringBuilder b = new StringBuilder();
if (opcode != null)
{
b.append(opcode.name());
}
else
{
b.append("NO-OP");
}
b.append('[');
b.append("len=").append(getPayloadLength());
b.append(",fin=").append(fin);
b.append(",masked=").append(masked);
b.append(",continuation=").append(continuation);
b.append(']');
return b.toString();
}
} }

View File

@ -86,10 +86,10 @@ public class WebSocketEventDriverTest
socket.capture.assertEventCount(6); socket.capture.assertEventCount(6);
socket.capture.assertEventStartsWith(0,"onConnect("); socket.capture.assertEventStartsWith(0,"onConnect(");
socket.capture.assertEventStartsWith(1,"onFrame(Ping"); socket.capture.assertEventStartsWith(1,"onFrame(PING[");
socket.capture.assertEventStartsWith(2,"onFrame(Text"); socket.capture.assertEventStartsWith(2,"onFrame(TEXT[");
socket.capture.assertEventStartsWith(3,"onFrame(Binary"); socket.capture.assertEventStartsWith(3,"onFrame(BINARY[");
socket.capture.assertEventStartsWith(4,"onFrame(Close"); socket.capture.assertEventStartsWith(4,"onFrame(CLOSE[");
socket.capture.assertEventStartsWith(5,"onClose(1001,"); socket.capture.assertEventStartsWith(5,"onClose(1001,");
} }