OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/spdy/spdy_test_util_common.h" | 5 #include "net/spdy/spdy_test_util_common.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 | 10 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 const char* data, | 219 const char* data, |
220 size_t len, | 220 size_t len, |
221 bool fin) override {} | 221 bool fin) override {} |
222 void OnStreamPadding(SpdyStreamId stream_id, size_t len) override {} | 222 void OnStreamPadding(SpdyStreamId stream_id, size_t len) override {} |
223 SpdyHeadersHandlerInterface* OnHeaderFrameStart( | 223 SpdyHeadersHandlerInterface* OnHeaderFrameStart( |
224 SpdyStreamId stream_id) override { | 224 SpdyStreamId stream_id) override { |
225 return nullptr; | 225 return nullptr; |
226 } | 226 } |
227 void OnHeaderFrameEnd(SpdyStreamId stream_id, bool end_headers) override {} | 227 void OnHeaderFrameEnd(SpdyStreamId stream_id, bool end_headers) override {} |
228 void OnSettings(bool clear_persisted) override {} | 228 void OnSettings(bool clear_persisted) override {} |
229 void OnSetting(SpdySettingsIds id, uint8 flags, uint32 value) override {} | 229 void OnSetting(SpdySettingsIds id, uint8_t flags, uint32_t value) override {} |
230 void OnPing(SpdyPingId unique_id, bool is_ack) override {} | 230 void OnPing(SpdyPingId unique_id, bool is_ack) override {} |
231 void OnRstStream(SpdyStreamId stream_id, | 231 void OnRstStream(SpdyStreamId stream_id, |
232 SpdyRstStreamStatus status) override {} | 232 SpdyRstStreamStatus status) override {} |
233 void OnGoAway(SpdyStreamId last_accepted_stream_id, | 233 void OnGoAway(SpdyStreamId last_accepted_stream_id, |
234 SpdyGoAwayStatus status, | 234 SpdyGoAwayStatus status, |
235 StringPiece debug_data) override {} | 235 StringPiece debug_data) override {} |
236 void OnWindowUpdate(SpdyStreamId stream_id, int delta_window_size) override {} | 236 void OnWindowUpdate(SpdyStreamId stream_id, int delta_window_size) override {} |
237 void OnPushPromise(SpdyStreamId stream_id, | 237 void OnPushPromise(SpdyStreamId stream_id, |
238 SpdyStreamId promised_stream_id, | 238 SpdyStreamId promised_stream_id, |
239 const SpdyHeaderBlock& headers) override {} | 239 const SpdyHeaderBlock& headers) override {} |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 SpdyStreamRequest* request, int result) { | 289 SpdyStreamRequest* request, int result) { |
290 if (result == OK) | 290 if (result == OK) |
291 request->ReleaseStream()->Cancel(); | 291 request->ReleaseStream()->Cancel(); |
292 SetResult(result); | 292 SetResult(result); |
293 } | 293 } |
294 | 294 |
295 MockECSignatureCreator::MockECSignatureCreator(crypto::ECPrivateKey* key) | 295 MockECSignatureCreator::MockECSignatureCreator(crypto::ECPrivateKey* key) |
296 : key_(key) { | 296 : key_(key) { |
297 } | 297 } |
298 | 298 |
299 bool MockECSignatureCreator::Sign(const uint8* data, | 299 bool MockECSignatureCreator::Sign(const uint8_t* data, |
300 int data_len, | 300 int data_len, |
301 std::vector<uint8>* signature) { | 301 std::vector<uint8_t>* signature) { |
302 std::vector<uint8> private_key_value; | 302 std::vector<uint8_t> private_key_value; |
303 key_->ExportValue(&private_key_value); | 303 key_->ExportValue(&private_key_value); |
304 std::string head = "fakesignature"; | 304 std::string head = "fakesignature"; |
305 std::string tail = "/fakesignature"; | 305 std::string tail = "/fakesignature"; |
306 | 306 |
307 signature->clear(); | 307 signature->clear(); |
308 signature->insert(signature->end(), head.begin(), head.end()); | 308 signature->insert(signature->end(), head.begin(), head.end()); |
309 signature->insert(signature->end(), private_key_value.begin(), | 309 signature->insert(signature->end(), private_key_value.begin(), |
310 private_key_value.end()); | 310 private_key_value.end()); |
311 signature->insert(signature->end(), '-'); | 311 signature->insert(signature->end(), '-'); |
312 signature->insert(signature->end(), data, data + data_len); | 312 signature->insert(signature->end(), data, data + data_len); |
313 signature->insert(signature->end(), tail.begin(), tail.end()); | 313 signature->insert(signature->end(), tail.begin(), tail.end()); |
314 return true; | 314 return true; |
315 } | 315 } |
316 | 316 |
317 bool MockECSignatureCreator::DecodeSignature( | 317 bool MockECSignatureCreator::DecodeSignature( |
318 const std::vector<uint8>& signature, | 318 const std::vector<uint8_t>& signature, |
319 std::vector<uint8>* out_raw_sig) { | 319 std::vector<uint8_t>* out_raw_sig) { |
320 *out_raw_sig = signature; | 320 *out_raw_sig = signature; |
321 return true; | 321 return true; |
322 } | 322 } |
323 | 323 |
324 MockECSignatureCreatorFactory::MockECSignatureCreatorFactory() { | 324 MockECSignatureCreatorFactory::MockECSignatureCreatorFactory() { |
325 crypto::ECSignatureCreator::SetFactoryForTesting(this); | 325 crypto::ECSignatureCreator::SetFactoryForTesting(this); |
326 } | 326 } |
327 | 327 |
328 MockECSignatureCreatorFactory::~MockECSignatureCreatorFactory() { | 328 MockECSignatureCreatorFactory::~MockECSignatureCreatorFactory() { |
329 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); | 329 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 } | 719 } |
720 | 720 |
721 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy( | 721 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy( |
722 base::StringPiece url) const { | 722 base::StringPiece url) const { |
723 scoped_ptr<SpdyHeaderBlock> headers(ConstructGetHeaderBlock(url)); | 723 scoped_ptr<SpdyHeaderBlock> headers(ConstructGetHeaderBlock(url)); |
724 return headers.Pass(); | 724 return headers.Pass(); |
725 } | 725 } |
726 | 726 |
727 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeadHeaderBlock( | 727 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeadHeaderBlock( |
728 base::StringPiece url, | 728 base::StringPiece url, |
729 int64 content_length) const { | 729 int64_t content_length) const { |
730 return ConstructHeaderBlock("HEAD", url, nullptr); | 730 return ConstructHeaderBlock("HEAD", url, nullptr); |
731 } | 731 } |
732 | 732 |
733 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPostHeaderBlock( | 733 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPostHeaderBlock( |
734 base::StringPiece url, | 734 base::StringPiece url, |
735 int64 content_length) const { | 735 int64_t content_length) const { |
736 return ConstructHeaderBlock("POST", url, &content_length); | 736 return ConstructHeaderBlock("POST", url, &content_length); |
737 } | 737 } |
738 | 738 |
739 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPutHeaderBlock( | 739 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPutHeaderBlock( |
740 base::StringPiece url, | 740 base::StringPiece url, |
741 int64 content_length) const { | 741 int64_t content_length) const { |
742 return ConstructHeaderBlock("PUT", url, &content_length); | 742 return ConstructHeaderBlock("PUT", url, &content_length); |
743 } | 743 } |
744 | 744 |
745 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame( | 745 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame( |
746 const SpdyHeaderInfo& header_info, | 746 const SpdyHeaderInfo& header_info, |
747 scoped_ptr<SpdyHeaderBlock> headers) const { | 747 scoped_ptr<SpdyHeaderBlock> headers) const { |
748 BufferedSpdyFramer framer(spdy_version_, header_info.compressed); | 748 BufferedSpdyFramer framer(spdy_version_, header_info.compressed); |
749 SpdyFrame* frame = NULL; | 749 SpdyFrame* frame = NULL; |
750 switch (header_info.kind) { | 750 switch (header_info.kind) { |
751 case DATA: | 751 case DATA: |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 878 |
879 if (spdy_version() > SPDY3) { | 879 if (spdy_version() > SPDY3) { |
880 SpdySettingsIR settings_ir; | 880 SpdySettingsIR settings_ir; |
881 settings_ir.set_is_ack(true); | 881 settings_ir.set_is_ack(true); |
882 return CreateFramer(false)->SerializeFrame(settings_ir); | 882 return CreateFramer(false)->SerializeFrame(settings_ir); |
883 } | 883 } |
884 // No settings ACK write occurs. Create an empty placeholder write. | 884 // No settings ACK write occurs. Create an empty placeholder write. |
885 return new SpdyFrame(kEmptyWrite, 0, false); | 885 return new SpdyFrame(kEmptyWrite, 0, false); |
886 } | 886 } |
887 | 887 |
888 SpdyFrame* SpdyTestUtil::ConstructSpdyPing(uint32 ping_id, bool is_ack) const { | 888 SpdyFrame* SpdyTestUtil::ConstructSpdyPing(uint32_t ping_id, |
| 889 bool is_ack) const { |
889 SpdyPingIR ping_ir(ping_id); | 890 SpdyPingIR ping_ir(ping_id); |
890 ping_ir.set_is_ack(is_ack); | 891 ping_ir.set_is_ack(is_ack); |
891 return CreateFramer(false)->SerializeFrame(ping_ir); | 892 return CreateFramer(false)->SerializeFrame(ping_ir); |
892 } | 893 } |
893 | 894 |
894 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway() const { | 895 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway() const { |
895 return ConstructSpdyGoAway(0); | 896 return ConstructSpdyGoAway(0); |
896 } | 897 } |
897 | 898 |
898 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway( | 899 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway( |
899 SpdyStreamId last_good_stream_id) const { | 900 SpdyStreamId last_good_stream_id) const { |
900 SpdyGoAwayIR go_ir(last_good_stream_id, GOAWAY_OK, "go away"); | 901 SpdyGoAwayIR go_ir(last_good_stream_id, GOAWAY_OK, "go away"); |
901 return CreateFramer(false)->SerializeFrame(go_ir); | 902 return CreateFramer(false)->SerializeFrame(go_ir); |
902 } | 903 } |
903 | 904 |
904 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway(SpdyStreamId last_good_stream_id, | 905 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway(SpdyStreamId last_good_stream_id, |
905 SpdyGoAwayStatus status, | 906 SpdyGoAwayStatus status, |
906 const std::string& desc) const { | 907 const std::string& desc) const { |
907 SpdyGoAwayIR go_ir(last_good_stream_id, status, desc); | 908 SpdyGoAwayIR go_ir(last_good_stream_id, status, desc); |
908 return CreateFramer(false)->SerializeFrame(go_ir); | 909 return CreateFramer(false)->SerializeFrame(go_ir); |
909 } | 910 } |
910 | 911 |
911 SpdyFrame* SpdyTestUtil::ConstructSpdyWindowUpdate( | 912 SpdyFrame* SpdyTestUtil::ConstructSpdyWindowUpdate( |
912 const SpdyStreamId stream_id, uint32 delta_window_size) const { | 913 const SpdyStreamId stream_id, |
| 914 uint32_t delta_window_size) const { |
913 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size); | 915 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size); |
914 return CreateFramer(false)->SerializeFrame(update_ir); | 916 return CreateFramer(false)->SerializeFrame(update_ir); |
915 } | 917 } |
916 | 918 |
917 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer | 919 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer |
918 // SpdyRstStreamIR). | 920 // SpdyRstStreamIR). |
919 SpdyFrame* SpdyTestUtil::ConstructSpdyRstStream( | 921 SpdyFrame* SpdyTestUtil::ConstructSpdyRstStream( |
920 SpdyStreamId stream_id, | 922 SpdyStreamId stream_id, |
921 SpdyRstStreamStatus status) const { | 923 SpdyRstStreamStatus status) const { |
922 SpdyRstStreamIR rst_ir(stream_id, status); | 924 SpdyRstStreamIR rst_ir(stream_id, status); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 block[GetStatusKey()] = "200"; | 1180 block[GetStatusKey()] = "200"; |
1179 MaybeAddVersionHeader(&block); | 1181 MaybeAddVersionHeader(&block); |
1180 block["hello"] = "bye"; | 1182 block["hello"] = "bye"; |
1181 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 1183 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
1182 | 1184 |
1183 return ConstructSpdyReply(stream_id, block); | 1185 return ConstructSpdyReply(stream_id, block); |
1184 } | 1186 } |
1185 | 1187 |
1186 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url, | 1188 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url, |
1187 SpdyStreamId stream_id, | 1189 SpdyStreamId stream_id, |
1188 int64 content_length, | 1190 int64_t content_length, |
1189 RequestPriority priority, | 1191 RequestPriority priority, |
1190 const char* const extra_headers[], | 1192 const char* const extra_headers[], |
1191 int extra_header_count) { | 1193 int extra_header_count) { |
1192 scoped_ptr<SpdyHeaderBlock> block( | 1194 scoped_ptr<SpdyHeaderBlock> block( |
1193 ConstructPostHeaderBlock(url, content_length)); | 1195 ConstructPostHeaderBlock(url, content_length)); |
1194 AppendToHeaderBlock(extra_headers, extra_header_count, block.get()); | 1196 AppendToHeaderBlock(extra_headers, extra_header_count, block.get()); |
1195 return ConstructSpdySyn(stream_id, *block, priority, false, false); | 1197 return ConstructSpdySyn(stream_id, *block, priority, false, false); |
1196 } | 1198 } |
1197 | 1199 |
1198 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost( | 1200 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost( |
(...skipping 17 matching lines...) Expand all Loading... |
1216 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, bool fin) { | 1218 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, bool fin) { |
1217 SpdyFramer framer(spdy_version_); | 1219 SpdyFramer framer(spdy_version_); |
1218 SpdyDataIR data_ir(stream_id, | 1220 SpdyDataIR data_ir(stream_id, |
1219 base::StringPiece(kUploadData, kUploadDataSize)); | 1221 base::StringPiece(kUploadData, kUploadDataSize)); |
1220 data_ir.set_fin(fin); | 1222 data_ir.set_fin(fin); |
1221 return framer.SerializeData(data_ir); | 1223 return framer.SerializeData(data_ir); |
1222 } | 1224 } |
1223 | 1225 |
1224 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, | 1226 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, |
1225 const char* data, | 1227 const char* data, |
1226 uint32 len, | 1228 uint32_t len, |
1227 bool fin) { | 1229 bool fin) { |
1228 SpdyFramer framer(spdy_version_); | 1230 SpdyFramer framer(spdy_version_); |
1229 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); | 1231 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); |
1230 data_ir.set_fin(fin); | 1232 data_ir.set_fin(fin); |
1231 return framer.SerializeData(data_ir); | 1233 return framer.SerializeData(data_ir); |
1232 } | 1234 } |
1233 | 1235 |
1234 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, | 1236 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, |
1235 const char* data, | 1237 const char* data, |
1236 uint32 len, | 1238 uint32_t len, |
1237 bool fin, | 1239 bool fin, |
1238 int padding_length) { | 1240 int padding_length) { |
1239 SpdyFramer framer(spdy_version_); | 1241 SpdyFramer framer(spdy_version_); |
1240 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); | 1242 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); |
1241 data_ir.set_fin(fin); | 1243 data_ir.set_fin(fin); |
1242 data_ir.set_padding_len(padding_length); | 1244 data_ir.set_padding_len(padding_length); |
1243 return framer.SerializeData(data_ir); | 1245 return framer.SerializeData(data_ir); |
1244 } | 1246 } |
1245 | 1247 |
1246 SpdyFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( | 1248 SpdyFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 return ":version"; | 1295 return ":version"; |
1294 } | 1296 } |
1295 | 1297 |
1296 const char* SpdyTestUtil::GetPathKey() const { | 1298 const char* SpdyTestUtil::GetPathKey() const { |
1297 return ":path"; | 1299 return ":path"; |
1298 } | 1300 } |
1299 | 1301 |
1300 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeaderBlock( | 1302 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeaderBlock( |
1301 base::StringPiece method, | 1303 base::StringPiece method, |
1302 base::StringPiece url, | 1304 base::StringPiece url, |
1303 int64* content_length) const { | 1305 int64_t* content_length) const { |
1304 std::string scheme, host, path; | 1306 std::string scheme, host, path; |
1305 ParseUrl(url.data(), &scheme, &host, &path); | 1307 ParseUrl(url.data(), &scheme, &host, &path); |
1306 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 1308 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
1307 if (include_version_header()) { | 1309 if (include_version_header()) { |
1308 (*headers)[GetVersionKey()] = "HTTP/1.1"; | 1310 (*headers)[GetVersionKey()] = "HTTP/1.1"; |
1309 } | 1311 } |
1310 (*headers)[GetMethodKey()] = method.as_string(); | 1312 (*headers)[GetMethodKey()] = method.as_string(); |
1311 (*headers)[GetHostKey()] = host.c_str(); | 1313 (*headers)[GetHostKey()] = host.c_str(); |
1312 (*headers)[GetSchemeKey()] = scheme.c_str(); | 1314 (*headers)[GetSchemeKey()] = scheme.c_str(); |
1313 (*headers)[GetPathKey()] = path.c_str(); | 1315 (*headers)[GetPathKey()] = path.c_str(); |
(...skipping 17 matching lines...) Expand all Loading... |
1331 } | 1333 } |
1332 } | 1334 } |
1333 | 1335 |
1334 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1336 void SpdyTestUtil::SetPriority(RequestPriority priority, |
1335 SpdySynStreamIR* ir) const { | 1337 SpdySynStreamIR* ir) const { |
1336 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1338 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
1337 priority, spdy_version())); | 1339 priority, spdy_version())); |
1338 } | 1340 } |
1339 | 1341 |
1340 } // namespace net | 1342 } // namespace net |
OLD | NEW |