OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <memory> | 10 #include <memory> |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 test_job_interceptor_->set_main_intercept_job(std::move(job)); | 155 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
156 request->Start(); | 156 request->Start(); |
157 | 157 |
158 base::RunLoop().Run(); | 158 base::RunLoop().Run(); |
159 EXPECT_EQ(OK, delegate_.request_status()); | 159 EXPECT_EQ(OK, delegate_.request_status()); |
160 EXPECT_EQ("Test Content", delegate_.data_received()); | 160 EXPECT_EQ("Test Content", delegate_.data_received()); |
161 } | 161 } |
162 | 162 |
163 // Received a malformed SDCH encoded response when there is no SdchManager. | 163 // Received a malformed SDCH encoded response when there is no SdchManager. |
164 TEST_F(URLRequestHttpJobSetUpSourceTest, | 164 TEST_F(URLRequestHttpJobSetUpSourceTest, |
165 SdchNotAdvertisedGotMalformedSdchResponse) { | 165 SdchNotAdvertisedGotMalformedSdchResponse) { |
xunjieli
2016/11/29 23:30:42
Could you change the name of this test to somethin
mef
2016/11/30 15:51:07
Done.
| |
166 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 166 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
167 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 167 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
168 "Content-Encoding: sdch\r\n" | 168 "Content-Encoding: sdch\r\n" |
169 "Content-Length: 12\r\n\r\n"), | 169 "Content-Length: 12\r\n\r\n"), |
170 MockRead("Test Content")}; | 170 MockRead("Test Content")}; |
171 | 171 |
172 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 172 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
173 arraysize(writes)); | 173 arraysize(writes)); |
174 socket_factory_.AddSocketDataProvider(&socket_data); | 174 socket_factory_.AddSocketDataProvider(&socket_data); |
175 | 175 |
176 // This test expects TestURLRequestContexts to have no SdchManager. | 176 // This test expects TestURLRequestContexts to have no SdchManager. |
177 DCHECK(!context_.sdch_manager()); | 177 DCHECK(!context_.sdch_manager()); |
178 | 178 |
179 std::unique_ptr<URLRequest> request = context_.CreateRequest( | 179 std::unique_ptr<URLRequest> request = context_.CreateRequest( |
180 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_); | 180 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_); |
181 std::unique_ptr<TestURLRequestHttpJob> job( | 181 std::unique_ptr<TestURLRequestHttpJob> job( |
182 new TestURLRequestHttpJob(request.get())); | 182 new TestURLRequestHttpJob(request.get())); |
183 test_job_interceptor_->set_main_intercept_job(std::move(job)); | 183 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
184 request->Start(); | 184 request->Start(); |
185 | 185 |
186 base::RunLoop().Run(); | 186 base::RunLoop().Run(); |
187 EXPECT_EQ(ERR_CONTENT_DECODING_INIT_FAILED, delegate_.request_status()); | 187 // Pass through the raw response tje same way as if received unknown encoding. |
xunjieli
2016/11/29 23:30:42
nit: typo in "the"
mef
2016/11/30 15:51:07
Done.
| |
188 EXPECT_EQ(OK, delegate_.request_status()); | |
189 EXPECT_EQ("Test Content", delegate_.data_received()); | |
188 } | 190 } |
189 | 191 |
190 class URLRequestHttpJobTest : public ::testing::Test { | 192 class URLRequestHttpJobTest : public ::testing::Test { |
191 protected: | 193 protected: |
192 URLRequestHttpJobTest() : context_(true) { | 194 URLRequestHttpJobTest() : context_(true) { |
193 context_.set_http_transaction_factory(&network_layer_); | 195 context_.set_http_transaction_factory(&network_layer_); |
194 | 196 |
195 // The |test_job_factory_| takes ownership of the interceptor. | 197 // The |test_job_factory_| takes ownership of the interceptor. |
196 test_job_interceptor_ = new TestJobInterceptor(); | 198 test_job_interceptor_ = new TestJobInterceptor(); |
197 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( | 199 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 new HttpNetworkSession::Params); | 771 new HttpNetworkSession::Params); |
770 context_.set_http_network_session_params(std::move(params)); | 772 context_.set_http_network_session_params(std::move(params)); |
771 context_.set_client_socket_factory(&socket_factory_); | 773 context_.set_client_socket_factory(&socket_factory_); |
772 context_.Init(); | 774 context_.Init(); |
773 } | 775 } |
774 | 776 |
775 MockClientSocketFactory socket_factory_; | 777 MockClientSocketFactory socket_factory_; |
776 TestURLRequestContext context_; | 778 TestURLRequestContext context_; |
777 }; | 779 }; |
778 | 780 |
781 // Received a malformed SDCH encoded response when there is no SdchManager. | |
xunjieli
2016/11/29 23:30:42
Could you adjust this comment to something like:
mef
2016/11/30 15:51:07
Done.
| |
782 TEST_F(URLRequestHttpJobWithSdchSupportTest, | |
783 SdchAdvertisedGotMalformedSdchResponse) { | |
784 MockWrite writes[] = { | |
785 MockWrite("GET / HTTP/1.1\r\n" | |
786 "Host: www.example.com\r\n" | |
787 "Connection: keep-alive\r\n" | |
788 "User-Agent:\r\n" | |
789 "Accept-Encoding: gzip, deflate, sdch\r\n" | |
790 "Accept-Language: en-us,fr\r\n\r\n")}; | |
791 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | |
792 "Content-Encoding: sdch\r\n" | |
793 "Content-Length: 12\r\n\r\n"), | |
794 MockRead("Test Content")}; | |
795 | |
796 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | |
797 arraysize(writes)); | |
798 socket_factory_.AddSocketDataProvider(&socket_data); | |
799 | |
800 MockSdchObserver sdch_observer; | |
801 SdchManager sdch_manager; | |
802 sdch_manager.AddObserver(&sdch_observer); | |
803 context_.set_sdch_manager(&sdch_manager); | |
804 TestDelegate delegate; | |
805 std::unique_ptr<URLRequest> request = context_.CreateRequest( | |
806 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | |
807 request->Start(); | |
808 | |
809 base::RunLoop().Run(); | |
810 // SDCH encoded content is silently passed through if it cannot be decoded. | |
811 // EXPECT_EQ(ERR_CONTENT_DECODING_INIT_FAILED, delegate.request_status()); | |
mef
2016/11/29 22:51:51
I would've expected an error if SDCH manager is pr
xunjieli
2016/11/29 23:30:42
This is expected. SdchPolicyDelegate::OnDictionary
mef
2016/11/30 15:51:07
Acknowledged. Thanks for explanation!
| |
812 // Pass through the raw response tje same way as if received unknown encoding. | |
xunjieli
2016/11/29 23:30:42
Could you remove this line and the line above?
May
mef
2016/11/30 15:51:07
Done.
| |
813 EXPECT_EQ(OK, delegate.request_status()); | |
814 EXPECT_EQ("Test Content", delegate.data_received()); | |
815 // Cleanup manager. | |
816 sdch_manager.RemoveObserver(&sdch_observer); | |
817 } | |
818 | |
779 TEST_F(URLRequestHttpJobWithSdchSupportTest, GetDictionary) { | 819 TEST_F(URLRequestHttpJobWithSdchSupportTest, GetDictionary) { |
780 MockWrite writes[] = { | 820 MockWrite writes[] = { |
781 MockWrite("GET / HTTP/1.1\r\n" | 821 MockWrite("GET / HTTP/1.1\r\n" |
782 "Host: example.com\r\n" | 822 "Host: example.com\r\n" |
783 "Connection: keep-alive\r\n" | 823 "Connection: keep-alive\r\n" |
784 "User-Agent:\r\n" | 824 "User-Agent:\r\n" |
785 "Accept-Encoding: gzip, deflate, sdch\r\n" | 825 "Accept-Encoding: gzip, deflate, sdch\r\n" |
786 "Accept-Language: en-us,fr\r\n\r\n")}; | 826 "Accept-Language: en-us,fr\r\n\r\n")}; |
787 | 827 |
788 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 828 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1057 base::RunLoop().RunUntilIdle(); | 1097 base::RunLoop().RunUntilIdle(); |
1058 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); | 1098 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); |
1059 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 1099 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
1060 } | 1100 } |
1061 | 1101 |
1062 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) | 1102 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
1063 | 1103 |
1064 } // namespace | 1104 } // namespace |
1065 | 1105 |
1066 } // namespace net | 1106 } // namespace net |
OLD | NEW |