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/url_request/url_request_job.h" | 5 #include "net/url_request/url_request_job.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "net/base/request_priority.h" | 10 #include "net/base/request_priority.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 transaction->handler = nullptr; | 86 transaction->handler = nullptr; |
87 transaction->read_handler = nullptr; | 87 transaction->read_handler = nullptr; |
88 if (GURL(original_url).SchemeIsCryptographic()) { | 88 if (GURL(original_url).SchemeIsCryptographic()) { |
89 transaction->cert = | 89 transaction->cert = |
90 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | 90 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); |
91 } else { | 91 } else { |
92 transaction->cert = nullptr; | 92 transaction->cert = nullptr; |
93 } | 93 } |
94 transaction->cert_status = 0; | 94 transaction->cert_status = 0; |
95 transaction->ssl_connection_status = 0; | 95 transaction->ssl_connection_status = 0; |
96 transaction->return_code = OK; | 96 transaction->start_return_code = OK; |
97 } | 97 } |
98 | 98 |
99 const MockTransaction kNoFilter_Transaction = { | 99 const MockTransaction kNoFilter_Transaction = { |
100 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, | 100 "http://www.google.com/gzyp", |
| 101 "GET", |
| 102 base::Time(), |
| 103 "", |
| 104 LOAD_NORMAL, |
101 "HTTP/1.1 200 OK", | 105 "HTTP/1.1 200 OK", |
102 "Cache-Control: max-age=10000\n" | 106 "Cache-Control: max-age=10000\n" |
103 "Content-Length: 30\n", // Intentionally wrong. | 107 "Content-Length: 30\n", // Intentionally wrong. |
104 base::Time(), | 108 base::Time(), |
105 "hello", TEST_MODE_NORMAL, nullptr, nullptr, 0, 0, OK, | 109 "hello", |
| 110 TEST_MODE_NORMAL, |
| 111 nullptr, |
| 112 nullptr, |
| 113 0, |
| 114 0, |
| 115 OK, |
| 116 OK, |
106 }; | 117 }; |
107 | 118 |
108 const MockTransaction kGZip_Transaction = { | 119 const MockTransaction kGZip_Transaction = { |
109 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, | 120 "http://www.google.com/gzyp", |
| 121 "GET", |
| 122 base::Time(), |
| 123 "", |
| 124 LOAD_NORMAL, |
110 "HTTP/1.1 200 OK", | 125 "HTTP/1.1 200 OK", |
111 "Cache-Control: max-age=10000\n" | 126 "Cache-Control: max-age=10000\n" |
112 "Content-Encoding: gzip\n" | 127 "Content-Encoding: gzip\n" |
113 "Content-Length: 30\n", // Intentionally wrong. | 128 "Content-Length: 30\n", // Intentionally wrong. |
114 base::Time(), | 129 base::Time(), |
115 "", TEST_MODE_NORMAL, &GZipServer, nullptr, nullptr, 0, 0, OK, | 130 "", |
| 131 TEST_MODE_NORMAL, |
| 132 &GZipServer, |
| 133 nullptr, |
| 134 nullptr, |
| 135 0, |
| 136 0, |
| 137 OK, |
| 138 OK, |
116 }; | 139 }; |
117 | 140 |
118 const MockTransaction kGzip_Slow_Transaction = { | 141 const MockTransaction kGzip_Slow_Transaction = { |
119 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, | 142 "http://www.google.com/gzyp", |
| 143 "GET", |
| 144 base::Time(), |
| 145 "", |
| 146 LOAD_NORMAL, |
120 "HTTP/1.1 200 OK", | 147 "HTTP/1.1 200 OK", |
121 "Cache-Control: max-age=10000\n" | 148 "Cache-Control: max-age=10000\n" |
122 "Content-Encoding: gzip\n", | 149 "Content-Encoding: gzip\n", |
123 base::Time(), "", TEST_MODE_SLOW_READ, &GZipHelloServer, nullptr, nullptr, | 150 base::Time(), |
124 0, 0, OK, | 151 "", |
| 152 TEST_MODE_SLOW_READ, |
| 153 &GZipHelloServer, |
| 154 nullptr, |
| 155 nullptr, |
| 156 0, |
| 157 0, |
| 158 OK, |
| 159 OK, |
125 }; | 160 }; |
126 | 161 |
127 const MockTransaction kRedirect_Transaction = { | 162 const MockTransaction kRedirect_Transaction = { |
128 "http://www.google.com/redirect", "GET", base::Time(), "", LOAD_NORMAL, | 163 "http://www.google.com/redirect", |
| 164 "GET", |
| 165 base::Time(), |
| 166 "", |
| 167 LOAD_NORMAL, |
129 "HTTP/1.1 302 Found", | 168 "HTTP/1.1 302 Found", |
130 "Cache-Control: max-age=10000\n" | 169 "Cache-Control: max-age=10000\n" |
131 "Location: http://www.google.com/destination\n" | 170 "Location: http://www.google.com/destination\n" |
132 "Content-Length: 5\n", | 171 "Content-Length: 5\n", |
133 base::Time(), "hello", TEST_MODE_NORMAL, nullptr, nullptr, nullptr, 0, 0, | 172 base::Time(), |
| 173 "hello", |
| 174 TEST_MODE_NORMAL, |
| 175 nullptr, |
| 176 nullptr, |
| 177 nullptr, |
| 178 0, |
| 179 0, |
| 180 OK, |
134 OK, | 181 OK, |
135 }; | 182 }; |
136 | 183 |
137 const MockTransaction kEmptyBodyGzip_Transaction = { | 184 const MockTransaction kEmptyBodyGzip_Transaction = { |
138 "http://www.google.com/empty_body", | 185 "http://www.google.com/empty_body", |
139 "GET", | 186 "GET", |
140 base::Time(), | 187 base::Time(), |
141 "", | 188 "", |
142 LOAD_NORMAL, | 189 LOAD_NORMAL, |
143 "HTTP/1.1 200 OK", | 190 "HTTP/1.1 200 OK", |
144 "Content-Encoding: gzip\n", | 191 "Content-Encoding: gzip\n", |
145 base::Time(), | 192 base::Time(), |
146 "", | 193 "", |
147 TEST_MODE_NORMAL, | 194 TEST_MODE_NORMAL, |
148 nullptr, | 195 nullptr, |
149 nullptr, | 196 nullptr, |
150 nullptr, | 197 nullptr, |
151 0, | 198 0, |
152 0, | 199 0, |
153 OK, | 200 OK, |
| 201 OK, |
154 }; | 202 }; |
155 | 203 |
156 const MockTransaction kInvalidContentGZip_Transaction = { | 204 const MockTransaction kInvalidContentGZip_Transaction = { |
157 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, | 205 "http://www.google.com/gzyp", |
| 206 "GET", |
| 207 base::Time(), |
| 208 "", |
| 209 LOAD_NORMAL, |
158 "HTTP/1.1 200 OK", | 210 "HTTP/1.1 200 OK", |
159 "Content-Encoding: gzip\n" | 211 "Content-Encoding: gzip\n" |
160 "Content-Length: 21\n", | 212 "Content-Length: 21\n", |
161 base::Time(), "not a valid gzip body", TEST_MODE_NORMAL, nullptr, nullptr, | 213 base::Time(), |
162 nullptr, 0, 0, OK, | 214 "not a valid gzip body", |
| 215 TEST_MODE_NORMAL, |
| 216 nullptr, |
| 217 nullptr, |
| 218 nullptr, |
| 219 0, |
| 220 0, |
| 221 OK, |
| 222 OK, |
163 }; | 223 }; |
164 | 224 |
165 const MockTransaction kBrotli_Slow_Transaction = { | 225 const MockTransaction kBrotli_Slow_Transaction = { |
166 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL, | 226 "http://www.google.com/brotli", |
| 227 "GET", |
| 228 base::Time(), |
| 229 "", |
| 230 LOAD_NORMAL, |
167 "HTTP/1.1 200 OK", | 231 "HTTP/1.1 200 OK", |
168 "Cache-Control: max-age=10000\n" | 232 "Cache-Control: max-age=10000\n" |
169 "Content-Encoding: br\n", | 233 "Content-Encoding: br\n", |
170 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, nullptr, | 234 base::Time(), |
171 0, 0, OK, | 235 "", |
| 236 TEST_MODE_SLOW_READ, |
| 237 &BrotliHelloServer, |
| 238 nullptr, |
| 239 nullptr, |
| 240 0, |
| 241 0, |
| 242 OK, |
| 243 OK, |
172 }; | 244 }; |
173 | 245 |
174 } // namespace | 246 } // namespace |
175 | 247 |
176 TEST(URLRequestJob, TransactionNoFilter) { | 248 TEST(URLRequestJob, TransactionNoFilter) { |
177 MockNetworkLayer network_layer; | 249 MockNetworkLayer network_layer; |
178 TestURLRequestContext context; | 250 TestURLRequestContext context; |
179 context.set_http_transaction_factory(&network_layer); | 251 context.set_http_transaction_factory(&network_layer); |
180 | 252 |
181 TestDelegate d; | 253 TestDelegate d; |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 783 |
712 EXPECT_FALSE(d.request_failed()); | 784 EXPECT_FALSE(d.request_failed()); |
713 EXPECT_EQ(200, req->GetResponseCode()); | 785 EXPECT_EQ(200, req->GetResponseCode()); |
714 EXPECT_EQ(kHelloData, d.data_received()); | 786 EXPECT_EQ(kHelloData, d.data_received()); |
715 EXPECT_TRUE(network_layer.done_reading_called()); | 787 EXPECT_TRUE(network_layer.done_reading_called()); |
716 | 788 |
717 RemoveMockTransaction(&kBrotli_Slow_Transaction); | 789 RemoveMockTransaction(&kBrotli_Slow_Transaction); |
718 } | 790 } |
719 | 791 |
720 } // namespace net | 792 } // namespace net |
OLD | NEW |