Chromium Code Reviews| Index: net/url_request/url_request_ftp_job_unittest.cc |
| diff --git a/net/url_request/url_request_ftp_job_unittest.cc b/net/url_request/url_request_ftp_job_unittest.cc |
| index 61dde75326d363335db7e96822a22b15e36355f0..789c236922bee7909ecb4622738f45761f3845e1 100644 |
| --- a/net/url_request/url_request_ftp_job_unittest.cc |
| +++ b/net/url_request/url_request_ftp_job_unittest.cc |
| @@ -2,12 +2,16 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_vector.h" |
| #include "base/run_loop.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "net/http/http_transaction_unittest.h" |
| #include "net/proxy/proxy_config_service.h" |
| #include "net/socket/socket_test_util.h" |
| #include "net/url_request/url_request.h" |
| #include "net/url_request/url_request_context.h" |
| +#include "net/url_request/url_request_ftp_job.h" |
| #include "net/url_request/url_request_status.h" |
| #include "net/url_request/url_request_test_util.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -49,6 +53,103 @@ class SimpleProxyConfigService : public ProxyConfigService { |
| Observer* observer_; |
| }; |
| +// Inherit from URLRequestFtpJob to expose the priority and some |
| +// other hidden functions. |
| +class TestURLRequestFtpJob : public URLRequestFtpJob { |
| + public: |
| + explicit TestURLRequestFtpJob(URLRequest* request) |
| + : URLRequestFtpJob(request, NULL, |
| + request->context()->ftp_transaction_factory(), |
| + request->context()->ftp_auth_cache()) {} |
| + |
| + RequestPriority priority() const { |
| + return priority_; |
| + } |
| + using URLRequestFtpJob::SetPriority; |
| + using URLRequestFtpJob::Start; |
| + using URLRequestFtpJob::Kill; |
| + |
| + protected: |
| + virtual ~TestURLRequestFtpJob() {} |
| +}; |
| + |
| +class URLRequestFtpJobBasicTest : public testing::Test { |
|
mmenke
2013/03/20 17:12:59
I think this test fixture name is confusing (As is
akalin
2013/03/21 01:30:33
Done.
|
| + protected: |
| + URLRequestFtpJobBasicTest() |
| + : req_(GURL("ftp://ftp.example.com"), &delegate_, &context_, NULL) { |
| + context_.set_proxy_service( |
| + new ProxyService(new SimpleProxyConfigService, NULL, NULL)); |
| + context_.set_http_transaction_factory(&network_layer_); |
| + } |
| + |
| + MockNetworkLayer network_layer_; |
| + TestURLRequestContext context_; |
| + TestDelegate delegate_; |
| + TestURLRequest req_; |
| +}; |
| + |
| +// Make sure that SetPriority actually sets the URLRequestFtpJob's |
| +// priority, both before and after start. |
| +TEST_F(URLRequestFtpJobBasicTest, SetPriorityBasic) { |
| + scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
| + EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| + |
| + job->SetPriority(LOW); |
| + EXPECT_EQ(LOW, job->priority()); |
| + |
| + job->Start(); |
| + EXPECT_EQ(LOW, job->priority()); |
| + |
| + job->SetPriority(MEDIUM); |
| + EXPECT_EQ(MEDIUM, job->priority()); |
| +} |
| + |
| +// Make sure that URLRequestFtpJob passes on its priority to its |
| +// transaction on start. |
| +TEST_F(URLRequestFtpJobBasicTest, SetTransactionPriorityOnStart) { |
| + scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
| + job->SetPriority(LOW); |
| + |
| + EXPECT_FALSE(network_layer_.last_transaction()); |
| + |
| + job->Start(); |
| + |
| + ASSERT_TRUE(network_layer_.last_transaction()); |
| + EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| +} |
| + |
| +// Make sure that URLRequestFtpJob passes on its priority updates to |
| +// its transaction. |
| +TEST_F(URLRequestFtpJobBasicTest, SetTransactionPriority) { |
| + scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
| + job->SetPriority(LOW); |
| + job->Start(); |
| + ASSERT_TRUE(network_layer_.last_transaction()); |
| + EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| + |
| + job->SetPriority(HIGHEST); |
| + EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); |
| +} |
| + |
| +// Make sure that URLRequestFtpJob passes on its priority updates to |
| +// newly-created transactions after the first one. |
| +TEST_F(URLRequestFtpJobBasicTest, SetSubsequentTransactionPriority) { |
| + scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
| + job->Start(); |
| + |
| + job->SetPriority(LOW); |
| + ASSERT_TRUE(network_layer_.last_transaction()); |
| + EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| + |
| + job->Kill(); |
| + network_layer_.ClearLastTransaction(); |
| + |
| + // Creates a second transaction. |
| + job->Start(); |
| + ASSERT_TRUE(network_layer_.last_transaction()); |
| + EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| +} |
| + |
| class FtpTestURLRequestContext : public TestURLRequestContext { |
| public: |
| FtpTestURLRequestContext(ClientSocketFactory* socket_factory, |