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

Side by Side Diff: net/websockets/websocket_job_unittest.cc

Issue 9425016: Change MockRead and MockWrite (et. al.) to take an IoMode enum, instead (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 8 years, 10 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 | « net/spdy/spdy_websocket_stream_unittest.cc ('k') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/websockets/websocket_job.h" 5 #include "net/websockets/websocket_job.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 // OrderedSocketData provide socket level verifiation by checking out-going 800 // OrderedSocketData provide socket level verifiation by checking out-going
801 // packets in comparison with the MockWrite array and emulating in-coming 801 // packets in comparison with the MockWrite array and emulating in-coming
802 // packets with MockRead array. 802 // packets with MockRead array.
803 803
804 void WebSocketJobTest::TestConnectByWebSocket(ThrottlingOption throttling) { 804 void WebSocketJobTest::TestConnectByWebSocket(ThrottlingOption throttling) {
805 // This is a test for verifying cooperation between WebSocketJob and 805 // This is a test for verifying cooperation between WebSocketJob and
806 // SocketStream. If |throttling| was |THROTTLING_OFF|, it test basic 806 // SocketStream. If |throttling| was |THROTTLING_OFF|, it test basic
807 // situation. If |throttling| was |THROTTLING_ON|, throttling limits the 807 // situation. If |throttling| was |THROTTLING_ON|, throttling limits the
808 // latter connection. 808 // latter connection.
809 MockWrite writes[] = { 809 MockWrite writes[] = {
810 MockWrite(true, 810 MockWrite(ASYNC,
811 kHandshakeRequestWithoutCookie, 811 kHandshakeRequestWithoutCookie,
812 kHandshakeRequestWithoutCookieLength, 812 kHandshakeRequestWithoutCookieLength,
813 1), 813 1),
814 MockWrite(true, 814 MockWrite(ASYNC,
815 kDataHello, 815 kDataHello,
816 kDataHelloLength, 816 kDataHelloLength,
817 3) 817 3)
818 }; 818 };
819 MockRead reads[] = { 819 MockRead reads[] = {
820 MockRead(true, 820 MockRead(ASYNC,
821 kHandshakeResponseWithoutCookie, 821 kHandshakeResponseWithoutCookie,
822 kHandshakeResponseWithoutCookieLength, 822 kHandshakeResponseWithoutCookieLength,
823 2), 823 2),
824 MockRead(true, 824 MockRead(ASYNC,
825 kDataWorld, 825 kDataWorld,
826 kDataWorldLength, 826 kDataWorldLength,
827 4), 827 4),
828 MockRead(false, 0, 5) // EOF 828 MockRead(SYNCHRONOUS, 0, 5) // EOF
829 }; 829 };
830 data_.reset(new OrderedSocketData( 830 data_.reset(new OrderedSocketData(
831 reads, arraysize(reads), writes, arraysize(writes))); 831 reads, arraysize(reads), writes, arraysize(writes)));
832 832
833 GURL url("ws://example.com/demo"); 833 GURL url("ws://example.com/demo");
834 MockSocketStreamDelegate delegate; 834 MockSocketStreamDelegate delegate;
835 WebSocketJobTest* test = this; 835 WebSocketJobTest* test = this;
836 if (throttling == THROTTLING_ON) 836 if (throttling == THROTTLING_ON)
837 delegate.SetOnStartOpenConnection( 837 delegate.SetOnStartOpenConnection(
838 base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test))); 838 base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 } 873 }
874 874
875 void WebSocketJobTest::TestConnectBySpdy( 875 void WebSocketJobTest::TestConnectBySpdy(
876 SpdyOption spdy, ThrottlingOption throttling) { 876 SpdyOption spdy, ThrottlingOption throttling) {
877 // This is a test for verifying cooperation between WebSocketJob and 877 // This is a test for verifying cooperation between WebSocketJob and
878 // SocketStream in the situation we have SPDY session to the server. If 878 // SocketStream in the situation we have SPDY session to the server. If
879 // |throttling| was |THROTTLING_ON|, throttling limits the latter connection. 879 // |throttling| was |THROTTLING_ON|, throttling limits the latter connection.
880 // If you enabled spdy, you should specify |spdy| as |SPDY_ON|. Expected 880 // If you enabled spdy, you should specify |spdy| as |SPDY_ON|. Expected
881 // results depend on its configuration. 881 // results depend on its configuration.
882 MockWrite writes_websocket[] = { 882 MockWrite writes_websocket[] = {
883 MockWrite(true, 883 MockWrite(ASYNC,
884 kHandshakeRequestWithoutCookie, 884 kHandshakeRequestWithoutCookie,
885 kHandshakeRequestWithoutCookieLength, 885 kHandshakeRequestWithoutCookieLength,
886 1), 886 1),
887 MockWrite(true, 887 MockWrite(ASYNC,
888 kDataHello, 888 kDataHello,
889 kDataHelloLength, 889 kDataHelloLength,
890 3) 890 3)
891 }; 891 };
892 MockRead reads_websocket[] = { 892 MockRead reads_websocket[] = {
893 MockRead(true, 893 MockRead(ASYNC,
894 kHandshakeResponseWithoutCookie, 894 kHandshakeResponseWithoutCookie,
895 kHandshakeResponseWithoutCookieLength, 895 kHandshakeResponseWithoutCookieLength,
896 2), 896 2),
897 MockRead(true, 897 MockRead(ASYNC,
898 kDataWorld, 898 kDataWorld,
899 kDataWorldLength, 899 kDataWorldLength,
900 4), 900 4),
901 MockRead(false, 0, 5) // EOF 901 MockRead(SYNCHRONOUS, 0, 5) // EOF
902 }; 902 };
903 903
904 const spdy::SpdyStreamId kStreamId = 1; 904 const spdy::SpdyStreamId kStreamId = 1;
905 scoped_ptr<spdy::SpdyFrame> request_frame( 905 scoped_ptr<spdy::SpdyFrame> request_frame(
906 ConstructSpdyWebSocketHandshakeRequestFrame( 906 ConstructSpdyWebSocketHandshakeRequestFrame(
907 kHandshakeRequestForSpdy, 907 kHandshakeRequestForSpdy,
908 arraysize(kHandshakeRequestForSpdy) / 2, 908 arraysize(kHandshakeRequestForSpdy) / 2,
909 kStreamId, 909 kStreamId,
910 MEDIUM)); 910 MEDIUM));
911 scoped_ptr<spdy::SpdyFrame> response_frame( 911 scoped_ptr<spdy::SpdyFrame> response_frame(
(...skipping 14 matching lines...) Expand all
926 kDataWorldLength, 926 kDataWorldLength,
927 kStreamId, 927 kStreamId,
928 false)); 928 false));
929 MockWrite writes_spdy[] = { 929 MockWrite writes_spdy[] = {
930 CreateMockWrite(*request_frame.get(), 1), 930 CreateMockWrite(*request_frame.get(), 1),
931 CreateMockWrite(*data_hello_frame.get(), 3), 931 CreateMockWrite(*data_hello_frame.get(), 3),
932 }; 932 };
933 MockRead reads_spdy[] = { 933 MockRead reads_spdy[] = {
934 CreateMockRead(*response_frame.get(), 2), 934 CreateMockRead(*response_frame.get(), 2),
935 CreateMockRead(*data_world_frame.get(), 4), 935 CreateMockRead(*data_world_frame.get(), 4),
936 MockRead(false, 0, 5) // EOF 936 MockRead(SYNCHRONOUS, 0, 5) // EOF
937 }; 937 };
938 938
939 if (spdy == SPDY_ON) 939 if (spdy == SPDY_ON)
940 data_.reset(new OrderedSocketData( 940 data_.reset(new OrderedSocketData(
941 reads_spdy, arraysize(reads_spdy), 941 reads_spdy, arraysize(reads_spdy),
942 writes_spdy, arraysize(writes_spdy))); 942 writes_spdy, arraysize(writes_spdy)));
943 else 943 else
944 data_.reset(new OrderedSocketData( 944 data_.reset(new OrderedSocketData(
945 reads_websocket, arraysize(reads_websocket), 945 reads_websocket, arraysize(reads_websocket),
946 writes_websocket, arraysize(writes_websocket))); 946 writes_websocket, arraysize(writes_websocket)));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 1085
1086 TEST_F(WebSocketJobTest, ThrottlingSpdySpdyEnabled) { 1086 TEST_F(WebSocketJobTest, ThrottlingSpdySpdyEnabled) {
1087 WebSocketJob::set_websocket_over_spdy_enabled(true); 1087 WebSocketJob::set_websocket_over_spdy_enabled(true);
1088 TestConnectBySpdy(SPDY_ON, THROTTLING_ON); 1088 TestConnectBySpdy(SPDY_ON, THROTTLING_ON);
1089 } 1089 }
1090 1090
1091 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation. 1091 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation.
1092 // TODO(toyoshim,yutak): Add tests to verify closing handshake. 1092 // TODO(toyoshim,yutak): Add tests to verify closing handshake.
1093 1093
1094 } // namespace net 1094 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_websocket_stream_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698