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 "net/url_request/url_request_ftp_job.h" |
| 6 |
| 7 #include "base/memory/ref_counted.h" |
5 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
6 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/http/http_transaction_unittest.h" |
7 #include "net/proxy/proxy_config_service.h" | 12 #include "net/proxy/proxy_config_service.h" |
8 #include "net/socket/socket_test_util.h" | 13 #include "net/socket/socket_test_util.h" |
9 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
10 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
11 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
12 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
14 | 19 |
15 namespace net { | 20 namespace net { |
16 | 21 |
(...skipping 25 matching lines...) Expand all Loading... |
42 void IncrementConfigId() { | 47 void IncrementConfigId() { |
43 config_.set_id(config_.id() + 1); | 48 config_.set_id(config_.id() + 1); |
44 observer_->OnProxyConfigChanged(config_, ProxyConfigService::CONFIG_VALID); | 49 observer_->OnProxyConfigChanged(config_, ProxyConfigService::CONFIG_VALID); |
45 } | 50 } |
46 | 51 |
47 private: | 52 private: |
48 ProxyConfig config_; | 53 ProxyConfig config_; |
49 Observer* observer_; | 54 Observer* observer_; |
50 }; | 55 }; |
51 | 56 |
| 57 // Inherit from URLRequestFtpJob to expose the priority and some |
| 58 // other hidden functions. |
| 59 class TestURLRequestFtpJob : public URLRequestFtpJob { |
| 60 public: |
| 61 explicit TestURLRequestFtpJob(URLRequest* request) |
| 62 : URLRequestFtpJob(request, NULL, |
| 63 request->context()->ftp_transaction_factory(), |
| 64 request->context()->ftp_auth_cache()) {} |
| 65 |
| 66 using URLRequestFtpJob::SetPriority; |
| 67 using URLRequestFtpJob::Start; |
| 68 using URLRequestFtpJob::Kill; |
| 69 using URLRequestFtpJob::priority; |
| 70 |
| 71 protected: |
| 72 virtual ~TestURLRequestFtpJob() {} |
| 73 }; |
| 74 |
| 75 // Fixture for priority-related tests. Priority matters when there is |
| 76 // an HTTP proxy. |
| 77 class URLRequestFtpJobPriorityTest : public testing::Test { |
| 78 protected: |
| 79 URLRequestFtpJobPriorityTest() |
| 80 : proxy_service_(new SimpleProxyConfigService, NULL, NULL), |
| 81 req_(GURL("ftp://ftp.example.com"), &delegate_, &context_, NULL) { |
| 82 context_.set_proxy_service(&proxy_service_); |
| 83 context_.set_http_transaction_factory(&network_layer_); |
| 84 } |
| 85 |
| 86 ProxyService proxy_service_; |
| 87 MockNetworkLayer network_layer_; |
| 88 TestURLRequestContext context_; |
| 89 TestDelegate delegate_; |
| 90 TestURLRequest req_; |
| 91 }; |
| 92 |
| 93 // Make sure that SetPriority actually sets the URLRequestFtpJob's |
| 94 // priority, both before and after start. |
| 95 TEST_F(URLRequestFtpJobPriorityTest, SetPriorityBasic) { |
| 96 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
| 97 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 98 |
| 99 job->SetPriority(LOWEST); |
| 100 EXPECT_EQ(LOWEST, job->priority()); |
| 101 |
| 102 job->SetPriority(LOW); |
| 103 EXPECT_EQ(LOW, job->priority()); |
| 104 |
| 105 job->Start(); |
| 106 EXPECT_EQ(LOW, job->priority()); |
| 107 |
| 108 job->SetPriority(MEDIUM); |
| 109 EXPECT_EQ(MEDIUM, job->priority()); |
| 110 } |
| 111 |
| 112 // Make sure that URLRequestFtpJob passes on its priority to its |
| 113 // transaction on start. |
| 114 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriorityOnStart) { |
| 115 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
| 116 job->SetPriority(LOW); |
| 117 |
| 118 EXPECT_FALSE(network_layer_.last_transaction()); |
| 119 |
| 120 job->Start(); |
| 121 |
| 122 ASSERT_TRUE(network_layer_.last_transaction()); |
| 123 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| 124 } |
| 125 |
| 126 // Make sure that URLRequestFtpJob passes on its priority updates to |
| 127 // its transaction. |
| 128 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriority) { |
| 129 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
| 130 job->SetPriority(LOW); |
| 131 job->Start(); |
| 132 ASSERT_TRUE(network_layer_.last_transaction()); |
| 133 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| 134 |
| 135 job->SetPriority(HIGHEST); |
| 136 EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); |
| 137 } |
| 138 |
| 139 // Make sure that URLRequestFtpJob passes on its priority updates to |
| 140 // newly-created transactions after the first one. |
| 141 TEST_F(URLRequestFtpJobPriorityTest, SetSubsequentTransactionPriority) { |
| 142 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
| 143 job->Start(); |
| 144 |
| 145 job->SetPriority(LOW); |
| 146 ASSERT_TRUE(network_layer_.last_transaction()); |
| 147 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| 148 |
| 149 job->Kill(); |
| 150 network_layer_.ClearLastTransaction(); |
| 151 |
| 152 // Creates a second transaction. |
| 153 job->Start(); |
| 154 ASSERT_TRUE(network_layer_.last_transaction()); |
| 155 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| 156 } |
| 157 |
52 class FtpTestURLRequestContext : public TestURLRequestContext { | 158 class FtpTestURLRequestContext : public TestURLRequestContext { |
53 public: | 159 public: |
54 FtpTestURLRequestContext(ClientSocketFactory* socket_factory, | 160 FtpTestURLRequestContext(ClientSocketFactory* socket_factory, |
55 ProxyService* proxy_service, | 161 ProxyService* proxy_service, |
56 NetworkDelegate* network_delegate) | 162 NetworkDelegate* network_delegate) |
57 : TestURLRequestContext(true) { | 163 : TestURLRequestContext(true) { |
58 set_client_socket_factory(socket_factory); | 164 set_client_socket_factory(socket_factory); |
59 context_storage_.set_proxy_service(proxy_service); | 165 context_storage_.set_proxy_service(proxy_service); |
60 set_network_delegate(network_delegate); | 166 set_network_delegate(network_delegate); |
61 Init(); | 167 Init(); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 EXPECT_TRUE(url_request2.status().is_success()); | 456 EXPECT_TRUE(url_request2.status().is_success()); |
351 EXPECT_EQ(2, network_delegate()->completed_requests()); | 457 EXPECT_EQ(2, network_delegate()->completed_requests()); |
352 EXPECT_EQ(0, network_delegate()->error_count()); | 458 EXPECT_EQ(0, network_delegate()->error_count()); |
353 EXPECT_FALSE(request_delegate2.auth_required_called()); | 459 EXPECT_FALSE(request_delegate2.auth_required_called()); |
354 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 460 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
355 } | 461 } |
356 | 462 |
357 } // namespace | 463 } // namespace |
358 | 464 |
359 } // namespace net | 465 } // namespace net |
OLD | NEW |