OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_utils.h" | 5 #include "net/spdy/spdy_test_utils.h" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 << description | 88 << description |
89 << "\n\nExpected:\n" | 89 << "\n\nExpected:\n" |
90 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len) | 90 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len) |
91 << "\nActual:\n" | 91 << "\nActual:\n" |
92 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len); | 92 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len); |
93 } | 93 } |
94 | 94 |
95 void SetFrameFlags(SpdySerializedFrame* frame, | 95 void SetFrameFlags(SpdySerializedFrame* frame, |
96 uint8_t flags, | 96 uint8_t flags, |
97 SpdyMajorVersion spdy_version) { | 97 SpdyMajorVersion spdy_version) { |
98 switch (spdy_version) { | 98 frame->data()[4] = flags; |
99 case SPDY3: | |
100 case HTTP2: | |
101 frame->data()[4] = flags; | |
102 break; | |
103 default: | |
104 LOG(FATAL) << "Unsupported SPDY version."; | |
105 } | |
106 } | 99 } |
107 | 100 |
108 void SetFrameLength(SpdySerializedFrame* frame, | 101 void SetFrameLength(SpdySerializedFrame* frame, |
109 size_t length, | 102 size_t length, |
110 SpdyMajorVersion spdy_version) { | 103 SpdyMajorVersion spdy_version) { |
111 switch (spdy_version) { | 104 CHECK_GT(1u << 14, length); |
112 case SPDY3: | 105 { |
113 CHECK_EQ(0u, length & ~kLengthMask); | 106 int32_t wire_length = base::HostToNet32(length); |
114 { | 107 memcpy(frame->data(), reinterpret_cast<char*>(&wire_length) + 1, 3); |
115 int32_t wire_length = base::HostToNet32(length); | |
116 // The length field in SPDY 3 is a 24-bit (3B) integer starting at | |
117 // offset 5. | |
118 memcpy(frame->data() + 5, reinterpret_cast<char*>(&wire_length) + 1, 3); | |
119 } | |
120 break; | |
121 case HTTP2: | |
122 CHECK_GT(1u<<14, length); | |
123 { | |
124 int32_t wire_length = base::HostToNet32(length); | |
125 memcpy(frame->data(), | |
126 reinterpret_cast<char*>(&wire_length) + 1, | |
127 3); | |
128 } | |
129 break; | |
130 default: | |
131 LOG(FATAL) << "Unsupported SPDY version."; | |
132 } | 108 } |
133 } | 109 } |
134 | 110 |
135 string a2b_hex(const char* hex_data) { | 111 string a2b_hex(const char* hex_data) { |
136 std::vector<uint8_t> output; | 112 std::vector<uint8_t> output; |
137 string result; | 113 string result; |
138 if (base::HexStringToBytes(hex_data, &output)) | 114 if (base::HexStringToBytes(hex_data, &output)) |
139 result.assign(reinterpret_cast<const char*>(&output[0]), output.size()); | 115 result.assign(reinterpret_cast<const char*>(&output[0]), output.size()); |
140 return result; | 116 return result; |
141 } | 117 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 bool TestServerPushDelegate::CancelPush(GURL url) { | 177 bool TestServerPushDelegate::CancelPush(GURL url) { |
202 auto itr = push_helpers.find(url); | 178 auto itr = push_helpers.find(url); |
203 DCHECK(itr != push_helpers.end()); | 179 DCHECK(itr != push_helpers.end()); |
204 itr->second->Cancel(); | 180 itr->second->Cancel(); |
205 push_helpers.erase(itr); | 181 push_helpers.erase(itr); |
206 return true; | 182 return true; |
207 } | 183 } |
208 | 184 |
209 } // namespace test | 185 } // namespace test |
210 } // namespace net | 186 } // namespace net |
OLD | NEW |