OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http_network_layer.h" | 5 #include "net/http/http_network_layer.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "net/base/net_log.h" | 9 #include "net/base/net_log.h" |
10 #include "net/cert/mock_cert_verifier.h" | 10 #include "net/cert/mock_cert_verifier.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 rv = callback.WaitForResult(); | 81 rv = callback.WaitForResult(); |
82 ASSERT_EQ(OK, rv); | 82 ASSERT_EQ(OK, rv); |
83 | 83 |
84 std::string contents; | 84 std::string contents; |
85 rv = ReadTransaction(trans.get(), &contents); | 85 rv = ReadTransaction(trans.get(), &contents); |
86 EXPECT_EQ(OK, rv); | 86 EXPECT_EQ(OK, rv); |
87 EXPECT_EQ(content, contents); | 87 EXPECT_EQ(content, contents); |
88 | 88 |
89 if (!header.empty()) { | 89 if (!header.empty()) { |
90 // We also have a server header here that isn't set by the proxy. | 90 // We also have a server header here that isn't set by the proxy. |
91 EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue( | 91 EXPECT_TRUE( |
92 header, value)); | 92 trans->GetResponseInfo()->headers->HasHeaderValue(header, value)); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 // Check that |proxy_count| proxies are in the retry list. | 96 // Check that |proxy_count| proxies are in the retry list. |
97 // These will be, in order, |bad_proxy| and |bad_proxy2|". | 97 // These will be, in order, |bad_proxy| and |bad_proxy2|". |
98 void TestBadProxies(unsigned int proxy_count, const std::string& bad_proxy, | 98 void TestBadProxies(unsigned int proxy_count, |
| 99 const std::string& bad_proxy, |
99 const std::string& bad_proxy2) { | 100 const std::string& bad_proxy2) { |
100 const ProxyRetryInfoMap& retry_info = proxy_service_->proxy_retry_info(); | 101 const ProxyRetryInfoMap& retry_info = proxy_service_->proxy_retry_info(); |
101 ASSERT_EQ(proxy_count, retry_info.size()); | 102 ASSERT_EQ(proxy_count, retry_info.size()); |
102 if (proxy_count > 0) | 103 if (proxy_count > 0) |
103 ASSERT_TRUE(retry_info.find(bad_proxy) != retry_info.end()); | 104 ASSERT_TRUE(retry_info.find(bad_proxy) != retry_info.end()); |
104 if (proxy_count > 1) | 105 if (proxy_count > 1) |
105 ASSERT_TRUE(retry_info.find(bad_proxy2) != retry_info.end()); | 106 ASSERT_TRUE(retry_info.find(bad_proxy2) != retry_info.end()); |
106 } | 107 } |
107 | 108 |
108 // Simulates a request through a proxy which returns a bypass, which is then | 109 // Simulates a request through a proxy which returns a bypass, which is then |
109 // retried through a second proxy that doesn't bypass. | 110 // retried through a second proxy that doesn't bypass. |
110 // Checks that the expected requests were issued, the expected content was | 111 // Checks that the expected requests were issued, the expected content was |
111 // received, and the first proxy |bad_proxy| was marked as bad. | 112 // received, and the first proxy |bad_proxy| was marked as bad. |
112 void TestProxyFallback(const std::string& bad_proxy) { | 113 void TestProxyFallback(const std::string& bad_proxy) { |
113 MockRead data_reads[] = { | 114 MockRead data_reads[] = { |
114 MockRead("HTTP/1.1 200 OK\r\n" | 115 MockRead( |
115 "Chrome-Proxy: bypass=0\r\n\r\n"), | 116 "HTTP/1.1 200 OK\r\n" |
116 MockRead("Bypass message"), | 117 "Chrome-Proxy: bypass=0\r\n\r\n"), |
117 MockRead(SYNCHRONOUS, OK), | 118 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
118 }; | 119 }; |
119 TestProxyFallbackWithMockReads(bad_proxy, "", data_reads, | 120 TestProxyFallbackWithMockReads( |
120 arraysize(data_reads), 1u); | 121 bad_proxy, "", data_reads, arraysize(data_reads), 1u); |
121 } | 122 } |
122 | 123 |
123 void TestProxyFallbackWithMockReads(const std::string& bad_proxy, | 124 void TestProxyFallbackWithMockReads(const std::string& bad_proxy, |
124 const std::string& bad_proxy2, | 125 const std::string& bad_proxy2, |
125 MockRead data_reads[], | 126 MockRead data_reads[], |
126 int data_reads_size, | 127 int data_reads_size, |
127 unsigned int expected_retry_info_size) { | 128 unsigned int expected_retry_info_size) { |
128 TestProxyFallbackByMethodWithMockReads(bad_proxy, bad_proxy2, data_reads, | 129 TestProxyFallbackByMethodWithMockReads(bad_proxy, |
129 data_reads_size, "GET", "content", | 130 bad_proxy2, |
130 true, expected_retry_info_size); | 131 data_reads, |
| 132 data_reads_size, |
| 133 "GET", |
| 134 "content", |
| 135 true, |
| 136 expected_retry_info_size); |
131 } | 137 } |
132 | 138 |
133 void TestProxyFallbackByMethodWithMockReads( | 139 void TestProxyFallbackByMethodWithMockReads( |
134 const std::string& bad_proxy, | 140 const std::string& bad_proxy, |
135 const std::string& bad_proxy2, | 141 const std::string& bad_proxy2, |
136 MockRead data_reads[], | 142 MockRead data_reads[], |
137 int data_reads_size, | 143 int data_reads_size, |
138 std::string method, | 144 std::string method, |
139 std::string content, | 145 std::string content, |
140 bool retry_expected, | 146 bool retry_expected, |
141 unsigned int expected_retry_info_size) { | 147 unsigned int expected_retry_info_size) { |
142 std::string trailer = | 148 std::string trailer = |
143 (method == "HEAD" || method == "PUT" || method == "POST") ? | 149 (method == "HEAD" || method == "PUT" || method == "POST") |
144 "Content-Length: 0\r\n\r\n" : "\r\n"; | 150 ? "Content-Length: 0\r\n\r\n" |
145 std::string request = | 151 : "\r\n"; |
146 base::StringPrintf("%s http://www.google.com/ HTTP/1.1\r\n" | 152 std::string request = base::StringPrintf( |
147 "Host: www.google.com\r\n" | 153 "%s http://www.google.com/ HTTP/1.1\r\n" |
148 "Proxy-Connection: keep-alive\r\n" | 154 "Host: www.google.com\r\n" |
149 "%s", method.c_str(), trailer.c_str()); | 155 "Proxy-Connection: keep-alive\r\n" |
| 156 "%s", |
| 157 method.c_str(), |
| 158 trailer.c_str()); |
150 | 159 |
151 MockWrite data_writes[] = { | 160 MockWrite data_writes[] = { |
152 MockWrite(request.c_str()), | 161 MockWrite(request.c_str()), |
153 }; | 162 }; |
154 | 163 |
155 StaticSocketDataProvider data1(data_reads, data_reads_size, | 164 StaticSocketDataProvider data1( |
156 data_writes, arraysize(data_writes)); | 165 data_reads, data_reads_size, data_writes, arraysize(data_writes)); |
157 mock_socket_factory_.AddSocketDataProvider(&data1); | 166 mock_socket_factory_.AddSocketDataProvider(&data1); |
158 | 167 |
159 // Second data provider returns the expected content. | 168 // Second data provider returns the expected content. |
160 MockRead data_reads2[3]; | 169 MockRead data_reads2[3]; |
161 size_t data_reads2_index = 0; | 170 size_t data_reads2_index = 0; |
162 data_reads2[data_reads2_index++] = MockRead("HTTP/1.0 200 OK\r\n" | 171 data_reads2[data_reads2_index++] = MockRead( |
163 "Server: not-proxy\r\n\r\n"); | 172 "HTTP/1.0 200 OK\r\n" |
| 173 "Server: not-proxy\r\n\r\n"); |
164 if (!content.empty()) | 174 if (!content.empty()) |
165 data_reads2[data_reads2_index++] = MockRead(content.c_str()); | 175 data_reads2[data_reads2_index++] = MockRead(content.c_str()); |
166 data_reads2[data_reads2_index++] = MockRead(SYNCHRONOUS, OK); | 176 data_reads2[data_reads2_index++] = MockRead(SYNCHRONOUS, OK); |
167 | 177 |
168 MockWrite data_writes2[] = { | 178 MockWrite data_writes2[] = { |
169 MockWrite(request.c_str()), | 179 MockWrite(request.c_str()), |
170 }; | 180 }; |
171 StaticSocketDataProvider data2(data_reads2, data_reads2_index, | 181 StaticSocketDataProvider data2( |
172 data_writes2, arraysize(data_writes2)); | 182 data_reads2, data_reads2_index, data_writes2, arraysize(data_writes2)); |
173 mock_socket_factory_.AddSocketDataProvider(&data2); | 183 mock_socket_factory_.AddSocketDataProvider(&data2); |
174 | 184 |
175 // Expect that we get "content" and not "Bypass message", and that there's | 185 // Expect that we get "content" and not "Bypass message", and that there's |
176 // a "not-proxy" "Server:" header in the final response. | 186 // a "not-proxy" "Server:" header in the final response. |
177 if (retry_expected) { | 187 if (retry_expected) { |
178 ExecuteRequestExpectingContentAndHeader(method, content, | 188 ExecuteRequestExpectingContentAndHeader( |
179 "server", "not-proxy"); | 189 method, content, "server", "not-proxy"); |
180 } else { | 190 } else { |
181 ExecuteRequestExpectingContentAndHeader(method, content, "", ""); | 191 ExecuteRequestExpectingContentAndHeader(method, content, "", ""); |
182 } | 192 } |
183 | 193 |
184 // We should also observe the bad proxy in the retry list. | 194 // We should also observe the bad proxy in the retry list. |
185 TestBadProxies(expected_retry_info_size, bad_proxy, bad_proxy2); | 195 TestBadProxies(expected_retry_info_size, bad_proxy, bad_proxy2); |
186 } | 196 } |
187 | 197 |
188 // Simulates a request through a proxy which returns a bypass, which is then | 198 // Simulates a request through a proxy which returns a bypass, which is then |
189 // retried through a direct connection to the origin site. | 199 // retried through a direct connection to the origin site. |
190 // Checks that the expected requests were issued, the expected content was | 200 // Checks that the expected requests were issued, the expected content was |
191 // received, and the proxy |bad_proxy| was marked as bad. | 201 // received, and the proxy |bad_proxy| was marked as bad. |
192 void TestProxyFallbackToDirect(const std::string& bad_proxy) { | 202 void TestProxyFallbackToDirect(const std::string& bad_proxy) { |
193 MockRead data_reads[] = { | 203 MockRead data_reads[] = { |
194 MockRead("HTTP/1.1 200 OK\r\n" | 204 MockRead( |
195 "Chrome-Proxy: bypass=0\r\n\r\n"), | 205 "HTTP/1.1 200 OK\r\n" |
196 MockRead("Bypass message"), | 206 "Chrome-Proxy: bypass=0\r\n\r\n"), |
197 MockRead(SYNCHRONOUS, OK), | 207 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
198 }; | 208 }; |
199 MockWrite data_writes[] = { | 209 MockWrite data_writes[] = { |
200 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | 210 MockWrite( |
201 "Host: www.google.com\r\n" | 211 "GET http://www.google.com/ HTTP/1.1\r\n" |
202 "Proxy-Connection: keep-alive\r\n\r\n"), | 212 "Host: www.google.com\r\n" |
| 213 "Proxy-Connection: keep-alive\r\n\r\n"), |
203 }; | 214 }; |
204 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), | 215 StaticSocketDataProvider data1( |
205 data_writes, arraysize(data_writes)); | 216 data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
206 mock_socket_factory_.AddSocketDataProvider(&data1); | 217 mock_socket_factory_.AddSocketDataProvider(&data1); |
207 | 218 |
208 // Second data provider returns the expected content. | 219 // Second data provider returns the expected content. |
209 MockRead data_reads2[] = { | 220 MockRead data_reads2[] = { |
210 MockRead("HTTP/1.0 200 OK\r\n" | 221 MockRead( |
211 "Server: not-proxy\r\n\r\n"), | 222 "HTTP/1.0 200 OK\r\n" |
212 MockRead("content"), | 223 "Server: not-proxy\r\n\r\n"), |
213 MockRead(SYNCHRONOUS, OK), | 224 MockRead("content"), MockRead(SYNCHRONOUS, OK), |
214 }; | 225 }; |
215 MockWrite data_writes2[] = { | 226 MockWrite data_writes2[] = { |
216 MockWrite("GET / HTTP/1.1\r\n" | 227 MockWrite( |
217 "Host: www.google.com\r\n" | 228 "GET / HTTP/1.1\r\n" |
218 "Connection: keep-alive\r\n\r\n"), | 229 "Host: www.google.com\r\n" |
| 230 "Connection: keep-alive\r\n\r\n"), |
219 }; | 231 }; |
220 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | 232 StaticSocketDataProvider data2(data_reads2, |
221 data_writes2, arraysize(data_writes2)); | 233 arraysize(data_reads2), |
| 234 data_writes2, |
| 235 arraysize(data_writes2)); |
222 mock_socket_factory_.AddSocketDataProvider(&data2); | 236 mock_socket_factory_.AddSocketDataProvider(&data2); |
223 | 237 |
224 // Expect that we get "content" and not "Bypass message", and that there's | 238 // Expect that we get "content" and not "Bypass message", and that there's |
225 // a "not-proxy" "Server:" header in the final response. | 239 // a "not-proxy" "Server:" header in the final response. |
226 ExecuteRequestExpectingContentAndHeader("GET", "content", | 240 ExecuteRequestExpectingContentAndHeader( |
227 "server", "not-proxy"); | 241 "GET", "content", "server", "not-proxy"); |
228 | 242 |
229 // We should also observe the bad proxy in the retry list. | 243 // We should also observe the bad proxy in the retry list. |
230 TestBadProxies(1u, bad_proxy, ""); | 244 TestBadProxies(1u, bad_proxy, ""); |
231 } | 245 } |
232 | 246 |
233 // Simulates a request through a proxy which returns a bypass, under a | 247 // Simulates a request through a proxy which returns a bypass, under a |
234 // configuration where there is no valid bypass. |proxy_count| proxies | 248 // configuration where there is no valid bypass. |proxy_count| proxies |
235 // are expected to be configured. | 249 // are expected to be configured. |
236 // Checks that the expected requests were issued, the bypass message was the | 250 // Checks that the expected requests were issued, the bypass message was the |
237 // final received content, and all proxies were marked as bad. | 251 // final received content, and all proxies were marked as bad. |
238 void TestProxyFallbackFail(unsigned int proxy_count, | 252 void TestProxyFallbackFail(unsigned int proxy_count, |
239 const std::string& bad_proxy, | 253 const std::string& bad_proxy, |
240 const std::string& bad_proxy2) { | 254 const std::string& bad_proxy2) { |
241 MockRead data_reads[] = { | 255 MockRead data_reads[] = { |
242 MockRead("HTTP/1.1 200 OK\r\n" | 256 MockRead( |
243 "Chrome-Proxy: bypass=0\r\n\r\n"), | 257 "HTTP/1.1 200 OK\r\n" |
244 MockRead("Bypass message"), | 258 "Chrome-Proxy: bypass=0\r\n\r\n"), |
245 MockRead(SYNCHRONOUS, OK), | 259 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
246 }; | 260 }; |
247 MockWrite data_writes[] = { | 261 MockWrite data_writes[] = { |
248 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | 262 MockWrite( |
249 "Host: www.google.com\r\n" | 263 "GET http://www.google.com/ HTTP/1.1\r\n" |
250 "Proxy-Connection: keep-alive\r\n\r\n"), | 264 "Host: www.google.com\r\n" |
| 265 "Proxy-Connection: keep-alive\r\n\r\n"), |
251 }; | 266 }; |
252 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), | 267 StaticSocketDataProvider data1( |
253 data_writes, arraysize(data_writes)); | 268 data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
254 StaticSocketDataProvider data2(data_reads, arraysize(data_reads), | 269 StaticSocketDataProvider data2( |
255 data_writes, arraysize(data_writes)); | 270 data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
256 | 271 |
257 mock_socket_factory_.AddSocketDataProvider(&data1); | 272 mock_socket_factory_.AddSocketDataProvider(&data1); |
258 if (proxy_count > 1) | 273 if (proxy_count > 1) |
259 mock_socket_factory_.AddSocketDataProvider(&data2); | 274 mock_socket_factory_.AddSocketDataProvider(&data2); |
260 | 275 |
261 // Expect that we get "Bypass message", and not "content".. | 276 // Expect that we get "Bypass message", and not "content".. |
262 ExecuteRequestExpectingContentAndHeader("GET", "Bypass message", "", ""); | 277 ExecuteRequestExpectingContentAndHeader("GET", "Bypass message", "", ""); |
263 | 278 |
264 // We should also observe the bad proxy or proxies in the retry list. | 279 // We should also observe the bad proxy or proxies in the retry list. |
265 TestBadProxies(proxy_count, bad_proxy, bad_proxy2); | 280 TestBadProxies(proxy_count, bad_proxy, bad_proxy2); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 ASSERT_TRUE(trans == NULL); | 313 ASSERT_TRUE(trans == NULL); |
299 | 314 |
300 factory_->OnResume(); | 315 factory_->OnResume(); |
301 | 316 |
302 rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 317 rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
303 EXPECT_EQ(OK, rv); | 318 EXPECT_EQ(OK, rv); |
304 } | 319 } |
305 | 320 |
306 TEST_F(HttpNetworkLayerTest, GET) { | 321 TEST_F(HttpNetworkLayerTest, GET) { |
307 MockRead data_reads[] = { | 322 MockRead data_reads[] = { |
308 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 323 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
309 MockRead("hello world"), | 324 MockRead(SYNCHRONOUS, OK), |
310 MockRead(SYNCHRONOUS, OK), | |
311 }; | 325 }; |
312 MockWrite data_writes[] = { | 326 MockWrite data_writes[] = { |
313 MockWrite("GET / HTTP/1.1\r\n" | 327 MockWrite( |
314 "Host: www.google.com\r\n" | 328 "GET / HTTP/1.1\r\n" |
315 "Connection: keep-alive\r\n" | 329 "Host: www.google.com\r\n" |
316 "User-Agent: Foo/1.0\r\n\r\n"), | 330 "Connection: keep-alive\r\n" |
| 331 "User-Agent: Foo/1.0\r\n\r\n"), |
317 }; | 332 }; |
318 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 333 StaticSocketDataProvider data( |
319 data_writes, arraysize(data_writes)); | 334 data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
320 mock_socket_factory_.AddSocketDataProvider(&data); | 335 mock_socket_factory_.AddSocketDataProvider(&data); |
321 | 336 |
322 TestCompletionCallback callback; | 337 TestCompletionCallback callback; |
323 | 338 |
324 HttpRequestInfo request_info; | 339 HttpRequestInfo request_info; |
325 request_info.url = GURL("http://www.google.com/"); | 340 request_info.url = GURL("http://www.google.com/"); |
326 request_info.method = "GET"; | 341 request_info.method = "GET"; |
327 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 342 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
328 "Foo/1.0"); | 343 "Foo/1.0"); |
329 request_info.load_flags = LOAD_NORMAL; | 344 request_info.load_flags = LOAD_NORMAL; |
(...skipping 27 matching lines...) Expand all Loading... |
357 TEST_F(HttpNetworkLayerTest, ServerTwoProxyBypassPac) { | 372 TEST_F(HttpNetworkLayerTest, ServerTwoProxyBypassPac) { |
358 std::string bad_proxy = GetDataReductionProxy(); | 373 std::string bad_proxy = GetDataReductionProxy(); |
359 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 374 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
360 "PROXY " + bad_proxy + "; PROXY good:8080")); | 375 "PROXY " + bad_proxy + "; PROXY good:8080")); |
361 TestProxyFallback(bad_proxy); | 376 TestProxyFallback(bad_proxy); |
362 } | 377 } |
363 | 378 |
364 TEST_F(HttpNetworkLayerTest, ServerTwoProxyBypassFixed) { | 379 TEST_F(HttpNetworkLayerTest, ServerTwoProxyBypassFixed) { |
365 std::string bad_proxy = GetDataReductionProxy(); | 380 std::string bad_proxy = GetDataReductionProxy(); |
366 ConfigureTestDependencies( | 381 ConfigureTestDependencies( |
367 ProxyService::CreateFixed(bad_proxy +", good:8080")); | 382 ProxyService::CreateFixed(bad_proxy + ", good:8080")); |
368 TestProxyFallback(bad_proxy); | 383 TestProxyFallback(bad_proxy); |
369 } | 384 } |
370 | 385 |
371 TEST_F(HttpNetworkLayerTest, BypassAndRetryIdempotentMethods) { | 386 TEST_F(HttpNetworkLayerTest, BypassAndRetryIdempotentMethods) { |
372 std::string bad_proxy = GetDataReductionProxy(); | 387 std::string bad_proxy = GetDataReductionProxy(); |
373 const struct { | 388 const struct { |
374 std::string method; | 389 std::string method; |
375 std::string content; | 390 std::string content; |
376 bool expected_to_retry; | 391 bool expected_to_retry; |
377 } tests[] = { | 392 } tests[] = { |
378 { | 393 { |
379 "GET", | 394 "GET", "content", true, |
380 "content", | 395 }, |
381 true, | 396 { |
382 }, | 397 "OPTIONS", "content", true, |
383 { | 398 }, |
384 "OPTIONS", | 399 { |
385 "content", | 400 "HEAD", "", true, |
386 true, | 401 }, |
387 }, | 402 { |
388 { | 403 "PUT", "", true, |
389 "HEAD", | 404 }, |
390 "", | 405 { |
391 true, | 406 "DELETE", "content", true, |
392 }, | 407 }, |
393 { | 408 { |
394 "PUT", | 409 "TRACE", "content", true, |
395 "", | 410 }, |
396 true, | 411 { |
397 }, | 412 "POST", "Bypass message", false, |
398 { | 413 }, |
399 "DELETE", | 414 }; |
400 "content", | |
401 true, | |
402 }, | |
403 { | |
404 "TRACE", | |
405 "content", | |
406 true, | |
407 }, | |
408 { | |
409 "POST", | |
410 "Bypass message", | |
411 false, | |
412 }, | |
413 }; | |
414 | 415 |
415 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 416 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
416 ConfigureTestDependencies( | 417 ConfigureTestDependencies( |
417 ProxyService::CreateFixed(bad_proxy +", good:8080")); | 418 ProxyService::CreateFixed(bad_proxy + ", good:8080")); |
418 MockRead data_reads[] = { | 419 MockRead data_reads[] = { |
419 MockRead("HTTP/1.1 200 OK\r\n" | 420 MockRead( |
420 "Chrome-Proxy: bypass=0\r\n\r\n"), | 421 "HTTP/1.1 200 OK\r\n" |
421 MockRead("Bypass message"), | 422 "Chrome-Proxy: bypass=0\r\n\r\n"), |
422 MockRead(SYNCHRONOUS, OK), | 423 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
423 }; | 424 }; |
424 TestProxyFallbackByMethodWithMockReads(bad_proxy, "", data_reads, | 425 TestProxyFallbackByMethodWithMockReads(bad_proxy, |
| 426 "", |
| 427 data_reads, |
425 arraysize(data_reads), | 428 arraysize(data_reads), |
426 tests[i].method, | 429 tests[i].method, |
427 tests[i].content, | 430 tests[i].content, |
428 tests[i].expected_to_retry, 1u); | 431 tests[i].expected_to_retry, |
| 432 1u); |
429 } | 433 } |
430 } | 434 } |
431 | 435 |
432 TEST_F(HttpNetworkLayerTest, ServerOneProxyWithDirectBypassPac) { | 436 TEST_F(HttpNetworkLayerTest, ServerOneProxyWithDirectBypassPac) { |
433 std::string bad_proxy = GetDataReductionProxy(); | 437 std::string bad_proxy = GetDataReductionProxy(); |
434 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 438 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
435 "PROXY " + bad_proxy + "; DIRECT")); | 439 "PROXY " + bad_proxy + "; DIRECT")); |
436 TestProxyFallbackToDirect(bad_proxy); | 440 TestProxyFallbackToDirect(bad_proxy); |
437 } | 441 } |
438 | 442 |
(...skipping 11 matching lines...) Expand all Loading... |
450 HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString(); | 454 HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString(); |
451 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 455 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
452 "PROXY " + bad_proxy + "; PROXY " + bad_proxy2)); | 456 "PROXY " + bad_proxy + "; PROXY " + bad_proxy2)); |
453 TestProxyFallbackFail(2u, bad_proxy, bad_proxy2); | 457 TestProxyFallbackFail(2u, bad_proxy, bad_proxy2); |
454 } | 458 } |
455 | 459 |
456 TEST_F(HttpNetworkLayerTest, ServerTwoProxyDoubleBypassFixed) { | 460 TEST_F(HttpNetworkLayerTest, ServerTwoProxyDoubleBypassFixed) { |
457 std::string bad_proxy = GetDataReductionProxy(); | 461 std::string bad_proxy = GetDataReductionProxy(); |
458 std::string bad_proxy2 = | 462 std::string bad_proxy2 = |
459 HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString(); | 463 HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString(); |
460 ConfigureTestDependencies(ProxyService::CreateFixed( | 464 ConfigureTestDependencies( |
461 bad_proxy + ", " + bad_proxy2)); | 465 ProxyService::CreateFixed(bad_proxy + ", " + bad_proxy2)); |
462 TestProxyFallbackFail(2u, bad_proxy, bad_proxy2); | 466 TestProxyFallbackFail(2u, bad_proxy, bad_proxy2); |
463 } | 467 } |
464 #endif | 468 #endif |
465 | 469 |
466 TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassPac) { | 470 TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassPac) { |
467 std::string bad_proxy = GetDataReductionProxy(); | 471 std::string bad_proxy = GetDataReductionProxy(); |
468 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 472 ConfigureTestDependencies( |
469 "PROXY " + bad_proxy)); | 473 ProxyService::CreateFixedFromPacResult("PROXY " + bad_proxy)); |
470 TestProxyFallbackFail(1u, bad_proxy, ""); | 474 TestProxyFallbackFail(1u, bad_proxy, ""); |
471 } | 475 } |
472 | 476 |
473 TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassFixed) { | 477 TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassFixed) { |
474 std::string bad_proxy = GetDataReductionProxy(); | 478 std::string bad_proxy = GetDataReductionProxy(); |
475 ConfigureTestDependencies(ProxyService::CreateFixed(bad_proxy)); | 479 ConfigureTestDependencies(ProxyService::CreateFixed(bad_proxy)); |
476 TestProxyFallbackFail(1u, bad_proxy, ""); | 480 TestProxyFallbackFail(1u, bad_proxy, ""); |
477 } | 481 } |
478 | 482 |
479 TEST_F(HttpNetworkLayerTest, ServerFallbackOn5xxError) { | 483 TEST_F(HttpNetworkLayerTest, ServerFallbackOn5xxError) { |
480 // Verify that "500 Internal Server Error", "502 Bad Gateway", and | 484 // Verify that "500 Internal Server Error", "502 Bad Gateway", and |
481 // "503 Service Unavailable" via the data reduction proxy induce proxy | 485 // "503 Service Unavailable" via the data reduction proxy induce proxy |
482 // fallback to a second proxy, if configured. | 486 // fallback to a second proxy, if configured. |
483 | 487 |
484 // To configure this test, we need to wire up a custom proxy service to use | 488 // To configure this test, we need to wire up a custom proxy service to use |
485 // a pair of proxies. We'll induce fallback via the first and return | 489 // a pair of proxies. We'll induce fallback via the first and return |
486 // the expected data via the second. | 490 // the expected data via the second. |
487 std::string data_reduction_proxy( | 491 std::string data_reduction_proxy( |
488 HostPortPair::FromURL(GURL(SPDY_PROXY_AUTH_ORIGIN)).ToString()); | 492 HostPortPair::FromURL(GURL(SPDY_PROXY_AUTH_ORIGIN)).ToString()); |
489 std::string pac_string = base::StringPrintf( | 493 std::string pac_string = base::StringPrintf("PROXY %s; PROXY good:8080", |
490 "PROXY %s; PROXY good:8080", data_reduction_proxy.data()); | 494 data_reduction_proxy.data()); |
491 | 495 |
492 std::string headers[] = { | 496 std::string headers[] = {"HTTP/1.1 500 Internal Server Error\r\n\r\n", |
493 "HTTP/1.1 500 Internal Server Error\r\n\r\n", | 497 "HTTP/1.1 502 Bad Gateway\r\n\r\n", |
494 "HTTP/1.1 502 Bad Gateway\r\n\r\n", | 498 "HTTP/1.1 503 Service Unavailable\r\n\r\n"}; |
495 "HTTP/1.1 503 Service Unavailable\r\n\r\n" | |
496 }; | |
497 | 499 |
498 for (size_t i = 0; i < arraysize(headers); ++i) { | 500 for (size_t i = 0; i < arraysize(headers); ++i) { |
499 ConfigureTestDependencies( | 501 ConfigureTestDependencies( |
500 ProxyService::CreateFixedFromPacResult(pac_string)); | 502 ProxyService::CreateFixedFromPacResult(pac_string)); |
501 | 503 |
502 MockRead data_reads[] = { | 504 MockRead data_reads[] = { |
503 MockRead(headers[i].c_str()), | 505 MockRead(headers[i].c_str()), MockRead("Bypass message"), |
504 MockRead("Bypass message"), | 506 MockRead(SYNCHRONOUS, OK), |
505 MockRead(SYNCHRONOUS, OK), | |
506 }; | 507 }; |
507 | 508 |
508 MockWrite data_writes[] = { | 509 MockWrite data_writes[] = { |
509 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | 510 MockWrite( |
510 "Host: www.google.com\r\n" | 511 "GET http://www.google.com/ HTTP/1.1\r\n" |
511 "Proxy-Connection: keep-alive\r\n\r\n"), | 512 "Host: www.google.com\r\n" |
| 513 "Proxy-Connection: keep-alive\r\n\r\n"), |
512 }; | 514 }; |
513 | 515 |
514 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), | 516 StaticSocketDataProvider data1( |
515 data_writes, arraysize(data_writes)); | 517 data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
516 mock_socket_factory_.AddSocketDataProvider(&data1); | 518 mock_socket_factory_.AddSocketDataProvider(&data1); |
517 | 519 |
518 // Second data provider returns the expected content. | 520 // Second data provider returns the expected content. |
519 MockRead data_reads2[] = { | 521 MockRead data_reads2[] = { |
520 MockRead("HTTP/1.0 200 OK\r\n" | 522 MockRead( |
521 "Server: not-proxy\r\n\r\n"), | 523 "HTTP/1.0 200 OK\r\n" |
522 MockRead("content"), | 524 "Server: not-proxy\r\n\r\n"), |
523 MockRead(SYNCHRONOUS, OK), | 525 MockRead("content"), MockRead(SYNCHRONOUS, OK), |
524 }; | 526 }; |
525 MockWrite data_writes2[] = { | 527 MockWrite data_writes2[] = { |
526 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | 528 MockWrite( |
527 "Host: www.google.com\r\n" | 529 "GET http://www.google.com/ HTTP/1.1\r\n" |
528 "Proxy-Connection: keep-alive\r\n\r\n"), | 530 "Host: www.google.com\r\n" |
| 531 "Proxy-Connection: keep-alive\r\n\r\n"), |
529 }; | 532 }; |
530 | 533 |
531 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | 534 StaticSocketDataProvider data2(data_reads2, |
532 data_writes2, arraysize(data_writes2)); | 535 arraysize(data_reads2), |
| 536 data_writes2, |
| 537 arraysize(data_writes2)); |
533 mock_socket_factory_.AddSocketDataProvider(&data2); | 538 mock_socket_factory_.AddSocketDataProvider(&data2); |
534 | 539 |
535 TestCompletionCallback callback; | 540 TestCompletionCallback callback; |
536 | 541 |
537 HttpRequestInfo request_info; | 542 HttpRequestInfo request_info; |
538 request_info.url = GURL("http://www.google.com/"); | 543 request_info.url = GURL("http://www.google.com/"); |
539 request_info.method = "GET"; | 544 request_info.method = "GET"; |
540 request_info.load_flags = LOAD_NORMAL; | 545 request_info.load_flags = LOAD_NORMAL; |
541 | 546 |
542 scoped_ptr<HttpTransaction> trans; | 547 scoped_ptr<HttpTransaction> trans; |
543 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 548 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
544 EXPECT_EQ(OK, rv); | 549 EXPECT_EQ(OK, rv); |
545 | 550 |
546 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 551 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
547 if (rv == ERR_IO_PENDING) | 552 if (rv == ERR_IO_PENDING) |
548 rv = callback.WaitForResult(); | 553 rv = callback.WaitForResult(); |
549 ASSERT_EQ(OK, rv); | 554 ASSERT_EQ(OK, rv); |
550 | 555 |
551 std::string contents; | 556 std::string contents; |
552 rv = ReadTransaction(trans.get(), &contents); | 557 rv = ReadTransaction(trans.get(), &contents); |
553 EXPECT_EQ(OK, rv); | 558 EXPECT_EQ(OK, rv); |
554 | 559 |
555 // We should obtain content from the second socket provider write | 560 // We should obtain content from the second socket provider write |
556 // corresponding to the fallback proxy. | 561 // corresponding to the fallback proxy. |
557 EXPECT_EQ("content", contents); | 562 EXPECT_EQ("content", contents); |
558 // We also have a server header here that isn't set by the proxy. | 563 // We also have a server header here that isn't set by the proxy. |
559 EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue( | 564 EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue("server", |
560 "server", "not-proxy")); | 565 "not-proxy")); |
561 // We should also observe the data reduction proxy in the retry list. | 566 // We should also observe the data reduction proxy in the retry list. |
562 ASSERT_EQ(1u, proxy_service_->proxy_retry_info().size()); | 567 ASSERT_EQ(1u, proxy_service_->proxy_retry_info().size()); |
563 EXPECT_EQ(data_reduction_proxy, | 568 EXPECT_EQ(data_reduction_proxy, |
564 (*proxy_service_->proxy_retry_info().begin()).first); | 569 (*proxy_service_->proxy_retry_info().begin()).first); |
565 } | 570 } |
566 } | 571 } |
567 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 572 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
568 | 573 |
569 TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) { | 574 TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) { |
570 // Verify that a Chrome-Proxy header is ignored when returned from a directly | 575 // Verify that a Chrome-Proxy header is ignored when returned from a directly |
571 // connected origin server. | 576 // connected origin server. |
572 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); | 577 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); |
573 | 578 |
574 MockRead data_reads[] = { | 579 MockRead data_reads[] = { |
575 MockRead("HTTP/1.1 200 OK\r\n" | 580 MockRead( |
576 "Chrome-Proxy: bypass=0\r\n\r\n"), | 581 "HTTP/1.1 200 OK\r\n" |
577 MockRead("Bypass message"), | 582 "Chrome-Proxy: bypass=0\r\n\r\n"), |
578 MockRead(SYNCHRONOUS, OK), | 583 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
579 }; | 584 }; |
580 MockWrite data_writes[] = { | 585 MockWrite data_writes[] = { |
581 MockWrite("GET / HTTP/1.1\r\n" | 586 MockWrite( |
582 "Host: www.google.com\r\n" | 587 "GET / HTTP/1.1\r\n" |
583 "Connection: keep-alive\r\n\r\n"), | 588 "Host: www.google.com\r\n" |
| 589 "Connection: keep-alive\r\n\r\n"), |
584 }; | 590 }; |
585 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), | 591 StaticSocketDataProvider data1( |
586 data_writes, arraysize(data_writes)); | 592 data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
587 mock_socket_factory_.AddSocketDataProvider(&data1); | 593 mock_socket_factory_.AddSocketDataProvider(&data1); |
588 TestCompletionCallback callback; | 594 TestCompletionCallback callback; |
589 | 595 |
590 HttpRequestInfo request_info; | 596 HttpRequestInfo request_info; |
591 request_info.url = GURL("http://www.google.com/"); | 597 request_info.url = GURL("http://www.google.com/"); |
592 request_info.method = "GET"; | 598 request_info.method = "GET"; |
593 request_info.load_flags = LOAD_NORMAL; | 599 request_info.load_flags = LOAD_NORMAL; |
594 | 600 |
595 scoped_ptr<HttpTransaction> trans; | 601 scoped_ptr<HttpTransaction> trans; |
596 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 602 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
(...skipping 16 matching lines...) Expand all Loading... |
613 | 619 |
614 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 620 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
615 TEST_F(HttpNetworkLayerTest, ServerFallbackWithProxyTimedBypass) { | 621 TEST_F(HttpNetworkLayerTest, ServerFallbackWithProxyTimedBypass) { |
616 // Verify that a Chrome-Proxy: bypass=<seconds> header induces proxy | 622 // Verify that a Chrome-Proxy: bypass=<seconds> header induces proxy |
617 // fallback to a second proxy, if configured. | 623 // fallback to a second proxy, if configured. |
618 std::string bad_proxy = GetDataReductionProxy(); | 624 std::string bad_proxy = GetDataReductionProxy(); |
619 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 625 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
620 "PROXY " + bad_proxy + "; PROXY good:8080")); | 626 "PROXY " + bad_proxy + "; PROXY good:8080")); |
621 | 627 |
622 MockRead data_reads[] = { | 628 MockRead data_reads[] = { |
623 MockRead("HTTP/1.1 200 OK\r\n" | 629 MockRead( |
624 "Connection: keep-alive\r\n" | 630 "HTTP/1.1 200 OK\r\n" |
625 "Chrome-Proxy: bypass=86400\r\n" | 631 "Connection: keep-alive\r\n" |
626 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"), | 632 "Chrome-Proxy: bypass=86400\r\n" |
627 MockRead("Bypass message"), | 633 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"), |
628 MockRead(SYNCHRONOUS, OK), | 634 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
629 }; | 635 }; |
630 | 636 |
631 TestProxyFallbackWithMockReads(bad_proxy, "", data_reads, | 637 TestProxyFallbackWithMockReads( |
632 arraysize(data_reads), 1u); | 638 bad_proxy, "", data_reads, arraysize(data_reads), 1u); |
633 EXPECT_EQ(base::TimeDelta::FromSeconds(86400), | 639 EXPECT_EQ(base::TimeDelta::FromSeconds(86400), |
634 (*proxy_service_->proxy_retry_info().begin()).second.current_delay); | 640 (*proxy_service_->proxy_retry_info().begin()).second.current_delay); |
635 } | 641 } |
636 | 642 |
637 TEST_F(HttpNetworkLayerTest, ServerFallbackWithWrongViaHeader) { | 643 TEST_F(HttpNetworkLayerTest, ServerFallbackWithWrongViaHeader) { |
638 // Verify that a Via header that lacks the Chrome-Proxy induces proxy fallback | 644 // Verify that a Via header that lacks the Chrome-Proxy induces proxy fallback |
639 // to a second proxy, if configured. | 645 // to a second proxy, if configured. |
640 std::string chrome_proxy = GetDataReductionProxy(); | 646 std::string chrome_proxy = GetDataReductionProxy(); |
641 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 647 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
642 "PROXY " + chrome_proxy + "; PROXY good:8080")); | 648 "PROXY " + chrome_proxy + "; PROXY good:8080")); |
643 | 649 |
644 MockRead data_reads[] = { | 650 MockRead data_reads[] = { |
645 MockRead("HTTP/1.1 200 OK\r\n" | 651 MockRead( |
646 "Connection: keep-alive\r\n" | 652 "HTTP/1.1 200 OK\r\n" |
647 "Via: 1.0 some-other-proxy\r\n\r\n"), | 653 "Connection: keep-alive\r\n" |
648 MockRead("Bypass message"), | 654 "Via: 1.0 some-other-proxy\r\n\r\n"), |
649 MockRead(SYNCHRONOUS, OK), | 655 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
650 }; | 656 }; |
651 | 657 |
652 TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads, | 658 TestProxyFallbackWithMockReads( |
653 arraysize(data_reads), 1u); | 659 chrome_proxy, std::string(), data_reads, arraysize(data_reads), 1u); |
654 } | 660 } |
655 | 661 |
656 TEST_F(HttpNetworkLayerTest, ServerFallbackWithNoViaHeader) { | 662 TEST_F(HttpNetworkLayerTest, ServerFallbackWithNoViaHeader) { |
657 // Verify that the lack of a Via header induces proxy fallback to a second | 663 // Verify that the lack of a Via header induces proxy fallback to a second |
658 // proxy, if configured. | 664 // proxy, if configured. |
659 std::string chrome_proxy = GetDataReductionProxy(); | 665 std::string chrome_proxy = GetDataReductionProxy(); |
660 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 666 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
661 "PROXY " + chrome_proxy + "; PROXY good:8080")); | 667 "PROXY " + chrome_proxy + "; PROXY good:8080")); |
662 | 668 |
663 MockRead data_reads[] = { | 669 MockRead data_reads[] = { |
664 MockRead("HTTP/1.1 200 OK\r\n" | 670 MockRead( |
665 "Connection: keep-alive\r\n\r\n"), | 671 "HTTP/1.1 200 OK\r\n" |
666 MockRead("Bypass message"), | 672 "Connection: keep-alive\r\n\r\n"), |
667 MockRead(SYNCHRONOUS, OK), | 673 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
668 }; | 674 }; |
669 | 675 |
670 TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads, | 676 TestProxyFallbackWithMockReads( |
671 arraysize(data_reads), 1u); | 677 chrome_proxy, std::string(), data_reads, arraysize(data_reads), 1u); |
672 } | 678 } |
673 | 679 |
674 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) { | 680 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) { |
675 // Verify that Chrome will not be induced to bypass the data reduction proxy | 681 // Verify that Chrome will not be induced to bypass the data reduction proxy |
676 // when the data reduction proxy via header is absent on a 304. | 682 // when the data reduction proxy via header is absent on a 304. |
677 std::string chrome_proxy = GetDataReductionProxy(); | 683 std::string chrome_proxy = GetDataReductionProxy(); |
678 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 684 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
679 "PROXY " + chrome_proxy + "; PROXY good:8080")); | 685 "PROXY " + chrome_proxy + "; PROXY good:8080")); |
680 | 686 |
681 MockRead data_reads[] = { | 687 MockRead data_reads[] = { |
682 MockRead("HTTP/1.1 304 Not Modified\r\n" | 688 MockRead( |
683 "Connection: keep-alive\r\n\r\n"), | 689 "HTTP/1.1 304 Not Modified\r\n" |
684 MockRead(SYNCHRONOUS, OK), | 690 "Connection: keep-alive\r\n\r\n"), |
| 691 MockRead(SYNCHRONOUS, OK), |
685 }; | 692 }; |
686 | 693 |
687 TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(), | 694 TestProxyFallbackByMethodWithMockReads(chrome_proxy, |
688 data_reads, arraysize(data_reads), | 695 std::string(), |
689 "GET", std::string(), false, 0); | 696 data_reads, |
| 697 arraysize(data_reads), |
| 698 "GET", |
| 699 std::string(), |
| 700 false, |
| 701 0); |
690 } | 702 } |
691 | 703 |
692 TEST_F(HttpNetworkLayerTest, NoServerFallbackWithChainedViaHeader) { | 704 TEST_F(HttpNetworkLayerTest, NoServerFallbackWithChainedViaHeader) { |
693 // Verify that Chrome will not be induced to bypass the data reduction proxy | 705 // Verify that Chrome will not be induced to bypass the data reduction proxy |
694 // when the data reduction proxy via header is present, even if that header | 706 // when the data reduction proxy via header is present, even if that header |
695 // is chained. | 707 // is chained. |
696 std::string chrome_proxy = GetDataReductionProxy(); | 708 std::string chrome_proxy = GetDataReductionProxy(); |
697 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 709 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
698 "PROXY " + chrome_proxy + "; PROXY good:8080")); | 710 "PROXY " + chrome_proxy + "; PROXY good:8080")); |
699 | 711 |
700 MockRead data_reads[] = { | 712 MockRead data_reads[] = { |
701 MockRead("HTTP/1.1 200 OK\r\n" | 713 MockRead( |
702 "Connection: keep-alive\r\n" | 714 "HTTP/1.1 200 OK\r\n" |
703 "Via: 1.1 Chrome-Compression-Proxy, 1.0 some-other-proxy\r\n\r\n"), | 715 "Connection: keep-alive\r\n" |
704 MockRead("Bypass message"), | 716 "Via: 1.1 Chrome-Compression-Proxy, 1.0 some-other-proxy\r\n\r\n"), |
705 MockRead(SYNCHRONOUS, OK), | 717 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
706 }; | 718 }; |
707 | 719 |
708 TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(), | 720 TestProxyFallbackByMethodWithMockReads(chrome_proxy, |
709 data_reads, arraysize(data_reads), | 721 std::string(), |
710 "GET", "Bypass message", false, 0); | 722 data_reads, |
| 723 arraysize(data_reads), |
| 724 "GET", |
| 725 "Bypass message", |
| 726 false, |
| 727 0); |
711 } | 728 } |
712 | 729 |
713 TEST_F(HttpNetworkLayerTest, NoServerFallbackWithDeprecatedViaHeader) { | 730 TEST_F(HttpNetworkLayerTest, NoServerFallbackWithDeprecatedViaHeader) { |
714 // Verify that Chrome will not be induced to bypass the data reduction proxy | 731 // Verify that Chrome will not be induced to bypass the data reduction proxy |
715 // when the deprecated data reduction proxy via header is present, even if | 732 // when the deprecated data reduction proxy via header is present, even if |
716 // that header is chained. | 733 // that header is chained. |
717 std::string chrome_proxy = GetDataReductionProxy(); | 734 std::string chrome_proxy = GetDataReductionProxy(); |
718 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 735 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
719 "PROXY " + chrome_proxy + "; PROXY good:8080")); | 736 "PROXY " + chrome_proxy + "; PROXY good:8080")); |
720 | 737 |
721 MockRead data_reads[] = { | 738 MockRead data_reads[] = { |
722 MockRead("HTTP/1.1 200 OK\r\n" | 739 MockRead( |
723 "Connection: keep-alive\r\n" | 740 "HTTP/1.1 200 OK\r\n" |
724 "Via: 1.1 Chrome Compression Proxy\r\n\r\n"), | 741 "Connection: keep-alive\r\n" |
725 MockRead("Bypass message"), | 742 "Via: 1.1 Chrome Compression Proxy\r\n\r\n"), |
726 MockRead(SYNCHRONOUS, OK), | 743 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
727 }; | 744 }; |
728 | 745 |
729 TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(), | 746 TestProxyFallbackByMethodWithMockReads(chrome_proxy, |
730 data_reads, arraysize(data_reads), | 747 std::string(), |
731 "GET", "Bypass message", false, 0); | 748 data_reads, |
| 749 arraysize(data_reads), |
| 750 "GET", |
| 751 "Bypass message", |
| 752 false, |
| 753 0); |
732 } | 754 } |
733 | 755 |
734 #if defined(DATA_REDUCTION_FALLBACK_HOST) | 756 #if defined(DATA_REDUCTION_FALLBACK_HOST) |
735 TEST_F(HttpNetworkLayerTest, ServerFallbackWithProxyTimedBypassAll) { | 757 TEST_F(HttpNetworkLayerTest, ServerFallbackWithProxyTimedBypassAll) { |
736 // Verify that a Chrome-Proxy: block=<seconds> header bypasses a | 758 // Verify that a Chrome-Proxy: block=<seconds> header bypasses a |
737 // a configured Chrome-Proxy and fallback and induces proxy fallback to a | 759 // a configured Chrome-Proxy and fallback and induces proxy fallback to a |
738 // third proxy, if configured. | 760 // third proxy, if configured. |
739 std::string bad_proxy = GetDataReductionProxy(); | 761 std::string bad_proxy = GetDataReductionProxy(); |
740 std::string fallback_proxy = GetChromeFallbackProxy(); | 762 std::string fallback_proxy = GetChromeFallbackProxy(); |
741 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 763 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
742 "PROXY " + bad_proxy + "; PROXY " + fallback_proxy + | 764 "PROXY " + bad_proxy + "; PROXY " + fallback_proxy + |
743 "; PROXY good:8080")); | 765 "; PROXY good:8080")); |
744 | 766 |
745 MockRead data_reads[] = { | 767 MockRead data_reads[] = { |
746 MockRead("HTTP/1.1 200 OK\r\n" | 768 MockRead( |
747 "Connection: keep-alive\r\n" | 769 "HTTP/1.1 200 OK\r\n" |
748 "Chrome-Proxy: block=86400\r\n" | 770 "Connection: keep-alive\r\n" |
749 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"), | 771 "Chrome-Proxy: block=86400\r\n" |
750 MockRead("Bypass message"), | 772 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"), |
751 MockRead(SYNCHRONOUS, OK), | 773 MockRead("Bypass message"), MockRead(SYNCHRONOUS, OK), |
752 }; | 774 }; |
753 | 775 |
754 TestProxyFallbackWithMockReads(bad_proxy, fallback_proxy, data_reads, | 776 TestProxyFallbackWithMockReads( |
755 arraysize(data_reads), 2u); | 777 bad_proxy, fallback_proxy, data_reads, arraysize(data_reads), 2u); |
756 EXPECT_EQ(base::TimeDelta::FromSeconds(86400), | 778 EXPECT_EQ(base::TimeDelta::FromSeconds(86400), |
757 (*proxy_service_->proxy_retry_info().begin()).second.current_delay); | 779 (*proxy_service_->proxy_retry_info().begin()).second.current_delay); |
758 } | 780 } |
759 #endif // defined(DATA_REDUCTION_FALLBACK_HOST) | 781 #endif // defined(DATA_REDUCTION_FALLBACK_HOST) |
760 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 782 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
761 | 783 |
762 TEST_F(HttpNetworkLayerTest, NetworkVerified) { | 784 TEST_F(HttpNetworkLayerTest, NetworkVerified) { |
763 MockRead data_reads[] = { | 785 MockRead data_reads[] = { |
764 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 786 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
765 MockRead("hello world"), | 787 MockRead(SYNCHRONOUS, OK), |
766 MockRead(SYNCHRONOUS, OK), | |
767 }; | 788 }; |
768 MockWrite data_writes[] = { | 789 MockWrite data_writes[] = { |
769 MockWrite("GET / HTTP/1.1\r\n" | 790 MockWrite( |
770 "Host: www.google.com\r\n" | 791 "GET / HTTP/1.1\r\n" |
771 "Connection: keep-alive\r\n" | 792 "Host: www.google.com\r\n" |
772 "User-Agent: Foo/1.0\r\n\r\n"), | 793 "Connection: keep-alive\r\n" |
| 794 "User-Agent: Foo/1.0\r\n\r\n"), |
773 }; | 795 }; |
774 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 796 StaticSocketDataProvider data( |
775 data_writes, arraysize(data_writes)); | 797 data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
776 mock_socket_factory_.AddSocketDataProvider(&data); | 798 mock_socket_factory_.AddSocketDataProvider(&data); |
777 | 799 |
778 TestCompletionCallback callback; | 800 TestCompletionCallback callback; |
779 | 801 |
780 HttpRequestInfo request_info; | 802 HttpRequestInfo request_info; |
781 request_info.url = GURL("http://www.google.com/"); | 803 request_info.url = GURL("http://www.google.com/"); |
782 request_info.method = "GET"; | 804 request_info.method = "GET"; |
783 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 805 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
784 "Foo/1.0"); | 806 "Foo/1.0"); |
785 request_info.load_flags = LOAD_NORMAL; | 807 request_info.load_flags = LOAD_NORMAL; |
786 | 808 |
787 scoped_ptr<HttpTransaction> trans; | 809 scoped_ptr<HttpTransaction> trans; |
788 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 810 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
789 EXPECT_EQ(OK, rv); | 811 EXPECT_EQ(OK, rv); |
790 | 812 |
791 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 813 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
792 ASSERT_EQ(OK, callback.GetResult(rv)); | 814 ASSERT_EQ(OK, callback.GetResult(rv)); |
793 | 815 |
794 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed); | 816 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed); |
795 } | 817 } |
796 | 818 |
797 TEST_F(HttpNetworkLayerTest, NetworkUnVerified) { | 819 TEST_F(HttpNetworkLayerTest, NetworkUnVerified) { |
798 MockRead data_reads[] = { | 820 MockRead data_reads[] = { |
799 MockRead(ASYNC, ERR_CONNECTION_RESET), | 821 MockRead(ASYNC, ERR_CONNECTION_RESET), |
800 }; | 822 }; |
801 MockWrite data_writes[] = { | 823 MockWrite data_writes[] = { |
802 MockWrite("GET / HTTP/1.1\r\n" | 824 MockWrite( |
803 "Host: www.google.com\r\n" | 825 "GET / HTTP/1.1\r\n" |
804 "Connection: keep-alive\r\n" | 826 "Host: www.google.com\r\n" |
805 "User-Agent: Foo/1.0\r\n\r\n"), | 827 "Connection: keep-alive\r\n" |
| 828 "User-Agent: Foo/1.0\r\n\r\n"), |
806 }; | 829 }; |
807 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 830 StaticSocketDataProvider data( |
808 data_writes, arraysize(data_writes)); | 831 data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
809 mock_socket_factory_.AddSocketDataProvider(&data); | 832 mock_socket_factory_.AddSocketDataProvider(&data); |
810 | 833 |
811 TestCompletionCallback callback; | 834 TestCompletionCallback callback; |
812 | 835 |
813 HttpRequestInfo request_info; | 836 HttpRequestInfo request_info; |
814 request_info.url = GURL("http://www.google.com/"); | 837 request_info.url = GURL("http://www.google.com/"); |
815 request_info.method = "GET"; | 838 request_info.method = "GET"; |
816 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 839 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
817 "Foo/1.0"); | 840 "Foo/1.0"); |
818 request_info.load_flags = LOAD_NORMAL; | 841 request_info.load_flags = LOAD_NORMAL; |
819 | 842 |
820 scoped_ptr<HttpTransaction> trans; | 843 scoped_ptr<HttpTransaction> trans; |
821 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 844 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
822 EXPECT_EQ(OK, rv); | 845 EXPECT_EQ(OK, rv); |
823 | 846 |
824 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 847 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
825 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv)); | 848 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv)); |
826 | 849 |
827 // If the response info is null, that means that any consumer won't | 850 // If the response info is null, that means that any consumer won't |
828 // see the network accessed bit set. | 851 // see the network accessed bit set. |
829 EXPECT_EQ(NULL, trans->GetResponseInfo()); | 852 EXPECT_EQ(NULL, trans->GetResponseInfo()); |
830 } | 853 } |
831 | 854 |
832 } // namespace | 855 } // namespace |
833 | 856 |
834 } // namespace net | 857 } // namespace net |
OLD | NEW |