end to end test with text frames (ssl is broken)
diff --git a/src/mochiweb_websocket.erl b/src/mochiweb_websocket.erl
index cc3127e..b7a4a62 100644
--- a/src/mochiweb_websocket.erl
+++ b/src/mochiweb_websocket.erl
@@ -27,6 +27,9 @@
 
 -export([loop/5, upgrade_connection/2, request/5]).
 -export([send/3]).
+-ifdef(TEST).
+-compile(export_all).
+-endif.
 
 loop(Socket, Body, State, WsVersion, ReplyChannel) ->
     ok = mochiweb_socket:setopts(Socket, [{packet, 0}, {active, once}]),
@@ -276,11 +279,3 @@
   {Buffer, Rest};
 parse_hixie(<<H, T/binary>>, Buffer) ->
   parse_hixie(T, <<Buffer/binary, H>>).
-
-%%
-%% Tests
-%%
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--compile(export_all).
--endif.
diff --git a/test/mochiweb_test_util.erl b/test/mochiweb_test_util.erl
index 690f134..0801ab5 100644
--- a/test/mochiweb_test_util.erl
+++ b/test/mochiweb_test_util.erl
@@ -35,7 +35,9 @@
                 ({send, Data}) ->
                     gen_tcp:send(Socket, Data);
                 ({setopts, L}) ->
-                    inet:setopts(Socket, L)
+                    inet:setopts(Socket, L);
+                (get) ->
+                    Socket
             end;
         ssl ->
             {ok, Socket} = ssl:connect("127.0.0.1", Port, [{ssl_imp, new} | Opts]),
@@ -46,7 +48,9 @@
                 ({send, Data}) ->
                     ssl:send(Socket, Data);
                 ({setopts, L}) ->
-                    ssl:setopts(Socket, L)
+                    ssl:setopts(Socket, L);
+                (get) ->
+                    {ssl, Socket}
             end
     end.
 
diff --git a/test/mochiweb_websocket_tests.erl b/test/mochiweb_websocket_tests.erl
index 20967fb..4ca404b 100644
--- a/test/mochiweb_websocket_tests.erl
+++ b/test/mochiweb_websocket_tests.erl
@@ -99,10 +99,13 @@
                                    fun end_to_end_ws_loop/3),
     ReentryWs(ok).
 
-end_to_end_ws_loop(_Payload, State, _ReplyChannel) ->
+end_to_end_ws_loop(Payload, State, ReplyChannel) ->
+    %% Echo server
+    lists:foreach(ReplyChannel, Payload),
     State.
 
 end_to_end_client(S) ->
+    %% Key and Accept per https://tools.ietf.org/html/rfc6455
     UpgradeReq = string:join(
                    ["GET / HTTP/1.1",
                     "Host: localhost",
@@ -123,6 +126,27 @@
              {"Sec-Websocket-Accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="}])),
     ?assertEqual([], gb_trees:to_list(D)),
     ok = S({setopts, [{packet, raw}]}),
+    %% The first message sent over telegraph :)
+    SmallMessage = <<"What hath God wrought?">>,
+    ok = S({send,
+       << 1:1, %% Fin
+          0:1, %% Rsv1
+          0:1, %% Rsv2
+          0:1, %% Rsv3
+          2:4, %% Opcode, 1 = text frame
+          1:1, %% Mask on
+          (byte_size(SmallMessage)):7, %% Length, <125 case
+          0:32, %% Mask (trivial)
+          SmallMessage/binary >>}),
+    {ok, WsFrames} = S(recv),
+    << 1:1, %% Fin
+       0:1, %% Rsv1
+       0:1, %% Rsv2
+       0:1, %% Rsv3
+       1:4, %% Opcode, text frame (all mochiweb suports for now)
+       MsgSize:8, %% Expecting small size
+       SmallMessage/binary >> = WsFrames,
+    ?assertEqual(MsgSize, byte_size(SmallMessage)),
     ok.
 
 gb_from_list(L) ->