Chromium Code Reviews| 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 : req_(GURL("ftp://ftp.example.com"), &delegate_, &context_, NULL) { | |
| 81 context_.set_proxy_service( | |
| 82 new ProxyService(new SimpleProxyConfigService, NULL, NULL)); | |
| 83 context_.set_http_transaction_factory(&network_layer_); | |
| 84 } | |
| 85 | |
| 86 MockNetworkLayer network_layer_; | |
| 87 TestURLRequestContext context_; | |
| 88 TestDelegate delegate_; | |
| 89 TestURLRequest req_; | |
| 90 }; | |
| 91 | |
| 92 // Make sure that SetPriority actually sets the URLRequestFtpJob's | |
| 93 // priority, both before and after start. | |
| 94 TEST_F(URLRequestFtpJobPriorityTest, SetPriorityBasic) { | |
| 95 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); | |
| 96 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | |
| 97 | |
| 98 job->SetPriority(LOWEST); | |
|
akalin
2013/03/22 00:22:02
As discussed, adding an explicit test for LOWEST
| |
| 99 EXPECT_EQ(LOWEST, job->priority()); | |
| 100 | |
| 101 job->SetPriority(LOW); | |
| 102 EXPECT_EQ(LOW, job->priority()); | |
| 103 | |
| 104 job->Start(); | |
| 105 EXPECT_EQ(LOW, job->priority()); | |
| 106 | |
| 107 job->SetPriority(MEDIUM); | |
| 108 EXPECT_EQ(MEDIUM, job->priority()); | |
| 109 } | |
| 110 | |
| 111 // Make sure that URLRequestFtpJob passes on its priority to its | |
| 112 // transaction on start. | |
| 113 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriorityOnStart) { | |
| 114 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); | |
| 115 job->SetPriority(LOW); | |
| 116 | |
| 117 EXPECT_FALSE(network_layer_.last_transaction()); | |
| 118 | |
| 119 job->Start(); | |
| 120 | |
| 121 ASSERT_TRUE(network_layer_.last_transaction()); | |
| 122 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | |
| 123 } | |
| 124 | |
| 125 // Make sure that URLRequestFtpJob passes on its priority updates to | |
| 126 // its transaction. | |
| 127 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriority) { | |
| 128 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); | |
| 129 job->SetPriority(LOW); | |
| 130 job->Start(); | |
| 131 ASSERT_TRUE(network_layer_.last_transaction()); | |
| 132 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | |
| 133 | |
| 134 job->SetPriority(HIGHEST); | |
| 135 EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); | |
| 136 } | |
| 137 | |
| 138 // Make sure that URLRequestFtpJob passes on its priority updates to | |
| 139 // newly-created transactions after the first one. | |
| 140 TEST_F(URLRequestFtpJobPriorityTest, SetSubsequentTransactionPriority) { | |
| 141 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); | |
| 142 job->Start(); | |
| 143 | |
| 144 job->SetPriority(LOW); | |
| 145 ASSERT_TRUE(network_layer_.last_transaction()); | |
| 146 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | |
| 147 | |
| 148 job->Kill(); | |
| 149 network_layer_.ClearLastTransaction(); | |
| 150 | |
| 151 // Creates a second transaction. | |
| 152 job->Start(); | |
| 153 ASSERT_TRUE(network_layer_.last_transaction()); | |
| 154 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | |
| 155 } | |
| 156 | |
| 52 class FtpTestURLRequestContext : public TestURLRequestContext { | 157 class FtpTestURLRequestContext : public TestURLRequestContext { |
| 53 public: | 158 public: |
| 54 FtpTestURLRequestContext(ClientSocketFactory* socket_factory, | 159 FtpTestURLRequestContext(ClientSocketFactory* socket_factory, |
| 55 ProxyService* proxy_service, | 160 ProxyService* proxy_service, |
| 56 NetworkDelegate* network_delegate) | 161 NetworkDelegate* network_delegate) |
| 57 : TestURLRequestContext(true) { | 162 : TestURLRequestContext(true) { |
| 58 set_client_socket_factory(socket_factory); | 163 set_client_socket_factory(socket_factory); |
| 59 context_storage_.set_proxy_service(proxy_service); | 164 context_storage_.set_proxy_service(proxy_service); |
| 60 set_network_delegate(network_delegate); | 165 set_network_delegate(network_delegate); |
| 61 Init(); | 166 Init(); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 EXPECT_TRUE(url_request2.status().is_success()); | 455 EXPECT_TRUE(url_request2.status().is_success()); |
| 351 EXPECT_EQ(2, network_delegate()->completed_requests()); | 456 EXPECT_EQ(2, network_delegate()->completed_requests()); |
| 352 EXPECT_EQ(0, network_delegate()->error_count()); | 457 EXPECT_EQ(0, network_delegate()->error_count()); |
| 353 EXPECT_FALSE(request_delegate2.auth_required_called()); | 458 EXPECT_FALSE(request_delegate2.auth_required_called()); |
| 354 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 459 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
| 355 } | 460 } |
| 356 | 461 |
| 357 } // namespace | 462 } // namespace |
| 358 | 463 |
| 359 } // namespace net | 464 } // namespace net |
| OLD | NEW |