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 ids[] = { |
229 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x00000000), | 229 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x00000000), |
230 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xffffffff), | 230 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xffffffff), |
231 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xff000001), | 231 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xff000001), |
232 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0xffffffff), | |
233 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x01000002), | 232 SettingsFlagsAndId::FromWireFormat(spdy_version_, 0x01000002), |
234 SettingsFlagsAndId(3, 1) | 233 SettingsFlagsAndId(6, 9) |
235 }; | 234 }; |
236 | 235 |
237 for (size_t index = 0; index < arraysize(ids); ++index) { | 236 for (size_t index = 0; index < arraysize(ids); ++index) { |
238 settings.insert(settings.end(), std::make_pair(ids[index], index)); | 237 SettingsFlagsAndId flags_and_id = ids[index]; |
| 238 SpdySettingsIds id = static_cast<SpdySettingsIds>(flags_and_id.id()); |
| 239 SpdySettingsFlags flags = |
| 240 static_cast<SpdySettingsFlags>(flags_and_id.flags()); |
| 241 settings[id] = SettingsFlagsAndValue(flags, index); |
239 settings_frame.reset(framer.CreateSettings(settings)); | 242 settings_frame.reset(framer.CreateSettings(settings)); |
240 EXPECT_EQ(framer.protocol_version(), settings_frame->version()); | 243 EXPECT_EQ(framer.protocol_version(), settings_frame->version()); |
241 EXPECT_TRUE(settings_frame->is_control_frame()); | 244 EXPECT_TRUE(settings_frame->is_control_frame()); |
242 EXPECT_EQ(SETTINGS, settings_frame->type()); | 245 EXPECT_EQ(SETTINGS, settings_frame->type()); |
243 EXPECT_EQ(index + 1, settings_frame->num_entries()); | 246 EXPECT_EQ(index + 1, settings_frame->num_entries()); |
244 | 247 |
245 SpdySettings parsed_settings; | 248 SettingsMap parsed_settings; |
246 EXPECT_TRUE(framer.ParseSettings(settings_frame.get(), &parsed_settings)); | 249 EXPECT_TRUE(framer.ParseSettings(settings_frame.get(), &parsed_settings)); |
247 EXPECT_EQ(settings.size(), parsed_settings.size()); | 250 EXPECT_EQ(settings.size(), parsed_settings.size()); |
248 SpdySettings::const_iterator it = parsed_settings.begin(); | 251 SettingsMap::const_iterator it, it2; |
249 int pos = 0; | 252 for (it = parsed_settings.begin(); it != parsed_settings.end(); it++) { |
250 while (it != parsed_settings.end()) { | 253 it2 = settings.find(it->first); |
251 SettingsFlagsAndId parsed = it->first; | 254 EXPECT_EQ(it->first, it2->first); |
252 uint32 value = it->second; | 255 SettingsFlagsAndValue parsed = it->second; |
253 EXPECT_EQ(ids[pos].flags(), parsed.flags()); | 256 SettingsFlagsAndValue created = it2->second; |
254 EXPECT_EQ(ids[pos].id(), parsed.id()); | 257 EXPECT_EQ(created.first, parsed.first); |
255 EXPECT_EQ(static_cast<uint32>(pos), value); | 258 EXPECT_EQ(created.second, parsed.second); |
256 ++it; | |
257 ++pos; | |
258 } | 259 } |
259 } | 260 } |
260 } | 261 } |
261 | 262 |
262 TEST_P(SpdyProtocolTest, HasHeaderBlock) { | 263 TEST_P(SpdyProtocolTest, HasHeaderBlock) { |
263 SpdyControlFrame frame(SpdyControlFrame::kHeaderSize); | 264 SpdyControlFrame frame(SpdyControlFrame::kHeaderSize); |
264 for (SpdyControlType type = SYN_STREAM; | 265 for (SpdyControlType type = SYN_STREAM; |
265 type < NUM_CONTROL_FRAME_TYPES; | 266 type < NUM_CONTROL_FRAME_TYPES; |
266 type = static_cast<SpdyControlType>(type + 1)) { | 267 type = static_cast<SpdyControlType>(type + 1)) { |
267 frame.set_type(type); | 268 frame.set_type(type); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 383 |
383 rst_frame->set_status( | 384 rst_frame->set_status( |
384 static_cast<SpdyStatusCodes>(INVALID - 1)); | 385 static_cast<SpdyStatusCodes>(INVALID - 1)); |
385 EXPECT_EQ(INVALID, rst_frame->status()); | 386 EXPECT_EQ(INVALID, rst_frame->status()); |
386 | 387 |
387 rst_frame->set_status(NUM_STATUS_CODES); | 388 rst_frame->set_status(NUM_STATUS_CODES); |
388 EXPECT_EQ(INVALID, rst_frame->status()); | 389 EXPECT_EQ(INVALID, rst_frame->status()); |
389 } | 390 } |
390 | 391 |
391 } // namespace net | 392 } // namespace net |
OLD | NEW |