| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/quic/quic_client_promised_info.h" | 5 #include "net/quic/quic_client_promised_info.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 8 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 9 #include "net/gfe2/balsa_headers.h" | 11 #include "net/gfe2/balsa_headers.h" |
| 10 #include "net/quic/quic_client.h" | 12 #include "net/quic/quic_client.h" |
| 11 #include "net/quic/quic_client_session.h" | 13 #include "net/quic/quic_client_session.h" |
| 12 #include "net/quic/quic_spdy_client_stream.h" | 14 #include "net/quic/quic_spdy_client_stream.h" |
| 13 #include "net/quic/quic_utils.h" | 15 #include "net/quic/quic_utils.h" |
| 14 #include "net/quic/spdy_balsa_utils.h" | 16 #include "net/quic/spdy_balsa_utils.h" |
| 15 #include "net/quic/spdy_utils.h" | 17 #include "net/quic/spdy_utils.h" |
| 16 #include "net/quic/test_tools/crypto_test_utils.h" | 18 #include "net/quic/test_tools/crypto_test_utils.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 bool authorized_; | 65 bool authorized_; |
| 64 | 66 |
| 65 DISALLOW_COPY_AND_ASSIGN(MockQuicClientSession); | 67 DISALLOW_COPY_AND_ASSIGN(MockQuicClientSession); |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 class QuicClientPromisedInfoTest : public ::testing::Test { | 70 class QuicClientPromisedInfoTest : public ::testing::Test { |
| 69 public: | 71 public: |
| 70 class StreamVisitor; | 72 class StreamVisitor; |
| 71 | 73 |
| 72 QuicClientPromisedInfoTest() | 74 QuicClientPromisedInfoTest() |
| 73 : connection_( | 75 : connection_(new StrictMock<MockConnection>(&helper_, |
| 74 new StrictMock<MockConnection>(&helper_, Perspective::IS_CLIENT)), | 76 &alarm_factory_, |
| 77 Perspective::IS_CLIENT)), |
| 75 session_(connection_, &push_promise_index_), | 78 session_(connection_, &push_promise_index_), |
| 76 body_("hello world"), | 79 body_("hello world"), |
| 77 promise_id_(gfe_quic::test::kServerDataStreamId1) { | 80 promise_id_(gfe_quic::test::kServerDataStreamId1) { |
| 78 FLAGS_quic_supports_push_promise = true; | 81 FLAGS_quic_supports_push_promise = true; |
| 79 | 82 |
| 80 session_.Initialize(); | 83 session_.Initialize(); |
| 81 | 84 |
| 82 headers_.SetResponseFirstline("HTTP/1.1", 200, "Ok"); | 85 headers_.SetResponseFirstline("HTTP/1.1", 200, "Ok"); |
| 83 headers_.ReplaceOrAppendHeader("content-length", "11"); | 86 headers_.ReplaceOrAppendHeader("content-length", "11"); |
| 84 headers_string_ = SpdyBalsaUtils::SerializeResponseHeaders(headers_); | 87 headers_string_ = SpdyBalsaUtils::SerializeResponseHeaders(headers_); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 QuicSpdyClientStream* rendezvous_stream_; | 138 QuicSpdyClientStream* rendezvous_stream_; |
| 136 }; | 139 }; |
| 137 | 140 |
| 138 void ReceivePromise(QuicStreamId id) { | 141 void ReceivePromise(QuicStreamId id) { |
| 139 stream_->OnStreamHeaders(serialized_push_promise_); | 142 stream_->OnStreamHeaders(serialized_push_promise_); |
| 140 | 143 |
| 141 stream_->OnPromiseHeadersComplete(id, serialized_push_promise_.size()); | 144 stream_->OnPromiseHeadersComplete(id, serialized_push_promise_.size()); |
| 142 } | 145 } |
| 143 | 146 |
| 144 MockConnectionHelper helper_; | 147 MockConnectionHelper helper_; |
| 148 MockAlarmFactory alarm_factory_; |
| 145 StrictMock<MockConnection>* connection_; | 149 StrictMock<MockConnection>* connection_; |
| 146 QuicClientPushPromiseIndex push_promise_index_; | 150 QuicClientPushPromiseIndex push_promise_index_; |
| 147 | 151 |
| 148 MockQuicClientSession session_; | 152 MockQuicClientSession session_; |
| 149 std::unique_ptr<QuicSpdyClientStream> stream_; | 153 std::unique_ptr<QuicSpdyClientStream> stream_; |
| 150 std::unique_ptr<StreamVisitor> stream_visitor_; | 154 std::unique_ptr<StreamVisitor> stream_visitor_; |
| 151 std::unique_ptr<QuicSpdyClientStream> promised_stream_; | 155 std::unique_ptr<QuicSpdyClientStream> promised_stream_; |
| 152 BalsaHeaders headers_; | 156 BalsaHeaders headers_; |
| 153 string headers_string_; | 157 string headers_string_; |
| 154 string body_; | 158 string body_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 169 TEST_F(QuicClientPromisedInfoTest, PushPromiseCleanupAlarm) { | 173 TEST_F(QuicClientPromisedInfoTest, PushPromiseCleanupAlarm) { |
| 170 ReceivePromise(promise_id_); | 174 ReceivePromise(promise_id_); |
| 171 | 175 |
| 172 // Verify that the promise is in the unclaimed streams map. | 176 // Verify that the promise is in the unclaimed streams map. |
| 173 QuicClientPromisedInfo* promised = session_.GetPromisedById(promise_id_); | 177 QuicClientPromisedInfo* promised = session_.GetPromisedById(promise_id_); |
| 174 ASSERT_NE(promised, nullptr); | 178 ASSERT_NE(promised, nullptr); |
| 175 | 179 |
| 176 // Fire the alarm that will cancel the promised stream. | 180 // Fire the alarm that will cancel the promised stream. |
| 177 EXPECT_CALL(*connection_, | 181 EXPECT_CALL(*connection_, |
| 178 SendRstStream(promise_id_, QUIC_STREAM_CANCELLED, 0)); | 182 SendRstStream(promise_id_, QUIC_STREAM_CANCELLED, 0)); |
| 179 helper_.FireAlarm(QuicClientPromisedInfoPeer::GetAlarm(promised)); | 183 alarm_factory_.FireAlarm(QuicClientPromisedInfoPeer::GetAlarm(promised)); |
| 180 | 184 |
| 181 // Verify that the promise is gone after the alarm fires. | 185 // Verify that the promise is gone after the alarm fires. |
| 182 EXPECT_EQ(session_.GetPromisedById(promise_id_), nullptr); | 186 EXPECT_EQ(session_.GetPromisedById(promise_id_), nullptr); |
| 183 EXPECT_EQ(session_.GetPromisedByUrl(promise_url_), nullptr); | 187 EXPECT_EQ(session_.GetPromisedByUrl(promise_url_), nullptr); |
| 184 } | 188 } |
| 185 | 189 |
| 186 TEST_F(QuicClientPromisedInfoTest, PushPromiseInvalidMethod) { | 190 TEST_F(QuicClientPromisedInfoTest, PushPromiseInvalidMethod) { |
| 187 // Promise with an unsafe method | 191 // Promise with an unsafe method |
| 188 push_promise_[":method"] = "PUT"; | 192 push_promise_[":method"] = "PUT"; |
| 189 serialized_push_promise_ = | 193 serialized_push_promise_ = |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 EXPECT_FALSE(delegate.rendezvous_fired()); | 371 EXPECT_FALSE(delegate.rendezvous_fired()); |
| 368 EXPECT_EQ(delegate.rendezvous_stream(), nullptr); | 372 EXPECT_EQ(delegate.rendezvous_stream(), nullptr); |
| 369 | 373 |
| 370 // Promise is gone | 374 // Promise is gone |
| 371 EXPECT_EQ(session_.GetPromisedById(promise_id_), nullptr); | 375 EXPECT_EQ(session_.GetPromisedById(promise_id_), nullptr); |
| 372 } | 376 } |
| 373 | 377 |
| 374 } // namespace | 378 } // namespace |
| 375 } // namespace test | 379 } // namespace test |
| 376 } // namespace net | 380 } // namespace net |
| OLD | NEW |