OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 16507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16518 trans.Start(&request, callback.callback(), NetLogWithSource())); | 16518 trans.Start(&request, callback.callback(), NetLogWithSource())); |
16519 base::RunLoop().RunUntilIdle(); | 16519 base::RunLoop().RunUntilIdle(); |
16520 | 16520 |
16521 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16521 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
16522 HttpRequestHeaders headers; | 16522 HttpRequestHeaders headers; |
16523 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16523 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
16524 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16524 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
16525 } | 16525 } |
16526 #endif // !defined(OS_IOS) | 16526 #endif // !defined(OS_IOS) |
16527 | 16527 |
| 16528 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 16529 const std::string& accept_encoding, |
| 16530 const std::string& content_encoding, |
| 16531 bool should_match) { |
| 16532 HttpRequestInfo request; |
| 16533 request.method = "GET"; |
| 16534 request.url = GURL("http://www.foo.com/"); |
| 16535 request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 16536 accept_encoding); |
| 16537 |
| 16538 std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 16539 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16540 // Send headers successfully, but get an error while sending the body. |
| 16541 MockWrite data_writes[] = { |
| 16542 MockWrite("GET / HTTP/1.1\r\n" |
| 16543 "Host: www.foo.com\r\n" |
| 16544 "Connection: keep-alive\r\n" |
| 16545 "Accept-Encoding: "), |
| 16546 MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 16547 }; |
| 16548 |
| 16549 MockRead data_reads[] = { |
| 16550 MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Content-Encoding: "), |
| 16551 MockRead(content_encoding.data()), MockRead("\r\n\r\n"), |
| 16552 MockRead(SYNCHRONOUS, OK), |
| 16553 }; |
| 16554 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16555 arraysize(data_writes)); |
| 16556 session_deps->socket_factory->AddSocketDataProvider(&data); |
| 16557 |
| 16558 TestCompletionCallback callback; |
| 16559 |
| 16560 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16561 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16562 |
| 16563 rv = callback.WaitForResult(); |
| 16564 if (should_match) { |
| 16565 EXPECT_THAT(rv, IsOk()); |
| 16566 } else { |
| 16567 EXPECT_THAT(rv, IsError(ERR_INVALID_CONTENT_ENCODING)); |
| 16568 } |
| 16569 } |
| 16570 |
| 16571 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
| 16572 CheckContentEncodingMatching(&session_deps_, "foo", "foo", true); |
| 16573 } |
| 16574 |
| 16575 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
| 16576 CheckContentEncodingMatching(&session_deps_, "foo", "food", false); |
| 16577 } |
| 16578 |
| 16579 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 16580 CheckContentEncodingMatching(&session_deps_, "gzip", "x-gzip", true); |
| 16581 } |
| 16582 |
| 16583 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 16584 CheckContentEncodingMatching(&session_deps_, "foo,bar", "foo", true); |
| 16585 } |
| 16586 |
| 16587 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding5) { |
| 16588 CheckContentEncodingMatching(&session_deps_, "foo,bar", "bar", true); |
| 16589 } |
| 16590 |
| 16591 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding6) { |
| 16592 CheckContentEncodingMatching(&session_deps_, "bar; q=0", "bar", false); |
| 16593 } |
| 16594 |
| 16595 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding7) { |
| 16596 CheckContentEncodingMatching(&session_deps_, "bar; q=0.000", "bar", false); |
| 16597 } |
| 16598 |
| 16599 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding8) { |
| 16600 CheckContentEncodingMatching(&session_deps_, "bar; q=0.001", "bar", true); |
| 16601 } |
| 16602 |
| 16603 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding9) { |
| 16604 CheckContentEncodingMatching(&session_deps_, "bar; q=1", "bar", true); |
| 16605 } |
| 16606 |
| 16607 TEST_F(HttpNetworkTransactionTest, MatchContentEncodingA) { |
| 16608 CheckContentEncodingMatching(&session_deps_, "bar; q=0,foo", "bar", false); |
| 16609 } |
| 16610 |
16528 } // namespace net | 16611 } // namespace net |
OLD | NEW |