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

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

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: Created 3 years, 8 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') | net/spdy/spdy_test_utils.h » ('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 (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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 using net::test::IsOk; 44 using net::test::IsOk;
45 45
46 namespace net { 46 namespace net {
47 47
48 namespace { 48 namespace {
49 49
50 // Parses a URL into the scheme, host, and path components required for a 50 // Parses a URL into the scheme, host, and path components required for a
51 // SPDY request. 51 // SPDY request.
52 void ParseUrl(SpdyStringPiece url, 52 void ParseUrl(SpdyStringPiece url,
53 std::string* scheme, 53 SpdyString* scheme,
54 std::string* host, 54 SpdyString* host,
55 std::string* path) { 55 SpdyString* path) {
56 GURL gurl(url); 56 GURL gurl(url);
57 path->assign(gurl.PathForRequest()); 57 path->assign(gurl.PathForRequest());
58 scheme->assign(gurl.scheme()); 58 scheme->assign(gurl.scheme());
59 host->assign(gurl.host()); 59 host->assign(gurl.host());
60 if (gurl.has_port()) { 60 if (gurl.has_port()) {
61 host->append(":"); 61 host->append(":");
62 host->append(gurl.port()); 62 host->append(gurl.port());
63 } 63 }
64 } 64 }
65 65
(...skipping 16 matching lines...) Expand all
82 } 82 }
83 83
84 // Adds headers and values to a map. 84 // Adds headers and values to a map.
85 // |extra_headers| is an array of { name, value } pairs, arranged as strings 85 // |extra_headers| is an array of { name, value } pairs, arranged as strings
86 // where the even entries are the header names, and the odd entries are the 86 // where the even entries are the header names, and the odd entries are the
87 // header values. 87 // header values.
88 // |headers| gets filled in from |extra_headers|. 88 // |headers| gets filled in from |extra_headers|.
89 void AppendToHeaderBlock(const char* const extra_headers[], 89 void AppendToHeaderBlock(const char* const extra_headers[],
90 int extra_header_count, 90 int extra_header_count,
91 SpdyHeaderBlock* headers) { 91 SpdyHeaderBlock* headers) {
92 std::string this_header; 92 SpdyString this_header;
93 std::string this_value; 93 SpdyString this_value;
94 94
95 if (!extra_header_count) 95 if (!extra_header_count)
96 return; 96 return;
97 97
98 // Sanity check: Non-NULL header list. 98 // Sanity check: Non-NULL header list.
99 DCHECK(NULL != extra_headers) << "NULL header value pair list"; 99 DCHECK(NULL != extra_headers) << "NULL header value pair list";
100 // Sanity check: Non-NULL header map. 100 // Sanity check: Non-NULL header map.
101 DCHECK(NULL != headers) << "NULL header map"; 101 DCHECK(NULL != headers) << "NULL header map";
102 // Copy in the headers. 102 // Copy in the headers.
103 for (int i = 0; i < extra_header_count; i++) { 103 for (int i = 0; i < extra_header_count; i++) {
104 // Sanity check: Non-empty header. 104 // Sanity check: Non-empty header.
105 DCHECK_NE('\0', *extra_headers[i * 2]) << "Empty header value pair"; 105 DCHECK_NE('\0', *extra_headers[i * 2]) << "Empty header value pair";
106 this_header = extra_headers[i * 2]; 106 this_header = extra_headers[i * 2];
107 std::string::size_type header_len = this_header.length(); 107 SpdyString::size_type header_len = this_header.length();
108 if (!header_len) 108 if (!header_len)
109 continue; 109 continue;
110 this_value = extra_headers[1 + (i * 2)]; 110 this_value = extra_headers[1 + (i * 2)];
111 std::string new_value; 111 SpdyString new_value;
112 if (headers->find(this_header) != headers->end()) { 112 if (headers->find(this_header) != headers->end()) {
113 // More than one entry in the header. 113 // More than one entry in the header.
114 // Don't add the header again, just the append to the value, 114 // Don't add the header again, just the append to the value,
115 // separated by a NULL character. 115 // separated by a NULL character.
116 116
117 // Adjust the value. 117 // Adjust the value.
118 new_value = (*headers)[this_header].as_string(); 118 new_value = (*headers)[this_header].as_string();
119 // Put in a NULL separator. 119 // Put in a NULL separator.
120 new_value.append(1, '\0'); 120 new_value.append(1, '\0');
121 // Append the new value. 121 // Append the new value.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 public: 186 public:
187 PriorityGetter() : priority_(0) {} 187 PriorityGetter() : priority_(0) {}
188 ~PriorityGetter() override {} 188 ~PriorityGetter() override {}
189 189
190 SpdyPriority priority() const { 190 SpdyPriority priority() const {
191 return priority_; 191 return priority_;
192 } 192 }
193 193
194 void OnError(SpdyFramer::SpdyFramerError spdy_framer_error) override {} 194 void OnError(SpdyFramer::SpdyFramerError spdy_framer_error) override {}
195 void OnStreamError(SpdyStreamId stream_id, 195 void OnStreamError(SpdyStreamId stream_id,
196 const std::string& description) override {} 196 const SpdyString& description) override {}
197 void OnHeaders(SpdyStreamId stream_id, 197 void OnHeaders(SpdyStreamId stream_id,
198 bool has_priority, 198 bool has_priority,
199 int weight, 199 int weight,
200 SpdyStreamId parent_stream_id, 200 SpdyStreamId parent_stream_id,
201 bool exclusive, 201 bool exclusive,
202 bool fin, 202 bool fin,
203 SpdyHeaderBlock headers) override { 203 SpdyHeaderBlock headers) override {
204 if (has_priority) { 204 if (has_priority) {
205 priority_ = Http2WeightToSpdy3Priority(weight); 205 priority_ = Http2WeightToSpdy3Priority(weight);
206 } 206 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 MockECSignatureCreator::MockECSignatureCreator(crypto::ECPrivateKey* key) 284 MockECSignatureCreator::MockECSignatureCreator(crypto::ECPrivateKey* key)
285 : key_(key) { 285 : key_(key) {
286 } 286 }
287 287
288 bool MockECSignatureCreator::Sign(const uint8_t* data, 288 bool MockECSignatureCreator::Sign(const uint8_t* data,
289 int data_len, 289 int data_len,
290 std::vector<uint8_t>* signature) { 290 std::vector<uint8_t>* signature) {
291 std::vector<uint8_t> private_key; 291 std::vector<uint8_t> private_key;
292 if (!key_->ExportPrivateKey(&private_key)) 292 if (!key_->ExportPrivateKey(&private_key))
293 return false; 293 return false;
294 std::string head = "fakesignature"; 294 SpdyString head = "fakesignature";
295 std::string tail = "/fakesignature"; 295 SpdyString tail = "/fakesignature";
296 296
297 signature->clear(); 297 signature->clear();
298 signature->insert(signature->end(), head.begin(), head.end()); 298 signature->insert(signature->end(), head.begin(), head.end());
299 signature->insert(signature->end(), private_key.begin(), private_key.end()); 299 signature->insert(signature->end(), private_key.begin(), private_key.end());
300 signature->insert(signature->end(), '-'); 300 signature->insert(signature->end(), '-');
301 signature->insert(signature->end(), data, data + data_len); 301 signature->insert(signature->end(), data, data + data_len);
302 signature->insert(signature->end(), tail.begin(), tail.end()); 302 signature->insert(signature->end(), tail.begin(), tail.end());
303 return true; 303 return true;
304 } 304 }
305 305
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 SpdyTestUtil::SpdyTestUtil() 696 SpdyTestUtil::SpdyTestUtil()
697 : headerless_spdy_framer_(SpdyFramer::ENABLE_COMPRESSION), 697 : headerless_spdy_framer_(SpdyFramer::ENABLE_COMPRESSION),
698 request_spdy_framer_(SpdyFramer::ENABLE_COMPRESSION), 698 request_spdy_framer_(SpdyFramer::ENABLE_COMPRESSION),
699 response_spdy_framer_(SpdyFramer::ENABLE_COMPRESSION), 699 response_spdy_framer_(SpdyFramer::ENABLE_COMPRESSION),
700 default_url_(GURL(kDefaultUrl)) {} 700 default_url_(GURL(kDefaultUrl)) {}
701 701
702 SpdyTestUtil::~SpdyTestUtil() {} 702 SpdyTestUtil::~SpdyTestUtil() {}
703 703
704 void SpdyTestUtil::AddUrlToHeaderBlock(SpdyStringPiece url, 704 void SpdyTestUtil::AddUrlToHeaderBlock(SpdyStringPiece url,
705 SpdyHeaderBlock* headers) const { 705 SpdyHeaderBlock* headers) const {
706 std::string scheme, host, path; 706 SpdyString scheme, host, path;
707 ParseUrl(url, &scheme, &host, &path); 707 ParseUrl(url, &scheme, &host, &path);
708 (*headers)[GetHostKey()] = host; 708 (*headers)[GetHostKey()] = host;
709 (*headers)[GetSchemeKey()] = scheme; 709 (*headers)[GetSchemeKey()] = scheme;
710 (*headers)[GetPathKey()] = path; 710 (*headers)[GetPathKey()] = path;
711 } 711 }
712 712
713 // static 713 // static
714 SpdyHeaderBlock SpdyTestUtil::ConstructGetHeaderBlock(SpdyStringPiece url) { 714 SpdyHeaderBlock SpdyTestUtil::ConstructGetHeaderBlock(SpdyStringPiece url) {
715 return ConstructHeaderBlock("GET", url, NULL); 715 return ConstructHeaderBlock("GET", url, NULL);
716 } 716 }
(...skipping 15 matching lines...) Expand all
732 int64_t content_length) { 732 int64_t content_length) {
733 return ConstructHeaderBlock("POST", url, &content_length); 733 return ConstructHeaderBlock("POST", url, &content_length);
734 } 734 }
735 735
736 // static 736 // static
737 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock(SpdyStringPiece url, 737 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock(SpdyStringPiece url,
738 int64_t content_length) { 738 int64_t content_length) {
739 return ConstructHeaderBlock("PUT", url, &content_length); 739 return ConstructHeaderBlock("PUT", url, &content_length);
740 } 740 }
741 741
742 std::string SpdyTestUtil::ConstructSpdyReplyString( 742 SpdyString SpdyTestUtil::ConstructSpdyReplyString(
743 const SpdyHeaderBlock& headers) const { 743 const SpdyHeaderBlock& headers) const {
744 std::string reply_string; 744 SpdyString reply_string;
745 for (SpdyHeaderBlock::const_iterator it = headers.begin(); 745 for (SpdyHeaderBlock::const_iterator it = headers.begin();
746 it != headers.end(); ++it) { 746 it != headers.end(); ++it) {
747 std::string key = it->first.as_string(); 747 SpdyString key = it->first.as_string();
748 // Remove leading colon from pseudo headers. 748 // Remove leading colon from pseudo headers.
749 if (key[0] == ':') 749 if (key[0] == ':')
750 key = key.substr(1); 750 key = key.substr(1);
751 for (const std::string& value : 751 for (const SpdyString& value :
752 base::SplitString(it->second, SpdyStringPiece("\0", 1), 752 base::SplitString(it->second, SpdyStringPiece("\0", 1),
753 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 753 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
754 reply_string += key + ": " + value + "\n"; 754 reply_string += key + ": " + value + "\n";
755 } 755 }
756 } 756 }
757 return reply_string; 757 return reply_string;
758 } 758 }
759 759
760 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer 760 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer
761 // SpdySettingsIR). 761 // SpdySettingsIR).
(...skipping 28 matching lines...) Expand all
790 790
791 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway( 791 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway(
792 SpdyStreamId last_good_stream_id) { 792 SpdyStreamId last_good_stream_id) {
793 SpdyGoAwayIR go_ir(last_good_stream_id, ERROR_CODE_NO_ERROR, "go away"); 793 SpdyGoAwayIR go_ir(last_good_stream_id, ERROR_CODE_NO_ERROR, "go away");
794 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir)); 794 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir));
795 } 795 }
796 796
797 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway( 797 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway(
798 SpdyStreamId last_good_stream_id, 798 SpdyStreamId last_good_stream_id,
799 SpdyErrorCode error_code, 799 SpdyErrorCode error_code,
800 const std::string& desc) { 800 const SpdyString& desc) {
801 SpdyGoAwayIR go_ir(last_good_stream_id, error_code, desc); 801 SpdyGoAwayIR go_ir(last_good_stream_id, error_code, desc);
802 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir)); 802 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir));
803 } 803 }
804 804
805 SpdySerializedFrame SpdyTestUtil::ConstructSpdyWindowUpdate( 805 SpdySerializedFrame SpdyTestUtil::ConstructSpdyWindowUpdate(
806 const SpdyStreamId stream_id, 806 const SpdyStreamId stream_id,
807 uint32_t delta_window_size) { 807 uint32_t delta_window_size) {
808 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size); 808 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size);
809 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(update_ir)); 809 return SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(update_ir));
810 } 810 }
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 1143
1144 // static 1144 // static
1145 const char* SpdyTestUtil::GetPathKey() { 1145 const char* SpdyTestUtil::GetPathKey() {
1146 return ":path"; 1146 return ":path";
1147 } 1147 }
1148 1148
1149 // static 1149 // static
1150 SpdyHeaderBlock SpdyTestUtil::ConstructHeaderBlock(SpdyStringPiece method, 1150 SpdyHeaderBlock SpdyTestUtil::ConstructHeaderBlock(SpdyStringPiece method,
1151 SpdyStringPiece url, 1151 SpdyStringPiece url,
1152 int64_t* content_length) { 1152 int64_t* content_length) {
1153 std::string scheme, host, path; 1153 SpdyString scheme, host, path;
1154 ParseUrl(url, &scheme, &host, &path); 1154 ParseUrl(url, &scheme, &host, &path);
1155 SpdyHeaderBlock headers; 1155 SpdyHeaderBlock headers;
1156 headers[GetMethodKey()] = method.as_string(); 1156 headers[GetMethodKey()] = method.as_string();
1157 headers[GetHostKey()] = host.c_str(); 1157 headers[GetHostKey()] = host.c_str();
1158 headers[GetSchemeKey()] = scheme.c_str(); 1158 headers[GetSchemeKey()] = scheme.c_str();
1159 headers[GetPathKey()] = path.c_str(); 1159 headers[GetPathKey()] = path.c_str();
1160 if (content_length) { 1160 if (content_length) {
1161 std::string length_str = base::Int64ToString(*content_length); 1161 SpdyString length_str = base::Int64ToString(*content_length);
1162 headers["content-length"] = length_str; 1162 headers["content-length"] = length_str;
1163 } 1163 }
1164 return headers; 1164 return headers;
1165 } 1165 }
1166 1166
1167 } // namespace net 1167 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | net/spdy/spdy_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698