| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 ptr += 10; | 143 ptr += 10; |
| 144 if (idx % 100 == 0) { | 144 if (idx % 100 == 0) { |
| 145 ptr--; | 145 ptr--; |
| 146 *ptr++ = marker; | 146 *ptr++ = marker; |
| 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<net::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 net::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(); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 524 |
| 525 // we won't actually get a received reponse here because we've never run the | 525 // we won't actually get a received reponse here because we've never run the |
| 526 // message loop | 526 // message loop |
| 527 EXPECT_FALSE(d.received_data_before_response()); | 527 EXPECT_FALSE(d.received_data_before_response()); |
| 528 EXPECT_EQ(0, d.bytes_received()); | 528 EXPECT_EQ(0, d.bytes_received()); |
| 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<net::URLRequestContext> context(new TestURLRequestContext()); |
| 535 | 535 |
| 536 // populate cache | 536 // populate cache |
| 537 { | 537 { |
| 538 TestDelegate d; | 538 TestDelegate d; |
| 539 net::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(net::URLRequestStatus::SUCCESS, r.status().status()); | 543 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); |
| 544 } | 544 } |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 EXPECT_EQ(1, d.response_started_count()); | 1131 EXPECT_EQ(1, d.response_started_count()); |
| 1132 EXPECT_EQ(0, d.bytes_received()); | 1132 EXPECT_EQ(0, d.bytes_received()); |
| 1133 EXPECT_FALSE(d.received_data_before_response()); | 1133 EXPECT_FALSE(d.received_data_before_response()); |
| 1134 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 1134 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
| 1135 } | 1135 } |
| 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<net::URLRequestContext> context(new TestURLRequestContext()); |
| 1142 | 1142 |
| 1143 // populate the cache | 1143 // populate the cache |
| 1144 { | 1144 { |
| 1145 TestDelegate d; | 1145 TestDelegate d; |
| 1146 net::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(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 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<net::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 net::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(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 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<net::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 net::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<net::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 net::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<net::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 net::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()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1325 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 1325 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
| 1326 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1326 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1327 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1327 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1328 } | 1328 } |
| 1329 } | 1329 } |
| 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<net::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 net::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 |
| (...skipping 1289 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 |