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