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_protocol.h" | 5 #include "net/spdy/spdy_protocol.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "net/spdy/spdy_bitmasks.h" | 8 #include "net/spdy/spdy_bitmasks.h" |
9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 frame.set_flags(5u); | 208 frame.set_flags(5u); |
209 EXPECT_EQ(5u, frame.flags()); | 209 EXPECT_EQ(5u, frame.flags()); |
210 EXPECT_EQ(length, frame.length()); | 210 EXPECT_EQ(length, frame.length()); |
211 } | 211 } |
212 | 212 |
213 // Test various types of SETTINGS frames. | 213 // Test various types of SETTINGS frames. |
214 TEST_P(SpdyProtocolTest, TestSpdySettingsFrame) { | 214 TEST_P(SpdyProtocolTest, TestSpdySettingsFrame) { |
215 SpdyFramer framer(spdy_version_); | 215 SpdyFramer framer(spdy_version_); |
216 | 216 |
217 // Create a settings frame with no settings. | 217 // Create a settings frame with no settings. |
218 SpdySettings settings; | 218 SettingsMap settings; |
219 scoped_ptr<SpdySettingsControlFrame> settings_frame( | 219 scoped_ptr<SpdySettingsControlFrame> settings_frame( |
220 framer.CreateSettings(settings)); | 220 framer.CreateSettings(settings)); |
221 EXPECT_EQ(framer.protocol_version(), settings_frame->version()); | 221 EXPECT_EQ(framer.protocol_version(), settings_frame->version()); |
222 EXPECT_TRUE(settings_frame->is_control_frame()); | 222 EXPECT_TRUE(settings_frame->is_control_frame()); |
223 EXPECT_EQ(SETTINGS, settings_frame->type()); | 223 EXPECT_EQ(SETTINGS, settings_frame->type()); |
224 EXPECT_EQ(0u, settings_frame->num_entries()); | 224 EXPECT_EQ(0u, settings_frame->num_entries()); |
225 | 225 |
226 // We'll add several different ID/Flag combinations and then verify | 226 // We'll add several different ID/Flag combinations and then verify |
227 // that they encode and decode properly. | 227 // that they encode and decode properly. |
228 SettingsFlagsAndId ids[] = { | 228 SettingsFlagsAndId spdy2_ids[] = { |
229 // id = 0, flags = 0. | |
229 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x00000000), | 230 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x00000000), |
231 // id = 1, flags = 0xff. | |
232 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xff000001), | |
233 // id = 2, flags = 1. | |
234 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x01000002), | |
235 // id = 9, flags = 6. | |
236 SettingsFlagsAndId(6, 9), | |
237 // id = 0x00ffffff, flags = 0xff. | |
230 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xffffffff), | 238 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xffffffff), |
231 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xff000001), | |
232 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xffffffff), | |
233 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x01000002), | |
234 SettingsFlagsAndId(3, 1) | |
235 }; | 239 }; |
236 | 240 |
237 for (size_t index = 0; index < arraysize(ids); ++index) { | 241 SettingsFlagsAndId spdy3_ids[] = { |
238 settings.insert(settings.end(), std::make_pair(ids[index], index)); | 242 // id = 0, flags = 0. |
243 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x00000000), | |
244 // id = 1, flags = 2. | |
245 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x01000002), | |
246 // id = 9, flags = 6. | |
247 SettingsFlagsAndId(6, 9), | |
248 // id = 0xff, flags = 1. | |
249 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xff000001), | |
250 // id = 0x00ffffff, flags = 0xff. | |
251 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xffffffff), | |
252 }; | |
Ryan Hamilton
2012/04/12 17:11:21
How come the spdy2 and spdy3 settings are separate
ramant (doing other things)
2012/04/12 18:35:59
In the map, settings are stored in sorted order ba
Ryan Hamilton
2012/04/17 02:32:49
Perhaps I'm missing something, but it looks like b
ramant (doing other things)
2012/04/17 18:48:19
(sorry if already known)
We get data out of "ids"
| |
253 | |
254 SettingsFlagsAndId* ids; | |
255 size_t settings_size; | |
256 if (IsSpdy2()) { | |
257 ids = &spdy2_ids[0]; | |
258 settings_size = arraysize(spdy2_ids); | |
259 } else { | |
260 ids = &spdy3_ids[0]; | |
261 settings_size = arraysize(spdy3_ids); | |
262 } | |
263 | |
264 for (size_t index = 0; index < settings_size; ++index) { | |
265 SettingsFlagsAndId flags_and_id = ids[index]; | |
266 SpdySettingsIds id = static_cast<SpdySettingsIds>(flags_and_id.id()); | |
267 SpdySettingsFlags flags = | |
268 static_cast<SpdySettingsFlags>(flags_and_id.flags()); | |
269 settings[id] = SettingsFlagsAndValue(flags, index); | |
239 settings_frame.reset(framer.CreateSettings(settings)); | 270 settings_frame.reset(framer.CreateSettings(settings)); |
240 EXPECT_EQ(framer.protocol_version(), settings_frame->version()); | 271 EXPECT_EQ(framer.protocol_version(), settings_frame->version()); |
241 EXPECT_TRUE(settings_frame->is_control_frame()); | 272 EXPECT_TRUE(settings_frame->is_control_frame()); |
242 EXPECT_EQ(SETTINGS, settings_frame->type()); | 273 EXPECT_EQ(SETTINGS, settings_frame->type()); |
243 EXPECT_EQ(index + 1, settings_frame->num_entries()); | 274 EXPECT_EQ(index + 1, settings_frame->num_entries()); |
244 | 275 |
245 SpdySettings parsed_settings; | 276 SettingsMap parsed_settings; |
246 EXPECT_TRUE(framer.ParseSettings(settings_frame.get(), &parsed_settings)); | 277 EXPECT_TRUE(framer.ParseSettings(settings_frame.get(), &parsed_settings)); |
247 EXPECT_EQ(settings.size(), parsed_settings.size()); | 278 EXPECT_EQ(settings.size(), parsed_settings.size()); |
248 SpdySettings::const_iterator it = parsed_settings.begin(); | 279 SettingsMap::const_iterator it = parsed_settings.begin(); |
249 int pos = 0; | 280 int pos = 0; |
250 while (it != parsed_settings.end()) { | 281 while (it != parsed_settings.end()) { |
251 SettingsFlagsAndId parsed = it->first; | 282 SpdySettingsIds parsed_id = it->first; |
252 uint32 value = it->second; | 283 SettingsFlagsAndValue parsed = it->second; |
253 EXPECT_EQ(ids[pos].flags(), parsed.flags()); | 284 EXPECT_EQ(ids[pos].flags(), static_cast<uint8>(parsed.first)); |
254 EXPECT_EQ(ids[pos].id(), parsed.id()); | 285 EXPECT_EQ(ids[pos].id(), static_cast<uint32>(parsed_id)); |
255 EXPECT_EQ(static_cast<uint32>(pos), value); | 286 EXPECT_EQ(static_cast<uint32>(pos), parsed.second); |
256 ++it; | 287 ++it; |
257 ++pos; | 288 ++pos; |
258 } | 289 } |
259 } | 290 } |
260 } | 291 } |
261 | 292 |
262 TEST_P(SpdyProtocolTest, HasHeaderBlock) { | 293 TEST_P(SpdyProtocolTest, HasHeaderBlock) { |
263 SpdyControlFrame frame(SpdyControlFrame::kHeaderSize); | 294 SpdyControlFrame frame(SpdyControlFrame::kHeaderSize); |
264 for (SpdyControlType type = SYN_STREAM; | 295 for (SpdyControlType type = SYN_STREAM; |
265 type < NUM_CONTROL_FRAME_TYPES; | 296 type < NUM_CONTROL_FRAME_TYPES; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 | 413 |
383 rst_frame->set_status( | 414 rst_frame->set_status( |
384 static_cast<SpdyStatusCodes>(INVALID - 1)); | 415 static_cast<SpdyStatusCodes>(INVALID - 1)); |
385 EXPECT_EQ(INVALID, rst_frame->status()); | 416 EXPECT_EQ(INVALID, rst_frame->status()); |
386 | 417 |
387 rst_frame->set_status(NUM_STATUS_CODES); | 418 rst_frame->set_status(NUM_STATUS_CODES); |
388 EXPECT_EQ(INVALID, rst_frame->status()); | 419 EXPECT_EQ(INVALID, rst_frame->status()); |
389 } | 420 } |
390 | 421 |
391 } // namespace net | 422 } // namespace net |
OLD | NEW |