| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <sys/epoll.h> | 6 #include <sys/epoll.h> |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 2147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2158 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2158 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2159 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2159 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 2160 } | 2160 } |
| 2161 | 2161 |
| 2162 // A test stream that gives |response_body_| as an error response body. | 2162 // A test stream that gives |response_body_| as an error response body. |
| 2163 class ServerStreamWithErrorResponseBody : public QuicSimpleServerStream { | 2163 class ServerStreamWithErrorResponseBody : public QuicSimpleServerStream { |
| 2164 public: | 2164 public: |
| 2165 ServerStreamWithErrorResponseBody(QuicStreamId id, | 2165 ServerStreamWithErrorResponseBody(QuicStreamId id, |
| 2166 QuicSpdySession* session, | 2166 QuicSpdySession* session, |
| 2167 string response_body) | 2167 string response_body) |
| 2168 : QuicSimpleServerStream(id, session), response_body_(response_body) {} | 2168 : QuicSimpleServerStream(id, session), |
| 2169 response_body_(std::move(response_body)) {} |
| 2169 | 2170 |
| 2170 ~ServerStreamWithErrorResponseBody() override {} | 2171 ~ServerStreamWithErrorResponseBody() override {} |
| 2171 | 2172 |
| 2172 protected: | 2173 protected: |
| 2173 void SendErrorResponse() override { | 2174 void SendErrorResponse() override { |
| 2174 DVLOG(1) << "Sending error response for stream " << id(); | 2175 DVLOG(1) << "Sending error response for stream " << id(); |
| 2175 SpdyHeaderBlock headers; | 2176 SpdyHeaderBlock headers; |
| 2176 headers[":status"] = "500"; | 2177 headers[":status"] = "500"; |
| 2177 headers["content-length"] = base::UintToString(response_body_.size()); | 2178 headers["content-length"] = base::UintToString(response_body_.size()); |
| 2178 // This method must call CloseReadSide to cause the test case, StopReading | 2179 // This method must call CloseReadSide to cause the test case, StopReading |
| 2179 // is not sufficient. | 2180 // is not sufficient. |
| 2180 ReliableQuicStreamPeer::CloseReadSide(this); | 2181 ReliableQuicStreamPeer::CloseReadSide(this); |
| 2181 SendHeadersAndBody(std::move(headers), response_body_); | 2182 SendHeadersAndBody(std::move(headers), response_body_); |
| 2182 } | 2183 } |
| 2183 | 2184 |
| 2184 string response_body_; | 2185 string response_body_; |
| 2185 }; | 2186 }; |
| 2186 | 2187 |
| 2187 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { | 2188 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { |
| 2188 public: | 2189 public: |
| 2189 explicit StreamWithErrorFactory(string response_body) | 2190 explicit StreamWithErrorFactory(string response_body) |
| 2190 : response_body_(response_body) {} | 2191 : response_body_(std::move(response_body)) {} |
| 2191 | 2192 |
| 2192 ~StreamWithErrorFactory() override {} | 2193 ~StreamWithErrorFactory() override {} |
| 2193 | 2194 |
| 2194 QuicSimpleServerStream* CreateStream(QuicStreamId id, | 2195 QuicSimpleServerStream* CreateStream(QuicStreamId id, |
| 2195 QuicSpdySession* session) override { | 2196 QuicSpdySession* session) override { |
| 2196 return new ServerStreamWithErrorResponseBody(id, session, response_body_); | 2197 return new ServerStreamWithErrorResponseBody(id, session, response_body_); |
| 2197 } | 2198 } |
| 2198 | 2199 |
| 2199 private: | 2200 private: |
| 2200 string response_body_; | 2201 string response_body_; |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2616 AddRequestAndResponseWithServerPush("example.com", "/push_example", kBody, | 2617 AddRequestAndResponseWithServerPush("example.com", "/push_example", kBody, |
| 2617 push_urls, kNumResources, 0); | 2618 push_urls, kNumResources, 0); |
| 2618 client_->client()->set_response_listener(new TestResponseListener); | 2619 client_->client()->set_response_listener(new TestResponseListener); |
| 2619 | 2620 |
| 2620 // Send the first request: this will trigger the server to send all the push | 2621 // Send the first request: this will trigger the server to send all the push |
| 2621 // resources associated with this request, and these will be cached by the | 2622 // resources associated with this request, and these will be cached by the |
| 2622 // client. | 2623 // client. |
| 2623 EXPECT_EQ(kBody, client_->SendSynchronousRequest( | 2624 EXPECT_EQ(kBody, client_->SendSynchronousRequest( |
| 2624 "https://example.com/push_example")); | 2625 "https://example.com/push_example")); |
| 2625 | 2626 |
| 2626 for (string url : push_urls) { | 2627 for (const string& url : push_urls) { |
| 2627 // Sending subsequent requesets will not actually send anything on the wire, | 2628 // Sending subsequent requesets will not actually send anything on the wire, |
| 2628 // as the responses are already in the client's cache. | 2629 // as the responses are already in the client's cache. |
| 2629 DVLOG(1) << "send request for pushed stream on url " << url; | 2630 DVLOG(1) << "send request for pushed stream on url " << url; |
| 2630 string expected_body = "This is server push response body for " + url; | 2631 string expected_body = "This is server push response body for " + url; |
| 2631 string response_body = client_->SendSynchronousRequest(url); | 2632 string response_body = client_->SendSynchronousRequest(url); |
| 2632 DVLOG(1) << "response body " << response_body; | 2633 DVLOG(1) << "response body " << response_body; |
| 2633 EXPECT_EQ(expected_body, response_body); | 2634 EXPECT_EQ(expected_body, response_body); |
| 2634 } | 2635 } |
| 2635 // Expect only original request has been sent and push responses have been | 2636 // Expect only original request has been sent and push responses have been |
| 2636 // received as normal response. | 2637 // received as normal response. |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2920 EXPECT_EQ(kBarResponseBody, client_->response_body()); | 2921 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
| 2921 QuicConnectionStats client_stats = | 2922 QuicConnectionStats client_stats = |
| 2922 client_->client()->session()->connection()->GetStats(); | 2923 client_->client()->session()->connection()->GetStats(); |
| 2923 EXPECT_EQ(0u, client_stats.packets_lost); | 2924 EXPECT_EQ(0u, client_stats.packets_lost); |
| 2924 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 2925 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 2925 } | 2926 } |
| 2926 | 2927 |
| 2927 } // namespace | 2928 } // namespace |
| 2928 } // namespace test | 2929 } // namespace test |
| 2929 } // namespace net | 2930 } // namespace net |
| OLD | NEW |