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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 1901533002: Implementation of network level throttler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated latest round of comments." . Created 4 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <limits> 11 #include <limits>
12 #include <memory> 12 #include <memory>
13 #include <set>
13 #include <string> 14 #include <string>
14 #include <utility> 15 #include <utility>
15 #include <vector> 16 #include <vector>
16 17
17 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
18 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
19 #include "base/files/file_util.h" 20 #include "base/files/file_util.h"
20 #include "base/json/json_writer.h" 21 #include "base/json/json_writer.h"
21 #include "base/logging.h" 22 #include "base/logging.h"
22 #include "base/macros.h" 23 #include "base/macros.h"
23 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
24 #include "base/memory/weak_ptr.h" 25 #include "base/memory/weak_ptr.h"
25 #include "base/run_loop.h" 26 #include "base/run_loop.h"
26 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
27 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
28 #include "base/test/test_file_util.h" 29 #include "base/test/test_file_util.h"
29 #include "base/thread_task_runner_handle.h" 30 #include "base/thread_task_runner_handle.h"
30 #include "net/base/auth.h" 31 #include "net/base/auth.h"
31 #include "net/base/chunked_upload_data_stream.h" 32 #include "net/base/chunked_upload_data_stream.h"
32 #include "net/base/completion_callback.h" 33 #include "net/base/completion_callback.h"
33 #include "net/base/elements_upload_data_stream.h" 34 #include "net/base/elements_upload_data_stream.h"
34 #include "net/base/load_timing_info.h" 35 #include "net/base/load_timing_info.h"
35 #include "net/base/load_timing_info_test_util.h" 36 #include "net/base/load_timing_info_test_util.h"
36 #include "net/base/net_errors.h" 37 #include "net/base/net_errors.h"
38 #include "net/base/network_stream_throttler.h"
37 #include "net/base/proxy_delegate.h" 39 #include "net/base/proxy_delegate.h"
38 #include "net/base/request_priority.h" 40 #include "net/base/request_priority.h"
39 #include "net/base/test_completion_callback.h" 41 #include "net/base/test_completion_callback.h"
40 #include "net/base/test_data_directory.h" 42 #include "net/base/test_data_directory.h"
41 #include "net/base/test_proxy_delegate.h" 43 #include "net/base/test_proxy_delegate.h"
42 #include "net/base/upload_bytes_element_reader.h" 44 #include "net/base/upload_bytes_element_reader.h"
43 #include "net/base/upload_file_element_reader.h" 45 #include "net/base/upload_file_element_reader.h"
44 #include "net/cert/mock_cert_verifier.h" 46 #include "net/cert/mock_cert_verifier.h"
45 #include "net/dns/host_cache.h" 47 #include "net/dns/host_cache.h"
46 #include "net/dns/mock_host_resolver.h" 48 #include "net/dns/mock_host_resolver.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 110
109 // Test using the HTTP/2 protocol, without specifying a stream 111 // Test using the HTTP/2 protocol, without specifying a stream
110 // dependency based on the RequestPriority. 112 // dependency based on the RequestPriority.
111 kTestCaseHTTP2NoPriorityDependencies, 113 kTestCaseHTTP2NoPriorityDependencies,
112 114
113 // Test using the HTTP/2 protocol, specifying a stream 115 // Test using the HTTP/2 protocol, specifying a stream
114 // dependency based on the RequestPriority. 116 // dependency based on the RequestPriority.
115 kTestCaseHTTP2PriorityDependencies 117 kTestCaseHTTP2PriorityDependencies
116 }; 118 };
117 119
120 class TestNetworkStreamThrottler : public NetworkStreamThrottler {
121 public:
122 TestNetworkStreamThrottler()
123 : throttle_new_requests_(false),
124 num_set_priority_calls_(0),
125 last_priority_set_(IDLE) {}
126
127 ~TestNetworkStreamThrottler() override {
128 EXPECT_TRUE(outstanding_throttles_.empty());
129 }
130
131 // NetworkStreamThrottler
132 std::unique_ptr<Throttle> CreateThrottle(Delegate* delegate,
133 RequestPriority priority,
134 bool ignore_limits) override {
135 std::unique_ptr<TestThrottle> test_throttle(
136 new TestThrottle(throttle_new_requests_, delegate, this));
137 outstanding_throttles_.insert(test_throttle.get());
138 return std::move(test_throttle);
139 }
140
141 void UnthrottleAllRequests() {
142 std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_);
143 for (auto& throttle : outstanding_throttles_copy) {
144 if (throttle->IsThrottled())
145 throttle->Unthrottle();
146 }
147 }
148
149 void set_throttle_new_requests(bool throttle_new_requests) {
150 throttle_new_requests_ = throttle_new_requests;
151 }
152
153 // Includes both throttled and unthrottled throttles.
154 size_t num_outstanding_requests() const {
155 return outstanding_throttles_.size();
156 }
157
158 int num_set_priority_calls() const { return num_set_priority_calls_; }
159 RequestPriority last_priority_set() const { return last_priority_set_; }
160 void set_priority_change_closure(
161 const base::Closure& priority_change_closure) {
162 priority_change_closure_ = priority_change_closure;
163 }
164
165 private:
166 class TestThrottle : public NetworkStreamThrottler::Throttle {
167 public:
168 ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); }
169
170 // Throttle
171 bool IsThrottled() const override { return throttled_; }
172 void SetPriority(RequestPriority priority) override {
173 throttler_->SetPriorityCalled(priority);
174 }
175
176 TestThrottle(bool throttled,
177 Delegate* delegate,
178 TestNetworkStreamThrottler* throttler)
179 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {}
180
181 void Unthrottle() {
182 EXPECT_TRUE(throttled_);
183
184 throttled_ = false;
185 delegate_->OnThrottleStateChanged();
186 }
187
188 bool throttled_;
189 Delegate* delegate_;
190 TestNetworkStreamThrottler* throttler_;
191 };
192
193 void OnThrottleDestroyed(TestThrottle* throttle) {
194 outstanding_throttles_.erase(throttle);
195 }
196
197 void SetPriorityCalled(RequestPriority priority) {
198 ++num_set_priority_calls_;
199 last_priority_set_ = priority;
200 if (!priority_change_closure_.is_null())
201 priority_change_closure_.Run();
202 }
203
204 // Includes both throttled and unthrottled throttles.
205 std::set<TestThrottle*> outstanding_throttles_;
206 bool throttle_new_requests_;
207 int num_set_priority_calls_;
208 RequestPriority last_priority_set_;
209 base::Closure priority_change_closure_;
210
211 DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler);
212 };
213
118 const base::string16 kBar(ASCIIToUTF16("bar")); 214 const base::string16 kBar(ASCIIToUTF16("bar"));
119 const base::string16 kBar2(ASCIIToUTF16("bar2")); 215 const base::string16 kBar2(ASCIIToUTF16("bar2"));
120 const base::string16 kBar3(ASCIIToUTF16("bar3")); 216 const base::string16 kBar3(ASCIIToUTF16("bar3"));
121 const base::string16 kBaz(ASCIIToUTF16("baz")); 217 const base::string16 kBaz(ASCIIToUTF16("baz"));
122 const base::string16 kFirst(ASCIIToUTF16("first")); 218 const base::string16 kFirst(ASCIIToUTF16("first"));
123 const base::string16 kFoo(ASCIIToUTF16("foo")); 219 const base::string16 kFoo(ASCIIToUTF16("foo"));
124 const base::string16 kFoo2(ASCIIToUTF16("foo2")); 220 const base::string16 kFoo2(ASCIIToUTF16("foo2"));
125 const base::string16 kFoo3(ASCIIToUTF16("foo3")); 221 const base::string16 kFoo3(ASCIIToUTF16("foo3"));
126 const base::string16 kFou(ASCIIToUTF16("fou")); 222 const base::string16 kFou(ASCIIToUTF16("fou"));
127 const base::string16 kSecond(ASCIIToUTF16("second")); 223 const base::string16 kSecond(ASCIIToUTF16("second"));
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 headers->SetHeader("Origin", "http://www.example.org"); 349 headers->SetHeader("Origin", "http://www.example.org");
254 headers->SetHeader("Sec-WebSocket-Version", "13"); 350 headers->SetHeader("Sec-WebSocket-Version", "13");
255 headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); 351 headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
256 } 352 }
257 353
258 std::unique_ptr<HttpNetworkSession> CreateSession( 354 std::unique_ptr<HttpNetworkSession> CreateSession(
259 SpdySessionDependencies* session_deps) { 355 SpdySessionDependencies* session_deps) {
260 return SpdySessionDependencies::SpdyCreateSession(session_deps); 356 return SpdySessionDependencies::SpdyCreateSession(session_deps);
261 } 357 }
262 358
359 // Note that the pointer written into |*throttler| will only be valid
360 // for the lifetime of the returned HttpNetworkSession.
361 std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler(
362 SpdySessionDependencies* session_deps,
363 TestNetworkStreamThrottler** throttler) {
364 std::unique_ptr<HttpNetworkSession> session(
365 SpdySessionDependencies::SpdyCreateSession(session_deps));
366
367 std::unique_ptr<TestNetworkStreamThrottler> owned_throttler(
368 new TestNetworkStreamThrottler);
369 *throttler = owned_throttler.get();
370
371 HttpNetworkSessionPeer peer(session.get());
372 peer.SetNetworkStreamThrottler(std::move(owned_throttler));
373
374 return session;
375 }
376
263 } // namespace 377 } // namespace
264 378
265 class HttpNetworkTransactionTest 379 class HttpNetworkTransactionTest
266 : public PlatformTest, 380 : public PlatformTest,
267 public ::testing::WithParamInterface<TestCase> { 381 public ::testing::WithParamInterface<TestCase> {
268 public: 382 public:
269 virtual ~HttpNetworkTransactionTest() { 383 virtual ~HttpNetworkTransactionTest() {
270 // Important to restore the per-pool limit first, since the pool limit must 384 // Important to restore the per-pool limit first, since the pool limit must
271 // always be greater than group limit, and the tests reduce both limits. 385 // always be greater than group limit, and the tests reduce both limits.
272 ClientSocketPoolManager::set_max_sockets_per_pool( 386 ClientSocketPoolManager::set_max_sockets_per_pool(
(...skipping 15661 matching lines...) Expand 10 before | Expand all | Expand 10 after
15934 HttpRequestInfo request; 16048 HttpRequestInfo request;
15935 TestCompletionCallback callback; 16049 TestCompletionCallback callback;
15936 EXPECT_EQ(ERR_IO_PENDING, 16050 EXPECT_EQ(ERR_IO_PENDING,
15937 trans.Start(&request, callback.callback(), BoundNetLog())); 16051 trans.Start(&request, callback.callback(), BoundNetLog()));
15938 16052
15939 EXPECT_THAT(trans.server_ssl_config_.alpn_protos, 16053 EXPECT_THAT(trans.server_ssl_config_.alpn_protos,
15940 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); 16054 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11));
15941 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); 16055 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty());
15942 } 16056 }
15943 16057
16058 // Confirm that transactions with throttler is created in the unthrottled
16059 // state (and stays in that state) is not blocked.
16060 TEST_P(HttpNetworkTransactionTest, ThrottlingUnthrottled) {
16061 TestNetworkStreamThrottler* throttler(nullptr);
16062 std::unique_ptr<HttpNetworkSession> session(
16063 CreateSessionWithThrottler(&session_deps_, &throttler));
16064
16065 // Send a simple request and make sure it goes through.
16066 HttpRequestInfo request;
16067 request.method = "GET";
16068 request.url = GURL("http://www.example.org/");
16069 request.load_flags = 0;
16070
16071 std::unique_ptr<HttpTransaction> trans(
16072 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16073
16074 MockWrite data_writes[] = {
16075 MockWrite("GET / HTTP/1.1\r\n"
16076 "Host: www.example.org\r\n"
16077 "Connection: keep-alive\r\n\r\n"),
16078 };
16079 MockRead data_reads[] = {
16080 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16081 MockRead(SYNCHRONOUS, OK),
16082 };
16083 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16084 arraysize(data_writes));
16085 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16086
16087 TestCompletionCallback callback;
16088 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
16089 EXPECT_EQ(ERR_IO_PENDING, rv);
16090
16091 rv = callback.WaitForResult();
16092 EXPECT_EQ(OK, rv);
16093 }
16094
16095 // Confirm requests can be blocked by a throttler, and are resumed
16096 // when the throttle is unblocked.
16097 TEST_P(HttpNetworkTransactionTest, ThrottlingBasic) {
16098 TestNetworkStreamThrottler* throttler(nullptr);
16099 std::unique_ptr<HttpNetworkSession> session(
16100 CreateSessionWithThrottler(&session_deps_, &throttler));
16101
16102 // Send a simple request and make sure it goes through.
16103 HttpRequestInfo request;
16104 request.method = "GET";
16105 request.url = GURL("http://www.example.org/");
16106 request.load_flags = 0;
16107
16108 MockWrite data_writes[] = {
16109 MockWrite("GET / HTTP/1.1\r\n"
16110 "Host: www.example.org\r\n"
16111 "Connection: keep-alive\r\n\r\n"),
16112 };
16113 MockRead data_reads[] = {
16114 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16115 MockRead(SYNCHRONOUS, OK),
16116 };
16117 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16118 arraysize(data_writes));
16119 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16120
16121 // Start a request that will be throttled at start; confirm doesn't continue.
16122 throttler->set_throttle_new_requests(true);
16123 std::unique_ptr<HttpTransaction> trans(
16124 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16125
16126 TestCompletionCallback callback;
16127 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
16128 EXPECT_EQ(ERR_IO_PENDING, rv);
16129
16130 base::MessageLoop::current()->RunUntilIdle();
16131 EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState());
16132 EXPECT_FALSE(callback.have_result());
16133
16134 // Confirm the request goes on to complete when unthrottled.
16135 throttler->UnthrottleAllRequests();
16136 base::MessageLoop::current()->RunUntilIdle();
16137 ASSERT_TRUE(callback.have_result());
16138 EXPECT_EQ(OK, callback.WaitForResult());
16139 }
16140
16141 // Destroy a request while it's throttled.
16142 TEST_P(HttpNetworkTransactionTest, ThrottlingDestruction) {
16143 TestNetworkStreamThrottler* throttler(nullptr);
16144 std::unique_ptr<HttpNetworkSession> session(
16145 CreateSessionWithThrottler(&session_deps_, &throttler));
16146
16147 // Send a simple request and make sure it goes through.
16148 HttpRequestInfo request;
16149 request.method = "GET";
16150 request.url = GURL("http://www.example.org/");
16151 request.load_flags = 0;
16152
16153 MockWrite data_writes[] = {
16154 MockWrite("GET / HTTP/1.1\r\n"
16155 "Host: www.example.org\r\n"
16156 "Connection: keep-alive\r\n\r\n"),
16157 };
16158 MockRead data_reads[] = {
16159 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16160 MockRead(SYNCHRONOUS, OK),
16161 };
16162 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16163 arraysize(data_writes));
16164 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16165
16166 // Start a request that will be throttled at start; confirm doesn't continue.
16167 throttler->set_throttle_new_requests(true);
16168 std::unique_ptr<HttpTransaction> trans(
16169 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16170
16171 TestCompletionCallback callback;
16172 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
16173 EXPECT_EQ(ERR_IO_PENDING, rv);
16174
16175 base::MessageLoop::current()->RunUntilIdle();
16176 EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState());
16177 EXPECT_FALSE(callback.have_result());
16178
16179 EXPECT_EQ(1u, throttler->num_outstanding_requests());
16180 trans.reset();
16181 EXPECT_EQ(0u, throttler->num_outstanding_requests());
16182 }
16183
16184 // Confirm the throttler receives SetPriority calls.
16185 TEST_P(HttpNetworkTransactionTest, ThrottlingPrioritySet) {
16186 TestNetworkStreamThrottler* throttler(nullptr);
16187 std::unique_ptr<HttpNetworkSession> session(
16188 CreateSessionWithThrottler(&session_deps_, &throttler));
16189
16190 // Send a simple request and make sure it goes through.
16191 HttpRequestInfo request;
16192 request.method = "GET";
16193 request.url = GURL("http://www.example.org/");
16194 request.load_flags = 0;
16195
16196 MockWrite data_writes[] = {
16197 MockWrite("GET / HTTP/1.1\r\n"
16198 "Host: www.example.org\r\n"
16199 "Connection: keep-alive\r\n\r\n"),
16200 };
16201 MockRead data_reads[] = {
16202 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16203 MockRead(SYNCHRONOUS, OK),
16204 };
16205 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16206 arraysize(data_writes));
16207 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16208
16209 std::unique_ptr<HttpTransaction> trans(
16210 new HttpNetworkTransaction(IDLE, session.get()));
16211 throttler->set_throttle_new_requests(true);
16212 // Start the transaction to associate a throttle with it.
16213 TestCompletionCallback callback;
16214 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
16215 EXPECT_EQ(ERR_IO_PENDING, rv);
16216
16217 EXPECT_EQ(0, throttler->num_set_priority_calls());
16218 trans->SetPriority(LOW);
16219 EXPECT_EQ(1, throttler->num_set_priority_calls());
16220 EXPECT_EQ(LOW, throttler->last_priority_set());
16221
16222 throttler->UnthrottleAllRequests();
16223 base::MessageLoop::current()->RunUntilIdle();
16224 ASSERT_TRUE(callback.have_result());
16225 EXPECT_EQ(OK, callback.WaitForResult());
16226 }
16227
16228 // Confirm that unthrottling from a SetPriority call by the
16229 // throttler works properly.
16230 TEST_P(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) {
16231 TestNetworkStreamThrottler* throttler(nullptr);
16232 std::unique_ptr<HttpNetworkSession> session(
16233 CreateSessionWithThrottler(&session_deps_, &throttler));
16234
16235 // Send a simple request and make sure it goes through.
16236 HttpRequestInfo request;
16237 request.method = "GET";
16238 request.url = GURL("http://www.example.org/");
16239 request.load_flags = 0;
16240
16241 MockWrite data_writes[] = {
16242 MockWrite("GET / HTTP/1.1\r\n"
16243 "Host: www.example.org\r\n"
16244 "Connection: keep-alive\r\n\r\n"),
16245 };
16246 MockRead data_reads[] = {
16247 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16248 MockRead(SYNCHRONOUS, OK),
16249 };
16250 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16251 arraysize(data_writes));
16252 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16253
16254 StaticSocketDataProvider reads1(data_reads, arraysize(data_reads),
16255 data_writes, arraysize(data_writes));
16256 session_deps_.socket_factory->AddSocketDataProvider(&reads1);
16257
16258 // Start a request that will be throttled at start; confirm doesn't continue.
16259 throttler->set_throttle_new_requests(true);
16260 std::unique_ptr<HttpTransaction> trans(
16261 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16262
16263 TestCompletionCallback callback;
16264 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
16265 EXPECT_EQ(ERR_IO_PENDING, rv);
16266
16267 base::MessageLoop::current()->RunUntilIdle();
16268 EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState());
16269 EXPECT_FALSE(callback.have_result());
16270
16271 // Create a new request, call SetPriority on it to unthrottle,
16272 // and make sure that allows the original request to complete.
16273 std::unique_ptr<HttpTransaction> trans1(
16274 new HttpNetworkTransaction(LOW, session.get()));
16275 throttler->set_priority_change_closure(
16276 base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests,
16277 base::Unretained(throttler)));
16278
16279 // Start the transaction to associate a throttle with it.
16280 TestCompletionCallback callback1;
16281 rv = trans1->Start(&request, callback1.callback(), BoundNetLog());
16282 EXPECT_EQ(ERR_IO_PENDING, rv);
16283
16284 trans1->SetPriority(IDLE);
16285
16286 base::MessageLoop::current()->RunUntilIdle();
16287 ASSERT_TRUE(callback.have_result());
16288 EXPECT_EQ(OK, callback.WaitForResult());
16289 }
16290
16291 // Transaction will be destroyed when the unique_ptr goes out of scope.
16292 void DestroyTransaction(std::unique_ptr<HttpTransaction> transaction) {}
16293
16294 // Confirm that destroying a transaction from a SetPriority call by the
16295 // throttler works properly.
16296 TEST_P(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) {
16297 TestNetworkStreamThrottler* throttler(nullptr);
16298 std::unique_ptr<HttpNetworkSession> session(
16299 CreateSessionWithThrottler(&session_deps_, &throttler));
16300
16301 // Send a simple request and make sure it goes through.
16302 HttpRequestInfo request;
16303 request.method = "GET";
16304 request.url = GURL("http://www.example.org/");
16305 request.load_flags = 0;
16306
16307 MockWrite data_writes[] = {
16308 MockWrite("GET / HTTP/1.1\r\n"
16309 "Host: www.example.org\r\n"
16310 "Connection: keep-alive\r\n\r\n"),
16311 };
16312 MockRead data_reads[] = {
16313 MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"),
16314 MockRead(SYNCHRONOUS, OK),
16315 };
16316 StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes,
16317 arraysize(data_writes));
16318 session_deps_.socket_factory->AddSocketDataProvider(&reads);
16319
16320 StaticSocketDataProvider reads1(data_reads, arraysize(data_reads),
16321 data_writes, arraysize(data_writes));
16322 session_deps_.socket_factory->AddSocketDataProvider(&reads1);
16323
16324 // Start a request that will be throttled at start; confirm doesn't continue.
16325 throttler->set_throttle_new_requests(true);
16326 std::unique_ptr<HttpTransaction> trans(
16327 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
16328
16329 TestCompletionCallback callback;
16330 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
16331 EXPECT_EQ(ERR_IO_PENDING, rv);
16332
16333 base::MessageLoop::current()->RunUntilIdle();
16334 EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState());
16335 EXPECT_FALSE(callback.have_result());
16336
16337 // Arrange fo the set priority call on the above transaction to delete
16338 // the transaction.
16339 HttpTransaction* trans_p(trans.get());
16340 throttler->set_priority_change_closure(
16341 base::Bind(&DestroyTransaction, base::Passed(&trans)));
16342
16343 // Call it and check results (partially a "doesn't crash" test).
16344 trans_p->SetPriority(IDLE);
16345 trans_p = nullptr; // No longer a valid pointer.
16346
16347 base::MessageLoop::current()->RunUntilIdle();
16348 ASSERT_FALSE(callback.have_result());
16349 }
16350
15944 #if !defined(OS_IOS) 16351 #if !defined(OS_IOS)
15945 TEST_P(HttpNetworkTransactionTest, TokenBindingSpdy) { 16352 TEST_P(HttpNetworkTransactionTest, TokenBindingSpdy) {
15946 const std::string https_url = "https://www.example.com"; 16353 const std::string https_url = "https://www.example.com";
15947 HttpRequestInfo request; 16354 HttpRequestInfo request;
15948 request.url = GURL(https_url); 16355 request.url = GURL(https_url);
15949 request.method = "GET"; 16356 request.method = "GET";
15950 16357
15951 SSLSocketDataProvider ssl(ASYNC, OK); 16358 SSLSocketDataProvider ssl(ASYNC, OK);
15952 ssl.token_binding_negotiated = true; 16359 ssl.token_binding_negotiated = true;
15953 ssl.token_binding_key_param = TB_PARAM_ECDSAP256; 16360 ssl.token_binding_key_param = TB_PARAM_ECDSAP256;
(...skipping 19 matching lines...) Expand all
15973 base::MessageLoop::current()->RunUntilIdle(); 16380 base::MessageLoop::current()->RunUntilIdle();
15974 16381
15975 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 16382 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
15976 HttpRequestHeaders headers; 16383 HttpRequestHeaders headers;
15977 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 16384 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
15978 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 16385 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
15979 } 16386 }
15980 #endif // !defined(OS_IOS) 16387 #endif // !defined(OS_IOS)
15981 16388
15982 } // namespace net 16389 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698