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

Side by Side Diff: net/spdy/spdy_test_util_common.cc

Issue 2156643002: Move ~1000 SpdySerializedFrame instances from heap to stack in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/spdy/spdy_test_util_common.h ('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) 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 #include <utility> 10 #include <utility>
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 int64_t content_length) const { 683 int64_t content_length) const {
684 return ConstructHeaderBlock("POST", url, &content_length); 684 return ConstructHeaderBlock("POST", url, &content_length);
685 } 685 }
686 686
687 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock( 687 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock(
688 base::StringPiece url, 688 base::StringPiece url,
689 int64_t content_length) const { 689 int64_t content_length) const {
690 return ConstructHeaderBlock("PUT", url, &content_length); 690 return ConstructHeaderBlock("PUT", url, &content_length);
691 } 691 }
692 692
693 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame(
694 const SpdyHeaderInfo& header_info,
695 SpdyHeaderBlock headers) const {
696 BufferedSpdyFramer framer;
697 SpdySerializedFrame* frame = NULL;
698 switch (header_info.kind) {
699 case DATA:
700 frame = framer.CreateDataFrame(header_info.id, header_info.data,
701 header_info.data_length,
702 header_info.data_flags);
703 break;
704 case SYN_STREAM:
705 frame = framer.CreateSynStream(
706 header_info.id, header_info.assoc_id, header_info.priority,
707 header_info.control_flags, std::move(headers));
708 break;
709 case SYN_REPLY:
710 frame = framer.CreateSynReply(header_info.id, header_info.control_flags,
711 std::move(headers));
712 break;
713 case RST_STREAM:
714 frame = framer.CreateRstStream(header_info.id, header_info.status);
715 break;
716 case HEADERS:
717 frame = framer.CreateHeaders(header_info.id, header_info.control_flags,
718 header_info.weight, std::move(headers));
719 break;
720 default:
721 ADD_FAILURE();
722 break;
723 }
724 return frame;
725 }
726
727 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame(
728 const SpdyHeaderInfo& header_info,
729 const char* const extra_headers[],
730 int extra_header_count,
731 const char* const tail_headers[],
732 int tail_header_count) const {
733 SpdyHeaderBlock headers;
734 AppendToHeaderBlock(extra_headers, extra_header_count, &headers);
735 if (tail_headers && tail_header_count)
736 AppendToHeaderBlock(tail_headers, tail_header_count, &headers);
737 return ConstructSpdyFrame(header_info, std::move(headers));
738 }
739
740 std::string SpdyTestUtil::ConstructSpdyReplyString( 693 std::string SpdyTestUtil::ConstructSpdyReplyString(
741 const SpdyHeaderBlock& headers) const { 694 const SpdyHeaderBlock& headers) const {
742 std::string reply_string; 695 std::string reply_string;
743 for (SpdyHeaderBlock::const_iterator it = headers.begin(); 696 for (SpdyHeaderBlock::const_iterator it = headers.begin();
744 it != headers.end(); ++it) { 697 it != headers.end(); ++it) {
745 std::string key = it->first.as_string(); 698 std::string key = it->first.as_string();
746 // Remove leading colon from pseudo headers. 699 // Remove leading colon from pseudo headers.
747 if (key[0] == ':') 700 if (key[0] == ':')
748 key = key.substr(1); 701 key = key.substr(1);
749 for (const std::string& value : 702 for (const std::string& value :
750 base::SplitString(it->second, base::StringPiece("\0", 1), 703 base::SplitString(it->second, base::StringPiece("\0", 1),
751 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 704 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
752 reply_string += key + ": " + value + "\n"; 705 reply_string += key + ": " + value + "\n";
753 } 706 }
754 } 707 }
755 return reply_string; 708 return reply_string;
756 } 709 }
757 710
758 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer 711 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer
759 // SpdySettingsIR). 712 // SpdySettingsIR).
760 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySettings( 713 SpdySerializedFrame SpdyTestUtil::ConstructSpdySettings(
761 const SettingsMap& settings) { 714 const SettingsMap& settings) {
762 SpdySettingsIR settings_ir; 715 SpdySettingsIR settings_ir;
763 for (SettingsMap::const_iterator it = settings.begin(); 716 for (SettingsMap::const_iterator it = settings.begin();
764 it != settings.end(); 717 it != settings.end();
765 ++it) { 718 ++it) {
766 settings_ir.AddSetting( 719 settings_ir.AddSetting(
767 it->first, 720 it->first,
768 (it->second.first & SETTINGS_FLAG_PLEASE_PERSIST) != 0, 721 (it->second.first & SETTINGS_FLAG_PLEASE_PERSIST) != 0,
769 (it->second.first & SETTINGS_FLAG_PERSISTED) != 0, 722 (it->second.first & SETTINGS_FLAG_PERSISTED) != 0,
770 it->second.second); 723 it->second.second);
771 } 724 }
772 return new SpdySerializedFrame( 725 return SpdySerializedFrame(
773 headerless_spdy_framer_.SerializeFrame(settings_ir)); 726 headerless_spdy_framer_.SerializeFrame(settings_ir));
774 } 727 }
775 728
776 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySettingsAck() { 729 SpdySerializedFrame SpdyTestUtil::ConstructSpdySettingsAck() {
777 SpdySettingsIR settings_ir; 730 SpdySettingsIR settings_ir;
778 settings_ir.set_is_ack(true); 731 settings_ir.set_is_ack(true);
779 return new SpdySerializedFrame( 732 return SpdySerializedFrame(
780 headerless_spdy_framer_.SerializeFrame(settings_ir)); 733 headerless_spdy_framer_.SerializeFrame(settings_ir));
781 } 734 }
782 735
783 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPing(uint32_t ping_id, 736 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPing(uint32_t ping_id,
784 bool is_ack) { 737 bool is_ack) {
785 SpdyPingIR ping_ir(ping_id); 738 SpdyPingIR ping_ir(ping_id);
786 ping_ir.set_is_ack(is_ack); 739 ping_ir.set_is_ack(is_ack);
787 return new SpdySerializedFrame( 740 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(ping_ir));
788 headerless_spdy_framer_.SerializeFrame(ping_ir));
789 } 741 }
790 742
791 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGoAway() { 743 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway() {
792 return ConstructSpdyGoAway(0); 744 return ConstructSpdyGoAway(0);
793 } 745 }
794 746
795 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGoAway( 747 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway(
796 SpdyStreamId last_good_stream_id) { 748 SpdyStreamId last_good_stream_id) {
797 SpdyGoAwayIR go_ir(last_good_stream_id, GOAWAY_OK, "go away"); 749 SpdyGoAwayIR go_ir(last_good_stream_id, GOAWAY_OK, "go away");
798 return new SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir)); 750 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir));
799 } 751 }
800 752
801 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGoAway( 753 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway(
802 SpdyStreamId last_good_stream_id, 754 SpdyStreamId last_good_stream_id,
803 SpdyGoAwayStatus status, 755 SpdyGoAwayStatus status,
804 const std::string& desc) { 756 const std::string& desc) {
805 SpdyGoAwayIR go_ir(last_good_stream_id, status, desc); 757 SpdyGoAwayIR go_ir(last_good_stream_id, status, desc);
806 return new SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir)); 758 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir));
807 } 759 }
808 760
809 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyWindowUpdate( 761 SpdySerializedFrame SpdyTestUtil::ConstructSpdyWindowUpdate(
810 const SpdyStreamId stream_id, 762 const SpdyStreamId stream_id,
811 uint32_t delta_window_size) { 763 uint32_t delta_window_size) {
812 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size); 764 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size);
813 return new SpdySerializedFrame( 765 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(update_ir));
814 headerless_spdy_framer_.SerializeFrame(update_ir));
815 } 766 }
816 767
817 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer 768 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer
818 // SpdyRstStreamIR). 769 // SpdyRstStreamIR).
819 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyRstStream( 770 SpdySerializedFrame SpdyTestUtil::ConstructSpdyRstStream(
820 SpdyStreamId stream_id, 771 SpdyStreamId stream_id,
821 SpdyRstStreamStatus status) { 772 SpdyRstStreamStatus status) {
822 SpdyRstStreamIR rst_ir(stream_id, status); 773 SpdyRstStreamIR rst_ir(stream_id, status);
823 return new SpdySerializedFrame( 774 return SpdySerializedFrame(
824 headerless_spdy_framer_.SerializeRstStream(rst_ir)); 775 headerless_spdy_framer_.SerializeRstStream(rst_ir));
825 } 776 }
826 777
827 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( 778 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGet(
828 const char* const url, 779 const char* const url,
829 SpdyStreamId stream_id, 780 SpdyStreamId stream_id,
830 RequestPriority request_priority) { 781 RequestPriority request_priority) {
831 SpdyHeaderBlock block(ConstructGetHeaderBlock(url)); 782 SpdyHeaderBlock block(ConstructGetHeaderBlock(url));
832 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true); 783 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true);
833 } 784 }
834 785
835 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( 786 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGet(
836 const char* const extra_headers[], 787 const char* const extra_headers[],
837 int extra_header_count, 788 int extra_header_count,
838 int stream_id, 789 int stream_id,
839 RequestPriority request_priority, 790 RequestPriority request_priority,
840 bool direct) { 791 bool direct) {
841 SpdyHeaderBlock block; 792 SpdyHeaderBlock block;
842 block[GetMethodKey()] = "GET"; 793 block[GetMethodKey()] = "GET";
843 AddUrlToHeaderBlock(default_url_.spec(), &block); 794 AddUrlToHeaderBlock(default_url_.spec(), &block);
844 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 795 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
845 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true); 796 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true);
846 } 797 }
847 798
848 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyConnect( 799 SpdySerializedFrame SpdyTestUtil::ConstructSpdyConnect(
849 const char* const extra_headers[], 800 const char* const extra_headers[],
850 int extra_header_count, 801 int extra_header_count,
851 int stream_id, 802 int stream_id,
852 RequestPriority priority, 803 RequestPriority priority,
853 const HostPortPair& host_port_pair) { 804 const HostPortPair& host_port_pair) {
854 SpdyHeaderBlock block; 805 SpdyHeaderBlock block;
855 block[GetMethodKey()] = "CONNECT"; 806 block[GetMethodKey()] = "CONNECT";
856 block[GetHostKey()] = host_port_pair.ToString(); 807 block[GetHostKey()] = host_port_pair.ToString();
857 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 808 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
858 return ConstructSpdySyn(stream_id, std::move(block), priority, false); 809 return ConstructSpdySyn(stream_id, std::move(block), priority, false);
859 } 810 }
860 811
861 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush( 812 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPush(
862 const char* const extra_headers[], 813 const char* const extra_headers[],
863 int extra_header_count, 814 int extra_header_count,
864 int stream_id, 815 int stream_id,
865 int associated_stream_id, 816 int associated_stream_id,
866 const char* url) { 817 const char* url) {
867 SpdyHeaderBlock push_promise_header_block; 818 SpdyHeaderBlock push_promise_header_block;
868 AddUrlToHeaderBlock(url, &push_promise_header_block); 819 AddUrlToHeaderBlock(url, &push_promise_header_block);
869 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id, 820 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
870 std::move(push_promise_header_block)); 821 std::move(push_promise_header_block));
871 SpdySerializedFrame push_promise_frame( 822 SpdySerializedFrame push_promise_frame(
872 response_spdy_framer_.SerializeFrame(push_promise)); 823 response_spdy_framer_.SerializeFrame(push_promise));
873 824
874 SpdyHeaderBlock headers_header_block; 825 SpdyHeaderBlock headers_header_block;
875 headers_header_block[GetStatusKey()] = "200"; 826 headers_header_block[GetStatusKey()] = "200";
876 headers_header_block["hello"] = "bye"; 827 headers_header_block["hello"] = "bye";
877 AppendToHeaderBlock(extra_headers, extra_header_count, &headers_header_block); 828 AppendToHeaderBlock(extra_headers, extra_header_count, &headers_header_block);
878 SpdyHeadersIR headers(stream_id, std::move(headers_header_block)); 829 SpdyHeadersIR headers(stream_id, std::move(headers_header_block));
879 SpdySerializedFrame headers_frame( 830 SpdySerializedFrame headers_frame(
880 response_spdy_framer_.SerializeFrame(headers)); 831 response_spdy_framer_.SerializeFrame(headers));
881 832
882 int joint_data_size = push_promise_frame.size() + headers_frame.size(); 833 int joint_data_size = push_promise_frame.size() + headers_frame.size();
883 std::unique_ptr<char[]> data(new char[joint_data_size]); 834 std::unique_ptr<char[]> data(new char[joint_data_size]);
884 const SpdySerializedFrame* frames[2] = { 835 const SpdySerializedFrame* frames[2] = {
885 &push_promise_frame, &headers_frame, 836 &push_promise_frame, &headers_frame,
886 }; 837 };
887 int combined_size = 838 int combined_size =
888 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); 839 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size);
889 DCHECK_EQ(combined_size, joint_data_size); 840 DCHECK_EQ(combined_size, joint_data_size);
890 return new SpdySerializedFrame(data.release(), joint_data_size, true); 841 return SpdySerializedFrame(data.release(), joint_data_size, true);
891 } 842 }
892 843
893 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush( 844 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPush(
894 const char* const extra_headers[], 845 const char* const extra_headers[],
895 int extra_header_count, 846 int extra_header_count,
896 int stream_id, 847 int stream_id,
897 int associated_stream_id, 848 int associated_stream_id,
898 const char* url, 849 const char* url,
899 const char* status, 850 const char* status,
900 const char* location) { 851 const char* location) {
901 SpdyHeaderBlock push_promise_header_block; 852 SpdyHeaderBlock push_promise_header_block;
902 AddUrlToHeaderBlock(url, &push_promise_header_block); 853 AddUrlToHeaderBlock(url, &push_promise_header_block);
903 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id, 854 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
(...skipping 11 matching lines...) Expand all
915 response_spdy_framer_.SerializeFrame(headers)); 866 response_spdy_framer_.SerializeFrame(headers));
916 867
917 int joint_data_size = push_promise_frame.size() + headers_frame.size(); 868 int joint_data_size = push_promise_frame.size() + headers_frame.size();
918 std::unique_ptr<char[]> data(new char[joint_data_size]); 869 std::unique_ptr<char[]> data(new char[joint_data_size]);
919 const SpdySerializedFrame* frames[2] = { 870 const SpdySerializedFrame* frames[2] = {
920 &push_promise_frame, &headers_frame, 871 &push_promise_frame, &headers_frame,
921 }; 872 };
922 int combined_size = 873 int combined_size =
923 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); 874 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size);
924 DCHECK_EQ(combined_size, joint_data_size); 875 DCHECK_EQ(combined_size, joint_data_size);
925 return new SpdySerializedFrame(data.release(), joint_data_size, true); 876 return SpdySerializedFrame(data.release(), joint_data_size, true);
926 } 877 }
927 878
928 SpdySerializedFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( 879 SpdySerializedFrame SpdyTestUtil::ConstructInitialSpdyPushFrame(
929 SpdyHeaderBlock headers, 880 SpdyHeaderBlock headers,
930 int stream_id, 881 int stream_id,
931 int associated_stream_id) { 882 int associated_stream_id) {
932 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id, 883 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
933 std::move(headers)); 884 std::move(headers));
934 return new SpdySerializedFrame( 885 return SpdySerializedFrame(
935 response_spdy_framer_.SerializeFrame(push_promise)); 886 response_spdy_framer_.SerializeFrame(push_promise));
936 } 887 }
937 888
938 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPushHeaders( 889 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPushHeaders(
939 int stream_id, 890 int stream_id,
940 const char* const extra_headers[], 891 const char* const extra_headers[],
941 int extra_header_count) { 892 int extra_header_count) {
942 SpdyHeaderBlock header_block; 893 SpdyHeaderBlock header_block;
943 header_block[GetStatusKey()] = "200"; 894 header_block[GetStatusKey()] = "200";
944 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block); 895 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block);
945 SpdyHeadersIR headers(stream_id, std::move(header_block)); 896 SpdyHeadersIR headers(stream_id, std::move(header_block));
946 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers)); 897 return SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers));
947 } 898 }
948 899
949 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyResponseHeaders( 900 SpdySerializedFrame SpdyTestUtil::ConstructSpdyResponseHeaders(
950 int stream_id, 901 int stream_id,
951 SpdyHeaderBlock headers, 902 SpdyHeaderBlock headers,
952 bool fin) { 903 bool fin) {
953 SpdyHeadersIR spdy_headers(stream_id, std::move(headers)); 904 SpdyHeadersIR spdy_headers(stream_id, std::move(headers));
954 spdy_headers.set_fin(fin); 905 spdy_headers.set_fin(fin);
955 return new SpdySerializedFrame( 906 return SpdySerializedFrame(
956 response_spdy_framer_.SerializeFrame(spdy_headers)); 907 response_spdy_framer_.SerializeFrame(spdy_headers));
957 } 908 }
958 909
959 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, 910 SpdySerializedFrame SpdyTestUtil::ConstructSpdySyn(int stream_id,
960 SpdyHeaderBlock block, 911 SpdyHeaderBlock block,
961 RequestPriority priority, 912 RequestPriority priority,
962 bool fin) { 913 bool fin) {
963 // Get the stream id of the next highest priority request 914 // Get the stream id of the next highest priority request
964 // (most recent request of the same priority, or last request of 915 // (most recent request of the same priority, or last request of
965 // an earlier priority). 916 // an earlier priority).
966 // Note that this is a duplicate of the logic in Http2PriorityDependencies 917 // Note that this is a duplicate of the logic in Http2PriorityDependencies
967 // (slightly transformed as this is based on RequestPriority and that logic 918 // (slightly transformed as this is based on RequestPriority and that logic
968 // on SpdyPriority, but only slightly transformed) and hence tests using 919 // on SpdyPriority, but only slightly transformed) and hence tests using
969 // this function do not effectively test that logic. 920 // this function do not effectively test that logic.
970 // That logic is tested by the Http2PriorityDependencies unit tests. 921 // That logic is tested by the Http2PriorityDependencies unit tests.
971 int parent_stream_id = 0; 922 int parent_stream_id = 0;
972 for (int q = priority; q <= HIGHEST; ++q) { 923 for (int q = priority; q <= HIGHEST; ++q) {
973 if (!priority_to_stream_id_list_[q].empty()) { 924 if (!priority_to_stream_id_list_[q].empty()) {
974 parent_stream_id = priority_to_stream_id_list_[q].back(); 925 parent_stream_id = priority_to_stream_id_list_[q].back();
975 break; 926 break;
976 } 927 }
977 } 928 }
978 929
979 priority_to_stream_id_list_[priority].push_back(stream_id); 930 priority_to_stream_id_list_[priority].push_back(stream_id);
980 931
981 SpdyHeadersIR headers(stream_id, std::move(block)); 932 SpdyHeadersIR headers(stream_id, std::move(block));
982 headers.set_has_priority(true); 933 headers.set_has_priority(true);
983 headers.set_weight(Spdy3PriorityToHttp2Weight( 934 headers.set_weight(Spdy3PriorityToHttp2Weight(
984 ConvertRequestPriorityToSpdyPriority(priority))); 935 ConvertRequestPriorityToSpdyPriority(priority)));
985 if (dependency_priorities_) { 936 if (dependency_priorities_) {
986 headers.set_parent_stream_id(parent_stream_id); 937 headers.set_parent_stream_id(parent_stream_id);
987 headers.set_exclusive(true); 938 headers.set_exclusive(true);
988 } 939 }
989 headers.set_fin(fin); 940 headers.set_fin(fin);
990 return new SpdySerializedFrame(request_spdy_framer_.SerializeFrame(headers)); 941 return SpdySerializedFrame(request_spdy_framer_.SerializeFrame(headers));
991 } 942 }
992 943
993 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, 944 SpdySerializedFrame SpdyTestUtil::ConstructSpdyReply(int stream_id,
994 SpdyHeaderBlock headers) { 945 SpdyHeaderBlock headers) {
995 SpdyHeadersIR reply(stream_id, std::move(headers)); 946 SpdyHeadersIR reply(stream_id, std::move(headers));
996 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply)); 947 return SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply));
997 } 948 }
998 949
999 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError( 950 SpdySerializedFrame SpdyTestUtil::ConstructSpdySynReplyError(
1000 const char* const status, 951 const char* const status,
1001 const char* const* const extra_headers, 952 const char* const* const extra_headers,
1002 int extra_header_count, 953 int extra_header_count,
1003 int stream_id) { 954 int stream_id) {
1004 SpdyHeaderBlock block; 955 SpdyHeaderBlock block;
1005 block[GetStatusKey()] = status; 956 block[GetStatusKey()] = status;
1006 block["hello"] = "bye"; 957 block["hello"] = "bye";
1007 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 958 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1008 959
1009 return ConstructSpdyReply(stream_id, std::move(block)); 960 return ConstructSpdyReply(stream_id, std::move(block));
1010 } 961 }
1011 962
1012 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect( 963 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGetSynReplyRedirect(
1013 int stream_id) { 964 int stream_id) {
1014 static const char* const kExtraHeaders[] = { 965 static const char* const kExtraHeaders[] = {
1015 "location", "http://www.foo.com/index.php", 966 "location", "http://www.foo.com/index.php",
1016 }; 967 };
1017 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, 968 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders,
1018 arraysize(kExtraHeaders)/2, stream_id); 969 arraysize(kExtraHeaders)/2, stream_id);
1019 } 970 }
1020 971
1021 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { 972 SpdySerializedFrame SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) {
1022 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); 973 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1);
1023 } 974 }
1024 975
1025 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReply( 976 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGetSynReply(
1026 const char* const extra_headers[], 977 const char* const extra_headers[],
1027 int extra_header_count, 978 int extra_header_count,
1028 int stream_id) { 979 int stream_id) {
1029 SpdyHeaderBlock block; 980 SpdyHeaderBlock block;
1030 block[GetStatusKey()] = "200"; 981 block[GetStatusKey()] = "200";
1031 block["hello"] = "bye"; 982 block["hello"] = "bye";
1032 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 983 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1033 984
1034 return ConstructSpdyReply(stream_id, std::move(block)); 985 return ConstructSpdyReply(stream_id, std::move(block));
1035 } 986 }
1036 987
1037 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPost( 988 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPost(
1038 const char* url, 989 const char* url,
1039 SpdyStreamId stream_id, 990 SpdyStreamId stream_id,
1040 int64_t content_length, 991 int64_t content_length,
1041 RequestPriority priority, 992 RequestPriority priority,
1042 const char* const extra_headers[], 993 const char* const extra_headers[],
1043 int extra_header_count) { 994 int extra_header_count) {
1044 SpdyHeaderBlock block(ConstructPostHeaderBlock(url, content_length)); 995 SpdyHeaderBlock block(ConstructPostHeaderBlock(url, content_length));
1045 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 996 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1046 return ConstructSpdySyn(stream_id, std::move(block), priority, false); 997 return ConstructSpdySyn(stream_id, std::move(block), priority, false);
1047 } 998 }
1048 999
1049 SpdySerializedFrame* SpdyTestUtil::ConstructChunkedSpdyPost( 1000 SpdySerializedFrame SpdyTestUtil::ConstructChunkedSpdyPost(
1050 const char* const extra_headers[], 1001 const char* const extra_headers[],
1051 int extra_header_count) { 1002 int extra_header_count) {
1052 SpdyHeaderBlock block; 1003 SpdyHeaderBlock block;
1053 block[GetMethodKey()] = "POST"; 1004 block[GetMethodKey()] = "POST";
1054 AddUrlToHeaderBlock(default_url_.spec(), &block); 1005 AddUrlToHeaderBlock(default_url_.spec(), &block);
1055 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1006 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1056 return ConstructSpdySyn(1, std::move(block), LOWEST, false); 1007 return ConstructSpdySyn(1, std::move(block), LOWEST, false);
1057 } 1008 }
1058 1009
1059 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPostSynReply( 1010 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPostSynReply(
1060 const char* const extra_headers[], 1011 const char* const extra_headers[],
1061 int extra_header_count) { 1012 int extra_header_count) {
1062 // TODO(jgraettinger): Remove this method. 1013 // TODO(jgraettinger): Remove this method.
1063 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1); 1014 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1);
1064 } 1015 }
1065 1016
1066 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, 1017 SpdySerializedFrame SpdyTestUtil::ConstructSpdyDataFrame(int stream_id,
1067 bool fin) { 1018 bool fin) {
1068 SpdyFramer framer(HTTP2); 1019 SpdyFramer framer(HTTP2);
1069 SpdyDataIR data_ir(stream_id, 1020 SpdyDataIR data_ir(stream_id,
1070 base::StringPiece(kUploadData, kUploadDataSize)); 1021 base::StringPiece(kUploadData, kUploadDataSize));
1071 data_ir.set_fin(fin); 1022 data_ir.set_fin(fin);
1072 return new SpdySerializedFrame(framer.SerializeData(data_ir)); 1023 return SpdySerializedFrame(framer.SerializeData(data_ir));
1073 } 1024 }
1074 1025
1075 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, 1026 SpdySerializedFrame SpdyTestUtil::ConstructSpdyDataFrame(int stream_id,
1076 const char* data, 1027 const char* data,
1077 uint32_t len, 1028 uint32_t len,
1078 bool fin) { 1029 bool fin) {
1079 SpdyFramer framer(HTTP2); 1030 SpdyFramer framer(HTTP2);
1080 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); 1031 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len));
1081 data_ir.set_fin(fin); 1032 data_ir.set_fin(fin);
1082 return new SpdySerializedFrame(framer.SerializeData(data_ir)); 1033 return SpdySerializedFrame(framer.SerializeData(data_ir));
1083 } 1034 }
1084 1035
1085 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, 1036 SpdySerializedFrame SpdyTestUtil::ConstructSpdyDataFrame(int stream_id,
1086 const char* data, 1037 const char* data,
1087 uint32_t len, 1038 uint32_t len,
1088 bool fin, 1039 bool fin,
1089 int padding_length) { 1040 int padding_length) {
1090 SpdyFramer framer(HTTP2); 1041 SpdyFramer framer(HTTP2);
1091 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); 1042 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len));
1092 data_ir.set_fin(fin); 1043 data_ir.set_fin(fin);
1093 data_ir.set_padding_len(padding_length); 1044 data_ir.set_padding_len(padding_length);
1094 return new SpdySerializedFrame(framer.SerializeData(data_ir)); 1045 return SpdySerializedFrame(framer.SerializeData(data_ir));
1095 } 1046 }
1096 1047
1097 SpdySerializedFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( 1048 SpdySerializedFrame SpdyTestUtil::ConstructWrappedSpdyFrame(
1098 const std::unique_ptr<SpdySerializedFrame>& frame, 1049 const SpdySerializedFrame& frame,
1099 int stream_id) { 1050 int stream_id) {
1100 return ConstructSpdyBodyFrame(stream_id, frame->data(), 1051 return ConstructSpdyDataFrame(stream_id, frame.data(), frame.size(), false);
1101 frame->size(), false);
1102 } 1052 }
1103 1053
1104 SpdySerializedFrame SpdyTestUtil::SerializeFrame(const SpdyFrameIR& frame_ir) { 1054 SpdySerializedFrame SpdyTestUtil::SerializeFrame(const SpdyFrameIR& frame_ir) {
1105 return headerless_spdy_framer_.SerializeFrame(frame_ir); 1055 return headerless_spdy_framer_.SerializeFrame(frame_ir);
1106 } 1056 }
1107 1057
1108 void SpdyTestUtil::UpdateWithStreamDestruction(int stream_id) { 1058 void SpdyTestUtil::UpdateWithStreamDestruction(int stream_id) {
1109 for (auto priority_it = priority_to_stream_id_list_.begin(); 1059 for (auto priority_it = priority_to_stream_id_list_.begin();
1110 priority_it != priority_to_stream_id_list_.end(); ++priority_it) { 1060 priority_it != priority_to_stream_id_list_.end(); ++priority_it) {
1111 for (auto stream_it = priority_it->second.begin(); 1061 for (auto stream_it = priority_it->second.begin();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 } 1106 }
1157 return headers; 1107 return headers;
1158 } 1108 }
1159 1109
1160 void SpdyTestUtil::SetPriority(RequestPriority priority, 1110 void SpdyTestUtil::SetPriority(RequestPriority priority,
1161 SpdySynStreamIR* ir) const { 1111 SpdySynStreamIR* ir) const {
1162 ir->set_priority(ConvertRequestPriorityToSpdyPriority(priority)); 1112 ir->set_priority(ConvertRequestPriorityToSpdyPriority(priority));
1163 } 1113 }
1164 1114
1165 } // namespace net 1115 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698