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

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

Issue 1399303002: net/websockets: Convert int types from basictypes.h to the ones from stdint.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: websocket_deflate_stream.cc Created 5 years, 2 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
« no previous file with comments | « net/websockets/websocket_channel.cc ('k') | net/websockets/websocket_deflate_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // kDefaultSendQuotaLowWaterMark change. 129 // kDefaultSendQuotaLowWaterMark change.
130 const size_t kDefaultQuotaRefreshTrigger = (1 << 16) + 1; 130 const size_t kDefaultQuotaRefreshTrigger = (1 << 16) + 1;
131 131
132 const int kVeryBigTimeoutMillis = 60 * 60 * 24 * 1000; 132 const int kVeryBigTimeoutMillis = 60 * 60 * 24 * 1000;
133 133
134 // TestTimeouts::tiny_timeout() is 100ms! I could run halfway around the world 134 // TestTimeouts::tiny_timeout() is 100ms! I could run halfway around the world
135 // in that time! I would like my tests to run a bit quicker. 135 // in that time! I would like my tests to run a bit quicker.
136 const int kVeryTinyTimeoutMillis = 1; 136 const int kVeryTinyTimeoutMillis = 1;
137 137
138 // Enough quota to pass any test. 138 // Enough quota to pass any test.
139 const int64 kPlentyOfQuota = INT_MAX; 139 const int64_t kPlentyOfQuota = INT_MAX;
140 140
141 typedef WebSocketEventInterface::ChannelState ChannelState; 141 typedef WebSocketEventInterface::ChannelState ChannelState;
142 const ChannelState CHANNEL_ALIVE = WebSocketEventInterface::CHANNEL_ALIVE; 142 const ChannelState CHANNEL_ALIVE = WebSocketEventInterface::CHANNEL_ALIVE;
143 const ChannelState CHANNEL_DELETED = WebSocketEventInterface::CHANNEL_DELETED; 143 const ChannelState CHANNEL_DELETED = WebSocketEventInterface::CHANNEL_DELETED;
144 144
145 // This typedef mainly exists to avoid having to repeat the "NOLINT" incantation 145 // This typedef mainly exists to avoid having to repeat the "NOLINT" incantation
146 // all over the place. 146 // all over the place.
147 typedef StrictMock< MockFunction<void(int)> > Checkpoint; // NOLINT 147 typedef StrictMock< MockFunction<void(int)> > Checkpoint; // NOLINT
148 148
149 // This mock is for testing expectations about how the EventInterface is used. 149 // This mock is for testing expectations about how the EventInterface is used.
150 class MockWebSocketEventInterface : public WebSocketEventInterface { 150 class MockWebSocketEventInterface : public WebSocketEventInterface {
151 public: 151 public:
152 MockWebSocketEventInterface() {} 152 MockWebSocketEventInterface() {}
153 153
154 MOCK_METHOD2(OnAddChannelResponse, 154 MOCK_METHOD2(OnAddChannelResponse,
155 ChannelState(const std::string&, 155 ChannelState(const std::string&,
156 const std::string&)); // NOLINT 156 const std::string&)); // NOLINT
157 MOCK_METHOD3(OnDataFrame, 157 MOCK_METHOD3(OnDataFrame,
158 ChannelState(bool, 158 ChannelState(bool,
159 WebSocketMessageType, 159 WebSocketMessageType,
160 const std::vector<char>&)); // NOLINT 160 const std::vector<char>&)); // NOLINT
161 MOCK_METHOD1(OnFlowControl, ChannelState(int64)); // NOLINT 161 MOCK_METHOD1(OnFlowControl, ChannelState(int64_t)); // NOLINT
162 MOCK_METHOD0(OnClosingHandshake, ChannelState(void)); // NOLINT 162 MOCK_METHOD0(OnClosingHandshake, ChannelState(void)); // NOLINT
163 MOCK_METHOD1(OnFailChannel, ChannelState(const std::string&)); // NOLINT 163 MOCK_METHOD1(OnFailChannel, ChannelState(const std::string&)); // NOLINT
164 MOCK_METHOD3(OnDropChannel, 164 MOCK_METHOD3(OnDropChannel,
165 ChannelState(bool, uint16, const std::string&)); // NOLINT 165 ChannelState(bool, uint16_t, const std::string&)); // NOLINT
166 166
167 // We can't use GMock with scoped_ptr. 167 // We can't use GMock with scoped_ptr.
168 ChannelState OnStartOpeningHandshake( 168 ChannelState OnStartOpeningHandshake(
169 scoped_ptr<WebSocketHandshakeRequestInfo>) override { 169 scoped_ptr<WebSocketHandshakeRequestInfo>) override {
170 OnStartOpeningHandshakeCalled(); 170 OnStartOpeningHandshakeCalled();
171 return CHANNEL_ALIVE; 171 return CHANNEL_ALIVE;
172 } 172 }
173 ChannelState OnFinishOpeningHandshake( 173 ChannelState OnFinishOpeningHandshake(
174 scoped_ptr<WebSocketHandshakeResponseInfo>) override { 174 scoped_ptr<WebSocketHandshakeResponseInfo>) override {
175 OnFinishOpeningHandshakeCalled(); 175 OnFinishOpeningHandshakeCalled();
(...skipping 21 matching lines...) Expand all
197 class FakeWebSocketEventInterface : public WebSocketEventInterface { 197 class FakeWebSocketEventInterface : public WebSocketEventInterface {
198 ChannelState OnAddChannelResponse(const std::string& selected_protocol, 198 ChannelState OnAddChannelResponse(const std::string& selected_protocol,
199 const std::string& extensions) override { 199 const std::string& extensions) override {
200 return CHANNEL_ALIVE; 200 return CHANNEL_ALIVE;
201 } 201 }
202 ChannelState OnDataFrame(bool fin, 202 ChannelState OnDataFrame(bool fin,
203 WebSocketMessageType type, 203 WebSocketMessageType type,
204 const std::vector<char>& data) override { 204 const std::vector<char>& data) override {
205 return CHANNEL_ALIVE; 205 return CHANNEL_ALIVE;
206 } 206 }
207 ChannelState OnFlowControl(int64 quota) override { return CHANNEL_ALIVE; } 207 ChannelState OnFlowControl(int64_t quota) override { return CHANNEL_ALIVE; }
208 ChannelState OnClosingHandshake() override { return CHANNEL_ALIVE; } 208 ChannelState OnClosingHandshake() override { return CHANNEL_ALIVE; }
209 ChannelState OnFailChannel(const std::string& message) override { 209 ChannelState OnFailChannel(const std::string& message) override {
210 return CHANNEL_DELETED; 210 return CHANNEL_DELETED;
211 } 211 }
212 ChannelState OnDropChannel(bool was_clean, 212 ChannelState OnDropChannel(bool was_clean,
213 uint16 code, 213 uint16_t code,
214 const std::string& reason) override { 214 const std::string& reason) override {
215 return CHANNEL_DELETED; 215 return CHANNEL_DELETED;
216 } 216 }
217 ChannelState OnStartOpeningHandshake( 217 ChannelState OnStartOpeningHandshake(
218 scoped_ptr<WebSocketHandshakeRequestInfo> request) override { 218 scoped_ptr<WebSocketHandshakeRequestInfo> request) override {
219 return CHANNEL_ALIVE; 219 return CHANNEL_ALIVE;
220 } 220 }
221 ChannelState OnFinishOpeningHandshake( 221 ChannelState OnFinishOpeningHandshake(
222 scoped_ptr<WebSocketHandshakeResponseInfo> response) override { 222 scoped_ptr<WebSocketHandshakeResponseInfo> response) override {
223 return CHANNEL_ALIVE; 223 return CHANNEL_ALIVE;
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 const std::string& extensions) override { 849 const std::string& extensions) override {
850 return fixture_->DeleteIfDeleting(EVENT_ON_ADD_CHANNEL_RESPONSE); 850 return fixture_->DeleteIfDeleting(EVENT_ON_ADD_CHANNEL_RESPONSE);
851 } 851 }
852 852
853 ChannelState OnDataFrame(bool fin, 853 ChannelState OnDataFrame(bool fin,
854 WebSocketMessageType type, 854 WebSocketMessageType type,
855 const std::vector<char>& data) override { 855 const std::vector<char>& data) override {
856 return fixture_->DeleteIfDeleting(EVENT_ON_DATA_FRAME); 856 return fixture_->DeleteIfDeleting(EVENT_ON_DATA_FRAME);
857 } 857 }
858 858
859 ChannelState OnFlowControl(int64 quota) override { 859 ChannelState OnFlowControl(int64_t quota) override {
860 return fixture_->DeleteIfDeleting(EVENT_ON_FLOW_CONTROL); 860 return fixture_->DeleteIfDeleting(EVENT_ON_FLOW_CONTROL);
861 } 861 }
862 862
863 ChannelState OnClosingHandshake() override { 863 ChannelState OnClosingHandshake() override {
864 return fixture_->DeleteIfDeleting(EVENT_ON_CLOSING_HANDSHAKE); 864 return fixture_->DeleteIfDeleting(EVENT_ON_CLOSING_HANDSHAKE);
865 } 865 }
866 866
867 ChannelState OnFailChannel(const std::string& message) override { 867 ChannelState OnFailChannel(const std::string& message) override {
868 return fixture_->DeleteIfDeleting(EVENT_ON_FAIL_CHANNEL); 868 return fixture_->DeleteIfDeleting(EVENT_ON_FAIL_CHANNEL);
869 } 869 }
870 870
871 ChannelState OnDropChannel(bool was_clean, 871 ChannelState OnDropChannel(bool was_clean,
872 uint16 code, 872 uint16_t code,
873 const std::string& reason) override { 873 const std::string& reason) override {
874 return fixture_->DeleteIfDeleting(EVENT_ON_DROP_CHANNEL); 874 return fixture_->DeleteIfDeleting(EVENT_ON_DROP_CHANNEL);
875 } 875 }
876 876
877 ChannelState OnStartOpeningHandshake( 877 ChannelState OnStartOpeningHandshake(
878 scoped_ptr<WebSocketHandshakeRequestInfo> request) override { 878 scoped_ptr<WebSocketHandshakeRequestInfo> request) override {
879 return fixture_->DeleteIfDeleting(EVENT_ON_START_OPENING_HANDSHAKE); 879 return fixture_->DeleteIfDeleting(EVENT_ON_START_OPENING_HANDSHAKE);
880 } 880 }
881 ChannelState OnFinishOpeningHandshake( 881 ChannelState OnFinishOpeningHandshake(
882 scoped_ptr<WebSocketHandshakeResponseInfo> response) override { 882 scoped_ptr<WebSocketHandshakeResponseInfo> response) override {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 .Times(AnyNumber()); 960 .Times(AnyNumber());
961 } 961 }
962 }; 962 };
963 963
964 // Fixture for tests which test use of receive quota from the renderer. 964 // Fixture for tests which test use of receive quota from the renderer.
965 class WebSocketChannelFlowControlTest 965 class WebSocketChannelFlowControlTest
966 : public WebSocketChannelEventInterfaceTest { 966 : public WebSocketChannelEventInterfaceTest {
967 protected: 967 protected:
968 // Tests using this fixture should use CreateChannelAndConnectWithQuota() 968 // Tests using this fixture should use CreateChannelAndConnectWithQuota()
969 // instead of CreateChannelAndConnectSuccessfully(). 969 // instead of CreateChannelAndConnectSuccessfully().
970 void CreateChannelAndConnectWithQuota(int64 quota) { 970 void CreateChannelAndConnectWithQuota(int64_t quota) {
971 CreateChannelAndConnect(); 971 CreateChannelAndConnect();
972 channel_->SendFlowControl(quota); 972 channel_->SendFlowControl(quota);
973 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 973 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass());
974 } 974 }
975 975
976 virtual void CreateChannelAndConnectSuccesfully() { NOTREACHED(); } 976 virtual void CreateChannelAndConnectSuccesfully() { NOTREACHED(); }
977 }; 977 };
978 978
979 // Fixture for tests which test UTF-8 validation of received Text frames using a 979 // Fixture for tests which test UTF-8 validation of received Text frames using a
980 // mock WebSocketStream. 980 // mock WebSocketStream.
(...skipping 2427 matching lines...) Expand 10 before | Expand all | Expand 10 after
3408 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); 3408 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK");
3409 ASSERT_TRUE(read_frames); 3409 ASSERT_TRUE(read_frames);
3410 // Provide the "Close" message from the server. 3410 // Provide the "Close" message from the server.
3411 *read_frames = CreateFrameVector(frames); 3411 *read_frames = CreateFrameVector(frames);
3412 read_callback.Run(OK); 3412 read_callback.Run(OK);
3413 completion.WaitForResult(); 3413 completion.WaitForResult();
3414 } 3414 }
3415 3415
3416 } // namespace 3416 } // namespace
3417 } // namespace net 3417 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_channel.cc ('k') | net/websockets/websocket_deflate_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698