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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 // content is empty. | 1397 // content is empty. |
1398 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { | 1398 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { |
1399 TestDelegate d; | 1399 TestDelegate d; |
1400 URLRequest req(GURL("data:,"), &d, &default_context_); | 1400 URLRequest req(GURL("data:,"), &d, &default_context_); |
1401 req.Start(); | 1401 req.Start(); |
1402 MessageLoop::current()->Run(); | 1402 MessageLoop::current()->Run(); |
1403 EXPECT_EQ("", d.data_received()); | 1403 EXPECT_EQ("", d.data_received()); |
1404 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 1404 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
1405 } | 1405 } |
1406 | 1406 |
| 1407 // Make sure that SetPriority actually sets the URLRequest's priority |
| 1408 // correctly, both before and after start. |
| 1409 TEST_F(URLRequestTest, SetPriorityBasic) { |
| 1410 TestDelegate d; |
| 1411 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
| 1412 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
| 1413 |
| 1414 req.SetPriority(LOW); |
| 1415 EXPECT_EQ(LOW, req.priority()); |
| 1416 |
| 1417 req.Start(); |
| 1418 EXPECT_EQ(LOW, req.priority()); |
| 1419 |
| 1420 req.SetPriority(MEDIUM); |
| 1421 EXPECT_EQ(MEDIUM, req.priority()); |
| 1422 } |
| 1423 |
| 1424 // Make sure that URLRequest calls SetPriority on a job before calling |
| 1425 // Start on it. |
| 1426 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { |
| 1427 TestDelegate d; |
| 1428 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
| 1429 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
| 1430 |
| 1431 scoped_refptr<URLRequestTestJob> job = |
| 1432 new URLRequestTestJob(&req, &default_network_delegate_); |
| 1433 AddTestInterceptor()->set_main_intercept_job(job); |
| 1434 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 1435 |
| 1436 req.SetPriority(LOW); |
| 1437 |
| 1438 req.Start(); |
| 1439 EXPECT_EQ(LOW, job->priority()); |
| 1440 } |
| 1441 |
| 1442 // Make sure that URLRequest passes on its priority updates to its |
| 1443 // job. |
| 1444 TEST_F(URLRequestTest, SetJobPriority) { |
| 1445 TestDelegate d; |
| 1446 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
| 1447 |
| 1448 scoped_refptr<URLRequestTestJob> job = |
| 1449 new URLRequestTestJob(&req, &default_network_delegate_); |
| 1450 AddTestInterceptor()->set_main_intercept_job(job); |
| 1451 |
| 1452 req.SetPriority(LOW); |
| 1453 req.Start(); |
| 1454 EXPECT_EQ(LOW, job->priority()); |
| 1455 |
| 1456 req.SetPriority(MEDIUM); |
| 1457 EXPECT_EQ(MEDIUM, req.priority()); |
| 1458 EXPECT_EQ(MEDIUM, job->priority()); |
| 1459 } |
| 1460 |
1407 // TODO(droger): Support TestServer on iOS (see http://crbug.com/148666). | 1461 // TODO(droger): Support TestServer on iOS (see http://crbug.com/148666). |
1408 #if !defined(OS_IOS) | 1462 #if !defined(OS_IOS) |
1409 // A subclass of TestServer that uses a statically-configured hostname. This is | 1463 // A subclass of TestServer that uses a statically-configured hostname. This is |
1410 // to work around mysterious failures in chrome_frame_net_tests. See: | 1464 // to work around mysterious failures in chrome_frame_net_tests. See: |
1411 // http://crbug.com/114369 | 1465 // http://crbug.com/114369 |
1412 class LocalHttpTestServer : public TestServer { | 1466 class LocalHttpTestServer : public TestServer { |
1413 public: | 1467 public: |
1414 explicit LocalHttpTestServer(const base::FilePath& document_root) | 1468 explicit LocalHttpTestServer(const base::FilePath& document_root) |
1415 : TestServer(TestServer::TYPE_HTTP, | 1469 : TestServer(TestServer::TYPE_HTTP, |
1416 ScopedCustomUrlRequestTestHttpHost::value(), | 1470 ScopedCustomUrlRequestTestHttpHost::value(), |
(...skipping 2661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4078 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { | 4132 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { |
4079 TestDelegate d; | 4133 TestDelegate d; |
4080 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context); | 4134 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context); |
4081 req.Start(); | 4135 req.Start(); |
4082 MessageLoop::current()->Run(); | 4136 MessageLoop::current()->Run(); |
4083 EXPECT_EQ(tests[i].expected_response, d.data_received()) | 4137 EXPECT_EQ(tests[i].expected_response, d.data_received()) |
4084 << " Request = \"" << tests[i].request << "\""; | 4138 << " Request = \"" << tests[i].request << "\""; |
4085 } | 4139 } |
4086 } | 4140 } |
4087 | 4141 |
| 4142 // Make sure that URLRequest passes on its priority updates to |
| 4143 // newly-created jobs after the first one. |
| 4144 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { |
| 4145 ASSERT_TRUE(test_server_.Start()); |
| 4146 |
| 4147 TestDelegate d; |
| 4148 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
| 4149 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
| 4150 |
| 4151 scoped_refptr<URLRequestRedirectJob> redirect_job = |
| 4152 new URLRequestRedirectJob( |
| 4153 &req, &default_network_delegate_, test_server_.GetURL("echo"), |
| 4154 URLRequestRedirectJob::REDIRECT_302_FOUND); |
| 4155 AddTestInterceptor()->set_main_intercept_job(redirect_job); |
| 4156 |
| 4157 req.SetPriority(LOW); |
| 4158 req.Start(); |
| 4159 EXPECT_TRUE(req.is_pending()); |
| 4160 |
| 4161 scoped_refptr<URLRequestTestJob> job = |
| 4162 new URLRequestTestJob(&req, &default_network_delegate_); |
| 4163 AddTestInterceptor()->set_main_intercept_job(job); |
| 4164 |
| 4165 // Should trigger |job| to be started. |
| 4166 MessageLoop::current()->Run(); |
| 4167 EXPECT_EQ(LOW, job->priority()); |
| 4168 } |
| 4169 |
4088 class HTTPSRequestTest : public testing::Test { | 4170 class HTTPSRequestTest : public testing::Test { |
4089 public: | 4171 public: |
4090 HTTPSRequestTest() : default_context_(true) { | 4172 HTTPSRequestTest() : default_context_(true) { |
4091 default_context_.set_network_delegate(&default_network_delegate_); | 4173 default_context_.set_network_delegate(&default_network_delegate_); |
4092 default_context_.Init(); | 4174 default_context_.Init(); |
4093 } | 4175 } |
4094 virtual ~HTTPSRequestTest() {} | 4176 virtual ~HTTPSRequestTest() {} |
4095 | 4177 |
4096 protected: | 4178 protected: |
4097 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 4179 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5322 | 5404 |
5323 EXPECT_FALSE(r.is_pending()); | 5405 EXPECT_FALSE(r.is_pending()); |
5324 EXPECT_EQ(1, d->response_started_count()); | 5406 EXPECT_EQ(1, d->response_started_count()); |
5325 EXPECT_FALSE(d->received_data_before_response()); | 5407 EXPECT_FALSE(d->received_data_before_response()); |
5326 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 5408 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
5327 } | 5409 } |
5328 } | 5410 } |
5329 #endif // !defined(DISABLE_FTP_SUPPORT) | 5411 #endif // !defined(DISABLE_FTP_SUPPORT) |
5330 | 5412 |
5331 } // namespace net | 5413 } // namespace net |
OLD | NEW |