OLD | NEW |
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" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a | 53 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a |
54 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. | 54 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. |
55 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { | 55 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { |
56 // Use the blocking mock backend factory to force asynchronous completion | 56 // Use the blocking mock backend factory to force asynchronous completion |
57 // of quic_server_info->WaitForDataReady(), so that the callback will run. | 57 // of quic_server_info->WaitForDataReady(), so that the callback will run. |
58 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); | 58 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
59 MockHttpCache cache(factory); | 59 MockHttpCache cache(factory); |
60 QuicSessionKey server_key("www.verisign.com", 443, true, | 60 QuicSessionKey server_key("www.verisign.com", 443, true, |
61 kPrivacyModeDisabled); | 61 PRIVACY_MODE_DISABLED); |
62 scoped_ptr<QuicServerInfo> quic_server_info( | 62 scoped_ptr<QuicServerInfo> quic_server_info( |
63 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); | 63 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); |
64 quic_server_info->Start(); | 64 quic_server_info->Start(); |
65 TestCompletionCallback callback; | 65 TestCompletionCallback callback; |
66 int rv = quic_server_info->WaitForDataReady(callback.callback()); | 66 int rv = quic_server_info->WaitForDataReady(callback.callback()); |
67 EXPECT_EQ(ERR_IO_PENDING, rv); | 67 EXPECT_EQ(ERR_IO_PENDING, rv); |
68 // Now complete the backend creation and let the callback run. | 68 // Now complete the backend creation and let the callback run. |
69 factory->FinishCreation(); | 69 factory->FinishCreation(); |
70 EXPECT_EQ(OK, callback.GetResult(rv)); | 70 EXPECT_EQ(OK, callback.GetResult(rv)); |
71 } | 71 } |
72 | 72 |
73 // Tests the basic logic of storing, retrieving and updating data. | 73 // Tests the basic logic of storing, retrieving and updating data. |
74 TEST(DiskCacheBasedQuicServerInfo, Update) { | 74 TEST(DiskCacheBasedQuicServerInfo, Update) { |
75 MockHttpCache cache; | 75 MockHttpCache cache; |
76 AddMockTransaction(&kHostInfoTransaction1); | 76 AddMockTransaction(&kHostInfoTransaction1); |
77 TestCompletionCallback callback; | 77 TestCompletionCallback callback; |
78 | 78 |
79 QuicSessionKey server_key("www.google.com", 443, true, kPrivacyModeDisabled); | 79 QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); |
80 scoped_ptr<QuicServerInfo> quic_server_info( | 80 scoped_ptr<QuicServerInfo> quic_server_info( |
81 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); | 81 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); |
82 quic_server_info->Start(); | 82 quic_server_info->Start(); |
83 int rv = quic_server_info->WaitForDataReady(callback.callback()); | 83 int rv = quic_server_info->WaitForDataReady(callback.callback()); |
84 EXPECT_EQ(OK, callback.GetResult(rv)); | 84 EXPECT_EQ(OK, callback.GetResult(rv)); |
85 | 85 |
86 QuicServerInfo::State* state = quic_server_info->mutable_state(); | 86 QuicServerInfo::State* state = quic_server_info->mutable_state(); |
87 EXPECT_TRUE(state->certs.empty()); | 87 EXPECT_TRUE(state->certs.empty()); |
88 const string server_config_a = "server_config_a"; | 88 const string server_config_a = "server_config_a"; |
89 const string source_address_token_a = "source_address_token_a"; | 89 const string source_address_token_a = "source_address_token_a"; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 | 137 |
138 // Test that demonstrates different info is returned when the ports differ. | 138 // Test that demonstrates different info is returned when the ports differ. |
139 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { | 139 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { |
140 MockHttpCache cache; | 140 MockHttpCache cache; |
141 AddMockTransaction(&kHostInfoTransaction1); | 141 AddMockTransaction(&kHostInfoTransaction1); |
142 AddMockTransaction(&kHostInfoTransaction2); | 142 AddMockTransaction(&kHostInfoTransaction2); |
143 TestCompletionCallback callback; | 143 TestCompletionCallback callback; |
144 | 144 |
145 // Persist data for port 443. | 145 // Persist data for port 443. |
146 QuicSessionKey server_key1("www.google.com", 443, true, kPrivacyModeDisabled); | 146 QuicSessionKey server_key1("www.google.com", 443, true, |
| 147 PRIVACY_MODE_DISABLED); |
147 scoped_ptr<QuicServerInfo> quic_server_info1( | 148 scoped_ptr<QuicServerInfo> quic_server_info1( |
148 new DiskCacheBasedQuicServerInfo(server_key1, cache.http_cache())); | 149 new DiskCacheBasedQuicServerInfo(server_key1, cache.http_cache())); |
149 quic_server_info1->Start(); | 150 quic_server_info1->Start(); |
150 int rv = quic_server_info1->WaitForDataReady(callback.callback()); | 151 int rv = quic_server_info1->WaitForDataReady(callback.callback()); |
151 EXPECT_EQ(OK, callback.GetResult(rv)); | 152 EXPECT_EQ(OK, callback.GetResult(rv)); |
152 | 153 |
153 QuicServerInfo::State* state1 = quic_server_info1->mutable_state(); | 154 QuicServerInfo::State* state1 = quic_server_info1->mutable_state(); |
154 EXPECT_TRUE(state1->certs.empty()); | 155 EXPECT_TRUE(state1->certs.empty()); |
155 const string server_config_a = "server_config_a"; | 156 const string server_config_a = "server_config_a"; |
156 const string source_address_token_a = "source_address_token_a"; | 157 const string source_address_token_a = "source_address_token_a"; |
157 const string server_config_sig_a = "server_config_sig_a"; | 158 const string server_config_sig_a = "server_config_sig_a"; |
158 const string cert_a = "cert_a"; | 159 const string cert_a = "cert_a"; |
159 | 160 |
160 state1->server_config = server_config_a; | 161 state1->server_config = server_config_a; |
161 state1->source_address_token = source_address_token_a; | 162 state1->source_address_token = source_address_token_a; |
162 state1->server_config_sig = server_config_sig_a; | 163 state1->server_config_sig = server_config_sig_a; |
163 state1->certs.push_back(cert_a); | 164 state1->certs.push_back(cert_a); |
164 quic_server_info1->Persist(); | 165 quic_server_info1->Persist(); |
165 | 166 |
166 // Wait until Persist() does the work. | 167 // Wait until Persist() does the work. |
167 base::MessageLoop::current()->RunUntilIdle(); | 168 base::MessageLoop::current()->RunUntilIdle(); |
168 | 169 |
169 // Persist data for port 80. | 170 // Persist data for port 80. |
170 QuicSessionKey server_key2("www.google.com", 80, false, kPrivacyModeDisabled); | 171 QuicSessionKey server_key2("www.google.com", 80, false, |
| 172 PRIVACY_MODE_DISABLED); |
171 scoped_ptr<QuicServerInfo> quic_server_info2( | 173 scoped_ptr<QuicServerInfo> quic_server_info2( |
172 new DiskCacheBasedQuicServerInfo(server_key2, cache.http_cache())); | 174 new DiskCacheBasedQuicServerInfo(server_key2, cache.http_cache())); |
173 quic_server_info2->Start(); | 175 quic_server_info2->Start(); |
174 rv = quic_server_info2->WaitForDataReady(callback.callback()); | 176 rv = quic_server_info2->WaitForDataReady(callback.callback()); |
175 EXPECT_EQ(OK, callback.GetResult(rv)); | 177 EXPECT_EQ(OK, callback.GetResult(rv)); |
176 | 178 |
177 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); | 179 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
178 EXPECT_TRUE(state2->certs.empty()); | 180 EXPECT_TRUE(state2->certs.empty()); |
179 const string server_config_b = "server_config_b"; | 181 const string server_config_b = "server_config_b"; |
180 const string source_address_token_b = "source_address_token_b"; | 182 const string source_address_token_b = "source_address_token_b"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 RemoveMockTransaction(&kHostInfoTransaction2); | 225 RemoveMockTransaction(&kHostInfoTransaction2); |
224 RemoveMockTransaction(&kHostInfoTransaction1); | 226 RemoveMockTransaction(&kHostInfoTransaction1); |
225 } | 227 } |
226 | 228 |
227 // Test IsReadyToPersist when there is a pending write. | 229 // Test IsReadyToPersist when there is a pending write. |
228 TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) { | 230 TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) { |
229 MockHttpCache cache; | 231 MockHttpCache cache; |
230 AddMockTransaction(&kHostInfoTransaction1); | 232 AddMockTransaction(&kHostInfoTransaction1); |
231 TestCompletionCallback callback; | 233 TestCompletionCallback callback; |
232 | 234 |
233 QuicSessionKey server_key("www.google.com", 443, true, kPrivacyModeDisabled); | 235 QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); |
234 scoped_ptr<QuicServerInfo> quic_server_info( | 236 scoped_ptr<QuicServerInfo> quic_server_info( |
235 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); | 237 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); |
236 EXPECT_FALSE(quic_server_info->IsDataReady()); | 238 EXPECT_FALSE(quic_server_info->IsDataReady()); |
237 quic_server_info->Start(); | 239 quic_server_info->Start(); |
238 int rv = quic_server_info->WaitForDataReady(callback.callback()); | 240 int rv = quic_server_info->WaitForDataReady(callback.callback()); |
239 EXPECT_EQ(OK, callback.GetResult(rv)); | 241 EXPECT_EQ(OK, callback.GetResult(rv)); |
240 EXPECT_TRUE(quic_server_info->IsDataReady()); | 242 EXPECT_TRUE(quic_server_info->IsDataReady()); |
241 | 243 |
242 QuicServerInfo::State* state = quic_server_info->mutable_state(); | 244 QuicServerInfo::State* state = quic_server_info->mutable_state(); |
243 EXPECT_TRUE(state->certs.empty()); | 245 EXPECT_TRUE(state->certs.empty()); |
(...skipping 30 matching lines...) Expand all Loading... |
274 EXPECT_EQ(server_config_a, state1.server_config); | 276 EXPECT_EQ(server_config_a, state1.server_config); |
275 EXPECT_EQ(source_address_token_a, state1.source_address_token); | 277 EXPECT_EQ(source_address_token_a, state1.source_address_token); |
276 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); | 278 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); |
277 EXPECT_EQ(1U, state1.certs.size()); | 279 EXPECT_EQ(1U, state1.certs.size()); |
278 EXPECT_EQ(cert_a, state1.certs[0]); | 280 EXPECT_EQ(cert_a, state1.certs[0]); |
279 | 281 |
280 RemoveMockTransaction(&kHostInfoTransaction1); | 282 RemoveMockTransaction(&kHostInfoTransaction1); |
281 } | 283 } |
282 | 284 |
283 } // namespace net | 285 } // namespace net |
OLD | NEW |