Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: net/http/disk_cache_based_quic_server_info_unittest.cc

Issue 192583004: QUIC - use QuicSessionKey tuple (host, port, is_https) instead of server_hostname (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with TOT Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/http/disk_cache_based_quic_server_info.h" 5 #include "net/http/disk_cache_based_quic_server_info.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/http/mock_http_cache.h" 12 #include "net/http/mock_http_cache.h"
13 #include "net/quic/crypto/quic_server_info.h" 13 #include "net/quic/crypto/quic_server_info.h"
14 #include "net/quic/quic_session_key.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace { 17 namespace {
17 18
18 // This is an empty transaction, needed to register the URL and the test mode. 19 // This is an empty transaction, needed to register the URL and the test mode.
19 const MockTransaction kHostInfoTransaction = { 20 const MockTransaction kHostInfoTransaction1 = {
20 "quicserverinfo:https://www.google.com", 21 "quicserverinfo:https://www.google.com:443",
21 "", 22 "",
22 base::Time(), 23 base::Time(),
23 "", 24 "",
25 net::LOAD_NORMAL,
26 "",
27 "",
28 base::Time(),
29 "",
30 TEST_MODE_NORMAL,
31 NULL,
32 0
33 };
34
35 const MockTransaction kHostInfoTransaction2 = {
36 "quicserverinfo:http://www.google.com:80",
37 "",
38 base::Time(),
39 "",
24 net::LOAD_NORMAL, 40 net::LOAD_NORMAL,
25 "", 41 "",
26 "", 42 "",
27 base::Time(), 43 base::Time(),
28 "", 44 "",
29 TEST_MODE_NORMAL, 45 TEST_MODE_NORMAL,
30 NULL, 46 NULL,
31 0 47 0
32 }; 48 };
33 49
34 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a 50 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a
35 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. 51 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady.
36 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { 52 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) {
37 // Use the blocking mock backend factory to force asynchronous completion 53 // Use the blocking mock backend factory to force asynchronous completion
38 // of quic_server_info->WaitForDataReady(), so that the callback will run. 54 // of quic_server_info->WaitForDataReady(), so that the callback will run.
39 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 55 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
40 MockHttpCache cache(factory); 56 MockHttpCache cache(factory);
57 net::QuicSessionKey server_key("www.verisign.com", 443, true);
41 scoped_ptr<net::QuicServerInfo> quic_server_info( 58 scoped_ptr<net::QuicServerInfo> quic_server_info(
42 new net::DiskCacheBasedQuicServerInfo("https://www.verisign.com", 59 new net::DiskCacheBasedQuicServerInfo(server_key, cache.http_cache()));
43 cache.http_cache()));
44 quic_server_info->Start(); 60 quic_server_info->Start();
45 net::TestCompletionCallback callback; 61 net::TestCompletionCallback callback;
46 int rv = quic_server_info->WaitForDataReady(callback.callback()); 62 int rv = quic_server_info->WaitForDataReady(callback.callback());
47 EXPECT_EQ(net::ERR_IO_PENDING, rv); 63 EXPECT_EQ(net::ERR_IO_PENDING, rv);
48 // Now complete the backend creation and let the callback run. 64 // Now complete the backend creation and let the callback run.
49 factory->FinishCreation(); 65 factory->FinishCreation();
50 EXPECT_EQ(net::OK, callback.GetResult(rv)); 66 EXPECT_EQ(net::OK, callback.GetResult(rv));
51 } 67 }
52 68
53 // Tests the basic logic of storing, retrieving and updating data. 69 // Tests the basic logic of storing, retrieving and updating data.
54 TEST(DiskCacheBasedQuicServerInfo, Update) { 70 TEST(DiskCacheBasedQuicServerInfo, Update) {
55 MockHttpCache cache; 71 MockHttpCache cache;
56 AddMockTransaction(&kHostInfoTransaction); 72 AddMockTransaction(&kHostInfoTransaction1);
57 net::TestCompletionCallback callback; 73 net::TestCompletionCallback callback;
58 74
75 net::QuicSessionKey server_key("www.google.com", 443, true);
59 scoped_ptr<net::QuicServerInfo> quic_server_info( 76 scoped_ptr<net::QuicServerInfo> quic_server_info(
60 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", 77 new net::DiskCacheBasedQuicServerInfo(server_key, cache.http_cache()));
61 cache.http_cache()));
62 quic_server_info->Start(); 78 quic_server_info->Start();
63 int rv = quic_server_info->WaitForDataReady(callback.callback()); 79 int rv = quic_server_info->WaitForDataReady(callback.callback());
64 EXPECT_EQ(net::OK, callback.GetResult(rv)); 80 EXPECT_EQ(net::OK, callback.GetResult(rv));
65 81
66 net::QuicServerInfo::State* state = quic_server_info->mutable_state(); 82 net::QuicServerInfo::State* state = quic_server_info->mutable_state();
67 EXPECT_TRUE(state->certs.empty()); 83 EXPECT_TRUE(state->certs.empty());
68 const string server_config_a = "server_config_a"; 84 const string server_config_a = "server_config_a";
69 const string source_address_token_a = "source_address_token_a"; 85 const string source_address_token_a = "source_address_token_a";
70 const string server_config_sig_a = "server_config_sig_a"; 86 const string server_config_sig_a = "server_config_sig_a";
71 const string cert_a = "cert_a"; 87 const string cert_a = "cert_a";
72 const string cert_b = "cert_b"; 88 const string cert_b = "cert_b";
73 89
74 state->server_config = server_config_a; 90 state->server_config = server_config_a;
75 state->source_address_token = source_address_token_a; 91 state->source_address_token = source_address_token_a;
76 state->server_config_sig = server_config_sig_a; 92 state->server_config_sig = server_config_sig_a;
77 state->certs.push_back(cert_a); 93 state->certs.push_back(cert_a);
78 quic_server_info->Persist(); 94 quic_server_info->Persist();
79 95
80 // Wait until Persist() does the work. 96 // Wait until Persist() does the work.
81 base::MessageLoop::current()->RunUntilIdle(); 97 base::MessageLoop::current()->RunUntilIdle();
82 98
83 // Open the stored QuicServerInfo. 99 // Open the stored QuicServerInfo.
84 quic_server_info.reset( 100 quic_server_info.reset(
85 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", 101 new net::DiskCacheBasedQuicServerInfo(server_key, cache.http_cache()));
86 cache.http_cache()));
87 quic_server_info->Start(); 102 quic_server_info->Start();
88 rv = quic_server_info->WaitForDataReady(callback.callback()); 103 rv = quic_server_info->WaitForDataReady(callback.callback());
89 EXPECT_EQ(net::OK, callback.GetResult(rv)); 104 EXPECT_EQ(net::OK, callback.GetResult(rv));
90 105
91 // And now update the data. 106 // And now update the data.
92 state = quic_server_info->mutable_state(); 107 state = quic_server_info->mutable_state();
93 state->certs.push_back(cert_b); 108 state->certs.push_back(cert_b);
94 109
95 // Fail instead of DCHECKing double creates. 110 // Fail instead of DCHECKing double creates.
96 cache.disk_cache()->set_double_create_check(false); 111 cache.disk_cache()->set_double_create_check(false);
97 quic_server_info->Persist(); 112 quic_server_info->Persist();
98 base::MessageLoop::current()->RunUntilIdle(); 113 base::MessageLoop::current()->RunUntilIdle();
99 114
100 // Verify that the state was updated. 115 // Verify that the state was updated.
101 quic_server_info.reset( 116 quic_server_info.reset(
102 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", 117 new net::DiskCacheBasedQuicServerInfo(server_key, cache.http_cache()));
103 cache.http_cache()));
104 quic_server_info->Start(); 118 quic_server_info->Start();
105 rv = quic_server_info->WaitForDataReady(callback.callback()); 119 rv = quic_server_info->WaitForDataReady(callback.callback());
106 EXPECT_EQ(net::OK, callback.GetResult(rv)); 120 EXPECT_EQ(net::OK, callback.GetResult(rv));
107 121
108 const net::QuicServerInfo::State& state1 = quic_server_info->state(); 122 const net::QuicServerInfo::State& state1 = quic_server_info->state();
109 EXPECT_TRUE(quic_server_info->IsDataReady()); 123 EXPECT_TRUE(quic_server_info->IsDataReady());
110 EXPECT_EQ(server_config_a, state1.server_config); 124 EXPECT_EQ(server_config_a, state1.server_config);
111 EXPECT_EQ(source_address_token_a, state1.source_address_token); 125 EXPECT_EQ(source_address_token_a, state1.source_address_token);
112 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); 126 EXPECT_EQ(server_config_sig_a, state1.server_config_sig);
113 EXPECT_EQ(2U, state1.certs.size()); 127 EXPECT_EQ(2U, state1.certs.size());
114 EXPECT_EQ(cert_a, state1.certs[0]); 128 EXPECT_EQ(cert_a, state1.certs[0]);
115 EXPECT_EQ(cert_b, state1.certs[1]); 129 EXPECT_EQ(cert_b, state1.certs[1]);
116 130
117 RemoveMockTransaction(&kHostInfoTransaction); 131 RemoveMockTransaction(&kHostInfoTransaction1);
132 }
133
134 // Test that demonstrates different info is returned when the ports differ.
135 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) {
136 MockHttpCache cache;
137 AddMockTransaction(&kHostInfoTransaction1);
138 AddMockTransaction(&kHostInfoTransaction2);
139 net::TestCompletionCallback callback;
140
141 // Persist data for port 443.
142 net::QuicSessionKey server_key1("www.google.com", 443, true);
143 scoped_ptr<net::QuicServerInfo> quic_server_info1(
144 new net::DiskCacheBasedQuicServerInfo(server_key1, cache.http_cache()));
145 quic_server_info1->Start();
146 int rv = quic_server_info1->WaitForDataReady(callback.callback());
147 EXPECT_EQ(net::OK, callback.GetResult(rv));
148
149 net::QuicServerInfo::State* state1 = quic_server_info1->mutable_state();
150 EXPECT_TRUE(state1->certs.empty());
151 const string server_config_a = "server_config_a";
152 const string source_address_token_a = "source_address_token_a";
153 const string server_config_sig_a = "server_config_sig_a";
154 const string cert_a = "cert_a";
155
156 state1->server_config = server_config_a;
157 state1->source_address_token = source_address_token_a;
158 state1->server_config_sig = server_config_sig_a;
159 state1->certs.push_back(cert_a);
160 quic_server_info1->Persist();
161
162 // Wait until Persist() does the work.
163 base::MessageLoop::current()->RunUntilIdle();
164
165 // Persist data for port 80.
166 net::QuicSessionKey server_key2("www.google.com", 80, false);
167 scoped_ptr<net::QuicServerInfo> quic_server_info2(
168 new net::DiskCacheBasedQuicServerInfo(server_key2, cache.http_cache()));
169 quic_server_info2->Start();
170 rv = quic_server_info2->WaitForDataReady(callback.callback());
171 EXPECT_EQ(net::OK, callback.GetResult(rv));
172
173 net::QuicServerInfo::State* state2 = quic_server_info2->mutable_state();
174 EXPECT_TRUE(state2->certs.empty());
175 const string server_config_b = "server_config_b";
176 const string source_address_token_b = "source_address_token_b";
177 const string server_config_sig_b = "server_config_sig_b";
178 const string cert_b = "cert_b";
179
180 state2->server_config = server_config_b;
181 state2->source_address_token = source_address_token_b;
182 state2->server_config_sig = server_config_sig_b;
183 state2->certs.push_back(cert_b);
184 quic_server_info2->Persist();
185
186 // Wait until Persist() does the work.
187 base::MessageLoop::current()->RunUntilIdle();
188
189 // Verify the stored QuicServerInfo for port 443.
190 scoped_ptr<net::QuicServerInfo> quic_server_info(
191 new net::DiskCacheBasedQuicServerInfo(server_key1, cache.http_cache()));
192 quic_server_info->Start();
193 rv = quic_server_info->WaitForDataReady(callback.callback());
194 EXPECT_EQ(net::OK, callback.GetResult(rv));
195
196 const net::QuicServerInfo::State& state_a = quic_server_info->state();
197 EXPECT_TRUE(quic_server_info->IsDataReady());
198 EXPECT_EQ(server_config_a, state_a.server_config);
199 EXPECT_EQ(source_address_token_a, state_a.source_address_token);
200 EXPECT_EQ(server_config_sig_a, state_a.server_config_sig);
201 EXPECT_EQ(1U, state_a.certs.size());
202 EXPECT_EQ(cert_a, state_a.certs[0]);
203
204 // Verify the stored QuicServerInfo for port 80.
205 quic_server_info.reset(
206 new net::DiskCacheBasedQuicServerInfo(server_key2, cache.http_cache()));
207 quic_server_info->Start();
208 rv = quic_server_info->WaitForDataReady(callback.callback());
209 EXPECT_EQ(net::OK, callback.GetResult(rv));
210
211 const net::QuicServerInfo::State& state_b = quic_server_info->state();
212 EXPECT_TRUE(quic_server_info->IsDataReady());
213 EXPECT_EQ(server_config_b, state_b.server_config);
214 EXPECT_EQ(source_address_token_b, state_b.source_address_token);
215 EXPECT_EQ(server_config_sig_b, state_b.server_config_sig);
216 EXPECT_EQ(1U, state_b.certs.size());
217 EXPECT_EQ(cert_b, state_b.certs[0]);
218
219 RemoveMockTransaction(&kHostInfoTransaction2);
220 RemoveMockTransaction(&kHostInfoTransaction1);
118 } 221 }
119 222
120 } // namespace 223 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698