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