OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_channel.h" | 5 #include "net/websockets/websocket_channel.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <iostream> | 10 #include <iostream> |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 : event_interface_(new StrictMock<MockWebSocketEventInterface>) { | 927 : event_interface_(new StrictMock<MockWebSocketEventInterface>) { |
928 DefaultValue<ChannelState>::Set(CHANNEL_ALIVE); | 928 DefaultValue<ChannelState>::Set(CHANNEL_ALIVE); |
929 ON_CALL(*event_interface_, OnAddChannelResponse(true, _, _)) | 929 ON_CALL(*event_interface_, OnAddChannelResponse(true, _, _)) |
930 .WillByDefault(Return(CHANNEL_DELETED)); | 930 .WillByDefault(Return(CHANNEL_DELETED)); |
931 ON_CALL(*event_interface_, OnDropChannel(_, _, _)) | 931 ON_CALL(*event_interface_, OnDropChannel(_, _, _)) |
932 .WillByDefault(Return(CHANNEL_DELETED)); | 932 .WillByDefault(Return(CHANNEL_DELETED)); |
933 ON_CALL(*event_interface_, OnFailChannel(_)) | 933 ON_CALL(*event_interface_, OnFailChannel(_)) |
934 .WillByDefault(Return(CHANNEL_DELETED)); | 934 .WillByDefault(Return(CHANNEL_DELETED)); |
935 } | 935 } |
936 | 936 |
937 virtual ~WebSocketChannelEventInterfaceTest() { | 937 ~WebSocketChannelEventInterfaceTest() override { |
938 DefaultValue<ChannelState>::Clear(); | 938 DefaultValue<ChannelState>::Clear(); |
939 } | 939 } |
940 | 940 |
941 // Tests using this fixture must set expectations on the event_interface_ mock | 941 // Tests using this fixture must set expectations on the event_interface_ mock |
942 // object before calling CreateChannelAndConnect() or | 942 // object before calling CreateChannelAndConnect() or |
943 // CreateChannelAndConnectSuccessfully(). This will only work once per test | 943 // CreateChannelAndConnectSuccessfully(). This will only work once per test |
944 // case, but once should be enough. | 944 // case, but once should be enough. |
945 scoped_ptr<WebSocketEventInterface> CreateEventInterface() override { | 945 scoped_ptr<WebSocketEventInterface> CreateEventInterface() override { |
946 return scoped_ptr<WebSocketEventInterface>(event_interface_.release()); | 946 return scoped_ptr<WebSocketEventInterface>(event_interface_.release()); |
947 } | 947 } |
(...skipping 14 matching lines...) Expand all Loading... |
962 } | 962 } |
963 | 963 |
964 scoped_ptr<MockWebSocketStream> mock_stream_; | 964 scoped_ptr<MockWebSocketStream> mock_stream_; |
965 }; | 965 }; |
966 | 966 |
967 // Fixture for tests which test UTF-8 validation of sent Text frames via the | 967 // Fixture for tests which test UTF-8 validation of sent Text frames via the |
968 // EventInterface. | 968 // EventInterface. |
969 class WebSocketChannelSendUtf8Test | 969 class WebSocketChannelSendUtf8Test |
970 : public WebSocketChannelEventInterfaceTest { | 970 : public WebSocketChannelEventInterfaceTest { |
971 public: | 971 public: |
972 virtual void SetUp() { | 972 void SetUp() override { |
973 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); | 973 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); |
974 // For the purpose of the tests using this fixture, it doesn't matter | 974 // For the purpose of the tests using this fixture, it doesn't matter |
975 // whether these methods are called or not. | 975 // whether these methods are called or not. |
976 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _, _)) | 976 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _, _)) |
977 .Times(AnyNumber()); | 977 .Times(AnyNumber()); |
978 EXPECT_CALL(*event_interface_, OnFlowControl(_)) | 978 EXPECT_CALL(*event_interface_, OnFlowControl(_)) |
979 .Times(AnyNumber()); | 979 .Times(AnyNumber()); |
980 } | 980 } |
981 }; | 981 }; |
982 | 982 |
983 // Fixture for tests which test use of receive quota from the renderer. | 983 // Fixture for tests which test use of receive quota from the renderer. |
984 class WebSocketChannelFlowControlTest | 984 class WebSocketChannelFlowControlTest |
985 : public WebSocketChannelEventInterfaceTest { | 985 : public WebSocketChannelEventInterfaceTest { |
986 protected: | 986 protected: |
987 // Tests using this fixture should use CreateChannelAndConnectWithQuota() | 987 // Tests using this fixture should use CreateChannelAndConnectWithQuota() |
988 // instead of CreateChannelAndConnectSuccessfully(). | 988 // instead of CreateChannelAndConnectSuccessfully(). |
989 void CreateChannelAndConnectWithQuota(int64 quota) { | 989 void CreateChannelAndConnectWithQuota(int64 quota) { |
990 CreateChannelAndConnect(); | 990 CreateChannelAndConnect(); |
991 channel_->SendFlowControl(quota); | 991 channel_->SendFlowControl(quota); |
992 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); | 992 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); |
993 } | 993 } |
994 | 994 |
995 virtual void CreateChannelAndConnectSuccesfully() { NOTREACHED(); } | 995 virtual void CreateChannelAndConnectSuccesfully() { NOTREACHED(); } |
996 }; | 996 }; |
997 | 997 |
998 // Fixture for tests which test UTF-8 validation of received Text frames using a | 998 // Fixture for tests which test UTF-8 validation of received Text frames using a |
999 // mock WebSocketStream. | 999 // mock WebSocketStream. |
1000 class WebSocketChannelReceiveUtf8Test : public WebSocketChannelStreamTest { | 1000 class WebSocketChannelReceiveUtf8Test : public WebSocketChannelStreamTest { |
1001 public: | 1001 public: |
1002 virtual void SetUp() { | 1002 void SetUp() override { |
1003 // For the purpose of the tests using this fixture, it doesn't matter | 1003 // For the purpose of the tests using this fixture, it doesn't matter |
1004 // whether these methods are called or not. | 1004 // whether these methods are called or not. |
1005 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 1005 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
1006 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 1006 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
1007 } | 1007 } |
1008 }; | 1008 }; |
1009 | 1009 |
1010 // Simple test that everything that should be passed to the creator function is | 1010 // Simple test that everything that should be passed to the creator function is |
1011 // passed to the creator function. | 1011 // passed to the creator function. |
1012 TEST_F(WebSocketChannelTest, EverythingIsPassedToTheCreatorFunction) { | 1012 TEST_F(WebSocketChannelTest, EverythingIsPassedToTheCreatorFunction) { |
(...skipping 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3421 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); | 3421 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); |
3422 ASSERT_TRUE(read_frames); | 3422 ASSERT_TRUE(read_frames); |
3423 // Provide the "Close" message from the server. | 3423 // Provide the "Close" message from the server. |
3424 *read_frames = CreateFrameVector(frames); | 3424 *read_frames = CreateFrameVector(frames); |
3425 read_callback.Run(OK); | 3425 read_callback.Run(OK); |
3426 completion.WaitForResult(); | 3426 completion.WaitForResult(); |
3427 } | 3427 } |
3428 | 3428 |
3429 } // namespace | 3429 } // namespace |
3430 } // namespace net | 3430 } // namespace net |
OLD | NEW |