Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 12701011: [Net] Propagate priority changes from URLRequest to HttpTransaction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more tests Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 URLRequest passes on its priority updates to its
1408 // job.
1409 TEST_F(URLRequestTest, Priority) {
1410 TestDelegate d;
1411 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_);
1412 EXPECT_EQ(LOWEST, req.priority());
1413
1414 scoped_refptr<URLRequestTestJob> job =
1415 new URLRequestTestJob(&req, &default_network_delegate_);
1416 AddTestInterceptor()->set_main_intercept_job(job);
1417 EXPECT_EQ(IDLE, job->priority());
1418
1419 req.SetPriority(LOW);
1420 EXPECT_EQ(LOW, req.priority());
1421 // |req| doesn't know about |job| yet.
1422 EXPECT_EQ(IDLE, job->priority());
1423
1424 req.Start();
1425 // |req| should set |job|'s initial priority.
1426 EXPECT_EQ(LOW, job->priority());
1427
1428 req.SetPriority(HIGHEST);
1429 EXPECT_EQ(HIGHEST, req.priority());
1430 EXPECT_EQ(HIGHEST, job->priority());
1431 }
1432
1407 // TODO(droger): Support TestServer on iOS (see http://crbug.com/148666). 1433 // TODO(droger): Support TestServer on iOS (see http://crbug.com/148666).
1408 #if !defined(OS_IOS) 1434 #if !defined(OS_IOS)
1409 // A subclass of TestServer that uses a statically-configured hostname. This is 1435 // A subclass of TestServer that uses a statically-configured hostname. This is
1410 // to work around mysterious failures in chrome_frame_net_tests. See: 1436 // to work around mysterious failures in chrome_frame_net_tests. See:
1411 // http://crbug.com/114369 1437 // http://crbug.com/114369
1412 class LocalHttpTestServer : public TestServer { 1438 class LocalHttpTestServer : public TestServer {
1413 public: 1439 public:
1414 explicit LocalHttpTestServer(const base::FilePath& document_root) 1440 explicit LocalHttpTestServer(const base::FilePath& document_root)
1415 : TestServer(TestServer::TYPE_HTTP, 1441 : TestServer(TestServer::TYPE_HTTP,
1416 ScopedCustomUrlRequestTestHttpHost::value(), 1442 ScopedCustomUrlRequestTestHttpHost::value(),
(...skipping 2706 matching lines...) Expand 10 before | Expand all | Expand 10 after
4123 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { 4149 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
4124 TestDelegate d; 4150 TestDelegate d;
4125 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context); 4151 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context);
4126 req.Start(); 4152 req.Start();
4127 MessageLoop::current()->Run(); 4153 MessageLoop::current()->Run();
4128 EXPECT_EQ(tests[i].expected_response, d.data_received()) 4154 EXPECT_EQ(tests[i].expected_response, d.data_received())
4129 << " Request = \"" << tests[i].request << "\""; 4155 << " Request = \"" << tests[i].request << "\"";
4130 } 4156 }
4131 } 4157 }
4132 4158
4159 // Make sure that URLRequest passes on its priority updates to its job
4160 // even on redirect.
4161 TEST_F(URLRequestTestHTTP, PriorityRedirect) {
4162 ASSERT_TRUE(test_server_.Start());
4163
4164 TestDelegate d;
4165 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_);
4166 EXPECT_EQ(LOWEST, req.priority());
4167
4168 scoped_refptr<URLRequestRedirectJob> redirect_job =
4169 new URLRequestRedirectJob(
4170 &req, &default_network_delegate_, test_server_.GetURL("echo"),
4171 URLRequestRedirectJob::REDIRECT_302_FOUND);
4172 scoped_refptr<URLRequestTestJob> job =
4173 new URLRequestTestJob(&req, &default_network_delegate_);
4174
4175 AddTestInterceptor()->set_main_intercept_job(redirect_job);
4176
4177 EXPECT_EQ(IDLE, job->priority());
4178
4179 req.SetPriority(LOW);
4180 EXPECT_EQ(LOW, req.priority());
4181 EXPECT_EQ(IDLE, job->priority());
4182
4183 req.Start();
4184 EXPECT_TRUE(req.is_pending());
4185 EXPECT_EQ(IDLE, job->priority());
4186
4187 AddTestInterceptor()->set_main_intercept_job(job);
4188 EXPECT_EQ(IDLE, job->priority());
4189
4190 MessageLoop::current()->Run();
4191 EXPECT_EQ(LOW, job->priority());
4192
4193 req.SetPriority(HIGHEST);
4194 EXPECT_EQ(HIGHEST, req.priority());
4195 EXPECT_EQ(HIGHEST, job->priority());
4196 }
4197
4198
4133 class HTTPSRequestTest : public testing::Test { 4199 class HTTPSRequestTest : public testing::Test {
4134 public: 4200 public:
4135 HTTPSRequestTest() : default_context_(true) { 4201 HTTPSRequestTest() : default_context_(true) {
4136 default_context_.set_network_delegate(&default_network_delegate_); 4202 default_context_.set_network_delegate(&default_network_delegate_);
4137 default_context_.Init(); 4203 default_context_.Init();
4138 } 4204 }
4139 virtual ~HTTPSRequestTest() {} 4205 virtual ~HTTPSRequestTest() {}
4140 4206
4141 protected: 4207 protected:
4142 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 4208 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
5367 5433
5368 EXPECT_FALSE(r.is_pending()); 5434 EXPECT_FALSE(r.is_pending());
5369 EXPECT_EQ(1, d->response_started_count()); 5435 EXPECT_EQ(1, d->response_started_count());
5370 EXPECT_FALSE(d->received_data_before_response()); 5436 EXPECT_FALSE(d->received_data_before_response());
5371 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 5437 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
5372 } 5438 }
5373 } 5439 }
5374 #endif // !defined(DISABLE_FTP_SUPPORT) 5440 #endif // !defined(DISABLE_FTP_SUPPORT)
5375 5441
5376 } // namespace net 5442 } // namespace net
OLDNEW
« net/http/http_cache_transaction.cc ('K') | « net/url_request/url_request_test_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698