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

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

Issue 23856018: Changes to HttpNetworkTransaction for WebSocket Handshake (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rename SetWebSocketHandshakeCreateHelper Created 7 years, 1 month 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
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_network_session_peer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 FakeWebSocketHandshakeStreamCreateHelper
579 : public net::WebSocketHandshakeStreamBase::CreateHelper {
580 public:
581 virtual ~FakeWebSocketHandshakeStreamCreateHelper() {}
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
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 SetWebSocketHandshakeStreamCreateHelper on a cache
6318 // transaction passes on its argument to the underlying network transaction.
6319 TEST(HttpCache, SetWebSocketHandshakeStreamCreateHelper) {
6320 MockHttpCache cache;
6321
6322 FakeWebSocketHandshakeStreamCreateHelper create_helper;
6323 scoped_ptr<net::HttpTransaction> trans;
6324 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(
6325 net::IDLE, &trans, NULL));
6326 ASSERT_TRUE(trans.get());
6327
6328 EXPECT_FALSE(cache.network_layer()->last_transaction());
6329
6330 net::HttpRequestInfo info;
6331 info.url = GURL(kSimpleGET_Transaction.url);
6332 net::TestCompletionCallback callback;
6333 EXPECT_EQ(net::ERR_IO_PENDING,
6334 trans->Start(&info, callback.callback(), net::BoundNetLog()));
6335
6336 ASSERT_TRUE(cache.network_layer()->last_transaction());
6337 EXPECT_FALSE(cache.network_layer()->last_transaction()->
6338 websocket_handshake_stream_create_helper());
6339 trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper);
6340 EXPECT_EQ(&create_helper,
6341 cache.network_layer()->last_transaction()->
6342 websocket_handshake_stream_create_helper());
6343 EXPECT_EQ(net::OK, callback.WaitForResult());
6344 }
6345
6301 // Make sure that a cache transaction passes on its priority to 6346 // Make sure that a cache transaction passes on its priority to
6302 // newly-created network transactions. 6347 // newly-created network transactions.
6303 TEST(HttpCache, SetPriorityNewTransaction) { 6348 TEST(HttpCache, SetPriorityNewTransaction) {
6304 MockHttpCache cache; 6349 MockHttpCache cache;
6305 AddMockTransaction(&kRangeGET_TransactionOK); 6350 AddMockTransaction(&kRangeGET_TransactionOK);
6306 6351
6307 std::string raw_headers("HTTP/1.1 200 OK\n" 6352 std::string raw_headers("HTTP/1.1 200 OK\n"
6308 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" 6353 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
6309 "ETag: \"foo\"\n" 6354 "ETag: \"foo\"\n"
6310 "Accept-Ranges: bytes\n" 6355 "Accept-Ranges: bytes\n"
(...skipping 26 matching lines...) Expand all
6337 trans->SetPriority(net::HIGHEST); 6382 trans->SetPriority(net::HIGHEST);
6338 // Should trigger a new network transaction and pick up the new 6383 // Should trigger a new network transaction and pick up the new
6339 // priority. 6384 // priority.
6340 ReadAndVerifyTransaction(trans.get(), transaction); 6385 ReadAndVerifyTransaction(trans.get(), transaction);
6341 6386
6342 EXPECT_EQ(net::HIGHEST, 6387 EXPECT_EQ(net::HIGHEST,
6343 cache.network_layer()->last_create_transaction_priority()); 6388 cache.network_layer()->last_create_transaction_priority());
6344 6389
6345 RemoveMockTransaction(&kRangeGET_TransactionOK); 6390 RemoveMockTransaction(&kRangeGET_TransactionOK);
6346 } 6391 }
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_network_session_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698