| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 3205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3216 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); | 3216 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); |
| 3217 std::string contents("hello!"); | 3217 std::string contents("hello!"); |
| 3218 EXPECT_EQ(contents, d.data_received()); | 3218 EXPECT_EQ(contents, d.data_received()); |
| 3219 } | 3219 } |
| 3220 EXPECT_TRUE(data.at_read_eof()); | 3220 EXPECT_TRUE(data.at_read_eof()); |
| 3221 EXPECT_TRUE(data.at_write_eof()); | 3221 EXPECT_TRUE(data.at_write_eof()); |
| 3222 EXPECT_TRUE(data2.at_read_eof()); | 3222 EXPECT_TRUE(data2.at_read_eof()); |
| 3223 EXPECT_TRUE(data2.at_write_eof()); | 3223 EXPECT_TRUE(data2.at_write_eof()); |
| 3224 } | 3224 } |
| 3225 | 3225 |
| 3226 // Detect response with upper case headers and reset the stream. | |
| 3227 TEST_P(SpdyNetworkTransactionTest, UpperCaseHeaders) { | |
| 3228 if (GetParam().protocol > kProtoSPDY3) | |
| 3229 return; | |
| 3230 | |
| 3231 scoped_ptr<SpdyFrame> syn( | |
| 3232 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
| 3233 scoped_ptr<SpdyFrame> rst( | |
| 3234 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | |
| 3235 MockWrite writes[] = { | |
| 3236 CreateMockWrite(*syn, 0), | |
| 3237 CreateMockWrite(*rst, 2), | |
| 3238 }; | |
| 3239 | |
| 3240 const char* const kExtraHeaders[] = {"X-UpperCase", "yes"}; | |
| 3241 scoped_ptr<SpdyFrame> | |
| 3242 reply(spdy_util_.ConstructSpdyGetSynReply(kExtraHeaders, 1, 1)); | |
| 3243 MockRead reads[] = { | |
| 3244 CreateMockRead(*reply, 1), | |
| 3245 MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause | |
| 3246 }; | |
| 3247 | |
| 3248 HttpResponseInfo response; | |
| 3249 HttpResponseInfo response2; | |
| 3250 OrderedSocketData data(reads, arraysize(reads), | |
| 3251 writes, arraysize(writes)); | |
| 3252 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 3253 BoundNetLog(), GetParam(), NULL); | |
| 3254 helper.RunToCompletion(&data); | |
| 3255 TransactionHelperResult out = helper.output(); | |
| 3256 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | |
| 3257 } | |
| 3258 | |
| 3259 // Detect response with upper case headers in a HEADERS frame and reset the | |
| 3260 // stream. | |
| 3261 TEST_P(SpdyNetworkTransactionTest, UpperCaseHeadersInHeadersFrame) { | |
| 3262 if (GetParam().protocol > kProtoSPDY3) | |
| 3263 return; | |
| 3264 | |
| 3265 scoped_ptr<SpdyFrame> syn( | |
| 3266 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
| 3267 scoped_ptr<SpdyFrame> rst( | |
| 3268 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | |
| 3269 MockWrite writes[] = { | |
| 3270 CreateMockWrite(*syn, 0), | |
| 3271 CreateMockWrite(*rst, 2), | |
| 3272 }; | |
| 3273 | |
| 3274 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); | |
| 3275 (*initial_headers)[spdy_util_.GetStatusKey()] = "200 OK"; | |
| 3276 (*initial_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | |
| 3277 scoped_ptr<SpdyFrame> stream1_reply( | |
| 3278 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), | |
| 3279 false, | |
| 3280 1, | |
| 3281 LOWEST, | |
| 3282 SYN_REPLY, | |
| 3283 CONTROL_FLAG_NONE, | |
| 3284 0)); | |
| 3285 | |
| 3286 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); | |
| 3287 (*late_headers)["X-UpperCase"] = "yes"; | |
| 3288 scoped_ptr<SpdyFrame> stream1_headers( | |
| 3289 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), | |
| 3290 false, | |
| 3291 1, | |
| 3292 LOWEST, | |
| 3293 HEADERS, | |
| 3294 CONTROL_FLAG_NONE, | |
| 3295 0)); | |
| 3296 scoped_ptr<SpdyFrame> stream1_body( | |
| 3297 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 3298 MockRead reads[] = { | |
| 3299 CreateMockRead(*stream1_reply), | |
| 3300 CreateMockRead(*stream1_headers), | |
| 3301 CreateMockRead(*stream1_body), | |
| 3302 MockRead(ASYNC, 0, 0) // EOF | |
| 3303 }; | |
| 3304 | |
| 3305 DelayedSocketData data(1, reads, arraysize(reads), | |
| 3306 writes, arraysize(writes)); | |
| 3307 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 3308 BoundNetLog(), GetParam(), NULL); | |
| 3309 helper.RunToCompletion(&data); | |
| 3310 TransactionHelperResult out = helper.output(); | |
| 3311 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | |
| 3312 } | |
| 3313 | |
| 3314 // Detect push stream with upper case headers and reset the stream. | |
| 3315 TEST_P(SpdyNetworkTransactionTest, UpperCaseHeadersOnPush) { | |
| 3316 if (GetParam().protocol > kProtoSPDY3) | |
| 3317 return; | |
| 3318 | |
| 3319 scoped_ptr<SpdyFrame> syn( | |
| 3320 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
| 3321 scoped_ptr<SpdyFrame> rst( | |
| 3322 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); | |
| 3323 MockWrite writes[] = { | |
| 3324 CreateMockWrite(*syn, 0), | |
| 3325 CreateMockWrite(*rst, 2), | |
| 3326 }; | |
| 3327 | |
| 3328 scoped_ptr<SpdyFrame> | |
| 3329 reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | |
| 3330 const char* const extra_headers[] = {"X-UpperCase", "yes"}; | |
| 3331 scoped_ptr<SpdyFrame> | |
| 3332 push(spdy_util_.ConstructSpdyPush( | |
| 3333 extra_headers, 1, 2, 1, "http://www.google.com")); | |
| 3334 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 3335 MockRead reads[] = { | |
| 3336 CreateMockRead(*reply, 1), | |
| 3337 CreateMockRead(*push, 1), | |
| 3338 CreateMockRead(*body, 1), | |
| 3339 MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause | |
| 3340 }; | |
| 3341 | |
| 3342 HttpResponseInfo response; | |
| 3343 HttpResponseInfo response2; | |
| 3344 OrderedSocketData data(reads, arraysize(reads), | |
| 3345 writes, arraysize(writes)); | |
| 3346 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 3347 BoundNetLog(), GetParam(), NULL); | |
| 3348 helper.RunToCompletion(&data); | |
| 3349 TransactionHelperResult out = helper.output(); | |
| 3350 EXPECT_EQ(OK, out.rv); | |
| 3351 } | |
| 3352 | |
| 3353 // Send a spdy request to www.google.com. Get a pushed stream that redirects to | 3226 // Send a spdy request to www.google.com. Get a pushed stream that redirects to |
| 3354 // www.foo.com. | 3227 // www.foo.com. |
| 3355 TEST_P(SpdyNetworkTransactionTest, RedirectServerPush) { | 3228 TEST_P(SpdyNetworkTransactionTest, RedirectServerPush) { |
| 3356 if (GetParam().protocol > kProtoSPDY3) | 3229 if (GetParam().protocol > kProtoSPDY3) |
| 3357 return; | 3230 return; |
| 3358 | 3231 |
| 3359 const SpdyHeaderInfo kSynStartHeader = spdy_util_.MakeSpdyHeader(SYN_STREAM); | 3232 const SpdyHeaderInfo kSynStartHeader = spdy_util_.MakeSpdyHeader(SYN_STREAM); |
| 3360 | 3233 |
| 3361 scoped_ptr<SpdyHeaderBlock> headers( | 3234 scoped_ptr<SpdyHeaderBlock> headers( |
| 3362 spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); | 3235 spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); |
| (...skipping 2832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6195 base::MessageLoop::current()->RunUntilIdle(); | 6068 base::MessageLoop::current()->RunUntilIdle(); |
| 6196 | 6069 |
| 6197 // Read the server push body. | 6070 // Read the server push body. |
| 6198 std::string result2; | 6071 std::string result2; |
| 6199 ReadResult(trans2.get(), &data, &result2); | 6072 ReadResult(trans2.get(), &data, &result2); |
| 6200 // Read the response body. | 6073 // Read the response body. |
| 6201 std::string result; | 6074 std::string result; |
| 6202 ReadResult(trans, &data, &result); | 6075 ReadResult(trans, &data, &result); |
| 6203 | 6076 |
| 6204 // Verify that the received push data is same as the expected push data. | 6077 // Verify that the received push data is same as the expected push data. |
| 6205 EXPECT_EQ(result2.compare(expected_push_result), 0) | 6078 EXPECT_EQ(expected_push_result, result2); |
| 6206 << "Received data: " | |
| 6207 << result2 | |
| 6208 << "||||| Expected data: " | |
| 6209 << expected_push_result; | |
| 6210 | 6079 |
| 6211 // Verify the SYN_REPLY. | 6080 // Verify the SYN_REPLY. |
| 6212 // Copy the response info, because trans goes away. | 6081 // Copy the response info, because trans goes away. |
| 6213 response = *trans->GetResponseInfo(); | 6082 response = *trans->GetResponseInfo(); |
| 6214 response2 = *trans2->GetResponseInfo(); | 6083 response2 = *trans2->GetResponseInfo(); |
| 6215 | 6084 |
| 6216 VerifyStreamsClosed(helper); | 6085 VerifyStreamsClosed(helper); |
| 6217 | 6086 |
| 6218 // Verify the SYN_REPLY. | 6087 // Verify the SYN_REPLY. |
| 6219 EXPECT_TRUE(response.headers.get() != NULL); | 6088 EXPECT_TRUE(response.headers.get() != NULL); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6462 writes, arraysize(writes)); | 6331 writes, arraysize(writes)); |
| 6463 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 6332 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 6464 BoundNetLog(), GetParam(), NULL); | 6333 BoundNetLog(), GetParam(), NULL); |
| 6465 helper.RunToCompletion(&data); | 6334 helper.RunToCompletion(&data); |
| 6466 TransactionHelperResult out = helper.output(); | 6335 TransactionHelperResult out = helper.output(); |
| 6467 EXPECT_EQ(OK, out.rv); | 6336 EXPECT_EQ(OK, out.rv); |
| 6468 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 6337 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 6469 EXPECT_EQ("hello!hello!", out.response_data); | 6338 EXPECT_EQ("hello!hello!", out.response_data); |
| 6470 } | 6339 } |
| 6471 | 6340 |
| 6472 TEST_P(SpdyNetworkTransactionTest, SynReplyWithDuplicateLateHeaders) { | |
| 6473 if (GetParam().protocol > kProtoSPDY3) | |
| 6474 return; | |
| 6475 | |
| 6476 scoped_ptr<SpdyFrame> req( | |
| 6477 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
| 6478 MockWrite writes[] = { CreateMockWrite(*req) }; | |
| 6479 | |
| 6480 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); | |
| 6481 (*initial_headers)[spdy_util_.GetStatusKey()] = "200 OK"; | |
| 6482 (*initial_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | |
| 6483 scoped_ptr<SpdyFrame> stream1_reply( | |
| 6484 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), | |
| 6485 false, | |
| 6486 1, | |
| 6487 LOWEST, | |
| 6488 SYN_REPLY, | |
| 6489 CONTROL_FLAG_NONE, | |
| 6490 0)); | |
| 6491 | |
| 6492 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); | |
| 6493 (*late_headers)[spdy_util_.GetStatusKey()] = "500 Server Error"; | |
| 6494 scoped_ptr<SpdyFrame> stream1_headers( | |
| 6495 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), | |
| 6496 false, | |
| 6497 1, | |
| 6498 LOWEST, | |
| 6499 HEADERS, | |
| 6500 CONTROL_FLAG_NONE, | |
| 6501 0)); | |
| 6502 scoped_ptr<SpdyFrame> stream1_body( | |
| 6503 spdy_util_.ConstructSpdyBodyFrame(1, false)); | |
| 6504 scoped_ptr<SpdyFrame> stream1_body2( | |
| 6505 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 6506 MockRead reads[] = { | |
| 6507 CreateMockRead(*stream1_reply), | |
| 6508 CreateMockRead(*stream1_body), | |
| 6509 CreateMockRead(*stream1_headers), | |
| 6510 CreateMockRead(*stream1_body2), | |
| 6511 MockRead(ASYNC, 0, 0) // EOF | |
| 6512 }; | |
| 6513 | |
| 6514 DelayedSocketData data(1, reads, arraysize(reads), | |
| 6515 writes, arraysize(writes)); | |
| 6516 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 6517 BoundNetLog(), GetParam(), NULL); | |
| 6518 helper.RunToCompletion(&data); | |
| 6519 TransactionHelperResult out = helper.output(); | |
| 6520 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | |
| 6521 } | |
| 6522 | |
| 6523 TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { | 6341 TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { |
| 6524 if (GetParam().protocol > kProtoSPDY3) | 6342 if (GetParam().protocol > kProtoSPDY3) |
| 6525 return; | 6343 return; |
| 6526 | 6344 |
| 6527 // In this test we want to verify that we can't accidentally push content | 6345 // In this test we want to verify that we can't accidentally push content |
| 6528 // which can't be pushed by this content server. | 6346 // which can't be pushed by this content server. |
| 6529 // This test assumes that: | 6347 // This test assumes that: |
| 6530 // - if we're requesting http://www.foo.com/barbaz | 6348 // - if we're requesting http://www.foo.com/barbaz |
| 6531 // - the browser has made a connection to "www.foo.com". | 6349 // - the browser has made a connection to "www.foo.com". |
| 6532 | 6350 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6781 // And now we can allow everything else to run to completion. | 6599 // And now we can allow everything else to run to completion. |
| 6782 data.SetStop(10); | 6600 data.SetStop(10); |
| 6783 data.Run(); | 6601 data.Run(); |
| 6784 EXPECT_EQ(OK, callback2.WaitForResult()); | 6602 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 6785 EXPECT_EQ(OK, callback3.WaitForResult()); | 6603 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 6786 | 6604 |
| 6787 helper.VerifyDataConsumed(); | 6605 helper.VerifyDataConsumed(); |
| 6788 } | 6606 } |
| 6789 | 6607 |
| 6790 } // namespace net | 6608 } // namespace net |
| OLD | NEW |