1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/url_request/url_request_http_job.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/run_loop.h"
15 #include "base/strings/string_split.h"
16 #include "net/base/auth.h"
17 #include "net/base/request_priority.h"
18 #include "net/base/test_data_directory.h"
19 #include "net/cookies/cookie_store_test_helpers.h"
20 #include "net/http/http_transaction_factory.h"
21 #include "net/http/http_transaction_test_util.h"
22 #include "net/socket/socket_test_util.h"
23 #include "net/test/cert_test_util.h"
24 #include "net/url_request/url_request.h"
25 #include "net/url_request/url_request_status.h"
26 #include "net/url_request/url_request_test_util.h"
27 #include "net/websockets/websocket_handshake_stream_base.h"
28 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h"
36 using ::testing::Return
;
38 // Inherit from URLRequestHttpJob to expose the priority and some
39 // other hidden functions.
40 class TestURLRequestHttpJob
: public URLRequestHttpJob
{
42 explicit TestURLRequestHttpJob(URLRequest
* request
)
43 : URLRequestHttpJob(request
, request
->context()->network_delegate(),
44 request
->context()->http_user_agent_settings()) {}
46 using URLRequestHttpJob::SetPriority
;
47 using URLRequestHttpJob::Start
;
48 using URLRequestHttpJob::Kill
;
49 using URLRequestHttpJob::priority
;
52 ~TestURLRequestHttpJob() override
{}
55 class URLRequestHttpJobTest
: public ::testing::Test
{
57 URLRequestHttpJobTest()
58 : req_(context_
.CreateRequest(GURL("http://www.example.com"),
61 context_
.set_http_transaction_factory(&network_layer_
);
64 bool TransactionAcceptsSdchEncoding() {
65 base::WeakPtr
<MockNetworkTransaction
> transaction(
66 network_layer_
.last_transaction());
67 EXPECT_TRUE(transaction
);
68 if (!transaction
) return false;
70 const HttpRequestInfo
* request_info
= transaction
->request();
71 EXPECT_TRUE(request_info
);
72 if (!request_info
) return false;
74 std::string encoding_headers
;
75 bool get_success
= request_info
->extra_headers
.GetHeader(
76 "Accept-Encoding", &encoding_headers
);
77 EXPECT_TRUE(get_success
);
78 if (!get_success
) return false;
80 // This check isn't wrapped with EXPECT* macros because different
81 // results from this function may be expected in different tests.
82 for (const std::string
& token
:
83 base::SplitString(encoding_headers
, ", ", base::KEEP_WHITESPACE
,
84 base::SPLIT_WANT_NONEMPTY
)) {
85 if (base::EqualsCaseInsensitiveASCII(token
, "sdch"))
92 context_
.SetSdchManager(scoped_ptr
<SdchManager
>(new SdchManager
).Pass());
95 MockNetworkLayer network_layer_
;
96 TestURLRequestContext context_
;
97 TestDelegate delegate_
;
98 scoped_ptr
<URLRequest
> req_
;
101 class URLRequestHttpJobWithMockSocketsTest
: public ::testing::Test
{
103 URLRequestHttpJobWithMockSocketsTest()
104 : context_(new TestURLRequestContext(true)) {
105 context_
->set_client_socket_factory(&socket_factory_
);
106 context_
->set_network_delegate(&network_delegate_
);
107 context_
->set_backoff_manager(&manager_
);
111 MockClientSocketFactory socket_factory_
;
112 TestNetworkDelegate network_delegate_
;
113 URLRequestBackoffManager manager_
;
114 scoped_ptr
<TestURLRequestContext
> context_
;
117 TEST_F(URLRequestHttpJobWithMockSocketsTest
,
118 TestContentLengthSuccessfulRequest
) {
119 MockRead reads
[] = {MockRead("HTTP/1.1 200 OK\r\n"
120 "Content-Length: 12\r\n\r\n"),
121 MockRead("Test Content")};
123 StaticSocketDataProvider
socket_data(reads
, arraysize(reads
), nullptr, 0);
124 socket_factory_
.AddSocketDataProvider(&socket_data
);
126 TestDelegate delegate
;
127 scoped_ptr
<URLRequest
> request
=
128 context_
->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY
,
133 ASSERT_TRUE(request
->is_pending());
134 base::RunLoop().Run();
136 EXPECT_TRUE(request
->status().is_success());
137 EXPECT_EQ(12, request
->received_response_content_length());
138 EXPECT_EQ(51, network_delegate_
.total_network_bytes_received());
141 TEST_F(URLRequestHttpJobWithMockSocketsTest
,
142 TestContentLengthSuccessfulHttp09Request
) {
143 MockRead reads
[] = {MockRead("Test Content"),
144 MockRead(net::SYNCHRONOUS
, net::OK
)};
146 StaticSocketDataProvider
socket_data(reads
, arraysize(reads
), nullptr, 0);
147 socket_factory_
.AddSocketDataProvider(&socket_data
);
149 TestDelegate delegate
;
150 scoped_ptr
<URLRequest
> request
=
151 context_
->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY
,
156 ASSERT_TRUE(request
->is_pending());
157 base::RunLoop().Run();
159 EXPECT_TRUE(request
->status().is_success());
160 EXPECT_EQ(12, request
->received_response_content_length());
161 EXPECT_EQ(12, network_delegate_
.total_network_bytes_received());
164 TEST_F(URLRequestHttpJobWithMockSocketsTest
, TestContentLengthAbortedRequest
) {
165 MockRead reads
[] = {MockRead("HTTP/1.1 200 OK\r\n"
166 "Content-Length: 20\r\n\r\n"),
167 MockRead("Test Content"),
168 MockRead(net::SYNCHRONOUS
, net::ERR_FAILED
)};
170 StaticSocketDataProvider
socket_data(reads
, arraysize(reads
), nullptr, 0);
171 socket_factory_
.AddSocketDataProvider(&socket_data
);
173 TestDelegate delegate
;
174 scoped_ptr
<URLRequest
> request
=
175 context_
->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY
,
180 ASSERT_TRUE(request
->is_pending());
181 base::RunLoop().Run();
183 EXPECT_EQ(URLRequestStatus::FAILED
, request
->status().status());
184 EXPECT_EQ(12, request
->received_response_content_length());
185 EXPECT_EQ(51, network_delegate_
.total_network_bytes_received());
188 TEST_F(URLRequestHttpJobWithMockSocketsTest
,
189 TestContentLengthCancelledRequest
) {
190 MockRead reads
[] = {MockRead("HTTP/1.1 200 OK\r\n"
191 "Content-Length: 20\r\n\r\n"),
192 MockRead("Test Content"),
193 MockRead(net::SYNCHRONOUS
, net::ERR_IO_PENDING
)};
195 StaticSocketDataProvider
socket_data(reads
, arraysize(reads
), nullptr, 0);
196 socket_factory_
.AddSocketDataProvider(&socket_data
);
198 TestDelegate delegate
;
199 scoped_ptr
<URLRequest
> request
=
200 context_
->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY
,
204 delegate
.set_cancel_in_received_data(true);
206 base::RunLoop().RunUntilIdle();
208 EXPECT_EQ(URLRequestStatus::CANCELED
, request
->status().status());
209 EXPECT_EQ(12, request
->received_response_content_length());
210 EXPECT_EQ(51, network_delegate_
.total_network_bytes_received());
213 TEST_F(URLRequestHttpJobWithMockSocketsTest
,
214 TestNetworkBytesRedirectedRequest
) {
215 MockRead
redirect_read(
216 "HTTP/1.1 302 Found\r\n"
217 "Location: http://www.example.com\r\n\r\n");
218 StaticSocketDataProvider
redirect_socket_data(&redirect_read
, 1, nullptr, 0);
219 socket_factory_
.AddSocketDataProvider(&redirect_socket_data
);
221 MockRead response_reads
[] = {MockRead("HTTP/1.1 200 OK\r\n"
222 "Content-Length: 12\r\n\r\n"),
223 MockRead("Test Content")};
224 StaticSocketDataProvider
response_socket_data(
225 response_reads
, arraysize(response_reads
), nullptr, 0);
226 socket_factory_
.AddSocketDataProvider(&response_socket_data
);
228 TestDelegate delegate
;
229 scoped_ptr
<URLRequest
> request
=
230 context_
->CreateRequest(GURL("http://www.redirect.com"), DEFAULT_PRIORITY
,
235 ASSERT_TRUE(request
->is_pending());
236 base::RunLoop().RunUntilIdle();
238 EXPECT_TRUE(request
->status().is_success());
239 EXPECT_EQ(12, request
->received_response_content_length());
240 EXPECT_EQ(107, network_delegate_
.total_network_bytes_received());
243 TEST_F(URLRequestHttpJobWithMockSocketsTest
,
244 TestNetworkBytesCancelledAfterHeaders
) {
245 MockRead
read("HTTP/1.1 200 OK\r\n\r\n");
246 StaticSocketDataProvider
socket_data(&read
, 1, nullptr, 0);
247 socket_factory_
.AddSocketDataProvider(&socket_data
);
249 TestDelegate delegate
;
250 scoped_ptr
<URLRequest
> request
=
251 context_
->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY
,
255 delegate
.set_cancel_in_response_started(true);
257 base::RunLoop().RunUntilIdle();
259 EXPECT_EQ(URLRequestStatus::CANCELED
, request
->status().status());
260 EXPECT_EQ(19, network_delegate_
.total_network_bytes_received());
263 TEST_F(URLRequestHttpJobWithMockSocketsTest
,
264 TestNetworkBytesCancelledImmediately
) {
265 StaticSocketDataProvider
socket_data(nullptr, 0, nullptr, 0);
266 socket_factory_
.AddSocketDataProvider(&socket_data
);
268 TestDelegate delegate
;
269 scoped_ptr
<URLRequest
> request
=
270 context_
->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY
,
276 base::RunLoop().RunUntilIdle();
278 EXPECT_EQ(URLRequestStatus::CANCELED
, request
->status().status());
279 EXPECT_EQ(0, network_delegate_
.total_network_bytes_received());
282 TEST_F(URLRequestHttpJobWithMockSocketsTest
, BackoffHeader
) {
283 MockWrite writes
[] = {MockWrite(
285 "Host: www.example.com\r\n"
286 "Connection: keep-alive\r\n"
288 "Accept-Encoding: gzip, deflate\r\n"
289 "Accept-Language: en-us,fr\r\n\r\n")};
291 MockRead reads
[] = {MockRead(
292 "HTTP/1.1 200 OK\r\n"
294 "Content-Length: 9\r\n\r\n"),
295 MockRead("test.html")};
297 net::SSLSocketDataProvider
ssl_socket_data_provider(net::ASYNC
, net::OK
);
298 ssl_socket_data_provider
.SetNextProto(kProtoHTTP11
);
299 ssl_socket_data_provider
.cert
=
300 ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der");
301 socket_factory_
.AddSSLSocketDataProvider(&ssl_socket_data_provider
);
303 StaticSocketDataProvider
socket_data(reads
, arraysize(reads
), writes
,
305 socket_factory_
.AddSocketDataProvider(&socket_data
);
307 TestDelegate delegate1
;
308 scoped_ptr
<URLRequest
> request1
=
309 context_
->CreateRequest(GURL("https://www.example.com"), DEFAULT_PRIORITY
,
313 ASSERT_TRUE(request1
->is_pending());
314 base::RunLoop().Run();
316 EXPECT_TRUE(request1
->status().is_success());
317 EXPECT_EQ("test.html", delegate1
.data_received());
318 EXPECT_EQ(1, delegate1
.received_before_network_start_count());
319 EXPECT_EQ(1, manager_
.GetNumberOfEntriesForTests());
321 // Issue another request, and backoff logic should apply.
322 TestDelegate delegate2
;
323 scoped_ptr
<URLRequest
> request2
=
324 context_
->CreateRequest(GURL("https://www.example.com"), DEFAULT_PRIORITY
,
328 ASSERT_TRUE(request2
->is_pending());
329 base::RunLoop().Run();
331 EXPECT_FALSE(request2
->status().is_success());
332 EXPECT_EQ(ERR_TEMPORARY_BACKOFF
, request2
->status().error());
333 EXPECT_EQ(0, delegate2
.received_before_network_start_count());
336 TEST_F(URLRequestHttpJobWithMockSocketsTest
, BackoffHeaderNotSecure
) {
337 MockWrite writes
[] = {MockWrite(
339 "Host: www.example.com\r\n"
340 "Connection: keep-alive\r\n"
342 "Accept-Encoding: gzip, deflate\r\n"
343 "Accept-Language: en-us,fr\r\n\r\n")};
344 MockRead reads
[] = {MockRead(
345 "HTTP/1.1 200 OK\r\n"
347 "Content-Length: 9\r\n\r\n"),
348 MockRead("test.html")};
350 StaticSocketDataProvider
socket_data(reads
, arraysize(reads
), writes
,
352 socket_factory_
.AddSocketDataProvider(&socket_data
);
354 TestDelegate delegate
;
355 scoped_ptr
<URLRequest
> request
=
356 context_
->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY
,
360 ASSERT_TRUE(request
->is_pending());
361 base::RunLoop().Run();
363 EXPECT_TRUE(request
->status().is_success());
364 EXPECT_EQ("test.html", delegate
.data_received());
365 EXPECT_EQ(1, delegate
.received_before_network_start_count());
366 // Backoff logic does not apply to plain HTTP request.
367 EXPECT_EQ(0, manager_
.GetNumberOfEntriesForTests());
370 TEST_F(URLRequestHttpJobWithMockSocketsTest
, BackoffHeaderCachedResponse
) {
371 MockWrite writes
[] = {MockWrite(
373 "Host: www.example.com\r\n"
374 "Connection: keep-alive\r\n"
376 "Accept-Encoding: gzip, deflate\r\n"
377 "Accept-Language: en-us,fr\r\n\r\n")};
378 MockRead reads
[] = {MockRead(
379 "HTTP/1.1 200 OK\r\n"
381 "Cache-Control: max-age=120\r\n"
382 "Content-Length: 9\r\n\r\n"),
383 MockRead("test.html")};
385 net::SSLSocketDataProvider
ssl_socket_data_provider(net::ASYNC
, net::OK
);
386 ssl_socket_data_provider
.SetNextProto(kProtoHTTP11
);
387 ssl_socket_data_provider
.cert
=
388 ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der");
389 socket_factory_
.AddSSLSocketDataProvider(&ssl_socket_data_provider
);
391 StaticSocketDataProvider
socket_data(reads
, arraysize(reads
), writes
,
393 socket_factory_
.AddSocketDataProvider(&socket_data
);
395 TestDelegate delegate1
;
396 scoped_ptr
<URLRequest
> request1
=
397 context_
->CreateRequest(GURL("https://www.example.com"), DEFAULT_PRIORITY
,
401 ASSERT_TRUE(request1
->is_pending());
402 base::RunLoop().Run();
404 EXPECT_TRUE(request1
->status().is_success());
405 EXPECT_EQ("test.html", delegate1
.data_received());
406 EXPECT_EQ(1, delegate1
.received_before_network_start_count());
407 EXPECT_EQ(1, manager_
.GetNumberOfEntriesForTests());
409 // Backoff logic does not apply to a second request, since it is fetched
411 TestDelegate delegate2
;
412 scoped_ptr
<URLRequest
> request2
=
413 context_
->CreateRequest(GURL("https://www.example.com"), DEFAULT_PRIORITY
,
417 ASSERT_TRUE(request2
->is_pending());
418 base::RunLoop().Run();
419 EXPECT_TRUE(request2
->was_cached());
420 EXPECT_TRUE(request2
->status().is_success());
421 EXPECT_EQ(0, delegate2
.received_before_network_start_count());
424 TEST_F(URLRequestHttpJobTest
, TestCancelWhileReadingCookies
) {
425 context_
.set_cookie_store(new DelayedCookieMonster());
427 TestDelegate delegate
;
428 scoped_ptr
<URLRequest
> request
=
429 context_
.CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY
,
435 base::RunLoop().Run();
437 DCHECK_EQ(0, delegate
.received_before_network_start_count());
438 EXPECT_EQ(URLRequestStatus::CANCELED
, request
->status().status());
441 // Make sure that SetPriority actually sets the URLRequestHttpJob's
442 // priority, both before and after start.
443 TEST_F(URLRequestHttpJobTest
, SetPriorityBasic
) {
444 scoped_refptr
<TestURLRequestHttpJob
> job(
445 new TestURLRequestHttpJob(req_
.get()));
446 EXPECT_EQ(DEFAULT_PRIORITY
, job
->priority());
448 job
->SetPriority(LOWEST
);
449 EXPECT_EQ(LOWEST
, job
->priority());
451 job
->SetPriority(LOW
);
452 EXPECT_EQ(LOW
, job
->priority());
455 EXPECT_EQ(LOW
, job
->priority());
457 job
->SetPriority(MEDIUM
);
458 EXPECT_EQ(MEDIUM
, job
->priority());
461 // Make sure that URLRequestHttpJob passes on its priority to its
462 // transaction on start.
463 TEST_F(URLRequestHttpJobTest
, SetTransactionPriorityOnStart
) {
464 scoped_refptr
<TestURLRequestHttpJob
> job(
465 new TestURLRequestHttpJob(req_
.get()));
466 job
->SetPriority(LOW
);
468 EXPECT_FALSE(network_layer_
.last_transaction());
472 ASSERT_TRUE(network_layer_
.last_transaction());
473 EXPECT_EQ(LOW
, network_layer_
.last_transaction()->priority());
476 // Make sure that URLRequestHttpJob passes on its priority updates to
478 TEST_F(URLRequestHttpJobTest
, SetTransactionPriority
) {
479 scoped_refptr
<TestURLRequestHttpJob
> job(
480 new TestURLRequestHttpJob(req_
.get()));
481 job
->SetPriority(LOW
);
483 ASSERT_TRUE(network_layer_
.last_transaction());
484 EXPECT_EQ(LOW
, network_layer_
.last_transaction()->priority());
486 job
->SetPriority(HIGHEST
);
487 EXPECT_EQ(HIGHEST
, network_layer_
.last_transaction()->priority());
490 // Confirm we do advertise SDCH encoding in the case of a GET.
491 TEST_F(URLRequestHttpJobTest
, SdchAdvertisementGet
) {
493 req_
->set_method("GET"); // Redundant with default.
494 scoped_refptr
<TestURLRequestHttpJob
> job(
495 new TestURLRequestHttpJob(req_
.get()));
497 EXPECT_TRUE(TransactionAcceptsSdchEncoding());
500 // Confirm we don't advertise SDCH encoding in the case of a POST.
501 TEST_F(URLRequestHttpJobTest
, SdchAdvertisementPost
) {
503 req_
->set_method("POST");
504 scoped_refptr
<TestURLRequestHttpJob
> job(
505 new TestURLRequestHttpJob(req_
.get()));
507 EXPECT_FALSE(TransactionAcceptsSdchEncoding());
510 // This base class just serves to set up some things before the TestURLRequest
511 // constructor is called.
512 class URLRequestHttpJobWebSocketTestBase
: public ::testing::Test
{
514 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0),
516 // A Network Delegate is required for the WebSocketHandshakeStreamBase
517 // object to be passed on to the HttpNetworkTransaction.
518 context_
.set_network_delegate(&network_delegate_
);
520 // Attempting to create real ClientSocketHandles is not going to work out so
521 // well. Set up a fake socket factory.
522 socket_factory_
.AddSocketDataProvider(&socket_data_
);
523 context_
.set_client_socket_factory(&socket_factory_
);
527 StaticSocketDataProvider socket_data_
;
528 TestNetworkDelegate network_delegate_
;
529 MockClientSocketFactory socket_factory_
;
530 TestURLRequestContext context_
;
533 class URLRequestHttpJobWebSocketTest
534 : public URLRequestHttpJobWebSocketTestBase
{
536 URLRequestHttpJobWebSocketTest()
537 : req_(context_
.CreateRequest(GURL("ws://www.example.com"),
540 // The TestNetworkDelegate expects a call to NotifyBeforeURLRequest before
541 // anything else happens.
542 GURL
url("ws://localhost/");
543 TestCompletionCallback dummy
;
544 network_delegate_
.NotifyBeforeURLRequest(
545 req_
.get(), dummy
.callback(), &url
);
548 TestDelegate delegate_
;
549 scoped_ptr
<URLRequest
> req_
;
552 class MockCreateHelper
: public WebSocketHandshakeStreamBase::CreateHelper
{
554 // GoogleMock does not appear to play nicely with move-only types like
555 // scoped_ptr, so this forwarding method acts as a workaround.
556 WebSocketHandshakeStreamBase
* CreateBasicStream(
557 scoped_ptr
<ClientSocketHandle
> connection
,
558 bool using_proxy
) override
{
559 // Discard the arguments since we don't need them anyway.
560 return CreateBasicStreamMock();
563 MOCK_METHOD0(CreateBasicStreamMock
,
564 WebSocketHandshakeStreamBase
*());
566 MOCK_METHOD2(CreateSpdyStream
,
567 WebSocketHandshakeStreamBase
*(const base::WeakPtr
<SpdySession
>&,
571 class FakeWebSocketHandshakeStream
: public WebSocketHandshakeStreamBase
{
573 FakeWebSocketHandshakeStream() : initialize_stream_was_called_(false) {}
575 bool initialize_stream_was_called() const {
576 return initialize_stream_was_called_
;
579 // Fake implementation of HttpStreamBase methods.
580 int InitializeStream(const HttpRequestInfo
* request_info
,
581 RequestPriority priority
,
582 const BoundNetLog
& net_log
,
583 const CompletionCallback
& callback
) override
{
584 initialize_stream_was_called_
= true;
585 return ERR_IO_PENDING
;
588 int SendRequest(const HttpRequestHeaders
& request_headers
,
589 HttpResponseInfo
* response
,
590 const CompletionCallback
& callback
) override
{
591 return ERR_IO_PENDING
;
594 int ReadResponseHeaders(const CompletionCallback
& callback
) override
{
595 return ERR_IO_PENDING
;
598 int ReadResponseBody(IOBuffer
* buf
,
600 const CompletionCallback
& callback
) override
{
601 return ERR_IO_PENDING
;
604 void Close(bool not_reusable
) override
{}
606 bool IsResponseBodyComplete() const override
{ return false; }
608 bool IsConnectionReused() const override
{ return false; }
609 void SetConnectionReused() override
{}
611 bool CanReuseConnection() const override
{ return false; }
613 int64
GetTotalReceivedBytes() const override
{ return 0; }
614 int64_t GetTotalSentBytes() const override
{ return 0; }
616 bool GetLoadTimingInfo(LoadTimingInfo
* load_timing_info
) const override
{
620 void GetSSLInfo(SSLInfo
* ssl_info
) override
{}
622 void GetSSLCertRequestInfo(SSLCertRequestInfo
* cert_request_info
) override
{}
624 void Drain(HttpNetworkSession
* session
) override
{}
626 void SetPriority(RequestPriority priority
) override
{}
628 UploadProgress
GetUploadProgress() const override
{
629 return UploadProgress();
632 HttpStream
* RenewStreamForAuth() override
{ return nullptr; }
634 // Fake implementation of WebSocketHandshakeStreamBase method(s)
635 scoped_ptr
<WebSocketStream
> Upgrade() override
{
636 return scoped_ptr
<WebSocketStream
>();
640 bool initialize_stream_was_called_
;
643 TEST_F(URLRequestHttpJobWebSocketTest
, RejectedWithoutCreateHelper
) {
644 scoped_refptr
<TestURLRequestHttpJob
> job(
645 new TestURLRequestHttpJob(req_
.get()));
647 base::RunLoop().RunUntilIdle();
648 EXPECT_EQ(URLRequestStatus::FAILED
, req_
->status().status());
649 EXPECT_EQ(ERR_DISALLOWED_URL_SCHEME
, req_
->status().error());
652 TEST_F(URLRequestHttpJobWebSocketTest
, CreateHelperPassedThrough
) {
653 scoped_refptr
<TestURLRequestHttpJob
> job(
654 new TestURLRequestHttpJob(req_
.get()));
655 scoped_ptr
<MockCreateHelper
> create_helper(
656 new ::testing::StrictMock
<MockCreateHelper
>());
657 FakeWebSocketHandshakeStream
* fake_handshake_stream(
658 new FakeWebSocketHandshakeStream
);
659 // Ownership of fake_handshake_stream is transferred when CreateBasicStream()
661 EXPECT_CALL(*create_helper
, CreateBasicStreamMock())
662 .WillOnce(Return(fake_handshake_stream
));
663 req_
->SetUserData(WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
664 create_helper
.release());
665 req_
->SetLoadFlags(LOAD_DISABLE_CACHE
);
667 base::RunLoop().RunUntilIdle();
668 EXPECT_EQ(URLRequestStatus::IO_PENDING
, req_
->status().status());
669 EXPECT_TRUE(fake_handshake_stream
->initialize_stream_was_called());