OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/quic/quic_client_push_promise_index.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "net/quic/spdy_utils.h" | |
10 #include "net/quic/test_tools/crypto_test_utils.h" | |
11 #include "net/quic/test_tools/mock_quic_client_promised_info.h" | |
12 #include "net/quic/test_tools/quic_test_utils.h" | |
13 #include "net/tools/quic/quic_client_session.h" | |
14 | |
15 using testing::_; | |
16 using testing::Return; | |
17 using testing::StrictMock; | |
18 using std::string; | |
19 | |
20 namespace net { | |
21 namespace test { | |
22 namespace { | |
23 | |
24 class MockQuicClientSession : public QuicClientSession { | |
25 public: | |
26 explicit MockQuicClientSession(QuicConnection* connection, | |
27 QuicClientPushPromiseIndex* push_promise_index) | |
28 : QuicClientSession( | |
29 DefaultQuicConfig(), | |
30 connection, | |
31 QuicServerId("example.com", 443, PRIVACY_MODE_DISABLED), | |
32 &crypto_config_, | |
33 push_promise_index), | |
34 crypto_config_(CryptoTestUtils::ProofVerifierForTesting()) {} | |
35 ~MockQuicClientSession() override {} | |
36 | |
37 MOCK_METHOD1(CloseStream, void(QuicStreamId stream_id)); | |
38 | |
39 private: | |
40 QuicCryptoClientConfig crypto_config_; | |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(MockQuicClientSession); | |
43 }; | |
44 | |
45 class QuicClientPushPromiseIndexTest : public ::testing::Test { | |
46 public: | |
47 QuicClientPushPromiseIndexTest() | |
48 : connection_(new StrictMock<MockQuicConnection>(&helper_, | |
49 &alarm_factory_, | |
50 Perspective::IS_CLIENT)), | |
51 session_(connection_, &index_), | |
52 promised_(&session_, kServerDataStreamId1, url_) { | |
53 FLAGS_quic_supports_push_promise = true; | |
54 request_[":path"] = "/bar"; | |
55 request_[":authority"] = "www.google.com"; | |
56 request_[":version"] = "HTTP/1.1"; | |
57 request_[":method"] = "GET"; | |
58 request_[":scheme"] = "https"; | |
59 url_ = SpdyUtils::GetUrlFromHeaderBlock(request_); | |
60 } | |
61 | |
62 MockQuicConnectionHelper helper_; | |
63 MockAlarmFactory alarm_factory_; | |
64 StrictMock<MockQuicConnection>* connection_; | |
65 MockQuicClientSession session_; | |
66 QuicClientPushPromiseIndex index_; | |
67 SpdyHeaderBlock request_; | |
68 string url_; | |
69 MockQuicClientPromisedInfo promised_; | |
70 QuicClientPushPromiseIndex::TryHandle* handle_; | |
71 }; | |
72 | |
73 TEST_F(QuicClientPushPromiseIndexTest, TryRequestSuccess) { | |
74 (*index_.promised_by_url())[url_] = &promised_; | |
75 EXPECT_CALL(promised_, HandleClientRequest(_, _)) | |
76 .WillOnce(Return(QUIC_SUCCESS)); | |
77 EXPECT_EQ(index_.Try(request_, nullptr, &handle_), QUIC_SUCCESS); | |
78 } | |
79 | |
80 TEST_F(QuicClientPushPromiseIndexTest, TryRequestPending) { | |
81 (*index_.promised_by_url())[url_] = &promised_; | |
82 EXPECT_CALL(promised_, HandleClientRequest(_, _)) | |
83 .WillOnce(Return(QUIC_PENDING)); | |
84 EXPECT_EQ(index_.Try(request_, nullptr, &handle_), QUIC_PENDING); | |
85 } | |
86 | |
87 TEST_F(QuicClientPushPromiseIndexTest, TryRequestFailure) { | |
88 (*index_.promised_by_url())[url_] = &promised_; | |
89 EXPECT_CALL(promised_, HandleClientRequest(_, _)) | |
90 .WillOnce(Return(QUIC_FAILURE)); | |
91 EXPECT_EQ(index_.Try(request_, nullptr, &handle_), QUIC_FAILURE); | |
92 } | |
93 | |
94 TEST_F(QuicClientPushPromiseIndexTest, TryNoPromise) { | |
95 EXPECT_EQ(index_.Try(request_, nullptr, &handle_), QUIC_FAILURE); | |
96 } | |
97 | |
98 TEST_F(QuicClientPushPromiseIndexTest, GetNoPromise) { | |
99 EXPECT_EQ(index_.GetPromised(url_), nullptr); | |
100 } | |
101 | |
102 TEST_F(QuicClientPushPromiseIndexTest, GetPromise) { | |
103 (*index_.promised_by_url())[url_] = &promised_; | |
104 EXPECT_EQ(index_.GetPromised(url_), &promised_); | |
105 } | |
106 | |
107 } // namespace | |
108 } // namespace test | |
109 } // namespace net | |
OLD | NEW |