diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-22 03:25:04 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-22 03:25:04 +0000 |
commit | a1595312b958e430d54f55b7d93319d52da27d93 (patch) | |
tree | 674e609b96ab985e09c149b6e0df25a441632413 | |
parent | e99a796f5a7f1910e0da9400e5cabbc346ce1d37 (diff) | |
download | chromium_src-a1595312b958e430d54f55b7d93319d52da27d93.zip chromium_src-a1595312b958e430d54f55b7d93319d52da27d93.tar.gz chromium_src-a1595312b958e430d54f55b7d93319d52da27d93.tar.bz2 |
Fixes to socket_test_util.cc.
- Removes ref-counting from DelayedSocketData and OrderedSocketData.
- Calls CompleteRead (which reads from underlying data) only if
a Socket::Read call is "blocked" (previously returned with ERR_IO_PENDING).
- Removes unsafe pointers to the handed out sockets (the factory does not own them and cannot guarantee their lifetime).
BUG=110626
TEST=./net_unittests --gtest_filter=Spdy*:Http*:Socket*:WebSocket*:Ftp*
Review URL: http://codereview.chromium.org/9251019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118634 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/dns/dns_transaction_unittest.cc | 21 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction.h | 5 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction_unittest.cc | 4 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 66 | ||||
-rw-r--r-- | net/socket/socket_test_util.cc | 36 | ||||
-rw-r--r-- | net/socket/socket_test_util.h | 48 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_unittest.cc | 6 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream_unittest.cc | 9 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 204 | ||||
-rw-r--r-- | net/spdy/spdy_stream_unittest.cc | 4 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream_unittest.cc | 9 | ||||
-rw-r--r-- | net/websockets/websocket_job_unittest.cc | 24 |
12 files changed, 206 insertions, 230 deletions
diff --git a/net/dns/dns_transaction_unittest.cc b/net/dns/dns_transaction_unittest.cc index 3e3c2fe..14d9d8c 100644 --- a/net/dns/dns_transaction_unittest.cc +++ b/net/dns/dns_transaction_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -150,9 +150,9 @@ TEST_F(DnsTransactionTest, FirstTimeoutTest) { arraysize(kT0ResponseDatagram)) }; - scoped_refptr<DelayedSocketData> socket0_data( + scoped_ptr<DelayedSocketData> socket0_data( new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); - scoped_refptr<DelayedSocketData> socket1_data( + scoped_ptr<DelayedSocketData> socket1_data( new DelayedSocketData(0, reads0, arraysize(reads0), writes0, arraysize(writes0))); @@ -172,7 +172,6 @@ TEST_F(DnsTransactionTest, FirstTimeoutTest) { EXPECT_TRUE(socket0_data->at_write_eof()); EXPECT_TRUE(socket1_data->at_read_eof()); EXPECT_TRUE(socket1_data->at_write_eof()); - EXPECT_EQ(2u, factory().udp_client_sockets().size()); } // Test that after the first timeout we do a fresh connection, and after @@ -189,11 +188,11 @@ TEST_F(DnsTransactionTest, SecondTimeoutTest) { arraysize(kT0ResponseDatagram)) }; - scoped_refptr<DelayedSocketData> socket0_data( + scoped_ptr<DelayedSocketData> socket0_data( new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); - scoped_refptr<DelayedSocketData> socket1_data( + scoped_ptr<DelayedSocketData> socket1_data( new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); - scoped_refptr<DelayedSocketData> socket2_data( + scoped_ptr<DelayedSocketData> socket2_data( new DelayedSocketData(0, reads0, arraysize(reads0), writes0, arraysize(writes0))); @@ -216,7 +215,6 @@ TEST_F(DnsTransactionTest, SecondTimeoutTest) { EXPECT_TRUE(socket1_data->at_write_eof()); EXPECT_TRUE(socket2_data->at_read_eof()); EXPECT_TRUE(socket2_data->at_write_eof()); - EXPECT_EQ(3u, factory().udp_client_sockets().size()); } // Test that after the first timeout we do a fresh connection, and after @@ -228,11 +226,11 @@ TEST_F(DnsTransactionTest, ThirdTimeoutTest) { arraysize(kT0QueryDatagram)) }; - scoped_refptr<DelayedSocketData> socket0_data( + scoped_ptr<DelayedSocketData> socket0_data( new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); - scoped_refptr<DelayedSocketData> socket1_data( + scoped_ptr<DelayedSocketData> socket1_data( new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); - scoped_refptr<DelayedSocketData> socket2_data( + scoped_ptr<DelayedSocketData> socket2_data( new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); // Use short timeout to speed up the test. @@ -254,7 +252,6 @@ TEST_F(DnsTransactionTest, ThirdTimeoutTest) { EXPECT_TRUE(socket1_data->at_write_eof()); EXPECT_TRUE(socket2_data->at_read_eof()); EXPECT_TRUE(socket2_data->at_write_eof()); - EXPECT_EQ(3u, factory().udp_client_sockets().size()); } } // namespace diff --git a/net/ftp/ftp_network_transaction.h b/net/ftp/ftp_network_transaction.h index 3fec79d..be1cfdd 100644 --- a/net/ftp/ftp_network_transaction.h +++ b/net/ftp/ftp_network_transaction.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -49,6 +49,9 @@ class NET_EXPORT_PRIVATE FtpNetworkTransaction : public FtpTransaction { virtual uint64 GetUploadProgress() const OVERRIDE; private: + FRIEND_TEST_ALL_PREFIXES(FtpNetworkTransactionTest, + DownloadTransactionEvilPasvUnsafeHost); + enum Command { COMMAND_NONE, COMMAND_USER, diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index 08be329..8201ce0 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1062,7 +1062,7 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafeHost) { // The transaction fires the callback when we can start reading data. That // means that the data socket should be open. MockTCPClientSocket* data_socket = - mock_socket_factory_.GetMockTCPClientSocket(1); + static_cast<MockTCPClientSocket*>(transaction_.data_socket_.get()); ASSERT_TRUE(data_socket); ASSERT_TRUE(data_socket->IsConnected()); diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index f0dad75..f1db335 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -2148,12 +2148,12 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { MockRead(true, 0, 0), }; - scoped_refptr<DelayedSocketData> spdy_data( + scoped_ptr<DelayedSocketData> spdy_data( new DelayedSocketData( 1, // wait for one write to finish before reading. spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); SSLSocketDataProvider ssl(true, OK); ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; @@ -2237,10 +2237,10 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { MockRead(true, 0, 7), }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(data); + session_deps.socket_factory.AddSocketDataProvider(data.get()); SSLSocketDataProvider ssl(true, OK); ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; @@ -2331,11 +2331,11 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { MockRead(true, 0, 7), }; - scoped_refptr<OrderedSocketData> spdy_data( + scoped_ptr<OrderedSocketData> spdy_data( new OrderedSocketData( spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); SSLSocketDataProvider ssl(true, OK); ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; @@ -2406,11 +2406,11 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { MockRead(true, 0, 1), }; - scoped_refptr<OrderedSocketData> spdy_data( + scoped_ptr<OrderedSocketData> spdy_data( new OrderedSocketData( spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); SSLSocketDataProvider ssl(true, OK); ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; @@ -2475,11 +2475,11 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { MockRead(true, 0, 4), }; - scoped_refptr<OrderedSocketData> spdy_data( + scoped_ptr<OrderedSocketData> spdy_data( new OrderedSocketData( spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); SSLSocketDataProvider ssl(true, OK); ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; @@ -4732,7 +4732,7 @@ TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { MockRead(true, 0, 2), // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData( 1, // wait for one write to finish before reading. data_reads, arraysize(data_reads), @@ -4852,7 +4852,7 @@ TEST_F(HttpNetworkTransactionTest, ErrorResponseTofHttpsConnectViaSpdyProxy) { MockRead(true, 0, 3), // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData( 1, // wait for one write to finish before reading. data_reads, arraysize(data_reads), @@ -6910,12 +6910,12 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { MockRead(true, 0, 0), }; - scoped_refptr<DelayedSocketData> spdy_data( + scoped_ptr<DelayedSocketData> spdy_data( new DelayedSocketData( 1, // wait for one write to finish before reading. spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); MockConnect never_finishing_connect(false, ERR_IO_PENDING); StaticSocketDataProvider hanging_non_alternate_protocol_socket( @@ -7019,13 +7019,13 @@ TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { MockRead(true, 0, 0), }; - scoped_refptr<DelayedSocketData> spdy_data( + scoped_ptr<DelayedSocketData> spdy_data( new DelayedSocketData( 2, // wait for writes to finish before reading. spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); // Socket 4 is the successful Alternate-Protocol for transaction 3. - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. session_deps.socket_factory.AddSocketDataProvider(&hanging_socket); @@ -7264,11 +7264,11 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { MockRead(true, 0, 0, 4), // 6 }; - scoped_refptr<OrderedSocketData> spdy_data( + scoped_ptr<OrderedSocketData> spdy_data( new OrderedSocketData( spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); MockConnect never_finishing_connect(false, ERR_IO_PENDING); StaticSocketDataProvider hanging_non_alternate_protocol_socket( @@ -7365,12 +7365,12 @@ TEST_F(HttpNetworkTransactionTest, MockRead(true, 0, 0), }; - scoped_refptr<DelayedSocketData> spdy_data( + scoped_ptr<DelayedSocketData> spdy_data( new DelayedSocketData( 1, // wait for one write to finish before reading. spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); TestCompletionCallback callback; @@ -8246,12 +8246,12 @@ TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { MockRead(false, 0, 0) // Not async - return 0 immediately. }; - scoped_refptr<DelayedSocketData> spdy_data( + scoped_ptr<DelayedSocketData> spdy_data( new DelayedSocketData( 0, // don't wait in this case, immediate hangup. spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); TestCompletionCallback callback; @@ -8362,7 +8362,7 @@ TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { CreateMockRead(*data.get(), 6), MockRead(true, 0, 0, 6), }; - scoped_refptr<OrderedSocketData> data_2( + scoped_ptr<OrderedSocketData> data_2( new OrderedSocketData(data_reads_2, arraysize(data_reads_2), data_writes_2, arraysize(data_writes_2))); @@ -8643,12 +8643,12 @@ TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { MockRead(true, 0, 0), }; - scoped_refptr<DelayedSocketData> spdy_data( + scoped_ptr<DelayedSocketData> spdy_data( new DelayedSocketData( 1, // wait for one write to finish before reading. spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); SSLSocketDataProvider ssl(true, OK); ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; @@ -9114,11 +9114,11 @@ TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { MockRead(true, 0, 7), }; - scoped_refptr<OrderedSocketData> spdy_data( + scoped_ptr<OrderedSocketData> spdy_data( new OrderedSocketData( spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); TestCompletionCallback callback; HttpRequestInfo request1; @@ -9268,11 +9268,11 @@ TEST_F(HttpNetworkTransactionTest, MockRead(true, 0, 7), }; - scoped_refptr<OrderedSocketData> spdy_data( + scoped_ptr<OrderedSocketData> spdy_data( new OrderedSocketData( spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy_data); + session_deps.socket_factory.AddSocketDataProvider(spdy_data.get()); TestCompletionCallback callback; HttpRequestInfo request1; @@ -9423,11 +9423,11 @@ TEST_F(HttpNetworkTransactionTest, CloseOldSpdySessionToOpenNewOne) { MockRead(true, ERR_IO_PENDING, 4), }; - scoped_refptr<OrderedSocketData> spdy1_data( + scoped_ptr<OrderedSocketData> spdy1_data( new OrderedSocketData( spdy1_reads, arraysize(spdy1_reads), spdy1_writes, arraysize(spdy1_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy1_data); + session_deps.socket_factory.AddSocketDataProvider(spdy1_data.get()); scoped_ptr<spdy::SpdyFrame> host2_req(ConstructSpdyGet( "https://www.b.com", false, 1, LOWEST)); @@ -9442,11 +9442,11 @@ TEST_F(HttpNetworkTransactionTest, CloseOldSpdySessionToOpenNewOne) { MockRead(true, ERR_IO_PENDING, 4), }; - scoped_refptr<OrderedSocketData> spdy2_data( + scoped_ptr<OrderedSocketData> spdy2_data( new OrderedSocketData( spdy2_reads, arraysize(spdy2_reads), spdy2_writes, arraysize(spdy2_writes))); - session_deps.socket_factory.AddSocketDataProvider(spdy2_data); + session_deps.socket_factory.AddSocketDataProvider(spdy2_data.get()); MockWrite http_write[] = { MockWrite("GET / HTTP/1.1\r\n" diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc index 275a403..baca959 100644 --- a/net/socket/socket_test_util.cc +++ b/net/socket/socket_test_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -253,6 +253,7 @@ DelayedSocketData::DelayedSocketData( MockWrite* writes, size_t writes_count) : StaticSocketDataProvider(reads, reads_count, writes, writes_count), write_delay_(write_delay), + read_in_progress_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { DCHECK_GE(write_delay_, 0); } @@ -262,6 +263,7 @@ DelayedSocketData::DelayedSocketData( size_t reads_count, MockWrite* writes, size_t writes_count) : StaticSocketDataProvider(reads, reads_count, writes, writes_count), write_delay_(write_delay), + read_in_progress_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { DCHECK_GE(write_delay_, 0); set_connect_data(connect); @@ -271,20 +273,23 @@ DelayedSocketData::~DelayedSocketData() { } void DelayedSocketData::ForceNextRead() { + DCHECK(read_in_progress_); write_delay_ = 0; CompleteRead(); } MockRead DelayedSocketData::GetNextRead() { - if (write_delay_ > 0) - return MockRead(true, ERR_IO_PENDING); - return StaticSocketDataProvider::GetNextRead(); + MockRead out = MockRead(true, ERR_IO_PENDING); + if (write_delay_ <= 0) + out = StaticSocketDataProvider::GetNextRead(); + read_in_progress_ = (out.result == ERR_IO_PENDING); + return out; } MockWriteResult DelayedSocketData::OnWrite(const std::string& data) { MockWriteResult rv = StaticSocketDataProvider::OnWrite(data); // Now that our write has completed, we can allow reads to continue. - if (!--write_delay_) + if (!--write_delay_ && read_in_progress_) MessageLoop::current()->PostDelayedTask( FROM_HERE, base::Bind(&DelayedSocketData::CompleteRead, @@ -295,12 +300,13 @@ MockWriteResult DelayedSocketData::OnWrite(const std::string& data) { void DelayedSocketData::Reset() { set_socket(NULL); + read_in_progress_ = false; weak_factory_.InvalidateWeakPtrs(); StaticSocketDataProvider::Reset(); } void DelayedSocketData::CompleteRead() { - if (socket()) + if (socket() && read_in_progress_) socket()->OnReadComplete(GetNextRead()); } @@ -353,6 +359,7 @@ MockRead OrderedSocketData::GetNextRead() { NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ - 1 << ": Read " << read_index(); DumpMockRead(next_read); + blocked_ = (next_read.result == ERR_IO_PENDING); return StaticSocketDataProvider::GetNextRead(); } NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ - 1 @@ -394,7 +401,7 @@ void OrderedSocketData::Reset() { } void OrderedSocketData::CompleteRead() { - if (socket()) { + if (socket() && blocked_) { NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_; socket()->OnReadComplete(GetNextRead()); } @@ -582,18 +589,6 @@ void MockClientSocketFactory::ResetNextMockIndexes() { mock_ssl_data_.ResetNextIndex(); } -MockTCPClientSocket* MockClientSocketFactory::GetMockTCPClientSocket( - size_t index) const { - DCHECK_LT(index, tcp_client_sockets_.size()); - return tcp_client_sockets_[index]; -} - -MockSSLClientSocket* MockClientSocketFactory::GetMockSSLClientSocket( - size_t index) const { - DCHECK_LT(index, ssl_client_sockets_.size()); - return ssl_client_sockets_[index]; -} - DatagramClientSocket* MockClientSocketFactory::CreateDatagramClientSocket( DatagramSocket::BindType bind_type, const RandIntCallback& rand_int_cb, @@ -602,7 +597,6 @@ DatagramClientSocket* MockClientSocketFactory::CreateDatagramClientSocket( SocketDataProvider* data_provider = mock_data_.GetNext(); MockUDPClientSocket* socket = new MockUDPClientSocket(data_provider, net_log); data_provider->set_socket(socket); - udp_client_sockets_.push_back(socket); return socket; } @@ -614,7 +608,6 @@ StreamSocket* MockClientSocketFactory::CreateTransportClientSocket( MockTCPClientSocket* socket = new MockTCPClientSocket(addresses, net_log, data_provider); data_provider->set_socket(socket); - tcp_client_sockets_.push_back(socket); return socket; } @@ -627,7 +620,6 @@ SSLClientSocket* MockClientSocketFactory::CreateSSLClientSocket( MockSSLClientSocket* socket = new MockSSLClientSocket(transport_socket, host_and_port, ssl_config, ssl_host_info, mock_ssl_data_.GetNext()); - ssl_client_sockets_.push_back(socket); return socket; } diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h index 393053b..a9739cd 100644 --- a/net/socket/socket_test_util.h +++ b/net/socket/socket_test_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -273,16 +273,15 @@ struct SSLSocketDataProvider { // A DataProvider where the client must write a request before the reads (e.g. // the response) will complete. -class DelayedSocketData : public StaticSocketDataProvider, - public base::RefCounted<DelayedSocketData> { +class DelayedSocketData : public StaticSocketDataProvider { public: // |write_delay| the number of MockWrites to complete before allowing // a MockRead to complete. // |reads| the list of MockRead completions. // |writes| the list of MockWrite completions. // Note: All MockReads and MockWrites must be async. - // Note: The MockRead and MockWrite lists musts end with a EOF - // e.g. a MockRead(true, 0, 0); + // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a + // MockRead(true, 0, 0); DelayedSocketData(int write_delay, MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count); @@ -293,8 +292,8 @@ class DelayedSocketData : public StaticSocketDataProvider, // a MockRead to complete. // |writes| the list of MockWrite completions. // Note: All MockReads and MockWrites must be async. - // Note: The MockRead and MockWrite lists musts end with a EOF - // e.g. a MockRead(true, 0, 0); + // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a + // MockRead(true, 0, 0); DelayedSocketData(const MockConnect& connect, int write_delay, MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count); @@ -310,6 +309,7 @@ class DelayedSocketData : public StaticSocketDataProvider, private: int write_delay_; + bool read_in_progress_; base::WeakPtrFactory<DelayedSocketData> weak_factory_; }; @@ -324,23 +324,23 @@ class DelayedSocketData : public StaticSocketDataProvider, // of data before a complete message has arrived, and provides support for // testing server push when the request is issued while the response is in the // middle of being received. -class OrderedSocketData : public StaticSocketDataProvider, - public base::RefCounted<OrderedSocketData> { +class OrderedSocketData : public StaticSocketDataProvider { public: // |reads| the list of MockRead completions. // |writes| the list of MockWrite completions. // Note: All MockReads and MockWrites must be async. - // Note: The MockRead and MockWrite lists musts end with a EOF - // e.g. a MockRead(true, 0, 0); + // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a + // MockRead(true, 0, 0); OrderedSocketData(MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count); + virtual ~OrderedSocketData(); // |connect| the result for the connect phase. // |reads| the list of MockRead completions. // |writes| the list of MockWrite completions. // Note: All MockReads and MockWrites must be async. - // Note: The MockRead and MockWrite lists musts end with a EOF - // e.g. a MockRead(true, 0, 0); + // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a + // MockRead(true, 0, 0); OrderedSocketData(const MockConnect& connect, MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count); @@ -355,9 +355,6 @@ class OrderedSocketData : public StaticSocketDataProvider, virtual void CompleteRead() OVERRIDE; private: - friend class base::RefCounted<OrderedSocketData>; - virtual ~OrderedSocketData(); - int sequence_number_; int loop_stop_stage_; bool blocked_; @@ -530,23 +527,9 @@ class MockClientSocketFactory : public ClientSocketFactory { void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); void ResetNextMockIndexes(); - // Return |index|-th MockTCPClientSocket (starting from 0) that the factory - // created. - MockTCPClientSocket* GetMockTCPClientSocket(size_t index) const; - - // Return |index|-th MockSSLClientSocket (starting from 0) that the factory - // created. - MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; - SocketDataProviderArray<SocketDataProvider>& mock_data() { return mock_data_; } - std::vector<MockTCPClientSocket*>& tcp_client_sockets() { - return tcp_client_sockets_; - } - std::vector<MockUDPClientSocket*>& udp_client_sockets() { - return udp_client_sockets_; - } // ClientSocketFactory virtual DatagramClientSocket* CreateDatagramClientSocket( @@ -569,11 +552,6 @@ class MockClientSocketFactory : public ClientSocketFactory { private: SocketDataProviderArray<SocketDataProvider> mock_data_; SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; - - // Store pointers to handed out sockets in case the test wants to get them. - std::vector<MockUDPClientSocket*> udp_client_sockets_; - std::vector<MockTCPClientSocket*> tcp_client_sockets_; - std::vector<MockSSLClientSocket*> ssl_client_sockets_; }; class MockClientSocket : public SSLClientSocket { diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index 69166a3..ef7e03e 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -299,7 +299,7 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) { AddWebSocketMessage("message1"); AddWebSocketMessage("message2"); - scoped_refptr<DelayedSocketData> data_provider( + scoped_ptr<DelayedSocketData> data_provider( new DelayedSocketData(1, data_reads, arraysize(data_reads), data_writes, arraysize(data_writes))); @@ -436,7 +436,7 @@ TEST_F(SocketStreamTest, IOPending) { AddWebSocketMessage("message1"); AddWebSocketMessage("message2"); - scoped_refptr<DelayedSocketData> data_provider( + scoped_ptr<DelayedSocketData> data_provider( new DelayedSocketData(1, data_reads, arraysize(data_reads), data_writes, arraysize(data_writes))); diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc index e2c7f8e..a217a6c 100644 --- a/net/spdy/spdy_http_stream_unittest.cc +++ b/net/spdy/spdy_http_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,7 +11,7 @@ namespace net { class SpdyHttpStreamTest : public testing::Test { public: - OrderedSocketData* data() { return data_; } + OrderedSocketData* data() { return data_.get(); } protected: SpdyHttpStreamTest() {} @@ -26,7 +26,8 @@ class SpdyHttpStreamTest : public testing::Test { MockWrite* writes, size_t writes_count, HostPortPair& host_port_pair) { HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); - data_ = new OrderedSocketData(reads, reads_count, writes, writes_count); + data_.reset(new OrderedSocketData(reads, reads_count, + writes, writes_count)); session_deps_.socket_factory->AddSocketDataProvider(data_.get()); http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); @@ -45,7 +46,7 @@ class SpdyHttpStreamTest : public testing::Test { return session_->InitializeWithSocket(connection.release(), false, OK); } SpdySessionDependencies session_deps_; - scoped_refptr<OrderedSocketData> data_; + scoped_ptr<OrderedSocketData> data_; scoped_refptr<HttpNetworkSession> http_session_; scoped_refptr<SpdySession> session_; scoped_refptr<TransportSocketParams> transport_params_; diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index e214d2d..98e27cf 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -560,7 +560,7 @@ TEST_P(SpdyNetworkTransactionTest, Get) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -610,7 +610,7 @@ TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); HttpRequestInfo http_req = CreateGetRequest(); @@ -670,10 +670,10 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGets) { MockRead(true, 0, 0), // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - scoped_refptr<OrderedSocketData> data_placeholder( + scoped_ptr<OrderedSocketData> data_placeholder( new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; @@ -754,13 +754,13 @@ TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBinding) { CreateMockRead(*fbody2), MockRead(true, 0, 0), // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); MockConnect never_finishing_connect(false, ERR_IO_PENDING); - scoped_refptr<OrderedSocketData> data_placeholder( + scoped_ptr<OrderedSocketData> data_placeholder( new OrderedSocketData(NULL, 0, NULL, 0)); data_placeholder->set_connect_data(never_finishing_connect); @@ -841,13 +841,13 @@ TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { CreateMockRead(*fbody2), MockRead(true, 0, 0), // EOF }; - scoped_refptr<OrderedSocketData> preconnect_data( + scoped_ptr<OrderedSocketData> preconnect_data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); MockConnect never_finishing_connect(true, ERR_IO_PENDING); - scoped_refptr<OrderedSocketData> data_placeholder( + scoped_ptr<OrderedSocketData> data_placeholder( new OrderedSocketData(NULL, 0, NULL, 0)); data_placeholder->set_connect_data(never_finishing_connect); @@ -968,10 +968,10 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { MockRead(true, 0, 0), // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - scoped_refptr<OrderedSocketData> data_placeholder( + scoped_ptr<OrderedSocketData> data_placeholder( new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; @@ -1108,10 +1108,10 @@ TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { MockRead(true, 0, 0), // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - scoped_refptr<OrderedSocketData> data_placeholder( + scoped_ptr<OrderedSocketData> data_placeholder( new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; @@ -1245,10 +1245,10 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { MockRead(true, 0, 0), // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - scoped_refptr<OrderedSocketData> data_placeholder( + scoped_ptr<OrderedSocketData> data_placeholder( new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; @@ -1375,10 +1375,10 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentSocketClose) { MockRead(true, ERR_CONNECTION_RESET, 0), // Abort! }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - scoped_refptr<OrderedSocketData> data_placeholder( + scoped_ptr<OrderedSocketData> data_placeholder( new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; @@ -1497,7 +1497,7 @@ TEST_P(SpdyNetworkTransactionTest, Put) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(request, @@ -1568,7 +1568,7 @@ TEST_P(SpdyNetworkTransactionTest, Head) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(request, @@ -1596,7 +1596,7 @@ TEST_P(SpdyNetworkTransactionTest, Post) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(2, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreatePostRequest(), @@ -1628,7 +1628,7 @@ TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(2, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), @@ -1666,7 +1666,7 @@ TEST_P(SpdyNetworkTransactionTest, NullPost) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -1710,7 +1710,7 @@ TEST_P(SpdyNetworkTransactionTest, EmptyPost) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -1747,7 +1747,7 @@ TEST_P(SpdyNetworkTransactionTest, PostWithEarlySynReply) { MockRead(false, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(0, reads, arraysize(reads), NULL, 0)); NormalSpdyTransactionHelper helper(request, BoundNetLog(), GetParam()); @@ -1811,7 +1811,7 @@ TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), NULL, 0)); NormalSpdyTransactionHelper helper(CreateGetRequest(), BoundNetLog(), GetParam()); @@ -1835,7 +1835,7 @@ TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -1923,7 +1923,7 @@ TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(0, reads, arraysize(reads), writes, arraysize(writes))); @@ -1988,7 +1988,7 @@ TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -2085,7 +2085,7 @@ TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(0, reads, arraysize(reads), writes, arraysize(writes))); @@ -2193,7 +2193,7 @@ TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { // Force all writes to happen before any read, last write will not // actually queue a frame, due to window size being 0. - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(nwrites, reads, arraysize(reads), writes.get(), nwrites)); @@ -2343,10 +2343,10 @@ TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { MockRead(true, 0, 0, 3), // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - scoped_refptr<DelayedSocketData> data2( + scoped_ptr<DelayedSocketData> data2( new DelayedSocketData(1, reads2, arraysize(reads2), writes2, arraysize(writes2))); @@ -2392,7 +2392,7 @@ TEST_P(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { MockRead(true, 0, 0, 5), // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); @@ -2488,10 +2488,10 @@ TEST_P(SpdyNetworkTransactionTest, RedirectGetRequest) { CreateMockRead(*body2, 3), MockRead(true, 0, 0, 4) // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - scoped_refptr<OrderedSocketData> data2( + scoped_ptr<OrderedSocketData> data2( new OrderedSocketData(reads2, arraysize(reads2), writes2, arraysize(writes2))); @@ -2614,10 +2614,10 @@ TEST_P(SpdyNetworkTransactionTest, RedirectServerPush) { CreateMockRead(*body2, 3), MockRead(true, 0, 0, 5) // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - scoped_refptr<OrderedSocketData> data2( + scoped_ptr<OrderedSocketData> data2( new OrderedSocketData(reads2, arraysize(reads2), writes2, arraysize(writes2))); @@ -2701,7 +2701,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { HttpResponseInfo response; HttpResponseInfo response2; std::string expected_push_result("pushed"); - scoped_refptr<OrderedSocketData> data(new OrderedSocketData( + scoped_ptr<OrderedSocketData> data(new OrderedSocketData( reads, arraysize(reads), writes, @@ -2754,7 +2754,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { HttpResponseInfo response; HttpResponseInfo response2; std::string expected_push_result("pushed"); - scoped_refptr<OrderedSocketData> data(new OrderedSocketData( + scoped_ptr<OrderedSocketData> data(new OrderedSocketData( reads, arraysize(reads), writes, @@ -2800,7 +2800,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { MockRead(true, ERR_IO_PENDING, 6), // Force a pause }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -2882,7 +2882,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) { HttpResponseInfo response; HttpResponseInfo response2; std::string expected_push_result("pushed"); - scoped_refptr<OrderedSocketData> data(new OrderedSocketData( + scoped_ptr<OrderedSocketData> data(new OrderedSocketData( reads, arraysize(reads), writes, @@ -2945,7 +2945,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { HttpResponseInfo response; HttpResponseInfo response2; std::string expected_push_result("pushed my darling hello my baby"); - scoped_refptr<OrderedSocketData> data(new OrderedSocketData( + scoped_ptr<OrderedSocketData> data(new OrderedSocketData( reads, arraysize(reads), writes, @@ -3009,7 +3009,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { HttpResponseInfo response; HttpResponseInfo response2; std::string expected_push_result("pushed my darling hello my baby"); - scoped_refptr<OrderedSocketData> data(new OrderedSocketData( + scoped_ptr<OrderedSocketData> data(new OrderedSocketData( reads, arraysize(reads), writes, @@ -3055,7 +3055,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { MockRead(true, ERR_IO_PENDING, 5) // Force a pause }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3117,7 +3117,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { MockRead(true, ERR_IO_PENDING, 5), // Force a pause }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3175,7 +3175,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { MockRead(true, ERR_IO_PENDING, 5) // Force a pause }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3264,7 +3264,7 @@ TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3413,7 +3413,7 @@ TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { request.extra_headers.SetHeader(header_key, header_value); } - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(request, @@ -3519,7 +3519,7 @@ TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3558,7 +3558,7 @@ TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3579,7 +3579,7 @@ TEST_P(SpdyNetworkTransactionTest, WriteError) { MockWrite(true, ERR_FAILED), }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(2, NULL, 0, writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3605,7 +3605,7 @@ TEST_P(SpdyNetworkTransactionTest, PartialWrite) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(kChunks, reads, arraysize(reads), writes.get(), kChunks)); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3637,7 +3637,7 @@ TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { CreateMockRead(*resp), }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -3669,7 +3669,7 @@ TEST_P(SpdyNetworkTransactionTest, NetLog) { net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), @@ -3771,7 +3771,7 @@ TEST_P(SpdyNetworkTransactionTest, BufferFull) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -3864,7 +3864,7 @@ TEST_P(SpdyNetworkTransactionTest, Buffering) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -3960,7 +3960,7 @@ TEST_P(SpdyNetworkTransactionTest, BufferedAll) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -4049,7 +4049,7 @@ TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -4130,7 +4130,7 @@ TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -4259,7 +4259,7 @@ TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); helper.AddData(data.get()); @@ -4377,7 +4377,7 @@ TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(2, reads, arraysize(reads), writes, arraysize(writes))); helper.AddData(data.get()); @@ -4421,12 +4421,12 @@ TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { MockRead(true, 0, 0), // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), BoundNetLog(), GetParam()); - helper.AddData(data); + helper.AddData(data.get()); helper.RunToCompletion(data.get()); TransactionHelperResult out = helper.output(); EXPECT_EQ(ERR_ABORTED, out.rv); @@ -4442,7 +4442,7 @@ TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { MockRead(false, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); BoundNetLog log; @@ -4524,21 +4524,25 @@ TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { MockRead(true, 0, 0, 3), }; - scoped_refptr<OrderedSocketData> data; + scoped_ptr<OrderedSocketData> data; switch(GetParam()) { case SPDYNOSSL: - data = new OrderedSocketData(reads_SPDYNOSSL, - arraysize(reads_SPDYNOSSL), - writes_SPDYNOSSL, - arraysize(writes_SPDYNOSSL)); + data.reset(new OrderedSocketData(reads_SPDYNOSSL, + arraysize(reads_SPDYNOSSL), + writes_SPDYNOSSL, + arraysize(writes_SPDYNOSSL))); break; case SPDYSSL: - data = new OrderedSocketData(reads_SPDYSSL, arraysize(reads_SPDYSSL), - writes_SPDYSSL, arraysize(writes_SPDYSSL)); + data.reset(new OrderedSocketData(reads_SPDYSSL, + arraysize(reads_SPDYSSL), + writes_SPDYSSL, + arraysize(writes_SPDYSSL))); break; case SPDYNPN: - data = new OrderedSocketData(reads_SPDYNPN, arraysize(reads_SPDYNPN), - writes_SPDYNPN, arraysize(writes_SPDYNPN)); + data.reset(new OrderedSocketData(reads_SPDYNPN, + arraysize(reads_SPDYNPN), + writes_SPDYNPN, + arraysize(writes_SPDYNPN))); break; default: NOTREACHED(); @@ -4600,7 +4604,7 @@ TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { MockRead(true, ERR_IO_PENDING, 4), // Force a pause MockRead(true, 0, 5) // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); helper.AddData(data.get()); @@ -4678,25 +4682,25 @@ TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { MockRead(true, 0, 0, 5), }; - scoped_refptr<OrderedSocketData> data_proxy; + scoped_ptr<OrderedSocketData> data_proxy; switch(GetParam()) { case SPDYNPN: - data_proxy = new OrderedSocketData(reads_SPDYNPN, - arraysize(reads_SPDYNPN), - writes_SPDYNPN, - arraysize(writes_SPDYNPN)); + data_proxy.reset(new OrderedSocketData(reads_SPDYNPN, + arraysize(reads_SPDYNPN), + writes_SPDYNPN, + arraysize(writes_SPDYNPN))); break; case SPDYNOSSL: - data_proxy = new OrderedSocketData(reads_SPDYNOSSL, - arraysize(reads_SPDYNOSSL), - writes_SPDYNOSSL, - arraysize(writes_SPDYNOSSL)); + data_proxy.reset(new OrderedSocketData(reads_SPDYNOSSL, + arraysize(reads_SPDYNOSSL), + writes_SPDYNOSSL, + arraysize(writes_SPDYNOSSL))); break; case SPDYSSL: - data_proxy = new OrderedSocketData(reads_SPDYSSL, - arraysize(reads_SPDYSSL), - writes_SPDYSSL, - arraysize(writes_SPDYSSL)); + data_proxy.reset(new OrderedSocketData(reads_SPDYSSL, + arraysize(reads_SPDYSSL), + writes_SPDYSSL, + arraysize(writes_SPDYSSL))); break; default: NOTREACHED(); @@ -4774,11 +4778,11 @@ TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; variant <= VARIANT_RST_DURING_READ_COMPLETION; ++variant) { - scoped_refptr<DelayedSocketData> data1( + scoped_ptr<DelayedSocketData> data1( new DelayedSocketData(1, reads, arraysize(reads), NULL, 0)); - scoped_refptr<DelayedSocketData> data2( + scoped_ptr<DelayedSocketData> data2( new DelayedSocketData(1, reads2, arraysize(reads2), NULL, 0)); @@ -4841,7 +4845,7 @@ TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); @@ -4859,7 +4863,7 @@ TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { MockRead("hello from http"), MockRead(false, OK), }; - scoped_refptr<DelayedSocketData> data2( + scoped_ptr<DelayedSocketData> data2( new DelayedSocketData(1, http_reads, arraysize(http_reads), NULL, 0)); NormalSpdyTransactionHelper helper2(CreateGetRequest(), @@ -4921,7 +4925,7 @@ TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { MockRead(true, 0, 7), }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes))); HttpRequestInfo request(CreateGetRequest()); @@ -5030,7 +5034,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) { HttpResponseInfo response; HttpResponseInfo response2; std::string expected_push_result("pushed"); - scoped_refptr<OrderedSocketData> data(new OrderedSocketData( + scoped_ptr<OrderedSocketData> data(new OrderedSocketData( reads, arraysize(reads), writes, @@ -5389,7 +5393,7 @@ TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -5447,7 +5451,7 @@ TEST_P(SpdyNetworkTransactionTest, SynReplyWithLateHeaders) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -5505,7 +5509,7 @@ TEST_P(SpdyNetworkTransactionTest, SynReplyWithDuplicateLateHeaders) { MockRead(true, 0, 0) // EOF }; - scoped_refptr<DelayedSocketData> data( + scoped_ptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), @@ -5583,7 +5587,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { }; HttpResponseInfo response; - scoped_refptr<OrderedSocketData> data(new OrderedSocketData( + scoped_ptr<OrderedSocketData> data(new OrderedSocketData( reads, arraysize(reads), writes, @@ -5596,7 +5600,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { NormalSpdyTransactionHelper helper(request, BoundNetLog(), GetParam()); helper.RunPreTestSetup(); - helper.AddData(data); + helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); @@ -5609,7 +5613,7 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { // Read the response body. std::string result; - ReadResult(trans, data, &result); + ReadResult(trans, data.get(), &result); // Verify that we consumed all test data. EXPECT_TRUE(data->at_read_eof()); @@ -5647,7 +5651,7 @@ TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { MockRead(true, 0, 6) // EOF }; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index b6314ca..b745fd0 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -170,7 +170,7 @@ TEST_F(SpdyStreamTest, SendDataAfterOpen) { reads[1].sequence_number = 3; reads[2].sequence_number = 4; - scoped_refptr<OrderedSocketData> data( + scoped_ptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); MockConnect connect_data(false, OK); diff --git a/net/spdy/spdy_websocket_stream_unittest.cc b/net/spdy/spdy_websocket_stream_unittest.cc index 0acbd0d..d3830d4 100644 --- a/net/spdy/spdy_websocket_stream_unittest.cc +++ b/net/spdy/spdy_websocket_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -159,7 +159,7 @@ class SpdyWebSocketStreamEventRecorder : public SpdyWebSocketStream::Delegate { class SpdyWebSocketStreamTest : public testing::Test { public: - OrderedSocketData* data() { return data_; } + OrderedSocketData* data() { return data_.get(); } void DoSendHelloFrame(SpdyWebSocketStreamEvent* event) { websocket_stream_->SendData(kMessageFrame, kMessageFrameLength); @@ -252,7 +252,8 @@ class SpdyWebSocketStreamTest : public testing::Test { int InitSession(MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count, bool throttling) { - data_ = new OrderedSocketData(reads, reads_count, writes, writes_count); + data_.reset(new OrderedSocketData(reads, reads_count, + writes, writes_count)); session_deps_.socket_factory->AddSocketDataProvider(data_.get()); http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); SpdySessionPool* spdy_session_pool(http_session_->spdy_session_pool()); @@ -289,7 +290,7 @@ class SpdyWebSocketStreamTest : public testing::Test { spdy::SpdySettings spdy_settings_to_set_; spdy::SpdySettings spdy_settings_to_send_; SpdySessionDependencies session_deps_; - scoped_refptr<OrderedSocketData> data_; + scoped_ptr<OrderedSocketData> data_; scoped_refptr<HttpNetworkSession> http_session_; scoped_refptr<SpdySession> session_; scoped_refptr<TransportSocketParams> transport_params_; diff --git a/net/websockets/websocket_job_unittest.cc b/net/websockets/websocket_job_unittest.cc index d729f27..e6243a0 100644 --- a/net/websockets/websocket_job_unittest.cc +++ b/net/websockets/websocket_job_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -256,12 +256,12 @@ class MockURLRequestContext : public net::URLRequestContext { class MockHttpTransactionFactory : public net::HttpTransactionFactory { public: - MockHttpTransactionFactory(scoped_refptr<net::OrderedSocketData>& data) { + MockHttpTransactionFactory(net::OrderedSocketData* data) { data_ = data; net::MockConnect connect_data(false, net::OK); data_->set_connect_data(connect_data); session_deps_.reset(new net::SpdySessionDependencies); - session_deps_->socket_factory->AddSocketDataProvider(data_.get()); + session_deps_->socket_factory->AddSocketDataProvider(data_); http_session_ = net::SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); host_port_pair_.set_host("example.com"); @@ -301,7 +301,7 @@ class MockHttpTransactionFactory : public net::HttpTransactionFactory { return http_session_.get(); } private: - scoped_refptr<net::OrderedSocketData> data_; + net::OrderedSocketData* data_; scoped_ptr<net::SpdySessionDependencies> session_deps_; scoped_refptr<net::HttpNetworkSession> http_session_; scoped_refptr<net::TransportSocketParams> transport_params_; @@ -368,7 +368,7 @@ class WebSocketJobTest : public PlatformTest { if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) { if (stream_type == STREAM_SPDY_WEBSOCKET) { - http_factory_.reset(new MockHttpTransactionFactory(data_)); + http_factory_.reset(new MockHttpTransactionFactory(data_.get())); context_->set_http_transaction_factory(http_factory_.get()); } @@ -448,7 +448,7 @@ class WebSocketJobTest : public PlatformTest { scoped_refptr<WebSocketJob> websocket_; scoped_refptr<SocketStream> socket_; scoped_ptr<MockClientSocketFactory> socket_factory_; - scoped_refptr<OrderedSocketData> data_; + scoped_ptr<OrderedSocketData> data_; TestCompletionCallback sync_test_callback_; scoped_refptr<MockSSLConfigService> ssl_config_service_; scoped_ptr<net::ProxyService> proxy_service_; @@ -827,8 +827,8 @@ void WebSocketJobTest::TestConnectByWebSocket(ThrottlingOption throttling) { 4), MockRead(false, 0, 5) // EOF }; - data_ = new OrderedSocketData( - reads, arraysize(reads), writes, arraysize(writes)); + data_.reset(new OrderedSocketData( + reads, arraysize(reads), writes, arraysize(writes))); GURL url("ws://example.com/demo"); MockSocketStreamDelegate delegate; @@ -937,13 +937,13 @@ void WebSocketJobTest::TestConnectBySpdy( }; if (spdy == SPDY_ON) - data_ = new OrderedSocketData( + data_.reset(new OrderedSocketData( reads_spdy, arraysize(reads_spdy), - writes_spdy, arraysize(writes_spdy)); + writes_spdy, arraysize(writes_spdy))); else - data_ = new OrderedSocketData( + data_.reset(new OrderedSocketData( reads_websocket, arraysize(reads_websocket), - writes_websocket, arraysize(writes_websocket)); + writes_websocket, arraysize(writes_websocket))); GURL url("ws://example.com/demo"); MockSocketStreamDelegate delegate; |