Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 2753453003: Reject unadvertised encodings (Closed)
Patch Set: Fix histo value comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16641 matching lines...) Expand 10 before | Expand all | Expand 10 after
16652 trans.Start(&request, callback.callback(), NetLogWithSource())); 16652 trans.Start(&request, callback.callback(), NetLogWithSource()));
16653 base::RunLoop().RunUntilIdle(); 16653 base::RunLoop().RunUntilIdle();
16654 16654
16655 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 16655 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
16656 HttpRequestHeaders headers; 16656 HttpRequestHeaders headers;
16657 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 16657 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
16658 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 16658 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
16659 } 16659 }
16660 #endif // !defined(OS_IOS) 16660 #endif // !defined(OS_IOS)
16661 16661
16662 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps,
16663 const std::string& accept_encoding,
16664 const std::string& content_encoding,
16665 bool should_match) {
16666 HttpRequestInfo request;
16667 request.method = "GET";
16668 request.url = GURL("http://www.foo.com/");
16669 request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding,
16670 accept_encoding);
16671
16672 std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps));
16673 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16674 // Send headers successfully, but get an error while sending the body.
16675 MockWrite data_writes[] = {
16676 MockWrite("GET / HTTP/1.1\r\n"
16677 "Host: www.foo.com\r\n"
16678 "Connection: keep-alive\r\n"
16679 "Accept-Encoding: "),
16680 MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"),
16681 };
16682
16683 MockRead data_reads[] = {
16684 MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Content-Encoding: "),
16685 MockRead(content_encoding.data()), MockRead("\r\n\r\n"),
16686 MockRead(SYNCHRONOUS, OK),
16687 };
16688 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
16689 arraysize(data_writes));
16690 session_deps->socket_factory->AddSocketDataProvider(&data);
16691
16692 TestCompletionCallback callback;
16693
16694 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
16695 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16696
16697 rv = callback.WaitForResult();
16698 if (should_match) {
16699 EXPECT_THAT(rv, IsOk());
16700 } else {
16701 EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED));
16702 }
16703 }
16704
16705 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) {
16706 CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", false);
16707 }
16708
16709 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) {
16710 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", true);
16711 }
16712
16713 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) {
16714 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip",
16715 false);
16716 }
16717
16662 } // namespace net 16718 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698