| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_network_transaction.h" | 5 #include "net/spdy/spdy_network_transaction.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "net/spdy/spdy_framer.h" | 21 #include "net/spdy/spdy_framer.h" |
| 22 #include "net/spdy/spdy_http_stream.h" | 22 #include "net/spdy/spdy_http_stream.h" |
| 23 #include "net/spdy/spdy_protocol.h" | 23 #include "net/spdy/spdy_protocol.h" |
| 24 #include "net/spdy/spdy_test_util.h" | 24 #include "net/spdy/spdy_test_util.h" |
| 25 #include "testing/platform_test.h" | 25 #include "testing/platform_test.h" |
| 26 | 26 |
| 27 //----------------------------------------------------------------------------- | 27 //----------------------------------------------------------------------------- |
| 28 | 28 |
| 29 namespace net { | 29 namespace net { |
| 30 | 30 |
| 31 // NOTE: In GCC, on a Mac, this can't be in an anonymous namespace! | |
| 32 // This struct holds information used to construct spdy control and data frames. | |
| 33 struct SpdyHeaderInfo { | |
| 34 int kind; | |
| 35 spdy::SpdyStreamId id; | |
| 36 spdy::SpdyStreamId assoc_id; | |
| 37 int priority; | |
| 38 spdy::SpdyControlFlags control_flags; | |
| 39 bool compressed; | |
| 40 int status; | |
| 41 const char* data; | |
| 42 uint32 data_length; | |
| 43 spdy::SpdyDataFlags data_flags; | |
| 44 }; | |
| 45 | |
| 46 namespace { | 31 namespace { |
| 47 | 32 |
| 48 // Helper to manage the lifetimes of the dependencies for a | 33 // Helper to manage the lifetimes of the dependencies for a |
| 49 // SpdyNetworkTransaction. | 34 // SpdyNetworkTransaction. |
| 50 class SessionDependencies { | 35 class SessionDependencies { |
| 51 public: | 36 public: |
| 52 // Default set of dependencies -- "null" proxy service. | 37 // Default set of dependencies -- "null" proxy service. |
| 53 SessionDependencies() | 38 SessionDependencies() |
| 54 : host_resolver(new MockHostResolver), | 39 : host_resolver(new MockHostResolver), |
| 55 proxy_service(ProxyService::CreateNull()), | 40 proxy_service(ProxyService::CreateNull()), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 86 session_deps->host_resolver, | 71 session_deps->host_resolver, |
| 87 session_deps->proxy_service, | 72 session_deps->proxy_service, |
| 88 &session_deps->socket_factory, | 73 &session_deps->socket_factory, |
| 89 session_deps->ssl_config_service, | 74 session_deps->ssl_config_service, |
| 90 session_deps->spdy_session_pool, | 75 session_deps->spdy_session_pool, |
| 91 session_deps->http_auth_handler_factory.get(), | 76 session_deps->http_auth_handler_factory.get(), |
| 92 NULL, | 77 NULL, |
| 93 NULL); | 78 NULL); |
| 94 } | 79 } |
| 95 | 80 |
| 96 // Chop a frame into an array of MockWrites. | |
| 97 // |data| is the frame to chop. | |
| 98 // |length| is the length of the frame to chop. | |
| 99 // |num_chunks| is the number of chunks to create. | |
| 100 MockWrite* ChopFrame(const char* data, int length, int num_chunks) { | |
| 101 MockWrite* chunks = new MockWrite[num_chunks]; | |
| 102 int chunk_size = length / num_chunks; | |
| 103 for (int index = 0; index < num_chunks; index++) { | |
| 104 const char* ptr = data + (index * chunk_size); | |
| 105 if (index == num_chunks - 1) | |
| 106 chunk_size += length % chunk_size; // The last chunk takes the remainder. | |
| 107 chunks[index] = MockWrite(true, ptr, chunk_size); | |
| 108 } | |
| 109 return chunks; | |
| 110 } | |
| 111 | |
| 112 // ---------------------------------------------------------------------------- | |
| 113 | |
| 114 // Adds headers and values to a map. | |
| 115 // |extra_headers| is an array of { name, value } pairs, arranged as strings | |
| 116 // where the even entries are the header names, and the odd entries are the | |
| 117 // header values. | |
| 118 // |headers| gets filled in from |extra_headers|. | |
| 119 void AppendHeadersToSpdyFrame(const char* const extra_headers[], | |
| 120 int extra_header_count, | |
| 121 spdy::SpdyHeaderBlock* headers) { | |
| 122 std::string this_header; | |
| 123 std::string this_value; | |
| 124 | |
| 125 if (!extra_header_count) | |
| 126 return; | |
| 127 | |
| 128 // Sanity check: Non-NULL header list. | |
| 129 DCHECK(NULL != extra_headers) << "NULL header value pair list"; | |
| 130 // Sanity check: Non-NULL header map. | |
| 131 DCHECK(NULL != headers) << "NULL header map"; | |
| 132 // Copy in the headers. | |
| 133 for (int i = 0; i < extra_header_count; i++) { | |
| 134 // Sanity check: Non-empty header. | |
| 135 DCHECK_NE('\0', *extra_headers[i * 2]) << "Empty header value pair"; | |
| 136 this_header = extra_headers[i * 2]; | |
| 137 std::string::size_type header_len = this_header.length(); | |
| 138 if (!header_len) | |
| 139 continue; | |
| 140 this_value = extra_headers[1 + (i * 2)]; | |
| 141 std::string new_value; | |
| 142 if (headers->find(this_header) != headers->end()) { | |
| 143 // More than one entry in the header. | |
| 144 // Don't add the header again, just the append to the value, | |
| 145 // separated by a NULL character. | |
| 146 | |
| 147 // Adjust the value. | |
| 148 new_value = (*headers)[this_header]; | |
| 149 // Put in a NULL separator. | |
| 150 new_value.append(1, '\0'); | |
| 151 // Append the new value. | |
| 152 new_value += this_value; | |
| 153 } else { | |
| 154 // Not a duplicate, just write the value. | |
| 155 new_value = this_value; | |
| 156 } | |
| 157 (*headers)[this_header] = new_value; | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 // Writes |str| of the given |len| to the buffer pointed to by |buffer_handle|. | |
| 162 // Uses a template so buffer_handle can be a char* or an unsigned char*. | |
| 163 // Updates the |*buffer_handle| pointer by |len| | |
| 164 // Returns the number of bytes written into *|buffer_handle| | |
| 165 template<class T> | |
| 166 int AppendToBuffer(const void* str, | |
| 167 int len, | |
| 168 T** buffer_handle, | |
| 169 int* buffer_len_remaining) { | |
| 170 if (len <= 0) | |
| 171 return 0; | |
| 172 DCHECK(NULL != buffer_handle) << "NULL buffer handle"; | |
| 173 DCHECK(NULL != *buffer_handle) << "NULL pointer"; | |
| 174 DCHECK(NULL != buffer_len_remaining) | |
| 175 << "NULL buffer remainder length pointer"; | |
| 176 DCHECK_GE(*buffer_len_remaining, len) << "Insufficient buffer size"; | |
| 177 memcpy(*buffer_handle, str, len); | |
| 178 *buffer_handle += len; | |
| 179 *buffer_len_remaining -= len; | |
| 180 return len; | |
| 181 } | |
| 182 | |
| 183 // Writes |val| to a location of size |len|, in big-endian format. | |
| 184 // in the buffer pointed to by |buffer_handle|. | |
| 185 // Updates the |*buffer_handle| pointer by |len| | |
| 186 // Returns the number of bytes written | |
| 187 int AppendToBuffer(int val, | |
| 188 int len, | |
| 189 unsigned char** buffer_handle, | |
| 190 int* buffer_len_remaining) { | |
| 191 if (len <= 0) | |
| 192 return 0; | |
| 193 DCHECK((size_t) len <= sizeof(len)) << "Data length too long for data type"; | |
| 194 DCHECK(NULL != buffer_handle) << "NULL buffer handle"; | |
| 195 DCHECK(NULL != *buffer_handle) << "NULL pointer"; | |
| 196 DCHECK(NULL != buffer_len_remaining) | |
| 197 << "NULL buffer remainder length pointer"; | |
| 198 DCHECK_GE(*buffer_len_remaining, len) << "Insufficient buffer size"; | |
| 199 for (int i = 0; i < len; i++) { | |
| 200 int shift = (8 * (len - (i + 1))); | |
| 201 unsigned char val_chunk = (val >> shift) & 0x0FF; | |
| 202 *(*buffer_handle)++ = val_chunk; | |
| 203 *buffer_len_remaining += 1; | |
| 204 } | |
| 205 return len; | |
| 206 } | |
| 207 | |
| 208 // Construct a SPDY packet. | |
| 209 // |head| is the start of the packet, up to but not including | |
| 210 // the header value pairs. | |
| 211 // |extra_headers| are the extra header-value pairs, which typically | |
| 212 // will vary the most between calls. | |
| 213 // |tail| is any (relatively constant) header-value pairs to add. | |
| 214 // |buffer| is the buffer we're filling in. | |
| 215 // Returns a SpdFrame. | |
| 216 spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo* header_info, | |
| 217 const char* const extra_headers[], | |
| 218 int extra_header_count, | |
| 219 const char* const tail[], | |
| 220 int tail_header_count) { | |
| 221 spdy::SpdyFramer framer; | |
| 222 spdy::SpdyHeaderBlock headers; | |
| 223 // Copy in the extra headers to our map. | |
| 224 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers); | |
| 225 // Copy in the tail headers to our map. | |
| 226 if (tail && tail_header_count) | |
| 227 AppendHeadersToSpdyFrame(tail, tail_header_count, &headers); | |
| 228 spdy::SpdyFrame* frame = NULL; | |
| 229 switch (header_info->kind) { | |
| 230 case spdy::SYN_STREAM: | |
| 231 frame = framer.CreateSynStream(header_info->id, header_info->assoc_id, | |
| 232 header_info->priority, | |
| 233 header_info->control_flags, | |
| 234 header_info->compressed, &headers); | |
| 235 break; | |
| 236 case spdy::SYN_REPLY: | |
| 237 frame = framer.CreateSynReply(header_info->id, header_info->control_flags, | |
| 238 header_info->compressed, &headers); | |
| 239 break; | |
| 240 case spdy::RST_STREAM: | |
| 241 frame = framer.CreateRstStream(header_info->id, header_info->status); | |
| 242 break; | |
| 243 default: | |
| 244 frame = framer.CreateDataFrame(header_info->id, header_info->data, | |
| 245 header_info->data_length, | |
| 246 header_info->data_flags); | |
| 247 break; | |
| 248 } | |
| 249 return frame; | |
| 250 } | |
| 251 | |
| 252 // Construct an expected SPDY reply string. | |
| 253 // |extra_headers| are the extra header-value pairs, which typically | |
| 254 // will vary the most between calls. | |
| 255 // |buffer| is the buffer we're filling in. | |
| 256 // Returns the number of bytes written into |buffer|. | |
| 257 int ConstructSpdyReply(const char* const extra_headers[], | |
| 258 int extra_header_count, | |
| 259 char* buffer, | |
| 260 int buffer_length) { | |
| 261 int packet_size = 0; | |
| 262 int header_count = 0; | |
| 263 char* buffer_write = buffer; | |
| 264 int buffer_left = buffer_length; | |
| 265 spdy::SpdyHeaderBlock headers; | |
| 266 if (!buffer || !buffer_length) | |
| 267 return 0; | |
| 268 // Copy in the extra headers. | |
| 269 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers); | |
| 270 header_count = headers.size(); | |
| 271 // The iterator gets us the list of header/value pairs in sorted order. | |
| 272 spdy::SpdyHeaderBlock::iterator next = headers.begin(); | |
| 273 spdy::SpdyHeaderBlock::iterator last = headers.end(); | |
| 274 for ( ; next != last; ++next) { | |
| 275 // Write the header. | |
| 276 int value_len, current_len, offset; | |
| 277 const char* header_string = next->first.c_str(); | |
| 278 packet_size += AppendToBuffer(header_string, | |
| 279 next->first.length(), | |
| 280 &buffer_write, | |
| 281 &buffer_left); | |
| 282 packet_size += AppendToBuffer(": ", | |
| 283 strlen(": "), | |
| 284 &buffer_write, | |
| 285 &buffer_left); | |
| 286 // Write the value(s). | |
| 287 const char* value_string = next->second.c_str(); | |
| 288 // Check if it's split among two or more values. | |
| 289 value_len = next->second.length(); | |
| 290 current_len = strlen(value_string); | |
| 291 offset = 0; | |
| 292 // Handle the first N-1 values. | |
| 293 while (current_len < value_len) { | |
| 294 // Finish this line -- write the current value. | |
| 295 packet_size += AppendToBuffer(value_string + offset, | |
| 296 current_len - offset, | |
| 297 &buffer_write, | |
| 298 &buffer_left); | |
| 299 packet_size += AppendToBuffer("\n", | |
| 300 strlen("\n"), | |
| 301 &buffer_write, | |
| 302 &buffer_left); | |
| 303 // Advance to next value. | |
| 304 offset = current_len + 1; | |
| 305 current_len += 1 + strlen(value_string + offset); | |
| 306 // Start another line -- add the header again. | |
| 307 packet_size += AppendToBuffer(header_string, | |
| 308 next->first.length(), | |
| 309 &buffer_write, | |
| 310 &buffer_left); | |
| 311 packet_size += AppendToBuffer(": ", | |
| 312 strlen(": "), | |
| 313 &buffer_write, | |
| 314 &buffer_left); | |
| 315 } | |
| 316 EXPECT_EQ(value_len, current_len); | |
| 317 // Copy the last (or only) value. | |
| 318 packet_size += AppendToBuffer(value_string + offset, | |
| 319 value_len - offset, | |
| 320 &buffer_write, | |
| 321 &buffer_left); | |
| 322 packet_size += AppendToBuffer("\n", | |
| 323 strlen("\n"), | |
| 324 &buffer_write, | |
| 325 &buffer_left); | |
| 326 } | |
| 327 return packet_size; | |
| 328 } | |
| 329 | |
| 330 // Construct an expected SPDY SETTINGS frame. | |
| 331 // |settings| are the settings to set. | |
| 332 // Returns the constructed frame. The caller takes ownership of the frame. | |
| 333 spdy::SpdyFrame* ConstructSpdySettings(spdy::SpdySettings settings) { | |
| 334 spdy::SpdyFramer framer; | |
| 335 return framer.CreateSettings(settings); | |
| 336 } | |
| 337 | |
| 338 // Construct a single SPDY header entry, for validation. | |
| 339 // |extra_headers| are the extra header-value pairs. | |
| 340 // |buffer| is the buffer we're filling in. | |
| 341 // |index| is the index of the header we want. | |
| 342 // Returns the number of bytes written into |buffer|. | |
| 343 int ConstructSpdyHeader(const char* const extra_headers[], | |
| 344 int extra_header_count, | |
| 345 char* buffer, | |
| 346 int buffer_length, | |
| 347 int index) { | |
| 348 const char* this_header = NULL; | |
| 349 const char* this_value = NULL; | |
| 350 if (!buffer || !buffer_length) | |
| 351 return 0; | |
| 352 *buffer = '\0'; | |
| 353 // Sanity check: Non-empty header list. | |
| 354 DCHECK(NULL != extra_headers) << "NULL extra headers pointer"; | |
| 355 // Sanity check: Index out of range. | |
| 356 DCHECK((index >= 0) && (index < extra_header_count)) | |
| 357 << "Index " << index | |
| 358 << " out of range [0, " << extra_header_count << ")"; | |
| 359 this_header = extra_headers[index * 2]; | |
| 360 // Sanity check: Non-empty header. | |
| 361 if (!*this_header) | |
| 362 return 0; | |
| 363 std::string::size_type header_len = strlen(this_header); | |
| 364 if (!header_len) | |
| 365 return 0; | |
| 366 this_value = extra_headers[1 + (index * 2)]; | |
| 367 // Sanity check: Non-empty value. | |
| 368 if (!*this_value) | |
| 369 this_value = ""; | |
| 370 int n = base::snprintf(buffer, | |
| 371 buffer_length, | |
| 372 "%s: %s\r\n", | |
| 373 this_header, | |
| 374 this_value); | |
| 375 return n; | |
| 376 } | |
| 377 | |
| 378 // Constructs a standard SPDY GET packet. | |
| 379 // |extra_headers| are the extra header-value pairs, which typically | |
| 380 // will vary the most between calls. | |
| 381 // Returns a SpdFrame. | |
| 382 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | |
| 383 int extra_header_count) { | |
| 384 SpdyHeaderInfo SynStartHeader = { | |
| 385 spdy::SYN_STREAM, // Kind = Syn | |
| 386 1, // Stream ID | |
| 387 0, // Associated stream ID | |
| 388 3, // Priority | |
| 389 spdy::CONTROL_FLAG_FIN, // Control Flags | |
| 390 false, // Compressed | |
| 391 200, // Status | |
| 392 NULL, // Data | |
| 393 0, // Length | |
| 394 spdy::DATA_FLAG_NONE // Data Flags | |
| 395 }; | |
| 396 static const char* const kStandardGetHeaders[] = { | |
| 397 "method", | |
| 398 "GET", | |
| 399 "url", | |
| 400 "http://www.google.com/", | |
| 401 "version", | |
| 402 "HTTP/1.1" | |
| 403 }; | |
| 404 return ConstructSpdyPacket( | |
| 405 &SynStartHeader, | |
| 406 extra_headers, | |
| 407 extra_header_count, | |
| 408 kStandardGetHeaders, | |
| 409 arraysize(kStandardGetHeaders) / 2); | |
| 410 } | |
| 411 | |
| 412 } // namespace | 81 } // namespace |
| 413 | 82 |
| 414 class SpdyNetworkTransactionTest : public PlatformTest { | 83 class SpdyNetworkTransactionTest : public PlatformTest { |
| 415 protected: | 84 protected: |
| 416 virtual void SetUp() { | 85 virtual void SetUp() { |
| 417 // By default, all tests turn off compression. | 86 // By default, all tests turn off compression. |
| 418 EnableCompression(false); | 87 EnableCompression(false); |
| 419 google_get_request_initialized_ = false; | 88 google_get_request_initialized_ = false; |
| 420 } | 89 } |
| 421 | 90 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 186 |
| 518 // Verify SpdyNetworkTransaction constructor. | 187 // Verify SpdyNetworkTransaction constructor. |
| 519 TEST_F(SpdyNetworkTransactionTest, Constructor) { | 188 TEST_F(SpdyNetworkTransactionTest, Constructor) { |
| 520 SessionDependencies session_deps; | 189 SessionDependencies session_deps; |
| 521 scoped_refptr<HttpNetworkSession> session = | 190 scoped_refptr<HttpNetworkSession> session = |
| 522 CreateSession(&session_deps); | 191 CreateSession(&session_deps); |
| 523 scoped_ptr<HttpTransaction> trans(new SpdyNetworkTransaction(session)); | 192 scoped_ptr<HttpTransaction> trans(new SpdyNetworkTransaction(session)); |
| 524 } | 193 } |
| 525 | 194 |
| 526 TEST_F(SpdyNetworkTransactionTest, Get) { | 195 TEST_F(SpdyNetworkTransactionTest, Get) { |
| 527 MockWrite writes[] = { | 196 // Construct the request. |
| 528 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 197 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 529 arraysize(kGetSyn)), | 198 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 530 }; | |
| 531 | 199 |
| 200 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 532 MockRead reads[] = { | 201 MockRead reads[] = { |
| 533 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 202 CreateMockRead(resp.get()), |
| 534 arraysize(kGetSynReply)), | |
| 535 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 203 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 536 arraysize(kGetBodyFrame)), | 204 arraysize(kGetBodyFrame)), |
| 537 MockRead(true, 0, 0) // EOF | 205 MockRead(true, 0, 0) // EOF |
| 538 }; | 206 }; |
| 539 | 207 |
| 540 scoped_refptr<DelayedSocketData> data( | 208 scoped_refptr<DelayedSocketData> data( |
| 541 new DelayedSocketData(1, reads, arraysize(reads), | 209 new DelayedSocketData(1, reads, arraysize(reads), |
| 542 writes, arraysize(writes))); | 210 writes, arraysize(writes))); |
| 543 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), | 211 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), |
| 544 data.get(), | 212 data.get(), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 EXPECT_EQ("hello!", out.response_data); | 252 EXPECT_EQ("hello!", out.response_data); |
| 585 } | 253 } |
| 586 | 254 |
| 587 // Test that a simple POST works. | 255 // Test that a simple POST works. |
| 588 TEST_F(SpdyNetworkTransactionTest, EmptyPost) { | 256 TEST_F(SpdyNetworkTransactionTest, EmptyPost) { |
| 589 static const unsigned char kEmptyPostSyn[] = { | 257 static const unsigned char kEmptyPostSyn[] = { |
| 590 0x80, 0x01, 0x00, 0x01, // header | 258 0x80, 0x01, 0x00, 0x01, // header |
| 591 0x01, 0x00, 0x00, 0x4a, // flags, len | 259 0x01, 0x00, 0x00, 0x4a, // flags, len |
| 592 0x00, 0x00, 0x00, 0x01, // stream id | 260 0x00, 0x00, 0x00, 0x01, // stream id |
| 593 0x00, 0x00, 0x00, 0x00, // associated | 261 0x00, 0x00, 0x00, 0x00, // associated |
| 594 0xc0, 0x00, 0x00, 0x03, // 4 headers | 262 0xc0, 0x00, 0x00, 0x03, // 3 headers |
| 595 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', | 263 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', |
| 596 0x00, 0x04, 'P', 'O', 'S', 'T', | 264 0x00, 0x04, 'P', 'O', 'S', 'T', |
| 597 0x00, 0x03, 'u', 'r', 'l', | 265 0x00, 0x03, 'u', 'r', 'l', |
| 598 0x00, 0x16, 'h', 't', 't', 'p', ':', '/', '/', 'w', 'w', 'w', | 266 0x00, 0x16, 'h', 't', 't', 'p', ':', '/', '/', 'w', 'w', 'w', |
| 599 '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', | 267 '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', |
| 600 'm', '/', | 268 'm', '/', |
| 601 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', | 269 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', |
| 602 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', | 270 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', |
| 603 }; | 271 }; |
| 604 | 272 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 | 352 |
| 685 // Test that the transaction doesn't crash when we get two replies on the same | 353 // Test that the transaction doesn't crash when we get two replies on the same |
| 686 // stream ID. See http://crbug.com/45639. | 354 // stream ID. See http://crbug.com/45639. |
| 687 TEST_F(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { | 355 TEST_F(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { |
| 688 SessionDependencies session_deps; | 356 SessionDependencies session_deps; |
| 689 HttpNetworkSession* session = CreateSession(&session_deps); | 357 HttpNetworkSession* session = CreateSession(&session_deps); |
| 690 | 358 |
| 691 // We disable SSL for this test. | 359 // We disable SSL for this test. |
| 692 SpdySession::SetSSLMode(false); | 360 SpdySession::SetSSLMode(false); |
| 693 | 361 |
| 694 MockWrite writes[] = { | 362 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 695 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 363 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 696 arraysize(kGetSyn)), | |
| 697 }; | |
| 698 | 364 |
| 365 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 699 MockRead reads[] = { | 366 MockRead reads[] = { |
| 700 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 367 CreateMockRead(resp.get()), |
| 701 arraysize(kGetSynReply)), | 368 CreateMockRead(resp.get()), |
| 702 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | |
| 703 arraysize(kGetSynReply)), | |
| 704 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 369 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 705 arraysize(kGetBodyFrame)), | 370 arraysize(kGetBodyFrame)), |
| 706 MockRead(true, 0, 0) // EOF | 371 MockRead(true, 0, 0) // EOF |
| 707 }; | 372 }; |
| 708 | 373 |
| 709 HttpRequestInfo request; | 374 HttpRequestInfo request; |
| 710 request.method = "GET"; | 375 request.method = "GET"; |
| 711 request.url = GURL("http://www.google.com/"); | 376 request.url = GURL("http://www.google.com/"); |
| 712 request.load_flags = 0; | 377 request.load_flags = 0; |
| 713 scoped_refptr<DelayedSocketData> data( | 378 scoped_refptr<DelayedSocketData> data( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 726 | 391 |
| 727 const HttpResponseInfo* response = trans->GetResponseInfo(); | 392 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 728 EXPECT_TRUE(response->headers != NULL); | 393 EXPECT_TRUE(response->headers != NULL); |
| 729 EXPECT_TRUE(response->was_fetched_via_spdy); | 394 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 730 std::string response_data; | 395 std::string response_data; |
| 731 rv = ReadTransaction(trans.get(), &response_data); | 396 rv = ReadTransaction(trans.get(), &response_data); |
| 732 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); | 397 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); |
| 733 } | 398 } |
| 734 | 399 |
| 735 TEST_F(SpdyNetworkTransactionTest, CancelledTransaction) { | 400 TEST_F(SpdyNetworkTransactionTest, CancelledTransaction) { |
| 401 // Construct the request. |
| 402 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 736 MockWrite writes[] = { | 403 MockWrite writes[] = { |
| 737 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 404 CreateMockWrite(req.get()), |
| 738 arraysize(kGetSyn)), | |
| 739 MockRead(true, 0, 0) // EOF | 405 MockRead(true, 0, 0) // EOF |
| 740 }; | 406 }; |
| 741 | 407 |
| 408 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 742 MockRead reads[] = { | 409 MockRead reads[] = { |
| 743 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 410 CreateMockRead(resp.get()), |
| 744 arraysize(kGetSynReply)), | |
| 745 // This following read isn't used by the test, except during the | 411 // This following read isn't used by the test, except during the |
| 746 // RunAllPending() call at the end since the SpdySession survives the | 412 // RunAllPending() call at the end since the SpdySession survives the |
| 747 // SpdyNetworkTransaction and still tries to continue Read()'ing. Any | 413 // SpdyNetworkTransaction and still tries to continue Read()'ing. Any |
| 748 // MockRead will do here. | 414 // MockRead will do here. |
| 749 MockRead(true, 0, 0) // EOF | 415 MockRead(true, 0, 0) // EOF |
| 750 }; | 416 }; |
| 751 | 417 |
| 752 // We disable SSL for this test. | 418 // We disable SSL for this test. |
| 753 SpdySession::SetSSLMode(false); | 419 SpdySession::SetSSLMode(false); |
| 754 | 420 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 784 } | 450 } |
| 785 | 451 |
| 786 private: | 452 private: |
| 787 const SpdyNetworkTransaction* trans; | 453 const SpdyNetworkTransaction* trans; |
| 788 }; | 454 }; |
| 789 | 455 |
| 790 // Verify that the client can correctly deal with the user callback deleting the | 456 // Verify that the client can correctly deal with the user callback deleting the |
| 791 // transaction. Failures will usually be valgrind errors. See | 457 // transaction. Failures will usually be valgrind errors. See |
| 792 // http://crbug.com/46925 | 458 // http://crbug.com/46925 |
| 793 TEST_F(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { | 459 TEST_F(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { |
| 794 MockWrite writes[] = { | 460 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 795 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 461 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 796 arraysize(kGetSyn), 1), | |
| 797 }; | |
| 798 | 462 |
| 463 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 799 MockRead reads[] = { | 464 MockRead reads[] = { |
| 800 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 465 CreateMockRead(resp.get(), 2), |
| 801 arraysize(kGetSynReply), 2), | |
| 802 MockRead(true, ERR_IO_PENDING, 3), // Force a pause | 466 MockRead(true, ERR_IO_PENDING, 3), // Force a pause |
| 803 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 467 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 804 arraysize(kGetBodyFrame), 4), | 468 arraysize(kGetBodyFrame), 4), |
| 805 MockRead(true, 0, 0, 5), // EOF | 469 MockRead(true, 0, 0, 5), // EOF |
| 806 }; | 470 }; |
| 807 | 471 |
| 808 HttpRequestInfo request; | 472 HttpRequestInfo request; |
| 809 request.method = "GET"; | 473 request.method = "GET"; |
| 810 request.url = GURL("http://www.google.com/"); | 474 request.url = GURL("http://www.google.com/"); |
| 811 request.load_flags = 0; | 475 request.load_flags = 0; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 // name/value pair. The comma-separated list is just a single value. | 578 // name/value pair. The comma-separated list is just a single value. |
| 915 { syn_reply3, sizeof(syn_reply3), | 579 { syn_reply3, sizeof(syn_reply3), |
| 916 "cookie: val1,val2\n" | 580 "cookie: val1,val2\n" |
| 917 "status: 200\n" | 581 "status: 200\n" |
| 918 "url: /index.php\n" | 582 "url: /index.php\n" |
| 919 "version: HTTP/1.1\n" | 583 "version: HTTP/1.1\n" |
| 920 } | 584 } |
| 921 }; | 585 }; |
| 922 | 586 |
| 923 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 587 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 924 MockWrite writes[] = { | 588 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 925 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 589 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 926 arraysize(kGetSyn)), | |
| 927 }; | |
| 928 | 590 |
| 929 MockRead reads[] = { | 591 MockRead reads[] = { |
| 930 MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), | 592 MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), |
| 931 test_cases[i].syn_reply_length), | 593 test_cases[i].syn_reply_length), |
| 932 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 594 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 933 arraysize(kGetBodyFrame)), | 595 arraysize(kGetBodyFrame)), |
| 934 MockRead(true, 0, 0) // EOF | 596 MockRead(true, 0, 0) // EOF |
| 935 }; | 597 }; |
| 936 | 598 |
| 937 scoped_refptr<DelayedSocketData> data( | 599 scoped_refptr<DelayedSocketData> data( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 958 } | 620 } |
| 959 } | 621 } |
| 960 | 622 |
| 961 // Verify that various SynReply headers parse vary fields correctly | 623 // Verify that various SynReply headers parse vary fields correctly |
| 962 // through the HTTP layer, and the response matches the request. | 624 // through the HTTP layer, and the response matches the request. |
| 963 TEST_F(SpdyNetworkTransactionTest, SynReplyHeadersVary) { | 625 TEST_F(SpdyNetworkTransactionTest, SynReplyHeadersVary) { |
| 964 static const SpdyHeaderInfo syn_reply_info = { | 626 static const SpdyHeaderInfo syn_reply_info = { |
| 965 spdy::SYN_REPLY, // Syn Reply | 627 spdy::SYN_REPLY, // Syn Reply |
| 966 1, // Stream ID | 628 1, // Stream ID |
| 967 0, // Associated Stream ID | 629 0, // Associated Stream ID |
| 968 3, // Priority | 630 SPDY_PRIORITY_LOWEST, // Priority |
| 969 spdy::CONTROL_FLAG_NONE, // Control Flags | 631 spdy::CONTROL_FLAG_NONE, // Control Flags |
| 970 false, // Compressed | 632 false, // Compressed |
| 971 200, // Status | 633 spdy::INVALID, // Status |
| 972 NULL, // Data | 634 NULL, // Data |
| 973 0, // Data Length | 635 0, // Data Length |
| 974 spdy::DATA_FLAG_NONE // Data Flags | 636 spdy::DATA_FLAG_NONE // Data Flags |
| 975 }; | 637 }; |
| 976 // Modify the following data to change/add test cases: | 638 // Modify the following data to change/add test cases: |
| 977 struct SynReplyTests { | 639 struct SynReplyTests { |
| 978 const SpdyHeaderInfo* syn_reply; | 640 const SpdyHeaderInfo* syn_reply; |
| 979 bool vary_matches; | 641 bool vary_matches; |
| 980 int num_headers[2]; | 642 int num_headers[2]; |
| 981 const char* extra_headers[2][16]; | 643 const char* extra_headers[2][16]; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 } | 706 } |
| 1045 }; | 707 }; |
| 1046 | 708 |
| 1047 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 709 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 1048 // Construct the request. | 710 // Construct the request. |
| 1049 scoped_ptr<spdy::SpdyFrame> frame_req( | 711 scoped_ptr<spdy::SpdyFrame> frame_req( |
| 1050 ConstructSpdyGet(test_cases[i].extra_headers[0], | 712 ConstructSpdyGet(test_cases[i].extra_headers[0], |
| 1051 test_cases[i].num_headers[0])); | 713 test_cases[i].num_headers[0])); |
| 1052 | 714 |
| 1053 MockWrite writes[] = { | 715 MockWrite writes[] = { |
| 1054 MockWrite( | 716 CreateMockWrite(frame_req.get()), |
| 1055 true, | |
| 1056 frame_req->data(), | |
| 1057 frame_req->length() + spdy::SpdyFrame::size()), | |
| 1058 }; | 717 }; |
| 1059 | 718 |
| 1060 // Construct the reply. | 719 // Construct the reply. |
| 1061 scoped_ptr<spdy::SpdyFrame> frame_reply( | 720 scoped_ptr<spdy::SpdyFrame> frame_reply( |
| 1062 ConstructSpdyPacket(test_cases[i].syn_reply, | 721 ConstructSpdyPacket(test_cases[i].syn_reply, |
| 1063 test_cases[i].extra_headers[1], | 722 test_cases[i].extra_headers[1], |
| 1064 test_cases[i].num_headers[1], | 723 test_cases[i].num_headers[1], |
| 1065 NULL, | 724 NULL, |
| 1066 0)); | 725 0)); |
| 1067 | 726 |
| 1068 MockRead reads[] = { | 727 MockRead reads[] = { |
| 1069 MockRead(true, | 728 CreateMockRead(frame_reply.get()), |
| 1070 frame_reply->data(), | |
| 1071 frame_reply->length() + spdy::SpdyFrame::size()), | |
| 1072 MockRead(true, | 729 MockRead(true, |
| 1073 reinterpret_cast<const char*>(kGetBodyFrame), | 730 reinterpret_cast<const char*>(kGetBodyFrame), |
| 1074 arraysize(kGetBodyFrame)), | 731 arraysize(kGetBodyFrame)), |
| 1075 MockRead(true, 0, 0) // EOF | 732 MockRead(true, 0, 0) // EOF |
| 1076 }; | 733 }; |
| 1077 | 734 |
| 1078 // Attach the headers to the request. | 735 // Attach the headers to the request. |
| 1079 int header_count = test_cases[i].num_headers[0]; | 736 int header_count = test_cases[i].num_headers[0]; |
| 1080 | 737 |
| 1081 HttpRequestInfo request = CreateGetRequest(); | 738 HttpRequestInfo request = CreateGetRequest(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 std::string name, value, lines; | 771 std::string name, value, lines; |
| 1115 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 772 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 1116 lines.append(name); | 773 lines.append(name); |
| 1117 lines.append(": "); | 774 lines.append(": "); |
| 1118 lines.append(value); | 775 lines.append(value); |
| 1119 lines.append("\n"); | 776 lines.append("\n"); |
| 1120 } | 777 } |
| 1121 | 778 |
| 1122 // Construct the expected header reply string. | 779 // Construct the expected header reply string. |
| 1123 char reply_buffer[256] = ""; | 780 char reply_buffer[256] = ""; |
| 1124 ConstructSpdyReply(test_cases[i].extra_headers[1], | 781 ConstructSpdyReplyString(test_cases[i].extra_headers[1], |
| 1125 test_cases[i].num_headers[1], | 782 test_cases[i].num_headers[1], |
| 1126 reply_buffer, | 783 reply_buffer, |
| 1127 256); | 784 256); |
| 1128 | 785 |
| 1129 EXPECT_EQ(std::string(reply_buffer), lines) << i; | 786 EXPECT_EQ(std::string(reply_buffer), lines) << i; |
| 1130 } | 787 } |
| 1131 } | 788 } |
| 1132 | 789 |
| 1133 // Verify that we don't crash on invalid SynReply responses. | 790 // Verify that we don't crash on invalid SynReply responses. |
| 1134 TEST_F(SpdyNetworkTransactionTest, InvalidSynReply) { | 791 TEST_F(SpdyNetworkTransactionTest, InvalidSynReply) { |
| 1135 static const unsigned char kSynReplyMissingStatus[] = { | 792 static const unsigned char kSynReplyMissingStatus[] = { |
| 1136 0x80, 0x01, 0x00, 0x02, | 793 0x80, 0x01, 0x00, 0x02, |
| 1137 0x00, 0x00, 0x00, 0x3f, | 794 0x00, 0x00, 0x00, 0x3f, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1159 | 816 |
| 1160 struct SynReplyTests { | 817 struct SynReplyTests { |
| 1161 const unsigned char* syn_reply; | 818 const unsigned char* syn_reply; |
| 1162 int syn_reply_length; | 819 int syn_reply_length; |
| 1163 } test_cases[] = { | 820 } test_cases[] = { |
| 1164 { kSynReplyMissingStatus, arraysize(kSynReplyMissingStatus) }, | 821 { kSynReplyMissingStatus, arraysize(kSynReplyMissingStatus) }, |
| 1165 { kSynReplyMissingVersion, arraysize(kSynReplyMissingVersion) } | 822 { kSynReplyMissingVersion, arraysize(kSynReplyMissingVersion) } |
| 1166 }; | 823 }; |
| 1167 | 824 |
| 1168 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 825 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 826 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1169 MockWrite writes[] = { | 827 MockWrite writes[] = { |
| 1170 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 828 CreateMockWrite(req.get()), |
| 1171 arraysize(kGetSyn)), | |
| 1172 MockWrite(true, 0, 0) // EOF | 829 MockWrite(true, 0, 0) // EOF |
| 1173 }; | 830 }; |
| 1174 | 831 |
| 1175 MockRead reads[] = { | 832 MockRead reads[] = { |
| 1176 MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), | 833 MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), |
| 1177 test_cases[i].syn_reply_length), | 834 test_cases[i].syn_reply_length), |
| 1178 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 835 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1179 arraysize(kGetBodyFrame)), | 836 arraysize(kGetBodyFrame)), |
| 1180 MockRead(true, 0, 0) // EOF | 837 MockRead(true, 0, 0) // EOF |
| 1181 }; | 838 }; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1204 }; | 861 }; |
| 1205 | 862 |
| 1206 struct SynReplyTests { | 863 struct SynReplyTests { |
| 1207 const unsigned char* syn_reply; | 864 const unsigned char* syn_reply; |
| 1208 int syn_reply_length; | 865 int syn_reply_length; |
| 1209 } test_cases[] = { | 866 } test_cases[] = { |
| 1210 { kSynReplyMassiveLength, arraysize(kSynReplyMassiveLength) } | 867 { kSynReplyMassiveLength, arraysize(kSynReplyMassiveLength) } |
| 1211 }; | 868 }; |
| 1212 | 869 |
| 1213 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 870 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 871 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1214 MockWrite writes[] = { | 872 MockWrite writes[] = { |
| 1215 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 873 CreateMockWrite(req.get()), |
| 1216 arraysize(kGetSyn)), | |
| 1217 MockWrite(true, 0, 0) // EOF | 874 MockWrite(true, 0, 0) // EOF |
| 1218 }; | 875 }; |
| 1219 | 876 |
| 1220 MockRead reads[] = { | 877 MockRead reads[] = { |
| 1221 MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), | 878 MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), |
| 1222 test_cases[i].syn_reply_length), | 879 test_cases[i].syn_reply_length), |
| 1223 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 880 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1224 arraysize(kGetBodyFrame)), | 881 arraysize(kGetBodyFrame)), |
| 1225 MockRead(true, 0, 0) // EOF | 882 MockRead(true, 0, 0) // EOF |
| 1226 }; | 883 }; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 }; | 1048 }; |
| 1392 | 1049 |
| 1393 static const char kPushBodyFrame2[] = " my darling"; | 1050 static const char kPushBodyFrame2[] = " my darling"; |
| 1394 static const char kPushBodyFrame3[] = " hello"; | 1051 static const char kPushBodyFrame3[] = " hello"; |
| 1395 static const char kPushBodyFrame4[] = " my baby"; | 1052 static const char kPushBodyFrame4[] = " my baby"; |
| 1396 | 1053 |
| 1397 const char syn_body_data1[] = "hello"; | 1054 const char syn_body_data1[] = "hello"; |
| 1398 const char syn_body_data2[] = "hello my darling hello my baby"; | 1055 const char syn_body_data2[] = "hello my darling hello my baby"; |
| 1399 const char* syn_body_data = NULL; | 1056 const char* syn_body_data = NULL; |
| 1400 | 1057 |
| 1401 MockWrite writes[] = { | 1058 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1402 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1059 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 1403 arraysize(kGetSyn)), | |
| 1404 }; | |
| 1405 | 1060 |
| 1406 // This array is for request before and after push is received. The push | 1061 // This array is for request before and after push is received. The push |
| 1407 // body is only one 'packet', to allow the initial transaction to read all | 1062 // body is only one 'packet', to allow the initial transaction to read all |
| 1408 // the push data before . | 1063 // the push data before . |
| 1409 MockRead reads1[] = { | 1064 MockRead reads1[] = { |
| 1410 MockRead(true, reinterpret_cast<const char*>(syn_reply), // 0 | 1065 MockRead(true, reinterpret_cast<const char*>(syn_reply), // 0 |
| 1411 arraysize(syn_reply), 2), | 1066 arraysize(syn_reply), 2), |
| 1412 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), // 1 | 1067 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), // 1 |
| 1413 arraysize(kGetBodyFrame), 3), | 1068 arraysize(kGetBodyFrame), 3), |
| 1414 MockRead(true, ERR_IO_PENDING, 4), // Force a pause // 2 | 1069 MockRead(true, ERR_IO_PENDING, 4), // Force a pause // 2 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 // The response time should be between the server push SYN and DATA. | 1200 // The response time should be between the server push SYN and DATA. |
| 1546 EXPECT_GE(response2.response_time.ToInternalValue(), | 1201 EXPECT_GE(response2.response_time.ToInternalValue(), |
| 1547 reads[first_push_data_frame - 1].time_stamp.ToInternalValue()); | 1202 reads[first_push_data_frame - 1].time_stamp.ToInternalValue()); |
| 1548 EXPECT_LE(response2.response_time.ToInternalValue(), | 1203 EXPECT_LE(response2.response_time.ToInternalValue(), |
| 1549 reads[first_push_data_frame].time_stamp.ToInternalValue()); | 1204 reads[first_push_data_frame].time_stamp.ToInternalValue()); |
| 1550 } | 1205 } |
| 1551 } | 1206 } |
| 1552 | 1207 |
| 1553 // Test that we shutdown correctly on write errors. | 1208 // Test that we shutdown correctly on write errors. |
| 1554 TEST_F(SpdyNetworkTransactionTest, WriteError) { | 1209 TEST_F(SpdyNetworkTransactionTest, WriteError) { |
| 1210 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1555 MockWrite writes[] = { | 1211 MockWrite writes[] = { |
| 1556 // We'll write 10 bytes successfully | 1212 // We'll write 10 bytes successfully |
| 1557 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), 10), | 1213 MockWrite(true, req->data(), 10), |
| 1558 // Followed by ERROR! | 1214 // Followed by ERROR! |
| 1559 MockWrite(true, ERR_FAILED), | 1215 MockWrite(true, ERR_FAILED), |
| 1560 MockWrite(true, 0, 0) // EOF | 1216 MockWrite(true, 0, 0) // EOF |
| 1561 }; | 1217 }; |
| 1562 | 1218 |
| 1219 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 1563 MockRead reads[] = { | 1220 MockRead reads[] = { |
| 1564 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1221 CreateMockRead(resp.get(), 2), |
| 1565 arraysize(kGetSynReply)), | |
| 1566 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1222 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1567 arraysize(kGetBodyFrame)), | 1223 arraysize(kGetBodyFrame)), |
| 1568 MockRead(true, 0, 0) // EOF | 1224 MockRead(true, 0, 0) // EOF |
| 1569 }; | 1225 }; |
| 1570 | 1226 |
| 1571 scoped_refptr<DelayedSocketData> data( | 1227 scoped_refptr<DelayedSocketData> data( |
| 1572 new DelayedSocketData(2, reads, arraysize(reads), | 1228 new DelayedSocketData(2, reads, arraysize(reads), |
| 1573 writes, arraysize(writes))); | 1229 writes, arraysize(writes))); |
| 1574 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), | 1230 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), |
| 1575 data.get(), | 1231 data.get(), |
| 1576 BoundNetLog()); | 1232 BoundNetLog()); |
| 1577 EXPECT_EQ(ERR_FAILED, out.rv); | 1233 EXPECT_EQ(ERR_FAILED, out.rv); |
| 1578 data->Reset(); | 1234 data->Reset(); |
| 1579 } | 1235 } |
| 1580 | 1236 |
| 1581 // Test that partial writes work. | 1237 // Test that partial writes work. |
| 1582 TEST_F(SpdyNetworkTransactionTest, PartialWrite) { | 1238 TEST_F(SpdyNetworkTransactionTest, PartialWrite) { |
| 1583 // Chop the SYN_STREAM frame into 5 chunks. | 1239 // Chop the SYN_STREAM frame into 5 chunks. |
| 1240 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1584 const int kChunks = 5; | 1241 const int kChunks = 5; |
| 1585 scoped_array<MockWrite> writes(ChopFrame( | 1242 scoped_array<MockWrite> writes(ChopFrame(req.get(), kChunks)); |
| 1586 reinterpret_cast<const char*>(kGetSyn), arraysize(kGetSyn), kChunks)); | |
| 1587 | 1243 |
| 1244 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 1588 MockRead reads[] = { | 1245 MockRead reads[] = { |
| 1589 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1246 CreateMockRead(resp.get()), |
| 1590 arraysize(kGetSynReply)), | |
| 1591 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1247 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1592 arraysize(kGetBodyFrame)), | 1248 arraysize(kGetBodyFrame)), |
| 1593 MockRead(true, 0, 0) // EOF | 1249 MockRead(true, 0, 0) // EOF |
| 1594 }; | 1250 }; |
| 1595 | 1251 |
| 1596 scoped_refptr<DelayedSocketData> data( | 1252 scoped_refptr<DelayedSocketData> data( |
| 1597 new DelayedSocketData(kChunks, reads, arraysize(reads), | 1253 new DelayedSocketData(kChunks, reads, arraysize(reads), |
| 1598 writes.get(), kChunks)); | 1254 writes.get(), kChunks)); |
| 1599 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), | 1255 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), |
| 1600 data.get(), | 1256 data.get(), |
| 1601 BoundNetLog()); | 1257 BoundNetLog()); |
| 1602 EXPECT_EQ(OK, out.rv); | 1258 EXPECT_EQ(OK, out.rv); |
| 1603 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1259 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1604 EXPECT_EQ("hello!", out.response_data); | 1260 EXPECT_EQ("hello!", out.response_data); |
| 1605 } | 1261 } |
| 1606 | 1262 |
| 1607 TEST_F(SpdyNetworkTransactionTest, ConnectFailure) { | 1263 TEST_F(SpdyNetworkTransactionTest, ConnectFailure) { |
| 1608 MockConnect connects[] = { | 1264 MockConnect connects[] = { |
| 1609 MockConnect(true, ERR_NAME_NOT_RESOLVED), | 1265 MockConnect(true, ERR_NAME_NOT_RESOLVED), |
| 1610 MockConnect(false, ERR_NAME_NOT_RESOLVED), | 1266 MockConnect(false, ERR_NAME_NOT_RESOLVED), |
| 1611 MockConnect(true, ERR_INTERNET_DISCONNECTED), | 1267 MockConnect(true, ERR_INTERNET_DISCONNECTED), |
| 1612 MockConnect(false, ERR_INTERNET_DISCONNECTED) | 1268 MockConnect(false, ERR_INTERNET_DISCONNECTED) |
| 1613 }; | 1269 }; |
| 1614 | 1270 |
| 1615 for (size_t index = 0; index < arraysize(connects); ++index) { | 1271 for (size_t index = 0; index < arraysize(connects); ++index) { |
| 1272 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1616 MockWrite writes[] = { | 1273 MockWrite writes[] = { |
| 1617 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1274 CreateMockWrite(req.get()), |
| 1618 arraysize(kGetSyn)), | |
| 1619 MockWrite(true, 0, 0) // EOF | 1275 MockWrite(true, 0, 0) // EOF |
| 1620 }; | 1276 }; |
| 1621 | 1277 |
| 1278 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 1622 MockRead reads[] = { | 1279 MockRead reads[] = { |
| 1623 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1280 CreateMockRead(resp.get()), |
| 1624 arraysize(kGetSynReply)), | |
| 1625 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1281 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1626 arraysize(kGetBodyFrame)), | 1282 arraysize(kGetBodyFrame)), |
| 1627 MockRead(true, 0, 0) // EOF | 1283 MockRead(true, 0, 0) // EOF |
| 1628 }; | 1284 }; |
| 1629 | 1285 |
| 1630 scoped_refptr<DelayedSocketData> data( | 1286 scoped_refptr<DelayedSocketData> data( |
| 1631 new DelayedSocketData(connects[index], 1, reads, arraysize(reads), | 1287 new DelayedSocketData(connects[index], 1, reads, arraysize(reads), |
| 1632 writes, arraysize(writes))); | 1288 writes, arraysize(writes))); |
| 1633 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), | 1289 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), |
| 1634 data.get(), | 1290 data.get(), |
| 1635 BoundNetLog()); | 1291 BoundNetLog()); |
| 1636 EXPECT_EQ(connects[index].result, out.rv); | 1292 EXPECT_EQ(connects[index].result, out.rv); |
| 1637 } | 1293 } |
| 1638 } | 1294 } |
| 1639 | 1295 |
| 1640 // In this test, we enable compression, but get a uncompressed SynReply from | 1296 // In this test, we enable compression, but get a uncompressed SynReply from |
| 1641 // the server. Verify that teardown is all clean. | 1297 // the server. Verify that teardown is all clean. |
| 1642 TEST_F(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { | 1298 TEST_F(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { |
| 1643 MockWrite writes[] = { | 1299 MockWrite writes[] = { |
| 1644 MockWrite(true, reinterpret_cast<const char*>(kGetSynCompressed), | 1300 MockWrite(true, reinterpret_cast<const char*>(kGetSynCompressed), |
| 1645 arraysize(kGetSynCompressed)), | 1301 arraysize(kGetSynCompressed)), |
| 1646 MockWrite(true, 0, 0) // EOF | 1302 MockWrite(true, 0, 0) // EOF |
| 1647 }; | 1303 }; |
| 1648 | 1304 |
| 1305 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 1649 MockRead reads[] = { | 1306 MockRead reads[] = { |
| 1650 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1307 CreateMockRead(resp.get()), |
| 1651 arraysize(kGetSynReply)), | |
| 1652 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1308 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1653 arraysize(kGetBodyFrame)), | 1309 arraysize(kGetBodyFrame)), |
| 1654 MockRead(true, 0, 0) // EOF | 1310 MockRead(true, 0, 0) // EOF |
| 1655 }; | 1311 }; |
| 1656 | 1312 |
| 1657 // For this test, we turn on the normal compression. | 1313 // For this test, we turn on the normal compression. |
| 1658 EnableCompression(true); | 1314 EnableCompression(true); |
| 1659 | 1315 |
| 1660 scoped_refptr<DelayedSocketData> data( | 1316 scoped_refptr<DelayedSocketData> data( |
| 1661 new DelayedSocketData(1, reads, arraysize(reads), | 1317 new DelayedSocketData(1, reads, arraysize(reads), |
| 1662 writes, arraysize(writes))); | 1318 writes, arraysize(writes))); |
| 1663 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), | 1319 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), |
| 1664 data.get(), | 1320 data.get(), |
| 1665 BoundNetLog()); | 1321 BoundNetLog()); |
| 1666 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); | 1322 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); |
| 1667 data->Reset(); | 1323 data->Reset(); |
| 1668 | 1324 |
| 1669 EnableCompression(false); | 1325 EnableCompression(false); |
| 1670 } | 1326 } |
| 1671 | 1327 |
| 1672 // Test that the NetLog contains good data for a simple GET request. | 1328 // Test that the NetLog contains good data for a simple GET request. |
| 1673 TEST_F(SpdyNetworkTransactionTest, NetLog) { | 1329 TEST_F(SpdyNetworkTransactionTest, NetLog) { |
| 1674 MockWrite writes[] = { | 1330 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1675 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1331 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 1676 arraysize(kGetSyn)), | |
| 1677 }; | |
| 1678 | 1332 |
| 1333 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 1679 MockRead reads[] = { | 1334 MockRead reads[] = { |
| 1680 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1335 CreateMockRead(resp.get()), |
| 1681 arraysize(kGetSynReply)), | |
| 1682 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1336 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1683 arraysize(kGetBodyFrame)), | 1337 arraysize(kGetBodyFrame)), |
| 1684 MockRead(true, 0, 0) // EOF | 1338 MockRead(true, 0, 0) // EOF |
| 1685 }; | 1339 }; |
| 1686 | 1340 |
| 1687 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); | 1341 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); |
| 1688 | 1342 |
| 1689 scoped_refptr<DelayedSocketData> data( | 1343 scoped_refptr<DelayedSocketData> data( |
| 1690 new DelayedSocketData(1, reads, arraysize(reads), | 1344 new DelayedSocketData(1, reads, arraysize(reads), |
| 1691 writes, arraysize(writes))); | 1345 writes, arraysize(writes))); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 pos = net::ExpectLogContainsSomewhere(log.entries(), pos + 1, | 1381 pos = net::ExpectLogContainsSomewhere(log.entries(), pos + 1, |
| 1728 net::NetLog::TYPE_SPDY_TRANSACTION_READ_BODY, | 1382 net::NetLog::TYPE_SPDY_TRANSACTION_READ_BODY, |
| 1729 net::NetLog::PHASE_END); | 1383 net::NetLog::PHASE_END); |
| 1730 } | 1384 } |
| 1731 | 1385 |
| 1732 // Since we buffer the IO from the stream to the renderer, this test verifies | 1386 // Since we buffer the IO from the stream to the renderer, this test verifies |
| 1733 // that when we read out the maximum amount of data (e.g. we received 50 bytes | 1387 // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 1734 // on the network, but issued a Read for only 5 of those bytes) that the data | 1388 // on the network, but issued a Read for only 5 of those bytes) that the data |
| 1735 // flow still works correctly. | 1389 // flow still works correctly. |
| 1736 TEST_F(SpdyNetworkTransactionTest, BufferFull) { | 1390 TEST_F(SpdyNetworkTransactionTest, BufferFull) { |
| 1737 MockWrite writes[] = { | 1391 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1738 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1392 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 1739 arraysize(kGetSyn)), | |
| 1740 }; | |
| 1741 | 1393 |
| 1742 static const unsigned char kCombinedDataFrames[] = { | 1394 static const unsigned char kCombinedDataFrames[] = { |
| 1743 0x00, 0x00, 0x00, 0x01, // header | 1395 0x00, 0x00, 0x00, 0x01, // header |
| 1744 0x00, 0x00, 0x00, 0x06, // length | 1396 0x00, 0x00, 0x00, 0x06, // length |
| 1745 'g', 'o', 'o', 'd', 'b', 'y', | 1397 'g', 'o', 'o', 'd', 'b', 'y', |
| 1746 0x00, 0x00, 0x00, 0x01, // header | 1398 0x00, 0x00, 0x00, 0x01, // header |
| 1747 0x00, 0x00, 0x00, 0x06, // length | 1399 0x00, 0x00, 0x00, 0x06, // length |
| 1748 'e', ' ', 'w', 'o', 'r', 'l', | 1400 'e', ' ', 'w', 'o', 'r', 'l', |
| 1749 }; | 1401 }; |
| 1750 | 1402 |
| 1751 static const unsigned char kLastFrame[] = { | 1403 static const unsigned char kLastFrame[] = { |
| 1752 0x00, 0x00, 0x00, 0x01, // header | 1404 0x00, 0x00, 0x00, 0x01, // header |
| 1753 0x01, 0x00, 0x00, 0x01, // FIN, length | 1405 0x01, 0x00, 0x00, 0x01, // FIN, length |
| 1754 'd', | 1406 'd', |
| 1755 }; | 1407 }; |
| 1756 | 1408 |
| 1409 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 1757 MockRead reads[] = { | 1410 MockRead reads[] = { |
| 1758 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1411 CreateMockRead(resp.get()), |
| 1759 arraysize(kGetSynReply)), | |
| 1760 MockRead(true, ERR_IO_PENDING), // Force a pause | 1412 MockRead(true, ERR_IO_PENDING), // Force a pause |
| 1761 MockRead(true, reinterpret_cast<const char*>(kCombinedDataFrames), | 1413 MockRead(true, reinterpret_cast<const char*>(kCombinedDataFrames), |
| 1762 arraysize(kCombinedDataFrames)), | 1414 arraysize(kCombinedDataFrames)), |
| 1763 MockRead(true, ERR_IO_PENDING), // Force a pause | 1415 MockRead(true, ERR_IO_PENDING), // Force a pause |
| 1764 MockRead(true, reinterpret_cast<const char*>(kLastFrame), | 1416 MockRead(true, reinterpret_cast<const char*>(kLastFrame), |
| 1765 arraysize(kLastFrame)), | 1417 arraysize(kLastFrame)), |
| 1766 MockRead(true, 0, 0) // EOF | 1418 MockRead(true, 0, 0) // EOF |
| 1767 }; | 1419 }; |
| 1768 | 1420 |
| 1769 scoped_refptr<DelayedSocketData> data( | 1421 scoped_refptr<DelayedSocketData> data( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 | 1483 |
| 1832 EXPECT_EQ(OK, out.rv); | 1484 EXPECT_EQ(OK, out.rv); |
| 1833 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1485 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1834 EXPECT_EQ("goodbye world", out.response_data); | 1486 EXPECT_EQ("goodbye world", out.response_data); |
| 1835 } | 1487 } |
| 1836 | 1488 |
| 1837 // Verify that basic buffering works; when multiple data frames arrive | 1489 // Verify that basic buffering works; when multiple data frames arrive |
| 1838 // at the same time, ensure that we don't notify a read completion for | 1490 // at the same time, ensure that we don't notify a read completion for |
| 1839 // each data frame individually. | 1491 // each data frame individually. |
| 1840 TEST_F(SpdyNetworkTransactionTest, Buffering) { | 1492 TEST_F(SpdyNetworkTransactionTest, Buffering) { |
| 1841 MockWrite writes[] = { | 1493 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1842 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1494 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 1843 arraysize(kGetSyn)), | |
| 1844 }; | |
| 1845 | 1495 |
| 1846 // 4 data frames in a single read. | 1496 // 4 data frames in a single read. |
| 1847 static const unsigned char kCombinedDataFrames[] = { | 1497 static const unsigned char kCombinedDataFrames[] = { |
| 1848 0x00, 0x00, 0x00, 0x01, // header | 1498 0x00, 0x00, 0x00, 0x01, // header |
| 1849 0x00, 0x00, 0x00, 0x07, // length | 1499 0x00, 0x00, 0x00, 0x07, // length |
| 1850 'm', 'e', 's', 's', 'a', 'g', 'e', | 1500 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 1851 0x00, 0x00, 0x00, 0x01, // header | 1501 0x00, 0x00, 0x00, 0x01, // header |
| 1852 0x00, 0x00, 0x00, 0x07, // length | 1502 0x00, 0x00, 0x00, 0x07, // length |
| 1853 'm', 'e', 's', 's', 'a', 'g', 'e', | 1503 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 1854 0x00, 0x00, 0x00, 0x01, // header | 1504 0x00, 0x00, 0x00, 0x01, // header |
| 1855 0x00, 0x00, 0x00, 0x07, // length | 1505 0x00, 0x00, 0x00, 0x07, // length |
| 1856 'm', 'e', 's', 's', 'a', 'g', 'e', | 1506 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 1857 0x00, 0x00, 0x00, 0x01, // header | 1507 0x00, 0x00, 0x00, 0x01, // header |
| 1858 0x01, 0x00, 0x00, 0x07, // FIN, length | 1508 0x01, 0x00, 0x00, 0x07, // FIN, length |
| 1859 'm', 'e', 's', 's', 'a', 'g', 'e', | 1509 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 1860 }; | 1510 }; |
| 1861 | 1511 |
| 1512 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 1862 MockRead reads[] = { | 1513 MockRead reads[] = { |
| 1863 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1514 CreateMockRead(resp.get()), |
| 1864 arraysize(kGetSynReply)), | |
| 1865 MockRead(true, ERR_IO_PENDING), // Force a pause | 1515 MockRead(true, ERR_IO_PENDING), // Force a pause |
| 1866 MockRead(true, reinterpret_cast<const char*>(kCombinedDataFrames), | 1516 MockRead(true, reinterpret_cast<const char*>(kCombinedDataFrames), |
| 1867 arraysize(kCombinedDataFrames)), | 1517 arraysize(kCombinedDataFrames)), |
| 1868 MockRead(true, 0, 0) // EOF | 1518 MockRead(true, 0, 0) // EOF |
| 1869 }; | 1519 }; |
| 1870 | 1520 |
| 1871 scoped_refptr<DelayedSocketData> data( | 1521 scoped_refptr<DelayedSocketData> data( |
| 1872 new DelayedSocketData(1, reads, arraysize(reads), | 1522 new DelayedSocketData(1, reads, arraysize(reads), |
| 1873 writes, arraysize(writes))); | 1523 writes, arraysize(writes))); |
| 1874 | 1524 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1935 EXPECT_TRUE(data->at_read_eof()); | 1585 EXPECT_TRUE(data->at_read_eof()); |
| 1936 EXPECT_TRUE(data->at_write_eof()); | 1586 EXPECT_TRUE(data->at_write_eof()); |
| 1937 | 1587 |
| 1938 EXPECT_EQ(OK, out.rv); | 1588 EXPECT_EQ(OK, out.rv); |
| 1939 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1589 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1940 EXPECT_EQ("messagemessagemessagemessage", out.response_data); | 1590 EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 1941 } | 1591 } |
| 1942 | 1592 |
| 1943 // Verify the case where we buffer data but read it after it has been buffered. | 1593 // Verify the case where we buffer data but read it after it has been buffered. |
| 1944 TEST_F(SpdyNetworkTransactionTest, BufferedAll) { | 1594 TEST_F(SpdyNetworkTransactionTest, BufferedAll) { |
| 1945 MockWrite writes[] = { | 1595 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 1946 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1596 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 1947 arraysize(kGetSyn)), | |
| 1948 }; | |
| 1949 | 1597 |
| 1950 // The Syn Reply and all data frames in a single read. | 1598 // The Syn Reply and all data frames in a single read. |
| 1951 static const unsigned char kCombinedFrames[] = { | 1599 static const unsigned char kCombinedFrames[] = { |
| 1952 0x80, 0x01, 0x00, 0x02, // header | 1600 0x80, 0x01, 0x00, 0x02, // header |
| 1953 0x00, 0x00, 0x00, 0x45, | 1601 0x00, 0x00, 0x00, 0x45, |
| 1954 0x00, 0x00, 0x00, 0x01, | 1602 0x00, 0x00, 0x00, 0x01, |
| 1955 0x00, 0x00, 0x00, 0x04, // 4 headers | 1603 0x00, 0x00, 0x00, 0x04, // 4 headers |
| 1956 0x00, 0x05, 'h', 'e', 'l', 'l', 'o', | 1604 0x00, 0x05, 'h', 'e', 'l', 'l', 'o', |
| 1957 0x00, 0x03, 'b', 'y', 'e', | 1605 0x00, 0x03, 'b', 'y', 'e', |
| 1958 0x00, 0x06, 's', 't', 'a', 't', 'u', 's', | 1606 0x00, 0x06, 's', 't', 'a', 't', 'u', 's', |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2044 EXPECT_TRUE(data->at_read_eof()); | 1692 EXPECT_TRUE(data->at_read_eof()); |
| 2045 EXPECT_TRUE(data->at_write_eof()); | 1693 EXPECT_TRUE(data->at_write_eof()); |
| 2046 | 1694 |
| 2047 EXPECT_EQ(OK, out.rv); | 1695 EXPECT_EQ(OK, out.rv); |
| 2048 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1696 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2049 EXPECT_EQ("messagemessagemessagemessage", out.response_data); | 1697 EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 2050 } | 1698 } |
| 2051 | 1699 |
| 2052 // Verify the case where we buffer data and close the connection. | 1700 // Verify the case where we buffer data and close the connection. |
| 2053 TEST_F(SpdyNetworkTransactionTest, BufferedClosed) { | 1701 TEST_F(SpdyNetworkTransactionTest, BufferedClosed) { |
| 2054 MockWrite writes[] = { | 1702 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 2055 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1703 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 2056 arraysize(kGetSyn)), | |
| 2057 }; | |
| 2058 | 1704 |
| 2059 // All data frames in a single read. | 1705 // All data frames in a single read. |
| 2060 static const unsigned char kCombinedFrames[] = { | 1706 static const unsigned char kCombinedFrames[] = { |
| 2061 0x00, 0x00, 0x00, 0x01, // header | 1707 0x00, 0x00, 0x00, 0x01, // header |
| 2062 0x00, 0x00, 0x00, 0x07, // length | 1708 0x00, 0x00, 0x00, 0x07, // length |
| 2063 'm', 'e', 's', 's', 'a', 'g', 'e', | 1709 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 2064 0x00, 0x00, 0x00, 0x01, // header | 1710 0x00, 0x00, 0x00, 0x01, // header |
| 2065 0x00, 0x00, 0x00, 0x07, // length | 1711 0x00, 0x00, 0x00, 0x07, // length |
| 2066 'm', 'e', 's', 's', 'a', 'g', 'e', | 1712 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 2067 0x00, 0x00, 0x00, 0x01, // header | 1713 0x00, 0x00, 0x00, 0x01, // header |
| 2068 0x00, 0x00, 0x00, 0x07, // length | 1714 0x00, 0x00, 0x00, 0x07, // length |
| 2069 'm', 'e', 's', 's', 'a', 'g', 'e', | 1715 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 2070 0x00, 0x00, 0x00, 0x01, // header | 1716 0x00, 0x00, 0x00, 0x01, // header |
| 2071 0x00, 0x00, 0x00, 0x07, // length | 1717 0x00, 0x00, 0x00, 0x07, // length |
| 2072 'm', 'e', 's', 's', 'a', 'g', 'e', | 1718 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 2073 // NOTE: We didn't FIN the stream. | 1719 // NOTE: We didn't FIN the stream. |
| 2074 }; | 1720 }; |
| 2075 | 1721 |
| 1722 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 2076 MockRead reads[] = { | 1723 MockRead reads[] = { |
| 2077 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1724 CreateMockRead(resp.get()), |
| 2078 arraysize(kGetSynReply)), | |
| 2079 MockRead(true, ERR_IO_PENDING), // Force a wait | 1725 MockRead(true, ERR_IO_PENDING), // Force a wait |
| 2080 MockRead(true, reinterpret_cast<const char*>(kCombinedFrames), | 1726 MockRead(true, reinterpret_cast<const char*>(kCombinedFrames), |
| 2081 arraysize(kCombinedFrames)), | 1727 arraysize(kCombinedFrames)), |
| 2082 MockRead(true, 0, 0) // EOF | 1728 MockRead(true, 0, 0) // EOF |
| 2083 }; | 1729 }; |
| 2084 | 1730 |
| 2085 scoped_refptr<DelayedSocketData> data( | 1731 scoped_refptr<DelayedSocketData> data( |
| 2086 new DelayedSocketData(1, reads, arraysize(reads), | 1732 new DelayedSocketData(1, reads, arraysize(reads), |
| 2087 writes, arraysize(writes))); | 1733 writes, arraysize(writes))); |
| 2088 | 1734 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2146 // MockClientSocketFactory) are still alive. | 1792 // MockClientSocketFactory) are still alive. |
| 2147 MessageLoop::current()->RunAllPending(); | 1793 MessageLoop::current()->RunAllPending(); |
| 2148 | 1794 |
| 2149 // Verify that we consumed all test data. | 1795 // Verify that we consumed all test data. |
| 2150 EXPECT_TRUE(data->at_read_eof()); | 1796 EXPECT_TRUE(data->at_read_eof()); |
| 2151 EXPECT_TRUE(data->at_write_eof()); | 1797 EXPECT_TRUE(data->at_write_eof()); |
| 2152 } | 1798 } |
| 2153 | 1799 |
| 2154 // Verify the case where we buffer data and cancel the transaction. | 1800 // Verify the case where we buffer data and cancel the transaction. |
| 2155 TEST_F(SpdyNetworkTransactionTest, BufferedCancelled) { | 1801 TEST_F(SpdyNetworkTransactionTest, BufferedCancelled) { |
| 2156 MockWrite writes[] = { | 1802 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 2157 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1803 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 2158 arraysize(kGetSyn)), | |
| 2159 }; | |
| 2160 | 1804 |
| 2161 static const unsigned char kDataFrame[] = { | 1805 static const unsigned char kDataFrame[] = { |
| 2162 0x00, 0x00, 0x00, 0x01, // header | 1806 0x00, 0x00, 0x00, 0x01, // header |
| 2163 0x00, 0x00, 0x00, 0x07, // length | 1807 0x00, 0x00, 0x00, 0x07, // length |
| 2164 'm', 'e', 's', 's', 'a', 'g', 'e', | 1808 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 2165 // NOTE: We didn't FIN the stream. | 1809 // NOTE: We didn't FIN the stream. |
| 2166 }; | 1810 }; |
| 2167 | 1811 |
| 1812 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 2168 MockRead reads[] = { | 1813 MockRead reads[] = { |
| 2169 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1814 CreateMockRead(resp.get()), |
| 2170 arraysize(kGetSynReply)), | |
| 2171 MockRead(true, ERR_IO_PENDING), // Force a wait | 1815 MockRead(true, ERR_IO_PENDING), // Force a wait |
| 2172 MockRead(true, reinterpret_cast<const char*>(kDataFrame), | 1816 MockRead(true, reinterpret_cast<const char*>(kDataFrame), |
| 2173 arraysize(kDataFrame)), | 1817 arraysize(kDataFrame)), |
| 2174 MockRead(true, 0, 0) // EOF | 1818 MockRead(true, 0, 0) // EOF |
| 2175 }; | 1819 }; |
| 2176 | 1820 |
| 2177 scoped_refptr<DelayedSocketData> data( | 1821 scoped_refptr<DelayedSocketData> data( |
| 2178 new DelayedSocketData(1, reads, arraysize(reads), | 1822 new DelayedSocketData(1, reads, arraysize(reads), |
| 2179 writes, arraysize(writes))); | 1823 writes, arraysize(writes))); |
| 2180 | 1824 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2229 MessageLoop::current()->RunAllPending(); | 1873 MessageLoop::current()->RunAllPending(); |
| 2230 } | 1874 } |
| 2231 | 1875 |
| 2232 // Test that if the server requests persistence of settings, that we save | 1876 // Test that if the server requests persistence of settings, that we save |
| 2233 // the settings in the SpdySettingsStorage. | 1877 // the settings in the SpdySettingsStorage. |
| 2234 TEST_F(SpdyNetworkTransactionTest, SettingsSaved) { | 1878 TEST_F(SpdyNetworkTransactionTest, SettingsSaved) { |
| 2235 static const SpdyHeaderInfo kSynReplyInfo = { | 1879 static const SpdyHeaderInfo kSynReplyInfo = { |
| 2236 spdy::SYN_REPLY, // Syn Reply | 1880 spdy::SYN_REPLY, // Syn Reply |
| 2237 1, // Stream ID | 1881 1, // Stream ID |
| 2238 0, // Associated Stream ID | 1882 0, // Associated Stream ID |
| 2239 3, // Priority | 1883 SPDY_PRIORITY_LOWEST, // Priority |
| 2240 spdy::CONTROL_FLAG_NONE, // Control Flags | 1884 spdy::CONTROL_FLAG_NONE, // Control Flags |
| 2241 false, // Compressed | 1885 false, // Compressed |
| 2242 200, // Status | 1886 spdy::INVALID, // Status |
| 2243 NULL, // Data | 1887 NULL, // Data |
| 2244 0, // Data Length | 1888 0, // Data Length |
| 2245 spdy::DATA_FLAG_NONE // Data Flags | 1889 spdy::DATA_FLAG_NONE // Data Flags |
| 2246 }; | 1890 }; |
| 2247 static const char* const kExtraHeaders[] = { | 1891 static const char* const kExtraHeaders[] = { |
| 2248 "status", "200", | 1892 "status", "200", |
| 2249 "version", "HTTP/1.1" | 1893 "version", "HTTP/1.1" |
| 2250 }; | 1894 }; |
| 2251 | 1895 |
| 2252 SessionDependencies session_deps; | 1896 SessionDependencies session_deps; |
| 2253 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 1897 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 2254 | 1898 |
| 2255 // Verify that no settings exist initially. | 1899 // Verify that no settings exist initially. |
| 2256 HostPortPair host_port_pair("www.google.com", 80); | 1900 HostPortPair host_port_pair("www.google.com", 80); |
| 2257 EXPECT_TRUE(session->spdy_settings().Get(host_port_pair).empty()); | 1901 EXPECT_TRUE(session->spdy_settings().Get(host_port_pair).empty()); |
| 2258 | 1902 |
| 2259 // Construct the request. | 1903 // Construct the request. |
| 2260 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); | 1904 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 2261 | 1905 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 2262 MockWrite writes[] = { | |
| 2263 MockWrite(true, req->data(), req->length() + spdy::SpdyFrame::size()), | |
| 2264 }; | |
| 2265 | 1906 |
| 2266 // Construct the reply. | 1907 // Construct the reply. |
| 2267 scoped_ptr<spdy::SpdyFrame> reply( | 1908 scoped_ptr<spdy::SpdyFrame> reply( |
| 2268 ConstructSpdyPacket(&kSynReplyInfo, | 1909 ConstructSpdyPacket(&kSynReplyInfo, |
| 2269 kExtraHeaders, | 1910 kExtraHeaders, |
| 2270 arraysize(kExtraHeaders) / 2, | 1911 arraysize(kExtraHeaders) / 2, |
| 2271 NULL, | 1912 NULL, |
| 2272 0)); | 1913 0)); |
| 2273 | 1914 |
| 2274 unsigned int kSampleId1 = 0x1; | 1915 unsigned int kSampleId1 = 0x1; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2291 setting.set_id(kSampleId2); | 1932 setting.set_id(kSampleId2); |
| 2292 settings.push_back(std::make_pair(setting, kSampleValue2)); | 1933 settings.push_back(std::make_pair(setting, kSampleValue2)); |
| 2293 // Next add another persisted setting | 1934 // Next add another persisted setting |
| 2294 setting.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | 1935 setting.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); |
| 2295 setting.set_id(kSampleId3); | 1936 setting.set_id(kSampleId3); |
| 2296 settings.push_back(std::make_pair(setting, kSampleValue3)); | 1937 settings.push_back(std::make_pair(setting, kSampleValue3)); |
| 2297 settings_frame.reset(ConstructSpdySettings(settings)); | 1938 settings_frame.reset(ConstructSpdySettings(settings)); |
| 2298 } | 1939 } |
| 2299 | 1940 |
| 2300 MockRead reads[] = { | 1941 MockRead reads[] = { |
| 2301 MockRead(true, reply->data(), reply->length() + spdy::SpdyFrame::size()), | 1942 CreateMockRead(reply.get()), |
| 2302 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1943 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 2303 arraysize(kGetBodyFrame)), | 1944 arraysize(kGetBodyFrame)), |
| 2304 MockRead(true, settings_frame->data(), | 1945 CreateMockRead(settings_frame.get()), |
| 2305 settings_frame->length() + spdy::SpdyFrame::size()), | |
| 2306 MockRead(true, 0, 0) // EOF | 1946 MockRead(true, 0, 0) // EOF |
| 2307 }; | 1947 }; |
| 2308 | 1948 |
| 2309 scoped_refptr<DelayedSocketData> data( | 1949 scoped_refptr<DelayedSocketData> data( |
| 2310 new DelayedSocketData(1, reads, arraysize(reads), | 1950 new DelayedSocketData(1, reads, arraysize(reads), |
| 2311 writes, arraysize(writes))); | 1951 writes, arraysize(writes))); |
| 2312 TransactionHelperResult out = TransactionHelperWithSession( | 1952 TransactionHelperResult out = TransactionHelperWithSession( |
| 2313 CreateGetRequest(), data.get(), BoundNetLog(), | 1953 CreateGetRequest(), data.get(), BoundNetLog(), |
| 2314 &session_deps, session.get()); | 1954 &session_deps, session.get()); |
| 2315 EXPECT_EQ(OK, out.rv); | 1955 EXPECT_EQ(OK, out.rv); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2338 } | 1978 } |
| 2339 } | 1979 } |
| 2340 | 1980 |
| 2341 // Test that when there are settings saved that they are sent back to the | 1981 // Test that when there are settings saved that they are sent back to the |
| 2342 // server upon session establishment. | 1982 // server upon session establishment. |
| 2343 TEST_F(SpdyNetworkTransactionTest, SettingsPlayback) { | 1983 TEST_F(SpdyNetworkTransactionTest, SettingsPlayback) { |
| 2344 static const SpdyHeaderInfo kSynReplyInfo = { | 1984 static const SpdyHeaderInfo kSynReplyInfo = { |
| 2345 spdy::SYN_REPLY, // Syn Reply | 1985 spdy::SYN_REPLY, // Syn Reply |
| 2346 1, // Stream ID | 1986 1, // Stream ID |
| 2347 0, // Associated Stream ID | 1987 0, // Associated Stream ID |
| 2348 3, // Priority | 1988 SPDY_PRIORITY_LOWEST, // Priority |
| 2349 spdy::CONTROL_FLAG_NONE, // Control Flags | 1989 spdy::CONTROL_FLAG_NONE, // Control Flags |
| 2350 false, // Compressed | 1990 false, // Compressed |
| 2351 200, // Status | 1991 spdy::INVALID, // Status |
| 2352 NULL, // Data | 1992 NULL, // Data |
| 2353 0, // Data Length | 1993 0, // Data Length |
| 2354 spdy::DATA_FLAG_NONE // Data Flags | 1994 spdy::DATA_FLAG_NONE // Data Flags |
| 2355 }; | 1995 }; |
| 2356 static const char* kExtraHeaders[] = { | 1996 static const char* kExtraHeaders[] = { |
| 2357 "status", "200", | 1997 "status", "200", |
| 2358 "version", "HTTP/1.1" | 1998 "version", "HTTP/1.1" |
| 2359 }; | 1999 }; |
| 2360 | 2000 |
| 2361 SessionDependencies session_deps; | 2001 SessionDependencies session_deps; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2389 | 2029 |
| 2390 // Construct the SETTINGS frame. | 2030 // Construct the SETTINGS frame. |
| 2391 const spdy::SpdySettings& settings = | 2031 const spdy::SpdySettings& settings = |
| 2392 session->spdy_settings().Get(host_port_pair); | 2032 session->spdy_settings().Get(host_port_pair); |
| 2393 scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); | 2033 scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); |
| 2394 | 2034 |
| 2395 // Construct the request. | 2035 // Construct the request. |
| 2396 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); | 2036 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 2397 | 2037 |
| 2398 MockWrite writes[] = { | 2038 MockWrite writes[] = { |
| 2399 MockWrite(true, settings_frame->data(), | 2039 CreateMockWrite(settings_frame.get()), |
| 2400 settings_frame->length() + spdy::SpdyFrame::size()), | 2040 CreateMockWrite(req.get()), |
| 2401 MockWrite(true, req->data(), req->length() + spdy::SpdyFrame::size()), | |
| 2402 }; | 2041 }; |
| 2403 | 2042 |
| 2404 // Construct the reply. | 2043 // Construct the reply. |
| 2405 scoped_ptr<spdy::SpdyFrame> reply( | 2044 scoped_ptr<spdy::SpdyFrame> reply( |
| 2406 ConstructSpdyPacket(&kSynReplyInfo, | 2045 ConstructSpdyPacket(&kSynReplyInfo, |
| 2407 kExtraHeaders, | 2046 kExtraHeaders, |
| 2408 arraysize(kExtraHeaders) / 2, | 2047 arraysize(kExtraHeaders) / 2, |
| 2409 NULL, | 2048 NULL, |
| 2410 0)); | 2049 0)); |
| 2411 | 2050 |
| 2412 MockRead reads[] = { | 2051 MockRead reads[] = { |
| 2413 MockRead(true, reply->data(), reply->length() + spdy::SpdyFrame::size()), | 2052 CreateMockRead(reply.get()), |
| 2414 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 2053 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 2415 arraysize(kGetBodyFrame)), | 2054 arraysize(kGetBodyFrame)), |
| 2416 MockRead(true, 0, 0) // EOF | 2055 MockRead(true, 0, 0) // EOF |
| 2417 }; | 2056 }; |
| 2418 | 2057 |
| 2419 scoped_refptr<DelayedSocketData> data( | 2058 scoped_refptr<DelayedSocketData> data( |
| 2420 new DelayedSocketData(2, reads, arraysize(reads), | 2059 new DelayedSocketData(2, reads, arraysize(reads), |
| 2421 writes, arraysize(writes))); | 2060 writes, arraysize(writes))); |
| 2422 TransactionHelperResult out = TransactionHelperWithSession( | 2061 TransactionHelperResult out = TransactionHelperWithSession( |
| 2423 CreateGetRequest(), data.get(), BoundNetLog(), | 2062 CreateGetRequest(), data.get(), BoundNetLog(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2442 // Verify the second persisted setting. | 2081 // Verify the second persisted setting. |
| 2443 setting = saved_settings.front(); | 2082 setting = saved_settings.front(); |
| 2444 saved_settings.pop_front(); | 2083 saved_settings.pop_front(); |
| 2445 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); | 2084 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); |
| 2446 EXPECT_EQ(kSampleId2, setting.first.id()); | 2085 EXPECT_EQ(kSampleId2, setting.first.id()); |
| 2447 EXPECT_EQ(kSampleValue2, setting.second); | 2086 EXPECT_EQ(kSampleValue2, setting.second); |
| 2448 } | 2087 } |
| 2449 } | 2088 } |
| 2450 | 2089 |
| 2451 TEST_F(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { | 2090 TEST_F(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
| 2452 MockWrite writes[] = { | 2091 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 2453 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 2092 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 2454 arraysize(kGetSyn)), | |
| 2455 }; | |
| 2456 | 2093 |
| 2457 MockRead reads[] = { | 2094 MockRead reads[] = { |
| 2458 MockRead(true, reinterpret_cast<const char*>(kGoAway), | 2095 MockRead(true, reinterpret_cast<const char*>(kGoAway), |
| 2459 arraysize(kGoAway)), | 2096 arraysize(kGoAway)), |
| 2460 MockRead(true, 0, 0) // EOF | 2097 MockRead(true, 0, 0) // EOF |
| 2461 }; | 2098 }; |
| 2462 | 2099 |
| 2463 scoped_refptr<DelayedSocketData> data( | 2100 scoped_refptr<DelayedSocketData> data( |
| 2464 new DelayedSocketData(1, reads, arraysize(reads), | 2101 new DelayedSocketData(1, reads, arraysize(reads), |
| 2465 writes, arraysize(writes))); | 2102 writes, arraysize(writes))); |
| 2466 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), | 2103 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), |
| 2467 data.get(), | 2104 data.get(), |
| 2468 BoundNetLog()); | 2105 BoundNetLog()); |
| 2469 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); | 2106 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
| 2470 } | 2107 } |
| 2471 | 2108 |
| 2472 TEST_F(SpdyNetworkTransactionTest, CloseWithActiveStream) { | 2109 TEST_F(SpdyNetworkTransactionTest, CloseWithActiveStream) { |
| 2473 MockWrite writes[] = { | 2110 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); |
| 2474 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 2111 MockWrite writes[] = { CreateMockWrite(req.get()) }; |
| 2475 arraysize(kGetSyn)), | |
| 2476 }; | |
| 2477 | 2112 |
| 2113 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); |
| 2478 MockRead reads[] = { | 2114 MockRead reads[] = { |
| 2479 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 2115 CreateMockRead(resp.get()), |
| 2480 arraysize(kGetSynReply)), | |
| 2481 MockRead(false, 0, 0) // EOF | 2116 MockRead(false, 0, 0) // EOF |
| 2482 }; | 2117 }; |
| 2483 | 2118 |
| 2484 scoped_refptr<DelayedSocketData> data( | 2119 scoped_refptr<DelayedSocketData> data( |
| 2485 new DelayedSocketData(1, reads, arraysize(reads), | 2120 new DelayedSocketData(1, reads, arraysize(reads), |
| 2486 writes, arraysize(writes))); | 2121 writes, arraysize(writes))); |
| 2487 TransactionHelperResult out; | 2122 TransactionHelperResult out; |
| 2488 | 2123 |
| 2489 // We disable SSL for this test. | 2124 // We disable SSL for this test. |
| 2490 SpdySession::SetSSLMode(false); | 2125 SpdySession::SetSSLMode(false); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2509 EXPECT_TRUE(response->was_fetched_via_spdy); | 2144 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2510 out.rv = ReadTransaction(trans.get(), &out.response_data); | 2145 out.rv = ReadTransaction(trans.get(), &out.response_data); |
| 2511 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); | 2146 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
| 2512 | 2147 |
| 2513 // Verify that we consumed all test data. | 2148 // Verify that we consumed all test data. |
| 2514 EXPECT_TRUE(data->at_read_eof()); | 2149 EXPECT_TRUE(data->at_read_eof()); |
| 2515 EXPECT_TRUE(data->at_write_eof()); | 2150 EXPECT_TRUE(data->at_write_eof()); |
| 2516 } | 2151 } |
| 2517 | 2152 |
| 2518 } // namespace net | 2153 } // namespace net |
| OLD | NEW |