Chromium Code Reviews| Index: net/url_request/url_request_http_job_unittest.cc |
| diff --git a/net/url_request/url_request_http_job_unittest.cc b/net/url_request/url_request_http_job_unittest.cc |
| index dca3e8e979e7c2daa3801960b541255a5e1c7ef9..a171a460c9247ea7578908b4283e3b8f5d06a9a2 100644 |
| --- a/net/url_request/url_request_http_job_unittest.cc |
| +++ b/net/url_request/url_request_http_job_unittest.cc |
| @@ -52,6 +52,25 @@ class TestURLRequestHttpJob : public URLRequestHttpJob { |
| ~TestURLRequestHttpJob() override {} |
| }; |
| +bool AcceptsEncoding(const HttpRequestHeaders& headers, |
| + const std::string encoding) { |
| + std::string encoding_headers; |
| + bool get_success = headers.GetHeader("Accept-Encoding", &encoding_headers); |
| + EXPECT_TRUE(get_success); |
| + if (!get_success) |
| + return false; |
| + |
| + // This check isn't wrapped with EXPECT* macros because different |
| + // results from this function may be expected in different tests. |
| + for (const std::string& token : |
| + base::SplitString(encoding_headers, ", ", base::KEEP_WHITESPACE, |
| + base::SPLIT_WANT_NONEMPTY)) { |
| + if (base::EqualsCaseInsensitiveASCII(token, encoding)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| class URLRequestHttpJobTest : public ::testing::Test { |
| protected: |
| URLRequestHttpJobTest() |
| @@ -71,21 +90,7 @@ class URLRequestHttpJobTest : public ::testing::Test { |
| EXPECT_TRUE(request_info); |
| if (!request_info) return false; |
| - std::string encoding_headers; |
| - bool get_success = request_info->extra_headers.GetHeader( |
| - "Accept-Encoding", &encoding_headers); |
| - EXPECT_TRUE(get_success); |
| - if (!get_success) return false; |
| - |
| - // This check isn't wrapped with EXPECT* macros because different |
| - // results from this function may be expected in different tests. |
| - for (const std::string& token : |
| - base::SplitString(encoding_headers, ", ", base::KEEP_WHITESPACE, |
| - base::SPLIT_WANT_NONEMPTY)) { |
| - if (base::EqualsCaseInsensitiveASCII(token, "sdch")) |
| - return true; |
| - } |
| - return false; |
| + return AcceptsEncoding(request_info->extra_headers, "sdch"); |
| } |
| void EnableSdch() { |
| @@ -629,6 +634,48 @@ TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { |
| EXPECT_FALSE(TransactionAcceptsSdchEncoding()); |
| } |
| +class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test { |
| + protected: |
| + URLRequestHttpJobWithBrotliSupportTest() |
| + : context_(new TestURLRequestContext(true)) { |
| + scoped_ptr<HttpNetworkSession::Params> params( |
| + new HttpNetworkSession::Params); |
| + params->enable_brotli = true; |
| + context_->set_http_network_session_params(params.Pass()); |
| + context_->set_network_delegate(&network_delegate_); |
| + context_->Init(); |
| + } |
| + |
| + bool AcceptsBrotliEncoding() { |
| + return AcceptsEncoding(network_delegate_.last_headers(), "br"); |
|
xunjieli
2015/12/04 15:21:19
Let's not add "last_headers" to TestNetworkDelegat
eustas
2015/12/04 16:14:31
Great idea! Thank you. Done.
|
| + } |
| + |
| + void RunRequest(GURL url) { |
|
xunjieli
2015/12/04 15:21:19
nit: const GURL&
eustas
2015/12/04 16:14:31
Done.
|
| + scoped_ptr<URLRequest> req( |
| + context_->CreateRequest(url, DEFAULT_PRIORITY, &delegate_)); |
| + scoped_refptr<TestURLRequestHttpJob> job( |
| + new TestURLRequestHttpJob(req.get())); |
| + TestCompletionCallback dummy; |
| + network_delegate_.NotifyBeforeURLRequest(req.get(), dummy.callback(), &url); |
| + job->Start(); |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| + |
| + scoped_ptr<TestURLRequestContext> context_; |
|
xunjieli
2015/12/04 15:21:19
nit: add "private" before these variables.
eustas
2015/12/04 16:14:32
Done.
|
| + TestNetworkDelegate network_delegate_; |
| + TestDelegate delegate_; |
| +}; |
| + |
| +TEST_F(URLRequestHttpJobWithBrotliSupportTest, NoBrotliAdvertisementOverHttp) { |
| + RunRequest(GURL("http://www.example.com")); |
| + EXPECT_FALSE(AcceptsBrotliEncoding()); |
| +} |
| + |
| +TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) { |
| + RunRequest(GURL("https://www.example.com")); |
| + EXPECT_TRUE(AcceptsBrotliEncoding()); |
| +} |
| + |
| // This base class just serves to set up some things before the TestURLRequest |
| // constructor is called. |
| class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { |