OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_unittest.h" | 5 #include "net/url_request/url_request_unittest.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ssl_info.connection_status); | 112 ssl_info.connection_status); |
113 EXPECT_NE(0, cipher_suite); | 113 EXPECT_NE(0, cipher_suite); |
114 } | 114 } |
115 | 115 |
116 } // namespace | 116 } // namespace |
117 | 117 |
118 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 118 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
119 class URLRequestTest : public PlatformTest { | 119 class URLRequestTest : public PlatformTest { |
120 public: | 120 public: |
121 static void SetUpTestCase() { | 121 static void SetUpTestCase() { |
122 URLRequest::AllowFileAccess(); | 122 net::URLRequest::AllowFileAccess(); |
123 } | 123 } |
124 }; | 124 }; |
125 | 125 |
126 class URLRequestTestHTTP : public URLRequestTest { | 126 class URLRequestTestHTTP : public URLRequestTest { |
127 public: | 127 public: |
128 URLRequestTestHTTP() | 128 URLRequestTestHTTP() |
129 : test_server_(net::TestServer::TYPE_HTTP, | 129 : test_server_(net::TestServer::TYPE_HTTP, |
130 FilePath(FILE_PATH_LITERAL( | 130 FilePath(FILE_PATH_LITERAL( |
131 "net/data/url_request_unittest"))) { | 131 "net/data/url_request_unittest"))) { |
132 } | 132 } |
(...skipping 14 matching lines...) Expand all Loading... |
147 if (++marker > 'z') | 147 if (++marker > 'z') |
148 marker = 'a'; | 148 marker = 'a'; |
149 } | 149 } |
150 } | 150 } |
151 uploadBytes[kMsgSize] = '\0'; | 151 uploadBytes[kMsgSize] = '\0'; |
152 | 152 |
153 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 153 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
154 | 154 |
155 for (int i = 0; i < kIterations; ++i) { | 155 for (int i = 0; i < kIterations; ++i) { |
156 TestDelegate d; | 156 TestDelegate d; |
157 URLRequest r(test_server_.GetURL("echo"), &d); | 157 net::URLRequest r(test_server_.GetURL("echo"), &d); |
158 r.set_context(context); | 158 r.set_context(context); |
159 r.set_method(method.c_str()); | 159 r.set_method(method.c_str()); |
160 | 160 |
161 r.AppendBytesToUpload(uploadBytes, kMsgSize); | 161 r.AppendBytesToUpload(uploadBytes, kMsgSize); |
162 | 162 |
163 r.Start(); | 163 r.Start(); |
164 EXPECT_TRUE(r.is_pending()); | 164 EXPECT_TRUE(r.is_pending()); |
165 | 165 |
166 MessageLoop::current()->Run(); | 166 MessageLoop::current()->Run(); |
167 | 167 |
(...skipping 13 matching lines...) Expand all Loading... |
181 | 181 |
182 // In this unit test, we're using the HTTPTestServer as a proxy server and | 182 // In this unit test, we're using the HTTPTestServer as a proxy server and |
183 // issuing a CONNECT request with the magic host name "www.redirect.com". | 183 // issuing a CONNECT request with the magic host name "www.redirect.com". |
184 // The HTTPTestServer will return a 302 response, which we should not | 184 // The HTTPTestServer will return a 302 response, which we should not |
185 // follow. | 185 // follow. |
186 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 186 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
187 ASSERT_TRUE(test_server_.Start()); | 187 ASSERT_TRUE(test_server_.Start()); |
188 | 188 |
189 TestDelegate d; | 189 TestDelegate d; |
190 { | 190 { |
191 URLRequest r(GURL("https://www.redirect.com/"), &d); | 191 net::URLRequest r(GURL("https://www.redirect.com/"), &d); |
192 r.set_context( | 192 r.set_context( |
193 new TestURLRequestContext(test_server_.host_port_pair().ToString())); | 193 new TestURLRequestContext(test_server_.host_port_pair().ToString())); |
194 | 194 |
195 r.Start(); | 195 r.Start(); |
196 EXPECT_TRUE(r.is_pending()); | 196 EXPECT_TRUE(r.is_pending()); |
197 | 197 |
198 MessageLoop::current()->Run(); | 198 MessageLoop::current()->Run(); |
199 | 199 |
200 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 200 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
201 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 201 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
202 EXPECT_EQ(1, d.response_started_count()); | 202 EXPECT_EQ(1, d.response_started_count()); |
203 // We should not have followed the redirect. | 203 // We should not have followed the redirect. |
204 EXPECT_EQ(0, d.received_redirect_count()); | 204 EXPECT_EQ(0, d.received_redirect_count()); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 // In this unit test, we're using the HTTPTestServer as a proxy server and | 208 // In this unit test, we're using the HTTPTestServer as a proxy server and |
209 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 209 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
210 // The HTTPTestServer will return a 401 response, which we should balk at. | 210 // The HTTPTestServer will return a 401 response, which we should balk at. |
211 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 211 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
212 ASSERT_TRUE(test_server_.Start()); | 212 ASSERT_TRUE(test_server_.Start()); |
213 | 213 |
214 TestDelegate d; | 214 TestDelegate d; |
215 { | 215 { |
216 URLRequest r(GURL("https://www.server-auth.com/"), &d); | 216 net::URLRequest r(GURL("https://www.server-auth.com/"), &d); |
217 r.set_context( | 217 r.set_context( |
218 new TestURLRequestContext(test_server_.host_port_pair().ToString())); | 218 new TestURLRequestContext(test_server_.host_port_pair().ToString())); |
219 | 219 |
220 r.Start(); | 220 r.Start(); |
221 EXPECT_TRUE(r.is_pending()); | 221 EXPECT_TRUE(r.is_pending()); |
222 | 222 |
223 MessageLoop::current()->Run(); | 223 MessageLoop::current()->Run(); |
224 | 224 |
225 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 225 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
226 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 226 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 namespace { | 382 namespace { |
383 | 383 |
384 class SSLClientAuthTestDelegate : public TestDelegate { | 384 class SSLClientAuthTestDelegate : public TestDelegate { |
385 public: | 385 public: |
386 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { | 386 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { |
387 } | 387 } |
388 virtual void OnCertificateRequested( | 388 virtual void OnCertificateRequested( |
389 URLRequest* request, | 389 net::URLRequest* request, |
390 net::SSLCertRequestInfo* cert_request_info) { | 390 net::SSLCertRequestInfo* cert_request_info) { |
391 on_certificate_requested_count_++; | 391 on_certificate_requested_count_++; |
392 MessageLoop::current()->Quit(); | 392 MessageLoop::current()->Quit(); |
393 } | 393 } |
394 int on_certificate_requested_count() { | 394 int on_certificate_requested_count() { |
395 return on_certificate_requested_count_; | 395 return on_certificate_requested_count_; |
396 } | 396 } |
397 private: | 397 private: |
398 int on_certificate_requested_count_; | 398 int on_certificate_requested_count_; |
399 }; | 399 }; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 } | 529 } |
530 | 530 |
531 TEST_F(URLRequestTestHTTP, CancelTest5) { | 531 TEST_F(URLRequestTestHTTP, CancelTest5) { |
532 ASSERT_TRUE(test_server_.Start()); | 532 ASSERT_TRUE(test_server_.Start()); |
533 | 533 |
534 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 534 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
535 | 535 |
536 // populate cache | 536 // populate cache |
537 { | 537 { |
538 TestDelegate d; | 538 TestDelegate d; |
539 URLRequest r(test_server_.GetURL("cachetime"), &d); | 539 net::URLRequest r(test_server_.GetURL("cachetime"), &d); |
540 r.set_context(context); | 540 r.set_context(context); |
541 r.Start(); | 541 r.Start(); |
542 MessageLoop::current()->Run(); | 542 MessageLoop::current()->Run(); |
543 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 543 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
544 } | 544 } |
545 | 545 |
546 // cancel read from cache (see bug 990242) | 546 // cancel read from cache (see bug 990242) |
547 { | 547 { |
548 TestDelegate d; | 548 TestDelegate d; |
549 URLRequest r(test_server_.GetURL("cachetime"), &d); | 549 net::URLRequest r(test_server_.GetURL("cachetime"), &d); |
550 r.set_context(context); | 550 r.set_context(context); |
551 r.Start(); | 551 r.Start(); |
552 r.Cancel(); | 552 r.Cancel(); |
553 MessageLoop::current()->Run(); | 553 MessageLoop::current()->Run(); |
554 | 554 |
555 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 555 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
556 EXPECT_EQ(1, d.response_started_count()); | 556 EXPECT_EQ(1, d.response_started_count()); |
557 EXPECT_EQ(0, d.bytes_received()); | 557 EXPECT_EQ(0, d.bytes_received()); |
558 EXPECT_FALSE(d.received_data_before_response()); | 558 EXPECT_FALSE(d.received_data_before_response()); |
559 } | 559 } |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 } | 1136 } |
1137 | 1137 |
1138 TEST_F(URLRequestTestHTTP, VaryHeader) { | 1138 TEST_F(URLRequestTestHTTP, VaryHeader) { |
1139 ASSERT_TRUE(test_server_.Start()); | 1139 ASSERT_TRUE(test_server_.Start()); |
1140 | 1140 |
1141 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 1141 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1142 | 1142 |
1143 // populate the cache | 1143 // populate the cache |
1144 { | 1144 { |
1145 TestDelegate d; | 1145 TestDelegate d; |
1146 URLRequest req(test_server_.GetURL("echoheader?foo"), &d); | 1146 net::URLRequest req(test_server_.GetURL("echoheader?foo"), &d); |
1147 req.set_context(context); | 1147 req.set_context(context); |
1148 net::HttpRequestHeaders headers; | 1148 net::HttpRequestHeaders headers; |
1149 headers.SetHeader("foo", "1"); | 1149 headers.SetHeader("foo", "1"); |
1150 req.SetExtraRequestHeaders(headers); | 1150 req.SetExtraRequestHeaders(headers); |
1151 req.Start(); | 1151 req.Start(); |
1152 MessageLoop::current()->Run(); | 1152 MessageLoop::current()->Run(); |
1153 } | 1153 } |
1154 | 1154 |
1155 // expect a cache hit | 1155 // expect a cache hit |
1156 { | 1156 { |
1157 TestDelegate d; | 1157 TestDelegate d; |
1158 URLRequest req(test_server_.GetURL("echoheader?foo"), &d); | 1158 net::URLRequest req(test_server_.GetURL("echoheader?foo"), &d); |
1159 req.set_context(context); | 1159 req.set_context(context); |
1160 net::HttpRequestHeaders headers; | 1160 net::HttpRequestHeaders headers; |
1161 headers.SetHeader("foo", "1"); | 1161 headers.SetHeader("foo", "1"); |
1162 req.SetExtraRequestHeaders(headers); | 1162 req.SetExtraRequestHeaders(headers); |
1163 req.Start(); | 1163 req.Start(); |
1164 MessageLoop::current()->Run(); | 1164 MessageLoop::current()->Run(); |
1165 | 1165 |
1166 EXPECT_TRUE(req.was_cached()); | 1166 EXPECT_TRUE(req.was_cached()); |
1167 } | 1167 } |
1168 | 1168 |
1169 // expect a cache miss | 1169 // expect a cache miss |
1170 { | 1170 { |
1171 TestDelegate d; | 1171 TestDelegate d; |
1172 URLRequest req(test_server_.GetURL("echoheader?foo"), &d); | 1172 net::URLRequest req(test_server_.GetURL("echoheader?foo"), &d); |
1173 req.set_context(context); | 1173 req.set_context(context); |
1174 net::HttpRequestHeaders headers; | 1174 net::HttpRequestHeaders headers; |
1175 headers.SetHeader("foo", "2"); | 1175 headers.SetHeader("foo", "2"); |
1176 req.SetExtraRequestHeaders(headers); | 1176 req.SetExtraRequestHeaders(headers); |
1177 req.Start(); | 1177 req.Start(); |
1178 MessageLoop::current()->Run(); | 1178 MessageLoop::current()->Run(); |
1179 | 1179 |
1180 EXPECT_FALSE(req.was_cached()); | 1180 EXPECT_FALSE(req.was_cached()); |
1181 } | 1181 } |
1182 } | 1182 } |
1183 | 1183 |
1184 TEST_F(URLRequestTestHTTP, BasicAuth) { | 1184 TEST_F(URLRequestTestHTTP, BasicAuth) { |
1185 ASSERT_TRUE(test_server_.Start()); | 1185 ASSERT_TRUE(test_server_.Start()); |
1186 | 1186 |
1187 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 1187 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1188 | 1188 |
1189 // populate the cache | 1189 // populate the cache |
1190 { | 1190 { |
1191 TestDelegate d; | 1191 TestDelegate d; |
1192 d.set_username(kUser); | 1192 d.set_username(kUser); |
1193 d.set_password(kSecret); | 1193 d.set_password(kSecret); |
1194 | 1194 |
1195 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 1195 net::URLRequest r(test_server_.GetURL("auth-basic"), &d); |
1196 r.set_context(context); | 1196 r.set_context(context); |
1197 r.Start(); | 1197 r.Start(); |
1198 | 1198 |
1199 MessageLoop::current()->Run(); | 1199 MessageLoop::current()->Run(); |
1200 | 1200 |
1201 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1201 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
1202 } | 1202 } |
1203 | 1203 |
1204 // repeat request with end-to-end validation. since auth-basic results in a | 1204 // repeat request with end-to-end validation. since auth-basic results in a |
1205 // cachable page, we expect this test to result in a 304. in which case, the | 1205 // cachable page, we expect this test to result in a 304. in which case, the |
1206 // response should be fetched from the cache. | 1206 // response should be fetched from the cache. |
1207 { | 1207 { |
1208 TestDelegate d; | 1208 TestDelegate d; |
1209 d.set_username(kUser); | 1209 d.set_username(kUser); |
1210 d.set_password(kSecret); | 1210 d.set_password(kSecret); |
1211 | 1211 |
1212 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 1212 net::URLRequest r(test_server_.GetURL("auth-basic"), &d); |
1213 r.set_context(context); | 1213 r.set_context(context); |
1214 r.set_load_flags(net::LOAD_VALIDATE_CACHE); | 1214 r.set_load_flags(net::LOAD_VALIDATE_CACHE); |
1215 r.Start(); | 1215 r.Start(); |
1216 | 1216 |
1217 MessageLoop::current()->Run(); | 1217 MessageLoop::current()->Run(); |
1218 | 1218 |
1219 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1219 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
1220 | 1220 |
1221 // Should be the same cached document. | 1221 // Should be the same cached document. |
1222 EXPECT_TRUE(r.was_cached()); | 1222 EXPECT_TRUE(r.was_cached()); |
1223 } | 1223 } |
1224 } | 1224 } |
1225 | 1225 |
1226 // Check that Set-Cookie headers in 401 responses are respected. | 1226 // Check that Set-Cookie headers in 401 responses are respected. |
1227 // http://crbug.com/6450 | 1227 // http://crbug.com/6450 |
1228 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { | 1228 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { |
1229 ASSERT_TRUE(test_server_.Start()); | 1229 ASSERT_TRUE(test_server_.Start()); |
1230 | 1230 |
1231 GURL url_requiring_auth = | 1231 GURL url_requiring_auth = |
1232 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); | 1232 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); |
1233 | 1233 |
1234 // Request a page that will give a 401 containing a Set-Cookie header. | 1234 // Request a page that will give a 401 containing a Set-Cookie header. |
1235 // Verify that when the transaction is restarted, it includes the new cookie. | 1235 // Verify that when the transaction is restarted, it includes the new cookie. |
1236 { | 1236 { |
1237 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 1237 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1238 TestDelegate d; | 1238 TestDelegate d; |
1239 d.set_username(kUser); | 1239 d.set_username(kUser); |
1240 d.set_password(kSecret); | 1240 d.set_password(kSecret); |
1241 | 1241 |
1242 URLRequest r(url_requiring_auth, &d); | 1242 net::URLRequest r(url_requiring_auth, &d); |
1243 r.set_context(context); | 1243 r.set_context(context); |
1244 r.Start(); | 1244 r.Start(); |
1245 | 1245 |
1246 MessageLoop::current()->Run(); | 1246 MessageLoop::current()->Run(); |
1247 | 1247 |
1248 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1248 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
1249 | 1249 |
1250 // Make sure we sent the cookie in the restarted transaction. | 1250 // Make sure we sent the cookie in the restarted transaction. |
1251 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1251 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
1252 != std::string::npos); | 1252 != std::string::npos); |
1253 } | 1253 } |
1254 | 1254 |
1255 // Same test as above, except this time the restart is initiated earlier | 1255 // Same test as above, except this time the restart is initiated earlier |
1256 // (without user intervention since identity is embedded in the URL). | 1256 // (without user intervention since identity is embedded in the URL). |
1257 { | 1257 { |
1258 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 1258 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1259 TestDelegate d; | 1259 TestDelegate d; |
1260 | 1260 |
1261 GURL::Replacements replacements; | 1261 GURL::Replacements replacements; |
1262 std::string username("user2"); | 1262 std::string username("user2"); |
1263 std::string password("secret"); | 1263 std::string password("secret"); |
1264 replacements.SetUsernameStr(username); | 1264 replacements.SetUsernameStr(username); |
1265 replacements.SetPasswordStr(password); | 1265 replacements.SetPasswordStr(password); |
1266 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 1266 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
1267 | 1267 |
1268 URLRequest r(url_with_identity, &d); | 1268 net::URLRequest r(url_with_identity, &d); |
1269 r.set_context(context); | 1269 r.set_context(context); |
1270 r.Start(); | 1270 r.Start(); |
1271 | 1271 |
1272 MessageLoop::current()->Run(); | 1272 MessageLoop::current()->Run(); |
1273 | 1273 |
1274 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 1274 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
1275 | 1275 |
1276 // Make sure we sent the cookie in the restarted transaction. | 1276 // Make sure we sent the cookie in the restarted transaction. |
1277 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1277 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
1278 != std::string::npos); | 1278 != std::string::npos); |
1279 } | 1279 } |
1280 } | 1280 } |
1281 | 1281 |
1282 TEST_F(URLRequestTest, DoNotSendCookies) { | 1282 TEST_F(URLRequestTest, DoNotSendCookies) { |
1283 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1283 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1284 ASSERT_TRUE(test_server.Start()); | 1284 ASSERT_TRUE(test_server.Start()); |
1285 | 1285 |
1286 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 1286 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1287 | 1287 |
1288 // Set up a cookie. | 1288 // Set up a cookie. |
1289 { | 1289 { |
1290 TestDelegate d; | 1290 TestDelegate d; |
1291 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1291 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
1292 req.set_context(context); | 1292 req.set_context(context); |
1293 req.Start(); | 1293 req.Start(); |
1294 MessageLoop::current()->Run(); | 1294 MessageLoop::current()->Run(); |
1295 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1295 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1296 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1296 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1297 } | 1297 } |
1298 | 1298 |
1299 // Verify that the cookie is set. | 1299 // Verify that the cookie is set. |
1300 { | 1300 { |
1301 TestDelegate d; | 1301 TestDelegate d; |
(...skipping 28 matching lines...) Expand all Loading... |
1330 | 1330 |
1331 TEST_F(URLRequestTest, DoNotSaveCookies) { | 1331 TEST_F(URLRequestTest, DoNotSaveCookies) { |
1332 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1332 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1333 ASSERT_TRUE(test_server.Start()); | 1333 ASSERT_TRUE(test_server.Start()); |
1334 | 1334 |
1335 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 1335 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1336 | 1336 |
1337 // Set up a cookie. | 1337 // Set up a cookie. |
1338 { | 1338 { |
1339 TestDelegate d; | 1339 TestDelegate d; |
1340 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1340 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
1341 &d); | 1341 &d); |
1342 req.set_context(context); | 1342 req.set_context(context); |
1343 req.Start(); | 1343 req.Start(); |
1344 MessageLoop::current()->Run(); | 1344 MessageLoop::current()->Run(); |
1345 | 1345 |
1346 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1346 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1347 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1347 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1348 EXPECT_EQ(1, d.set_cookie_count()); | 1348 EXPECT_EQ(1, d.set_cookie_count()); |
1349 } | 1349 } |
1350 | 1350 |
1351 // Try to set-up another cookie and update the previous cookie. | 1351 // Try to set-up another cookie and update the previous cookie. |
1352 { | 1352 { |
1353 TestDelegate d; | 1353 TestDelegate d; |
1354 URLRequest req(test_server.GetURL( | 1354 net::URLRequest req(test_server.GetURL( |
1355 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 1355 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
1356 req.set_load_flags(net::LOAD_DO_NOT_SAVE_COOKIES); | 1356 req.set_load_flags(net::LOAD_DO_NOT_SAVE_COOKIES); |
1357 req.set_context(context); | 1357 req.set_context(context); |
1358 req.Start(); | 1358 req.Start(); |
1359 | 1359 |
1360 MessageLoop::current()->Run(); | 1360 MessageLoop::current()->Run(); |
1361 | 1361 |
1362 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 1362 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
1363 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1363 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1364 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1364 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
(...skipping 21 matching lines...) Expand all Loading... |
1386 | 1386 |
1387 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 1387 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
1388 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1388 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1389 ASSERT_TRUE(test_server.Start()); | 1389 ASSERT_TRUE(test_server.Start()); |
1390 | 1390 |
1391 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1391 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1392 | 1392 |
1393 // Set up a cookie. | 1393 // Set up a cookie. |
1394 { | 1394 { |
1395 TestDelegate d; | 1395 TestDelegate d; |
1396 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1396 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
1397 req.set_context(context); | 1397 req.set_context(context); |
1398 req.Start(); | 1398 req.Start(); |
1399 MessageLoop::current()->Run(); | 1399 MessageLoop::current()->Run(); |
1400 | 1400 |
1401 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1401 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1402 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1402 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1403 } | 1403 } |
1404 | 1404 |
1405 // Verify that the cookie is set. | 1405 // Verify that the cookie is set. |
1406 { | 1406 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 | 1440 |
1441 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 1441 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
1442 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1442 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1443 ASSERT_TRUE(test_server.Start()); | 1443 ASSERT_TRUE(test_server.Start()); |
1444 | 1444 |
1445 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1445 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1446 | 1446 |
1447 // Set up a cookie. | 1447 // Set up a cookie. |
1448 { | 1448 { |
1449 TestDelegate d; | 1449 TestDelegate d; |
1450 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1450 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
1451 &d); | 1451 &d); |
1452 req.set_context(context); | 1452 req.set_context(context); |
1453 req.Start(); | 1453 req.Start(); |
1454 MessageLoop::current()->Run(); | 1454 MessageLoop::current()->Run(); |
1455 | 1455 |
1456 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1456 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1457 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1457 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1458 } | 1458 } |
1459 | 1459 |
1460 // Try to set-up another cookie and update the previous cookie. | 1460 // Try to set-up another cookie and update the previous cookie. |
1461 { | 1461 { |
1462 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | 1462 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
1463 context->set_cookie_policy(&cookie_policy); | 1463 context->set_cookie_policy(&cookie_policy); |
1464 | 1464 |
1465 TestDelegate d; | 1465 TestDelegate d; |
1466 URLRequest req(test_server.GetURL( | 1466 net::URLRequest req(test_server.GetURL( |
1467 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 1467 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
1468 req.set_context(context); | 1468 req.set_context(context); |
1469 req.Start(); | 1469 req.Start(); |
1470 | 1470 |
1471 MessageLoop::current()->Run(); | 1471 MessageLoop::current()->Run(); |
1472 | 1472 |
1473 context->set_cookie_policy(NULL); | 1473 context->set_cookie_policy(NULL); |
1474 | 1474 |
1475 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1475 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1476 EXPECT_EQ(2, d.blocked_set_cookie_count()); | 1476 EXPECT_EQ(2, d.blocked_set_cookie_count()); |
(...skipping 20 matching lines...) Expand all Loading... |
1497 | 1497 |
1498 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 1498 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
1499 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1499 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1500 ASSERT_TRUE(test_server.Start()); | 1500 ASSERT_TRUE(test_server.Start()); |
1501 | 1501 |
1502 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1502 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1503 | 1503 |
1504 // Set up an empty cookie. | 1504 // Set up an empty cookie. |
1505 { | 1505 { |
1506 TestDelegate d; | 1506 TestDelegate d; |
1507 URLRequest req(test_server.GetURL("set-cookie"), &d); | 1507 net::URLRequest req(test_server.GetURL("set-cookie"), &d); |
1508 req.set_context(context); | 1508 req.set_context(context); |
1509 req.Start(); | 1509 req.Start(); |
1510 MessageLoop::current()->Run(); | 1510 MessageLoop::current()->Run(); |
1511 | 1511 |
1512 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1512 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1513 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1513 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1514 EXPECT_EQ(0, d.set_cookie_count()); | 1514 EXPECT_EQ(0, d.set_cookie_count()); |
1515 } | 1515 } |
1516 } | 1516 } |
1517 | 1517 |
1518 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 1518 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
1519 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1519 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1520 ASSERT_TRUE(test_server.Start()); | 1520 ASSERT_TRUE(test_server.Start()); |
1521 | 1521 |
1522 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1522 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1523 | 1523 |
1524 // Set up a cookie. | 1524 // Set up a cookie. |
1525 { | 1525 { |
1526 TestDelegate d; | 1526 TestDelegate d; |
1527 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1527 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
1528 req.set_context(context); | 1528 req.set_context(context); |
1529 req.Start(); | 1529 req.Start(); |
1530 MessageLoop::current()->Run(); | 1530 MessageLoop::current()->Run(); |
1531 | 1531 |
1532 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1532 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1533 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1533 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1534 } | 1534 } |
1535 | 1535 |
1536 // Verify that the cookie is set. | 1536 // Verify that the cookie is set. |
1537 { | 1537 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 | 1572 |
1573 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 1573 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
1574 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1574 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1575 ASSERT_TRUE(test_server.Start()); | 1575 ASSERT_TRUE(test_server.Start()); |
1576 | 1576 |
1577 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1577 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1578 | 1578 |
1579 // Set up a cookie. | 1579 // Set up a cookie. |
1580 { | 1580 { |
1581 TestDelegate d; | 1581 TestDelegate d; |
1582 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1582 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
1583 &d); | 1583 &d); |
1584 req.set_context(context); | 1584 req.set_context(context); |
1585 req.Start(); | 1585 req.Start(); |
1586 MessageLoop::current()->Run(); | 1586 MessageLoop::current()->Run(); |
1587 | 1587 |
1588 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1588 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1589 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1589 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1590 } | 1590 } |
1591 | 1591 |
1592 // Try to set-up another cookie and update the previous cookie. | 1592 // Try to set-up another cookie and update the previous cookie. |
1593 { | 1593 { |
1594 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE | | 1594 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE | |
1595 TestCookiePolicy::ASYNC); | 1595 TestCookiePolicy::ASYNC); |
1596 context->set_cookie_policy(&cookie_policy); | 1596 context->set_cookie_policy(&cookie_policy); |
1597 | 1597 |
1598 TestDelegate d; | 1598 TestDelegate d; |
1599 URLRequest req(test_server.GetURL( | 1599 net::URLRequest req(test_server.GetURL( |
1600 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 1600 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
1601 req.set_context(context); | 1601 req.set_context(context); |
1602 req.Start(); | 1602 req.Start(); |
1603 | 1603 |
1604 MessageLoop::current()->Run(); | 1604 MessageLoop::current()->Run(); |
1605 | 1605 |
1606 context->set_cookie_policy(NULL); | 1606 context->set_cookie_policy(NULL); |
1607 | 1607 |
1608 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1608 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1609 EXPECT_EQ(2, d.blocked_set_cookie_count()); | 1609 EXPECT_EQ(2, d.blocked_set_cookie_count()); |
(...skipping 22 matching lines...) Expand all Loading... |
1632 ASSERT_TRUE(test_server.Start()); | 1632 ASSERT_TRUE(test_server.Start()); |
1633 | 1633 |
1634 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1634 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1635 | 1635 |
1636 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); | 1636 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); |
1637 context->set_cookie_policy(&cookie_policy); | 1637 context->set_cookie_policy(&cookie_policy); |
1638 | 1638 |
1639 // Set up a cookie. | 1639 // Set up a cookie. |
1640 { | 1640 { |
1641 TestDelegate d; | 1641 TestDelegate d; |
1642 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1642 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
1643 &d); | 1643 &d); |
1644 req.set_context(context); | 1644 req.set_context(context); |
1645 req.Start(); // Triggers an asynchronous cookie policy check. | 1645 req.Start(); // Triggers an asynchronous cookie policy check. |
1646 | 1646 |
1647 // But, now we cancel the request by letting it go out of scope. This | 1647 // But, now we cancel the request by letting it go out of scope. This |
1648 // should not cause a crash. | 1648 // should not cause a crash. |
1649 | 1649 |
1650 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1650 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1651 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1651 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1652 } | 1652 } |
1653 | 1653 |
1654 context->set_cookie_policy(NULL); | 1654 context->set_cookie_policy(NULL); |
1655 | 1655 |
1656 // Let the cookie policy complete. Make sure it handles the destruction of | 1656 // Let the cookie policy complete. Make sure it handles the destruction of |
1657 // the URLRequest properly. | 1657 // the net::URLRequest properly. |
1658 MessageLoop::current()->RunAllPending(); | 1658 MessageLoop::current()->RunAllPending(); |
1659 } | 1659 } |
1660 | 1660 |
1661 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { | 1661 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { |
1662 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1662 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1663 ASSERT_TRUE(test_server.Start()); | 1663 ASSERT_TRUE(test_server.Start()); |
1664 | 1664 |
1665 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1665 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1666 | 1666 |
1667 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); | 1667 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); |
1668 context->set_cookie_policy(&cookie_policy); | 1668 context->set_cookie_policy(&cookie_policy); |
1669 | 1669 |
1670 // Set up a cookie. | 1670 // Set up a cookie. |
1671 { | 1671 { |
1672 TestDelegate d; | 1672 TestDelegate d; |
1673 d.set_cancel_in_get_cookies_blocked(true); | 1673 d.set_cancel_in_get_cookies_blocked(true); |
1674 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1674 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
1675 &d); | 1675 &d); |
1676 req.set_context(context); | 1676 req.set_context(context); |
1677 req.Start(); // Triggers an asynchronous cookie policy check. | 1677 req.Start(); // Triggers an asynchronous cookie policy check. |
1678 | 1678 |
1679 MessageLoop::current()->Run(); | 1679 MessageLoop::current()->Run(); |
1680 | 1680 |
1681 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1681 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1682 | 1682 |
1683 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1683 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1684 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1684 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1685 } | 1685 } |
1686 | 1686 |
1687 context->set_cookie_policy(NULL); | 1687 context->set_cookie_policy(NULL); |
1688 } | 1688 } |
1689 | 1689 |
1690 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { | 1690 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { |
1691 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1691 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1692 ASSERT_TRUE(test_server.Start()); | 1692 ASSERT_TRUE(test_server.Start()); |
1693 | 1693 |
1694 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1694 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1695 | 1695 |
1696 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | 1696 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
1697 context->set_cookie_policy(&cookie_policy); | 1697 context->set_cookie_policy(&cookie_policy); |
1698 | 1698 |
1699 // Set up a cookie. | 1699 // Set up a cookie. |
1700 { | 1700 { |
1701 TestDelegate d; | 1701 TestDelegate d; |
1702 d.set_cancel_in_set_cookie_blocked(true); | 1702 d.set_cancel_in_set_cookie_blocked(true); |
1703 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1703 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
1704 &d); | 1704 &d); |
1705 req.set_context(context); | 1705 req.set_context(context); |
1706 req.Start(); // Triggers an asynchronous cookie policy check. | 1706 req.Start(); // Triggers an asynchronous cookie policy check. |
1707 | 1707 |
1708 MessageLoop::current()->Run(); | 1708 MessageLoop::current()->Run(); |
1709 | 1709 |
1710 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1710 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1711 | 1711 |
1712 // Even though the response will contain 3 set-cookie headers, we expect | 1712 // Even though the response will contain 3 set-cookie headers, we expect |
1713 // only one to be blocked as that first one will cause OnSetCookie to be | 1713 // only one to be blocked as that first one will cause OnSetCookie to be |
1714 // called, which will cancel the request. Once canceled, it should not | 1714 // called, which will cancel the request. Once canceled, it should not |
(...skipping 11 matching lines...) Expand all Loading... |
1726 ASSERT_TRUE(test_server.Start()); | 1726 ASSERT_TRUE(test_server.Start()); |
1727 | 1727 |
1728 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1728 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1729 | 1729 |
1730 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); | 1730 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); |
1731 context->set_cookie_policy(&cookie_policy); | 1731 context->set_cookie_policy(&cookie_policy); |
1732 | 1732 |
1733 // Set up a cookie. | 1733 // Set up a cookie. |
1734 { | 1734 { |
1735 TestDelegate d; | 1735 TestDelegate d; |
1736 URLRequest req(test_server.GetURL( | 1736 net::URLRequest req(test_server.GetURL( |
1737 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); | 1737 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); |
1738 req.set_context(context); | 1738 req.set_context(context); |
1739 req.Start(); // Triggers an asynchronous cookie policy check. | 1739 req.Start(); // Triggers an asynchronous cookie policy check. |
1740 | 1740 |
1741 MessageLoop::current()->Run(); | 1741 MessageLoop::current()->Run(); |
1742 | 1742 |
1743 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1743 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1744 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1744 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1745 } | 1745 } |
1746 | 1746 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 req.SetExtraRequestHeaders(headers); | 1815 req.SetExtraRequestHeaders(headers); |
1816 req.Start(); | 1816 req.Start(); |
1817 MessageLoop::current()->Run(); | 1817 MessageLoop::current()->Run(); |
1818 EXPECT_EQ("POST", req.method()); | 1818 EXPECT_EQ("POST", req.method()); |
1819 EXPECT_EQ(kData, d.data_received()); | 1819 EXPECT_EQ(kData, d.data_received()); |
1820 } | 1820 } |
1821 | 1821 |
1822 // Custom URLRequestJobs for use with interceptor tests | 1822 // Custom URLRequestJobs for use with interceptor tests |
1823 class RestartTestJob : public URLRequestTestJob { | 1823 class RestartTestJob : public URLRequestTestJob { |
1824 public: | 1824 public: |
1825 explicit RestartTestJob(URLRequest* request) | 1825 explicit RestartTestJob(net::URLRequest* request) |
1826 : URLRequestTestJob(request, true) {} | 1826 : URLRequestTestJob(request, true) {} |
1827 protected: | 1827 protected: |
1828 virtual void StartAsync() { | 1828 virtual void StartAsync() { |
1829 this->NotifyRestartRequired(); | 1829 this->NotifyRestartRequired(); |
1830 } | 1830 } |
1831 private: | 1831 private: |
1832 ~RestartTestJob() {} | 1832 ~RestartTestJob() {} |
1833 }; | 1833 }; |
1834 | 1834 |
1835 class CancelTestJob : public URLRequestTestJob { | 1835 class CancelTestJob : public URLRequestTestJob { |
1836 public: | 1836 public: |
1837 explicit CancelTestJob(URLRequest* request) | 1837 explicit CancelTestJob(net::URLRequest* request) |
1838 : URLRequestTestJob(request, true) {} | 1838 : URLRequestTestJob(request, true) {} |
1839 protected: | 1839 protected: |
1840 virtual void StartAsync() { | 1840 virtual void StartAsync() { |
1841 request_->Cancel(); | 1841 request_->Cancel(); |
1842 } | 1842 } |
1843 private: | 1843 private: |
1844 ~CancelTestJob() {} | 1844 ~CancelTestJob() {} |
1845 }; | 1845 }; |
1846 | 1846 |
1847 class CancelThenRestartTestJob : public URLRequestTestJob { | 1847 class CancelThenRestartTestJob : public URLRequestTestJob { |
1848 public: | 1848 public: |
1849 explicit CancelThenRestartTestJob(URLRequest* request) | 1849 explicit CancelThenRestartTestJob(net::URLRequest* request) |
1850 : URLRequestTestJob(request, true) { | 1850 : URLRequestTestJob(request, true) { |
1851 } | 1851 } |
1852 protected: | 1852 protected: |
1853 virtual void StartAsync() { | 1853 virtual void StartAsync() { |
1854 request_->Cancel(); | 1854 request_->Cancel(); |
1855 this->NotifyRestartRequired(); | 1855 this->NotifyRestartRequired(); |
1856 } | 1856 } |
1857 private: | 1857 private: |
1858 ~CancelThenRestartTestJob() {} | 1858 ~CancelThenRestartTestJob() {} |
1859 }; | 1859 }; |
1860 | 1860 |
1861 // An Interceptor for use with interceptor tests | 1861 // An Interceptor for use with interceptor tests |
1862 class TestInterceptor : URLRequest::Interceptor { | 1862 class TestInterceptor : net::URLRequest::Interceptor { |
1863 public: | 1863 public: |
1864 TestInterceptor() | 1864 TestInterceptor() |
1865 : intercept_main_request_(false), restart_main_request_(false), | 1865 : intercept_main_request_(false), restart_main_request_(false), |
1866 cancel_main_request_(false), cancel_then_restart_main_request_(false), | 1866 cancel_main_request_(false), cancel_then_restart_main_request_(false), |
1867 simulate_main_network_error_(false), | 1867 simulate_main_network_error_(false), |
1868 intercept_redirect_(false), cancel_redirect_request_(false), | 1868 intercept_redirect_(false), cancel_redirect_request_(false), |
1869 intercept_final_response_(false), cancel_final_request_(false), | 1869 intercept_final_response_(false), cancel_final_request_(false), |
1870 did_intercept_main_(false), did_restart_main_(false), | 1870 did_intercept_main_(false), did_restart_main_(false), |
1871 did_cancel_main_(false), did_cancel_then_restart_main_(false), | 1871 did_cancel_main_(false), did_cancel_then_restart_main_(false), |
1872 did_simulate_error_main_(false), | 1872 did_simulate_error_main_(false), |
1873 did_intercept_redirect_(false), did_cancel_redirect_(false), | 1873 did_intercept_redirect_(false), did_cancel_redirect_(false), |
1874 did_intercept_final_(false), did_cancel_final_(false) { | 1874 did_intercept_final_(false), did_cancel_final_(false) { |
1875 URLRequest::RegisterRequestInterceptor(this); | 1875 net::URLRequest::RegisterRequestInterceptor(this); |
1876 } | 1876 } |
1877 | 1877 |
1878 ~TestInterceptor() { | 1878 ~TestInterceptor() { |
1879 URLRequest::UnregisterRequestInterceptor(this); | 1879 net::URLRequest::UnregisterRequestInterceptor(this); |
1880 } | 1880 } |
1881 | 1881 |
1882 virtual URLRequestJob* MaybeIntercept(URLRequest* request) { | 1882 virtual URLRequestJob* MaybeIntercept(net::URLRequest* request) { |
1883 if (restart_main_request_) { | 1883 if (restart_main_request_) { |
1884 restart_main_request_ = false; | 1884 restart_main_request_ = false; |
1885 did_restart_main_ = true; | 1885 did_restart_main_ = true; |
1886 return new RestartTestJob(request); | 1886 return new RestartTestJob(request); |
1887 } | 1887 } |
1888 if (cancel_main_request_) { | 1888 if (cancel_main_request_) { |
1889 cancel_main_request_ = false; | 1889 cancel_main_request_ = false; |
1890 did_cancel_main_ = true; | 1890 did_cancel_main_ = true; |
1891 return new CancelTestJob(request); | 1891 return new CancelTestJob(request); |
1892 } | 1892 } |
(...skipping 11 matching lines...) Expand all Loading... |
1904 if (!intercept_main_request_) | 1904 if (!intercept_main_request_) |
1905 return NULL; | 1905 return NULL; |
1906 intercept_main_request_ = false; | 1906 intercept_main_request_ = false; |
1907 did_intercept_main_ = true; | 1907 did_intercept_main_ = true; |
1908 return new URLRequestTestJob(request, | 1908 return new URLRequestTestJob(request, |
1909 main_headers_, | 1909 main_headers_, |
1910 main_data_, | 1910 main_data_, |
1911 true); | 1911 true); |
1912 } | 1912 } |
1913 | 1913 |
1914 virtual URLRequestJob* MaybeInterceptRedirect(URLRequest* request, | 1914 virtual URLRequestJob* MaybeInterceptRedirect(net::URLRequest* request, |
1915 const GURL& location) { | 1915 const GURL& location) { |
1916 if (cancel_redirect_request_) { | 1916 if (cancel_redirect_request_) { |
1917 cancel_redirect_request_ = false; | 1917 cancel_redirect_request_ = false; |
1918 did_cancel_redirect_ = true; | 1918 did_cancel_redirect_ = true; |
1919 return new CancelTestJob(request); | 1919 return new CancelTestJob(request); |
1920 } | 1920 } |
1921 if (!intercept_redirect_) | 1921 if (!intercept_redirect_) |
1922 return NULL; | 1922 return NULL; |
1923 intercept_redirect_ = false; | 1923 intercept_redirect_ = false; |
1924 did_intercept_redirect_ = true; | 1924 did_intercept_redirect_ = true; |
1925 return new URLRequestTestJob(request, | 1925 return new URLRequestTestJob(request, |
1926 redirect_headers_, | 1926 redirect_headers_, |
1927 redirect_data_, | 1927 redirect_data_, |
1928 true); | 1928 true); |
1929 } | 1929 } |
1930 | 1930 |
1931 virtual URLRequestJob* MaybeInterceptResponse(URLRequest* request) { | 1931 virtual URLRequestJob* MaybeInterceptResponse(net::URLRequest* request) { |
1932 if (cancel_final_request_) { | 1932 if (cancel_final_request_) { |
1933 cancel_final_request_ = false; | 1933 cancel_final_request_ = false; |
1934 did_cancel_final_ = true; | 1934 did_cancel_final_ = true; |
1935 return new CancelTestJob(request); | 1935 return new CancelTestJob(request); |
1936 } | 1936 } |
1937 if (!intercept_final_response_) | 1937 if (!intercept_final_response_) |
1938 return NULL; | 1938 return NULL; |
1939 intercept_final_response_ = false; | 1939 intercept_final_response_ = false; |
1940 did_intercept_final_ = true; | 1940 did_intercept_final_ = true; |
1941 return new URLRequestTestJob(request, | 1941 return new URLRequestTestJob(request, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 TEST_F(URLRequestTest, Intercept) { | 2012 TEST_F(URLRequestTest, Intercept) { |
2013 TestInterceptor interceptor; | 2013 TestInterceptor interceptor; |
2014 | 2014 |
2015 // intercept the main request and respond with a simple response | 2015 // intercept the main request and respond with a simple response |
2016 interceptor.intercept_main_request_ = true; | 2016 interceptor.intercept_main_request_ = true; |
2017 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 2017 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
2018 interceptor.main_data_ = TestInterceptor::ok_data(); | 2018 interceptor.main_data_ = TestInterceptor::ok_data(); |
2019 | 2019 |
2020 TestDelegate d; | 2020 TestDelegate d; |
2021 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 2021 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
2022 URLRequest::UserData* user_data0 = new URLRequest::UserData(); | 2022 net::URLRequest::UserData* user_data0 = new net::URLRequest::UserData(); |
2023 URLRequest::UserData* user_data1 = new URLRequest::UserData(); | 2023 net::URLRequest::UserData* user_data1 = new net::URLRequest::UserData(); |
2024 URLRequest::UserData* user_data2 = new URLRequest::UserData(); | 2024 net::URLRequest::UserData* user_data2 = new net::URLRequest::UserData(); |
2025 req.SetUserData(NULL, user_data0); | 2025 req.SetUserData(NULL, user_data0); |
2026 req.SetUserData(&user_data1, user_data1); | 2026 req.SetUserData(&user_data1, user_data1); |
2027 req.SetUserData(&user_data2, user_data2); | 2027 req.SetUserData(&user_data2, user_data2); |
2028 req.set_method("GET"); | 2028 req.set_method("GET"); |
2029 req.Start(); | 2029 req.Start(); |
2030 MessageLoop::current()->Run(); | 2030 MessageLoop::current()->Run(); |
2031 | 2031 |
2032 // Make sure we can retrieve our specific user data | 2032 // Make sure we can retrieve our specific user data |
2033 EXPECT_EQ(user_data0, req.GetUserData(NULL)); | 2033 EXPECT_EQ(user_data0, req.GetUserData(NULL)); |
2034 EXPECT_EQ(user_data1, req.GetUserData(&user_data1)); | 2034 EXPECT_EQ(user_data1, req.GetUserData(&user_data1)); |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2635 TestURLRequest | 2635 TestURLRequest |
2636 req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); | 2636 req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); |
2637 req.set_context(new TestURLRequestContext()); | 2637 req.set_context(new TestURLRequestContext()); |
2638 net::HttpRequestHeaders headers; | 2638 net::HttpRequestHeaders headers; |
2639 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 2639 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
2640 req.SetExtraRequestHeaders(headers); | 2640 req.SetExtraRequestHeaders(headers); |
2641 req.Start(); | 2641 req.Start(); |
2642 MessageLoop::current()->Run(); | 2642 MessageLoop::current()->Run(); |
2643 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 2643 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
2644 } | 2644 } |
OLD | NEW |