| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <windows.h> | 10 #include <windows.h> |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 EXPECT_FALSE(d.received_data_before_response()); | 1200 EXPECT_FALSE(d.received_data_before_response()); |
| 1201 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1201 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 1202 } | 1202 } |
| 1203 } | 1203 } |
| 1204 | 1204 |
| 1205 TEST_F(URLRequestTestHTTP, VaryHeader) { | 1205 TEST_F(URLRequestTestHTTP, VaryHeader) { |
| 1206 ASSERT_TRUE(NULL != server_.get()); | 1206 ASSERT_TRUE(NULL != server_.get()); |
| 1207 | 1207 |
| 1208 scoped_refptr<URLRequestContext> context = new URLRequestTestContext(); | 1208 scoped_refptr<URLRequestContext> context = new URLRequestTestContext(); |
| 1209 | 1209 |
| 1210 Time response_time; | |
| 1211 | |
| 1212 // populate the cache | 1210 // populate the cache |
| 1213 { | 1211 { |
| 1214 TestDelegate d; | 1212 TestDelegate d; |
| 1215 URLRequest req(server_->TestServerPage("echoheader?foo"), &d); | 1213 URLRequest req(server_->TestServerPage("echoheader?foo"), &d); |
| 1216 req.set_context(context); | 1214 req.set_context(context); |
| 1217 req.SetExtraRequestHeaders("foo:1"); | 1215 req.SetExtraRequestHeaders("foo:1"); |
| 1218 req.Start(); | 1216 req.Start(); |
| 1219 MessageLoop::current()->Run(); | 1217 MessageLoop::current()->Run(); |
| 1220 | |
| 1221 response_time = req.response_time(); | |
| 1222 } | 1218 } |
| 1223 | 1219 |
| 1224 // Make sure that the response time of a future response will be in the | |
| 1225 // future! | |
| 1226 PlatformThread::Sleep(10); | |
| 1227 | |
| 1228 // expect a cache hit | 1220 // expect a cache hit |
| 1229 { | 1221 { |
| 1230 TestDelegate d; | 1222 TestDelegate d; |
| 1231 URLRequest req(server_->TestServerPage("echoheader?foo"), &d); | 1223 URLRequest req(server_->TestServerPage("echoheader?foo"), &d); |
| 1232 req.set_context(context); | 1224 req.set_context(context); |
| 1233 req.SetExtraRequestHeaders("foo:1"); | 1225 req.SetExtraRequestHeaders("foo:1"); |
| 1234 req.Start(); | 1226 req.Start(); |
| 1235 MessageLoop::current()->Run(); | 1227 MessageLoop::current()->Run(); |
| 1236 | 1228 |
| 1237 EXPECT_TRUE(req.response_time() == response_time); | 1229 EXPECT_TRUE(req.was_cached()); |
| 1238 } | 1230 } |
| 1239 | 1231 |
| 1240 // expect a cache miss | 1232 // expect a cache miss |
| 1241 { | 1233 { |
| 1242 TestDelegate d; | 1234 TestDelegate d; |
| 1243 URLRequest req(server_->TestServerPage("echoheader?foo"), &d); | 1235 URLRequest req(server_->TestServerPage("echoheader?foo"), &d); |
| 1244 req.set_context(context); | 1236 req.set_context(context); |
| 1245 req.SetExtraRequestHeaders("foo:2"); | 1237 req.SetExtraRequestHeaders("foo:2"); |
| 1246 req.Start(); | 1238 req.Start(); |
| 1247 MessageLoop::current()->Run(); | 1239 MessageLoop::current()->Run(); |
| 1248 | 1240 |
| 1249 EXPECT_FALSE(req.response_time() == response_time); | 1241 EXPECT_FALSE(req.was_cached()); |
| 1250 } | 1242 } |
| 1251 } | 1243 } |
| 1252 | 1244 |
| 1253 // TODO(eroman): Broke with commit of r25484 -- this is depending on | 1245 TEST_F(URLRequestTestHTTP, BasicAuth) { |
| 1254 // the response time value. | |
| 1255 TEST_F(URLRequestTestHTTP, DISABLED_BasicAuth) { | |
| 1256 scoped_refptr<URLRequestContext> context = new URLRequestTestContext(); | 1246 scoped_refptr<URLRequestContext> context = new URLRequestTestContext(); |
| 1257 ASSERT_TRUE(NULL != server_.get()); | 1247 ASSERT_TRUE(NULL != server_.get()); |
| 1258 | 1248 |
| 1259 Time response_time; | |
| 1260 | |
| 1261 // populate the cache | 1249 // populate the cache |
| 1262 { | 1250 { |
| 1263 TestDelegate d; | 1251 TestDelegate d; |
| 1264 d.set_username(L"user"); | 1252 d.set_username(L"user"); |
| 1265 d.set_password(L"secret"); | 1253 d.set_password(L"secret"); |
| 1266 | 1254 |
| 1267 URLRequest r(server_->TestServerPage("auth-basic"), &d); | 1255 URLRequest r(server_->TestServerPage("auth-basic"), &d); |
| 1268 r.set_context(context); | 1256 r.set_context(context); |
| 1269 r.Start(); | 1257 r.Start(); |
| 1270 | 1258 |
| 1271 MessageLoop::current()->Run(); | 1259 MessageLoop::current()->Run(); |
| 1272 | 1260 |
| 1273 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1261 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 1274 | |
| 1275 response_time = r.response_time(); | |
| 1276 } | 1262 } |
| 1277 | 1263 |
| 1278 // Let some time pass so we can ensure that a future response will have a | |
| 1279 // response time value in the future. | |
| 1280 PlatformThread::Sleep(10 /* milliseconds */); | |
| 1281 | |
| 1282 // repeat request with end-to-end validation. since auth-basic results in a | 1264 // repeat request with end-to-end validation. since auth-basic results in a |
| 1283 // cachable page, we expect this test to result in a 304. in which case, the | 1265 // cachable page, we expect this test to result in a 304. in which case, the |
| 1284 // response should be fetched from the cache. | 1266 // response should be fetched from the cache. |
| 1285 { | 1267 { |
| 1286 TestDelegate d; | 1268 TestDelegate d; |
| 1287 d.set_username(L"user"); | 1269 d.set_username(L"user"); |
| 1288 d.set_password(L"secret"); | 1270 d.set_password(L"secret"); |
| 1289 | 1271 |
| 1290 URLRequest r(server_->TestServerPage("auth-basic"), &d); | 1272 URLRequest r(server_->TestServerPage("auth-basic"), &d); |
| 1291 r.set_context(context); | 1273 r.set_context(context); |
| 1292 r.set_load_flags(net::LOAD_VALIDATE_CACHE); | 1274 r.set_load_flags(net::LOAD_VALIDATE_CACHE); |
| 1293 r.Start(); | 1275 r.Start(); |
| 1294 | 1276 |
| 1295 MessageLoop::current()->Run(); | 1277 MessageLoop::current()->Run(); |
| 1296 | 1278 |
| 1297 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1279 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 1298 | 1280 |
| 1299 // Should be the same cached document, which means that the response time | 1281 // Should be the same cached document. |
| 1300 // should not have changed. | 1282 EXPECT_TRUE(r.was_cached()); |
| 1301 EXPECT_TRUE(response_time == r.response_time()); | |
| 1302 } | 1283 } |
| 1303 } | 1284 } |
| 1304 | 1285 |
| 1305 // Check that Set-Cookie headers in 401 responses are respected. | 1286 // Check that Set-Cookie headers in 401 responses are respected. |
| 1306 // http://crbug.com/6450 | 1287 // http://crbug.com/6450 |
| 1307 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { | 1288 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { |
| 1308 ASSERT_TRUE(NULL != server_.get()); | 1289 ASSERT_TRUE(NULL != server_.get()); |
| 1309 | 1290 |
| 1310 GURL url_requiring_auth = | 1291 GURL url_requiring_auth = |
| 1311 server_->TestServerPage("auth-basic?set-cookie-if-challenged"); | 1292 server_->TestServerPage("auth-basic?set-cookie-if-challenged"); |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2112 | 2093 |
| 2113 int64 file_size = 0; | 2094 int64 file_size = 0; |
| 2114 file_util::GetFileSize(app_path, &file_size); | 2095 file_util::GetFileSize(app_path, &file_size); |
| 2115 | 2096 |
| 2116 EXPECT_FALSE(r.is_pending()); | 2097 EXPECT_FALSE(r.is_pending()); |
| 2117 EXPECT_EQ(1, d.response_started_count()); | 2098 EXPECT_EQ(1, d.response_started_count()); |
| 2118 EXPECT_FALSE(d.received_data_before_response()); | 2099 EXPECT_FALSE(d.received_data_before_response()); |
| 2119 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 2100 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 2120 } | 2101 } |
| 2121 } | 2102 } |
| OLD | NEW |