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/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "net/http/http_request_headers.h" | 25 #include "net/http/http_request_headers.h" |
26 #include "net/http/http_request_info.h" | 26 #include "net/http/http_request_info.h" |
27 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
28 #include "net/http/http_response_info.h" | 28 #include "net/http/http_response_info.h" |
29 #include "net/http/http_transaction.h" | 29 #include "net/http/http_transaction.h" |
30 #include "net/http/http_transaction_delegate.h" | 30 #include "net/http/http_transaction_delegate.h" |
31 #include "net/http/http_transaction_unittest.h" | 31 #include "net/http/http_transaction_unittest.h" |
32 #include "net/http/http_util.h" | 32 #include "net/http/http_util.h" |
33 #include "net/http/mock_http_cache.h" | 33 #include "net/http/mock_http_cache.h" |
34 #include "net/ssl/ssl_cert_request_info.h" | 34 #include "net/ssl/ssl_cert_request_info.h" |
| 35 #include "net/websockets/websocket_handshake_stream_base.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 | 37 |
37 using base::Time; | 38 using base::Time; |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 // Tests the load timing values of a request that goes through a | 42 // Tests the load timing values of a request that goes through a |
42 // MockNetworkTransaction. | 43 // MockNetworkTransaction. |
43 void TestLoadTimingNetworkRequest(const net::LoadTimingInfo& load_timing_info) { | 44 void TestLoadTimingNetworkRequest(const net::LoadTimingInfo& load_timing_info) { |
44 EXPECT_FALSE(load_timing_info.socket_reused); | 45 EXPECT_FALSE(load_timing_info.socket_reused); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 }; | 568 }; |
568 | 569 |
569 struct Context { | 570 struct Context { |
570 Context() : result(net::ERR_IO_PENDING) {} | 571 Context() : result(net::ERR_IO_PENDING) {} |
571 | 572 |
572 int result; | 573 int result; |
573 net::TestCompletionCallback callback; | 574 net::TestCompletionCallback callback; |
574 scoped_ptr<net::HttpTransaction> trans; | 575 scoped_ptr<net::HttpTransaction> trans; |
575 }; | 576 }; |
576 | 577 |
| 578 class FakeWebSocketHandshakeStreamFactory |
| 579 : public net::WebSocketHandshakeStreamBase::Factory { |
| 580 public: |
| 581 virtual ~FakeWebSocketHandshakeStreamFactory() {} |
| 582 virtual net::WebSocketHandshakeStreamBase* CreateBasicStream( |
| 583 net::ClientSocketHandle* connect, bool using_proxy) OVERRIDE { |
| 584 return NULL; |
| 585 } |
| 586 virtual net::WebSocketHandshakeStreamBase* CreateSpdyStream( |
| 587 const base::WeakPtr<net::SpdySession>& session, |
| 588 bool use_relative_url) OVERRIDE { |
| 589 return NULL; |
| 590 } |
| 591 }; |
| 592 |
577 } // namespace | 593 } // namespace |
578 | 594 |
579 | 595 |
580 //----------------------------------------------------------------------------- | 596 //----------------------------------------------------------------------------- |
581 // Tests. | 597 // Tests. |
582 | 598 |
583 TEST(HttpCache, CreateThenDestroy) { | 599 TEST(HttpCache, CreateThenDestroy) { |
584 MockHttpCache cache; | 600 MockHttpCache cache; |
585 | 601 |
586 scoped_ptr<net::HttpTransaction> trans; | 602 scoped_ptr<net::HttpTransaction> trans; |
(...skipping 5704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6291 if (cache.network_layer()->last_transaction()) { | 6307 if (cache.network_layer()->last_transaction()) { |
6292 EXPECT_EQ(net::LOW, | 6308 EXPECT_EQ(net::LOW, |
6293 cache.network_layer()->last_create_transaction_priority()); | 6309 cache.network_layer()->last_create_transaction_priority()); |
6294 EXPECT_EQ(net::HIGHEST, | 6310 EXPECT_EQ(net::HIGHEST, |
6295 cache.network_layer()->last_transaction()->priority()); | 6311 cache.network_layer()->last_transaction()->priority()); |
6296 } | 6312 } |
6297 | 6313 |
6298 EXPECT_EQ(net::OK, callback.WaitForResult()); | 6314 EXPECT_EQ(net::OK, callback.WaitForResult()); |
6299 } | 6315 } |
6300 | 6316 |
| 6317 // Make sure that calling SetWebSocketHandshakeStreamFactory on a cache |
| 6318 // transaction passes on its factory updates to its underlying network |
| 6319 // transaction. |
| 6320 TEST(HttpCache, SetWebSocketHandshakeStreamFactory) { |
| 6321 MockHttpCache cache; |
| 6322 |
| 6323 FakeWebSocketHandshakeStreamFactory factory; |
| 6324 scoped_ptr<net::HttpTransaction> trans; |
| 6325 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction( |
| 6326 net::IDLE, &trans, NULL)); |
| 6327 ASSERT_TRUE(trans.get()); |
| 6328 |
| 6329 EXPECT_FALSE(cache.network_layer()->last_transaction()); |
| 6330 |
| 6331 net::HttpRequestInfo info; |
| 6332 info.url = GURL(kSimpleGET_Transaction.url); |
| 6333 net::TestCompletionCallback callback; |
| 6334 EXPECT_EQ(net::ERR_IO_PENDING, |
| 6335 trans->Start(&info, callback.callback(), net::BoundNetLog())); |
| 6336 |
| 6337 ASSERT_TRUE(cache.network_layer()->last_transaction()); |
| 6338 EXPECT_FALSE(cache.network_layer()->last_transaction()-> |
| 6339 websocket_handshake_stream_factory()); |
| 6340 trans->SetWebSocketHandshakeStreamFactory(&factory); |
| 6341 EXPECT_EQ(&factory, |
| 6342 cache.network_layer()->last_transaction()-> |
| 6343 websocket_handshake_stream_factory()); |
| 6344 EXPECT_EQ(net::OK, callback.WaitForResult()); |
| 6345 } |
| 6346 |
6301 // Make sure that a cache transaction passes on its priority to | 6347 // Make sure that a cache transaction passes on its priority to |
6302 // newly-created network transactions. | 6348 // newly-created network transactions. |
6303 TEST(HttpCache, SetPriorityNewTransaction) { | 6349 TEST(HttpCache, SetPriorityNewTransaction) { |
6304 MockHttpCache cache; | 6350 MockHttpCache cache; |
6305 AddMockTransaction(&kRangeGET_TransactionOK); | 6351 AddMockTransaction(&kRangeGET_TransactionOK); |
6306 | 6352 |
6307 std::string raw_headers("HTTP/1.1 200 OK\n" | 6353 std::string raw_headers("HTTP/1.1 200 OK\n" |
6308 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 6354 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
6309 "ETag: \"foo\"\n" | 6355 "ETag: \"foo\"\n" |
6310 "Accept-Ranges: bytes\n" | 6356 "Accept-Ranges: bytes\n" |
(...skipping 26 matching lines...) Expand all Loading... |
6337 trans->SetPriority(net::HIGHEST); | 6383 trans->SetPriority(net::HIGHEST); |
6338 // Should trigger a new network transaction and pick up the new | 6384 // Should trigger a new network transaction and pick up the new |
6339 // priority. | 6385 // priority. |
6340 ReadAndVerifyTransaction(trans.get(), transaction); | 6386 ReadAndVerifyTransaction(trans.get(), transaction); |
6341 | 6387 |
6342 EXPECT_EQ(net::HIGHEST, | 6388 EXPECT_EQ(net::HIGHEST, |
6343 cache.network_layer()->last_create_transaction_priority()); | 6389 cache.network_layer()->last_create_transaction_priority()); |
6344 | 6390 |
6345 RemoveMockTransaction(&kRangeGET_TransactionOK); | 6391 RemoveMockTransaction(&kRangeGET_TransactionOK); |
6346 } | 6392 } |
OLD | NEW |