Index: net/socket_stream/socket_stream_unittest.cc |
diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc |
index 069f92eb9ed53bd2fa2e7168eacd48ebfe920e34..d286827874c811221e0cd41774b0c1ee2e2af5d5 100644 |
--- a/net/socket_stream/socket_stream_unittest.cc |
+++ b/net/socket_stream/socket_stream_unittest.cc |
@@ -31,8 +31,13 @@ namespace { |
struct SocketStreamEvent { |
enum EventType { |
- EVENT_START_OPEN_CONNECTION, EVENT_CONNECTED, EVENT_SENT_DATA, |
- EVENT_RECEIVED_DATA, EVENT_CLOSE, EVENT_AUTH_REQUIRED, EVENT_ERROR, |
+ EVENT_START_OPEN_CONNECTION, |
+ EVENT_CONNECTED, |
+ EVENT_SENT_DATA, |
+ EVENT_RECEIVED_DATA, |
+ EVENT_CLOSE, |
+ EVENT_AUTH_REQUIRED, |
+ EVENT_ERROR, |
}; |
SocketStreamEvent(EventType type, |
@@ -41,8 +46,12 @@ struct SocketStreamEvent { |
const std::string& str, |
AuthChallengeInfo* auth_challenge_info, |
int error) |
- : event_type(type), socket(socket_stream), number(num), data(str), |
- auth_info(auth_challenge_info), error_code(error) {} |
+ : event_type(type), |
+ socket(socket_stream), |
+ number(num), |
+ data(str), |
+ auth_info(auth_challenge_info), |
+ error_code(error) {} |
EventType event_type; |
SocketStream* socket; |
@@ -69,8 +78,7 @@ class SocketStreamEventRecorder : public SocketStream::Delegate { |
const base::Callback<void(SocketStreamEvent*)>& callback) { |
on_connected_ = callback; |
} |
- void SetOnSentData( |
- const base::Callback<void(SocketStreamEvent*)>& callback) { |
+ void SetOnSentData(const base::Callback<void(SocketStreamEvent*)>& callback) { |
on_sent_data_ = callback; |
} |
void SetOnReceivedData( |
@@ -94,40 +102,51 @@ class SocketStreamEventRecorder : public SocketStream::Delegate { |
connection_callback_ = callback; |
events_.push_back( |
SocketStreamEvent(SocketStreamEvent::EVENT_START_OPEN_CONNECTION, |
- socket, 0, std::string(), NULL, OK)); |
+ socket, |
+ 0, |
+ std::string(), |
+ NULL, |
+ OK)); |
if (!on_start_open_connection_.is_null()) |
return on_start_open_connection_.Run(&events_.back()); |
return OK; |
} |
virtual void OnConnected(SocketStream* socket, |
int num_pending_send_allowed) OVERRIDE { |
- events_.push_back( |
- SocketStreamEvent(SocketStreamEvent::EVENT_CONNECTED, |
- socket, num_pending_send_allowed, std::string(), |
- NULL, OK)); |
+ events_.push_back(SocketStreamEvent(SocketStreamEvent::EVENT_CONNECTED, |
+ socket, |
+ num_pending_send_allowed, |
+ std::string(), |
+ NULL, |
+ OK)); |
if (!on_connected_.is_null()) |
on_connected_.Run(&events_.back()); |
} |
- virtual void OnSentData(SocketStream* socket, |
- int amount_sent) OVERRIDE { |
- events_.push_back( |
- SocketStreamEvent(SocketStreamEvent::EVENT_SENT_DATA, socket, |
- amount_sent, std::string(), NULL, OK)); |
+ virtual void OnSentData(SocketStream* socket, int amount_sent) OVERRIDE { |
+ events_.push_back(SocketStreamEvent(SocketStreamEvent::EVENT_SENT_DATA, |
+ socket, |
+ amount_sent, |
+ std::string(), |
+ NULL, |
+ OK)); |
if (!on_sent_data_.is_null()) |
on_sent_data_.Run(&events_.back()); |
} |
virtual void OnReceivedData(SocketStream* socket, |
- const char* data, int len) OVERRIDE { |
- events_.push_back( |
- SocketStreamEvent(SocketStreamEvent::EVENT_RECEIVED_DATA, socket, len, |
- std::string(data, len), NULL, OK)); |
+ const char* data, |
+ int len) OVERRIDE { |
+ events_.push_back(SocketStreamEvent(SocketStreamEvent::EVENT_RECEIVED_DATA, |
+ socket, |
+ len, |
+ std::string(data, len), |
+ NULL, |
+ OK)); |
if (!on_received_data_.is_null()) |
on_received_data_.Run(&events_.back()); |
} |
virtual void OnClose(SocketStream* socket) OVERRIDE { |
- events_.push_back( |
- SocketStreamEvent(SocketStreamEvent::EVENT_CLOSE, socket, 0, |
- std::string(), NULL, OK)); |
+ events_.push_back(SocketStreamEvent( |
+ SocketStreamEvent::EVENT_CLOSE, socket, 0, std::string(), NULL, OK)); |
if (!on_close_.is_null()) |
on_close_.Run(&events_.back()); |
if (!callback_.is_null()) |
@@ -135,25 +154,25 @@ class SocketStreamEventRecorder : public SocketStream::Delegate { |
} |
virtual void OnAuthRequired(SocketStream* socket, |
AuthChallengeInfo* auth_info) OVERRIDE { |
- events_.push_back( |
- SocketStreamEvent(SocketStreamEvent::EVENT_AUTH_REQUIRED, socket, 0, |
- std::string(), auth_info, OK)); |
+ events_.push_back(SocketStreamEvent(SocketStreamEvent::EVENT_AUTH_REQUIRED, |
+ socket, |
+ 0, |
+ std::string(), |
+ auth_info, |
+ OK)); |
if (!on_auth_required_.is_null()) |
on_auth_required_.Run(&events_.back()); |
} |
virtual void OnError(const SocketStream* socket, int error) OVERRIDE { |
- events_.push_back( |
- SocketStreamEvent(SocketStreamEvent::EVENT_ERROR, NULL, 0, |
- std::string(), NULL, error)); |
+ events_.push_back(SocketStreamEvent( |
+ SocketStreamEvent::EVENT_ERROR, NULL, 0, std::string(), NULL, error)); |
if (!on_error_.is_null()) |
on_error_.Run(&events_.back()); |
if (!callback_.is_null()) |
callback_.Run(error); |
} |
- void DoClose(SocketStreamEvent* event) { |
- event->socket->Close(); |
- } |
+ void DoClose(SocketStreamEvent* event) { event->socket->Close(); } |
void DoRestartWithAuth(SocketStreamEvent* event) { |
VLOG(1) << "RestartWithAuth username=" << credentials_.username() |
<< " password=" << credentials_.password(); |
@@ -164,9 +183,7 @@ class SocketStreamEventRecorder : public SocketStream::Delegate { |
} |
// Wakes up the SocketStream waiting for completion of OnStartOpenConnection() |
// of its delegate. |
- void CompleteConnection(int result) { |
- connection_callback_.Run(result); |
- } |
+ void CompleteConnection(int result) { connection_callback_.Run(result); } |
const std::vector<SocketStreamEvent>& GetSeenEvents() const { |
return events_; |
@@ -214,15 +231,16 @@ class SelfDeletingDelegate : public SocketStream::Delegate { |
EXPECT_EQ(socket_stream_->delegate(), this); |
} |
- virtual void OnConnected(SocketStream* socket, int max_pending_send_allowed) |
- OVERRIDE { |
+ virtual void OnConnected(SocketStream* socket, |
+ int max_pending_send_allowed) OVERRIDE { |
ADD_FAILURE() << "OnConnected() should not be called"; |
} |
virtual void OnSentData(SocketStream* socket, int amount_sent) OVERRIDE { |
ADD_FAILURE() << "OnSentData() should not be called"; |
} |
- virtual void OnReceivedData(SocketStream* socket, const char* data, int len) |
- OVERRIDE { |
+ virtual void OnReceivedData(SocketStream* socket, |
+ const char* data, |
+ int len) OVERRIDE { |
ADD_FAILURE() << "OnReceivedData() should not be called"; |
} |
virtual void OnClose(SocketStream* socket) OVERRIDE { |
@@ -248,8 +266,7 @@ class TestURLRequestContextWithProxy : public TestURLRequestContext { |
class TestSocketStreamNetworkDelegate : public TestNetworkDelegate { |
public: |
- TestSocketStreamNetworkDelegate() |
- : before_connect_result_(OK) {} |
+ TestSocketStreamNetworkDelegate() : before_connect_result_(OK) {} |
virtual ~TestSocketStreamNetworkDelegate() {} |
virtual int OnBeforeSocketStreamConnect( |
@@ -258,9 +275,7 @@ class TestSocketStreamNetworkDelegate : public TestNetworkDelegate { |
return before_connect_result_; |
} |
- void SetBeforeConnectResult(int result) { |
- before_connect_result_ = result; |
- } |
+ void SetBeforeConnectResult(int result) { before_connect_result_ = result; } |
private: |
int before_connect_result_; |
@@ -276,12 +291,10 @@ class SocketStreamTest : public PlatformTest { |
handshake_request_ = kWebSocketHandshakeRequest; |
handshake_response_ = kWebSocketHandshakeResponse; |
} |
- virtual void TearDown() { |
- mock_socket_factory_.reset(); |
- } |
+ virtual void TearDown() { mock_socket_factory_.reset(); } |
- virtual void SetWebSocketHandshakeMessage( |
- const char* request, const char* response) { |
+ virtual void SetWebSocketHandshakeMessage(const char* request, |
+ const char* response) { |
handshake_request_ = request; |
handshake_response_ = response; |
} |
@@ -298,8 +311,8 @@ class SocketStreamTest : public PlatformTest { |
// SocketStream::Delegate methods from the SocketStream. |
virtual void DoSendWebSocketHandshake(SocketStreamEvent* event) { |
- event->socket->SendData( |
- handshake_request_.data(), handshake_request_.size()); |
+ event->socket->SendData(handshake_request_.data(), |
+ handshake_request_.size()); |
} |
virtual void DoCloseFlushPendingWriteTest(SocketStreamEvent* event) { |
@@ -394,34 +407,31 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) { |
delegate->SetOnConnected(base::Bind( |
&SocketStreamTest::DoSendWebSocketHandshake, base::Unretained(this))); |
delegate->SetOnReceivedData(base::Bind( |
- &SocketStreamTest::DoCloseFlushPendingWriteTest, |
- base::Unretained(this))); |
+ &SocketStreamTest::DoCloseFlushPendingWriteTest, base::Unretained(this))); |
TestURLRequestContext context; |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
MockWrite data_writes[] = { |
- MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), |
- MockWrite(ASYNC, "\0message1\xff", 10), |
- MockWrite(ASYNC, "\0message2\xff", 10) |
- }; |
+ MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), |
+ MockWrite(ASYNC, "\0message1\xff", 10), |
+ MockWrite(ASYNC, "\0message2\xff", 10)}; |
MockRead data_reads[] = { |
- MockRead(SocketStreamTest::kWebSocketHandshakeResponse), |
- // Server doesn't close the connection after handshake. |
- MockRead(ASYNC, ERR_IO_PENDING) |
- }; |
+ MockRead(SocketStreamTest::kWebSocketHandshakeResponse), |
+ // Server doesn't close the connection after handshake. |
+ MockRead(ASYNC, ERR_IO_PENDING)}; |
AddWebSocketMessage("message1"); |
AddWebSocketMessage("message2"); |
- DelayedSocketData data_provider( |
- 1, data_reads, arraysize(data_reads), |
- data_writes, arraysize(data_writes)); |
+ DelayedSocketData data_provider(1, |
+ data_reads, |
+ arraysize(data_reads), |
+ data_writes, |
+ arraysize(data_writes)); |
- MockClientSocketFactory* mock_socket_factory = |
- GetMockClientSocketFactory(); |
+ MockClientSocketFactory* mock_socket_factory = GetMockClientSocketFactory(); |
mock_socket_factory->AddSocketDataProvider(&data_provider); |
socket_stream->SetClientSocketFactory(mock_socket_factory); |
@@ -454,19 +464,16 @@ TEST_F(SocketStreamTest, ResolveFailure) { |
// Make resolver fail. |
TestURLRequestContext context; |
- scoped_ptr<MockHostResolver> mock_host_resolver( |
- new MockHostResolver()); |
+ scoped_ptr<MockHostResolver> mock_host_resolver(new MockHostResolver()); |
mock_host_resolver->rules()->AddSimulatedFailure("example.com"); |
context.set_host_resolver(mock_host_resolver.get()); |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
// No read/write on socket is expected. |
StaticSocketDataProvider data_provider(NULL, 0, NULL, 0); |
- MockClientSocketFactory* mock_socket_factory = |
- GetMockClientSocketFactory(); |
+ MockClientSocketFactory* mock_socket_factory = GetMockClientSocketFactory(); |
mock_socket_factory->AddSocketDataProvider(&data_provider); |
socket_stream->SetClientSocketFactory(mock_socket_factory); |
@@ -491,14 +498,12 @@ TEST_F(SocketStreamTest, ExceedMaxPendingSendAllowed) { |
TestURLRequestContext context; |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
DelayedSocketData data_provider(1, NULL, 0, NULL, 0); |
- MockClientSocketFactory* mock_socket_factory = |
- GetMockClientSocketFactory(); |
+ MockClientSocketFactory* mock_socket_factory = GetMockClientSocketFactory(); |
mock_socket_factory->AddSocketDataProvider(&data_provider); |
socket_stream->SetClientSocketFactory(mock_socket_factory); |
@@ -520,36 +525,41 @@ TEST_F(SocketStreamTest, ExceedMaxPendingSendAllowed) { |
TEST_F(SocketStreamTest, BasicAuthProxy) { |
MockClientSocketFactory mock_socket_factory; |
MockWrite data_writes1[] = { |
- MockWrite("CONNECT example.com:80 HTTP/1.1\r\n" |
- "Host: example.com\r\n" |
- "Proxy-Connection: keep-alive\r\n\r\n"), |
+ MockWrite( |
+ "CONNECT example.com:80 HTTP/1.1\r\n" |
+ "Host: example.com\r\n" |
+ "Proxy-Connection: keep-alive\r\n\r\n"), |
}; |
MockRead data_reads1[] = { |
- MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
- MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
- MockRead("\r\n"), |
+ MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
+ MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
+ MockRead("\r\n"), |
}; |
- StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
- data_writes1, arraysize(data_writes1)); |
+ StaticSocketDataProvider data1(data_reads1, |
+ arraysize(data_reads1), |
+ data_writes1, |
+ arraysize(data_writes1)); |
mock_socket_factory.AddSocketDataProvider(&data1); |
MockWrite data_writes2[] = { |
- MockWrite("CONNECT example.com:80 HTTP/1.1\r\n" |
- "Host: example.com\r\n" |
- "Proxy-Connection: keep-alive\r\n" |
- "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
+ MockWrite( |
+ "CONNECT example.com:80 HTTP/1.1\r\n" |
+ "Host: example.com\r\n" |
+ "Proxy-Connection: keep-alive\r\n" |
+ "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
}; |
MockRead data_reads2[] = { |
- MockRead("HTTP/1.1 200 Connection Established\r\n"), |
- MockRead("Proxy-agent: Apache/2.2.8\r\n"), |
- MockRead("\r\n"), |
- // SocketStream::DoClose is run asynchronously. Socket can be read after |
- // "\r\n". We have to give ERR_IO_PENDING to SocketStream then to indicate |
- // server doesn't close the connection. |
- MockRead(ASYNC, ERR_IO_PENDING) |
- }; |
- StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
- data_writes2, arraysize(data_writes2)); |
+ MockRead("HTTP/1.1 200 Connection Established\r\n"), |
+ MockRead("Proxy-agent: Apache/2.2.8\r\n"), MockRead("\r\n"), |
+ // SocketStream::DoClose is run asynchronously. Socket can be read after |
+ // "\r\n". We have to give ERR_IO_PENDING to SocketStream then to |
+ // indicate |
+ // server doesn't close the connection. |
+ MockRead(ASYNC, ERR_IO_PENDING)}; |
+ StaticSocketDataProvider data2(data_reads2, |
+ arraysize(data_reads2), |
+ data_writes2, |
+ arraysize(data_writes2)); |
mock_socket_factory.AddSocketDataProvider(&data2); |
TestCompletionCallback test_callback; |
@@ -558,17 +568,16 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { |
new SocketStreamEventRecorder(test_callback.callback())); |
delegate->SetOnConnected(base::Bind(&SocketStreamEventRecorder::DoClose, |
base::Unretained(delegate.get()))); |
- delegate->SetAuthInfo(AuthCredentials(ASCIIToUTF16("foo"), |
- ASCIIToUTF16("bar"))); |
- delegate->SetOnAuthRequired(base::Bind( |
- &SocketStreamEventRecorder::DoRestartWithAuth, |
- base::Unretained(delegate.get()))); |
+ delegate->SetAuthInfo( |
+ AuthCredentials(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"))); |
+ delegate->SetOnAuthRequired( |
+ base::Bind(&SocketStreamEventRecorder::DoRestartWithAuth, |
+ base::Unretained(delegate.get()))); |
TestURLRequestContextWithProxy context("myproxy:70"); |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
socket_stream->SetClientSocketFactory(&mock_socket_factory); |
@@ -593,21 +602,20 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { |
TEST_F(SocketStreamTest, BasicAuthProxyWithAuthCache) { |
MockClientSocketFactory mock_socket_factory; |
MockWrite data_writes[] = { |
- // WebSocket(SocketStream) always uses CONNECT when it is configured to use |
- // proxy so the port may not be 443. |
- MockWrite("CONNECT example.com:80 HTTP/1.1\r\n" |
- "Host: example.com\r\n" |
- "Proxy-Connection: keep-alive\r\n" |
- "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
- }; |
- MockRead data_reads[] = { |
- MockRead("HTTP/1.1 200 Connection Established\r\n"), |
- MockRead("Proxy-agent: Apache/2.2.8\r\n"), |
- MockRead("\r\n"), |
- MockRead(ASYNC, ERR_IO_PENDING) |
+ // WebSocket(SocketStream) always uses CONNECT when it is configured to |
+ // use |
+ // proxy so the port may not be 443. |
+ MockWrite( |
+ "CONNECT example.com:80 HTTP/1.1\r\n" |
+ "Host: example.com\r\n" |
+ "Proxy-Connection: keep-alive\r\n" |
+ "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
}; |
- StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
- data_writes, arraysize(data_writes)); |
+ MockRead data_reads[] = {MockRead("HTTP/1.1 200 Connection Established\r\n"), |
+ MockRead("Proxy-agent: Apache/2.2.8\r\n"), |
+ MockRead("\r\n"), MockRead(ASYNC, ERR_IO_PENDING)}; |
+ StaticSocketDataProvider data( |
+ data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
mock_socket_factory.AddSocketDataProvider(&data); |
TestCompletionCallback test_callback; |
@@ -623,13 +631,11 @@ TEST_F(SocketStreamTest, BasicAuthProxyWithAuthCache) { |
"MyRealm1", |
HttpAuth::AUTH_SCHEME_BASIC, |
"Basic realm=MyRealm1", |
- AuthCredentials(ASCIIToUTF16("foo"), |
- ASCIIToUTF16("bar")), |
+ AuthCredentials(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")), |
"/"); |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
socket_stream->SetClientSocketFactory(&mock_socket_factory); |
@@ -649,19 +655,19 @@ TEST_F(SocketStreamTest, BasicAuthProxyWithAuthCache) { |
TEST_F(SocketStreamTest, WSSBasicAuthProxyWithAuthCache) { |
MockClientSocketFactory mock_socket_factory; |
MockWrite data_writes1[] = { |
- MockWrite("CONNECT example.com:443 HTTP/1.1\r\n" |
- "Host: example.com\r\n" |
- "Proxy-Connection: keep-alive\r\n" |
- "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
+ MockWrite( |
+ "CONNECT example.com:443 HTTP/1.1\r\n" |
+ "Host: example.com\r\n" |
+ "Proxy-Connection: keep-alive\r\n" |
+ "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
}; |
- MockRead data_reads1[] = { |
- MockRead("HTTP/1.1 200 Connection Established\r\n"), |
- MockRead("Proxy-agent: Apache/2.2.8\r\n"), |
- MockRead("\r\n"), |
- MockRead(ASYNC, ERR_IO_PENDING) |
- }; |
- StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
- data_writes1, arraysize(data_writes1)); |
+ MockRead data_reads1[] = {MockRead("HTTP/1.1 200 Connection Established\r\n"), |
+ MockRead("Proxy-agent: Apache/2.2.8\r\n"), |
+ MockRead("\r\n"), MockRead(ASYNC, ERR_IO_PENDING)}; |
+ StaticSocketDataProvider data1(data_reads1, |
+ arraysize(data_reads1), |
+ data_writes1, |
+ arraysize(data_writes1)); |
mock_socket_factory.AddSocketDataProvider(&data1); |
SSLSocketDataProvider data2(ASYNC, OK); |
@@ -680,13 +686,11 @@ TEST_F(SocketStreamTest, WSSBasicAuthProxyWithAuthCache) { |
"MyRealm1", |
HttpAuth::AUTH_SCHEME_BASIC, |
"Basic realm=MyRealm1", |
- AuthCredentials(ASCIIToUTF16("foo"), |
- ASCIIToUTF16("bar")), |
+ AuthCredentials(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")), |
"/"); |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("wss://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("wss://example.com/demo"), delegate.get(), &context, NULL)); |
socket_stream->SetClientSocketFactory(&mock_socket_factory); |
@@ -708,39 +712,36 @@ TEST_F(SocketStreamTest, IOPending) { |
scoped_ptr<SocketStreamEventRecorder> delegate( |
new SocketStreamEventRecorder(test_callback.callback())); |
- delegate->SetOnStartOpenConnection(base::Bind( |
- &SocketStreamTest::DoIOPending, base::Unretained(this))); |
+ delegate->SetOnStartOpenConnection( |
+ base::Bind(&SocketStreamTest::DoIOPending, base::Unretained(this))); |
delegate->SetOnConnected(base::Bind( |
&SocketStreamTest::DoSendWebSocketHandshake, base::Unretained(this))); |
delegate->SetOnReceivedData(base::Bind( |
- &SocketStreamTest::DoCloseFlushPendingWriteTest, |
- base::Unretained(this))); |
+ &SocketStreamTest::DoCloseFlushPendingWriteTest, base::Unretained(this))); |
TestURLRequestContext context; |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
MockWrite data_writes[] = { |
- MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), |
- MockWrite(ASYNC, "\0message1\xff", 10), |
- MockWrite(ASYNC, "\0message2\xff", 10) |
- }; |
+ MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), |
+ MockWrite(ASYNC, "\0message1\xff", 10), |
+ MockWrite(ASYNC, "\0message2\xff", 10)}; |
MockRead data_reads[] = { |
- MockRead(SocketStreamTest::kWebSocketHandshakeResponse), |
- // Server doesn't close the connection after handshake. |
- MockRead(ASYNC, ERR_IO_PENDING) |
- }; |
+ MockRead(SocketStreamTest::kWebSocketHandshakeResponse), |
+ // Server doesn't close the connection after handshake. |
+ MockRead(ASYNC, ERR_IO_PENDING)}; |
AddWebSocketMessage("message1"); |
AddWebSocketMessage("message2"); |
- DelayedSocketData data_provider( |
- 1, data_reads, arraysize(data_reads), |
- data_writes, arraysize(data_writes)); |
+ DelayedSocketData data_provider(1, |
+ data_reads, |
+ arraysize(data_reads), |
+ data_writes, |
+ arraysize(data_writes)); |
- MockClientSocketFactory* mock_socket_factory = |
- GetMockClientSocketFactory(); |
+ MockClientSocketFactory* mock_socket_factory = GetMockClientSocketFactory(); |
mock_socket_factory->AddSocketDataProvider(&data_provider); |
socket_stream->SetClientSocketFactory(mock_socket_factory); |
@@ -779,9 +780,8 @@ TEST_F(SocketStreamTest, SwitchToSpdy) { |
TestURLRequestContext context; |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
socket_stream->Connect(); |
@@ -801,14 +801,13 @@ TEST_F(SocketStreamTest, SwitchAfterPending) { |
scoped_ptr<SocketStreamEventRecorder> delegate( |
new SocketStreamEventRecorder(test_callback.callback())); |
- delegate->SetOnStartOpenConnection(base::Bind( |
- &SocketStreamTest::DoIOPending, base::Unretained(this))); |
+ delegate->SetOnStartOpenConnection( |
+ base::Bind(&SocketStreamTest::DoIOPending, base::Unretained(this))); |
TestURLRequestContext context; |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
socket_stream->Connect(); |
io_test_callback_.WaitForResult(); |
@@ -831,22 +830,20 @@ TEST_F(SocketStreamTest, SwitchAfterPending) { |
// Test a connection though a secure proxy. |
TEST_F(SocketStreamTest, SecureProxyConnectError) { |
MockClientSocketFactory mock_socket_factory; |
- MockWrite data_writes[] = { |
- MockWrite("CONNECT example.com:80 HTTP/1.1\r\n" |
- "Host: example.com\r\n" |
- "Proxy-Connection: keep-alive\r\n\r\n") |
- }; |
+ MockWrite data_writes[] = {MockWrite( |
+ "CONNECT example.com:80 HTTP/1.1\r\n" |
+ "Host: example.com\r\n" |
+ "Proxy-Connection: keep-alive\r\n\r\n")}; |
MockRead data_reads[] = { |
- MockRead("HTTP/1.1 200 Connection Established\r\n"), |
- MockRead("Proxy-agent: Apache/2.2.8\r\n"), |
- MockRead("\r\n"), |
- // SocketStream::DoClose is run asynchronously. Socket can be read after |
- // "\r\n". We have to give ERR_IO_PENDING to SocketStream then to indicate |
- // server doesn't close the connection. |
- MockRead(ASYNC, ERR_IO_PENDING) |
- }; |
- StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
- data_writes, arraysize(data_writes)); |
+ MockRead("HTTP/1.1 200 Connection Established\r\n"), |
+ MockRead("Proxy-agent: Apache/2.2.8\r\n"), MockRead("\r\n"), |
+ // SocketStream::DoClose is run asynchronously. Socket can be read after |
+ // "\r\n". We have to give ERR_IO_PENDING to SocketStream then to |
+ // indicate |
+ // server doesn't close the connection. |
+ MockRead(ASYNC, ERR_IO_PENDING)}; |
+ StaticSocketDataProvider data( |
+ data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
mock_socket_factory.AddSocketDataProvider(&data); |
SSLSocketDataProvider ssl(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
mock_socket_factory.AddSSLSocketDataProvider(&ssl); |
@@ -859,9 +856,8 @@ TEST_F(SocketStreamTest, SecureProxyConnectError) { |
delegate->SetOnConnected(base::Bind(&SocketStreamEventRecorder::DoClose, |
base::Unretained(delegate.get()))); |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
socket_stream->SetClientSocketFactory(&mock_socket_factory); |
@@ -882,22 +878,20 @@ TEST_F(SocketStreamTest, SecureProxyConnectError) { |
// Test a connection though a secure proxy. |
TEST_F(SocketStreamTest, SecureProxyConnect) { |
MockClientSocketFactory mock_socket_factory; |
- MockWrite data_writes[] = { |
- MockWrite("CONNECT example.com:80 HTTP/1.1\r\n" |
- "Host: example.com\r\n" |
- "Proxy-Connection: keep-alive\r\n\r\n") |
- }; |
+ MockWrite data_writes[] = {MockWrite( |
+ "CONNECT example.com:80 HTTP/1.1\r\n" |
+ "Host: example.com\r\n" |
+ "Proxy-Connection: keep-alive\r\n\r\n")}; |
MockRead data_reads[] = { |
- MockRead("HTTP/1.1 200 Connection Established\r\n"), |
- MockRead("Proxy-agent: Apache/2.2.8\r\n"), |
- MockRead("\r\n"), |
- // SocketStream::DoClose is run asynchronously. Socket can be read after |
- // "\r\n". We have to give ERR_IO_PENDING to SocketStream then to indicate |
- // server doesn't close the connection. |
- MockRead(ASYNC, ERR_IO_PENDING) |
- }; |
- StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
- data_writes, arraysize(data_writes)); |
+ MockRead("HTTP/1.1 200 Connection Established\r\n"), |
+ MockRead("Proxy-agent: Apache/2.2.8\r\n"), MockRead("\r\n"), |
+ // SocketStream::DoClose is run asynchronously. Socket can be read after |
+ // "\r\n". We have to give ERR_IO_PENDING to SocketStream then to |
+ // indicate |
+ // server doesn't close the connection. |
+ MockRead(ASYNC, ERR_IO_PENDING)}; |
+ StaticSocketDataProvider data( |
+ data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); |
mock_socket_factory.AddSocketDataProvider(&data); |
SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
mock_socket_factory.AddSSLSocketDataProvider(&ssl); |
@@ -910,9 +904,8 @@ TEST_F(SocketStreamTest, SecureProxyConnect) { |
delegate->SetOnConnected(base::Bind(&SocketStreamEventRecorder::DoClose, |
base::Unretained(delegate.get()))); |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
socket_stream->SetClientSocketFactory(&mock_socket_factory); |
@@ -942,9 +935,8 @@ TEST_F(SocketStreamTest, BeforeConnectFailed) { |
network_delegate.SetBeforeConnectResult(ERR_ACCESS_DENIED); |
context.set_network_delegate(&network_delegate); |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
socket_stream->Connect(); |
@@ -974,9 +966,8 @@ TEST_F(SocketStreamTest, OnErrorDetachDelegate) { |
mock_socket_factory.AddSocketDataProvider(&data); |
TestURLRequestContext context; |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://localhost:9998/echo"), delegate, |
- &context, NULL)); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://localhost:9998/echo"), delegate, &context, NULL)); |
socket_stream->SetClientSocketFactory(&mock_socket_factory); |
delegate->set_socket_stream(socket_stream); |
// The delegate pointer will become invalid during the test. Set it to NULL to |
@@ -994,11 +985,10 @@ TEST_F(SocketStreamTest, NullContextSocketStreamShouldNotCrash) { |
scoped_ptr<SocketStreamEventRecorder> delegate( |
new SocketStreamEventRecorder(test_callback.callback())); |
TestURLRequestContext context; |
- scoped_refptr<SocketStream> socket_stream( |
- new SocketStream(GURL("ws://example.com/demo"), delegate.get(), |
- &context, NULL)); |
- delegate->SetOnStartOpenConnection(base::Bind( |
- &SocketStreamTest::DoIOPending, base::Unretained(this))); |
+ scoped_refptr<SocketStream> socket_stream(new SocketStream( |
+ GURL("ws://example.com/demo"), delegate.get(), &context, NULL)); |
+ delegate->SetOnStartOpenConnection( |
+ base::Bind(&SocketStreamTest::DoIOPending, base::Unretained(this))); |
delegate->SetOnConnected(base::Bind( |
&SocketStreamTest::DoSendWebSocketHandshake, base::Unretained(this))); |
delegate->SetOnReceivedData(base::Bind( |
@@ -1006,17 +996,19 @@ TEST_F(SocketStreamTest, NullContextSocketStreamShouldNotCrash) { |
base::Unretained(this))); |
MockWrite data_writes[] = { |
- MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), |
+ MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), |
}; |
MockRead data_reads[] = { |
- MockRead(SocketStreamTest::kWebSocketHandshakeResponse), |
+ MockRead(SocketStreamTest::kWebSocketHandshakeResponse), |
}; |
AddWebSocketMessage("message1"); |
AddWebSocketMessage("message2"); |
- DelayedSocketData data_provider( |
- 1, data_reads, arraysize(data_reads), |
- data_writes, arraysize(data_writes)); |
+ DelayedSocketData data_provider(1, |
+ data_reads, |
+ arraysize(data_reads), |
+ data_writes, |
+ arraysize(data_writes)); |
MockClientSocketFactory* mock_socket_factory = GetMockClientSocketFactory(); |
mock_socket_factory->AddSocketDataProvider(&data_provider); |