Index: net/websockets/websocket_job_spdy2_unittest.cc |
=================================================================== |
--- net/websockets/websocket_job_spdy2_unittest.cc (revision 124690) |
+++ net/websockets/websocket_job_spdy2_unittest.cc (working copy) |
@@ -28,14 +28,16 @@ |
#include "net/socket/socket_test_util.h" |
#include "net/socket_stream/socket_stream.h" |
#include "net/spdy/spdy_session.h" |
-#include "net/spdy/spdy_test_util.h" |
-#include "net/spdy/spdy_websocket_test_util.h" |
+#include "net/spdy/spdy_test_util_spdy2.h" |
+#include "net/spdy/spdy_websocket_test_util_spdy2.h" |
#include "net/url_request/url_request_context.h" |
#include "net/websockets/websocket_throttle.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/platform_test.h" |
+using namespace net::test_spdy2; |
+ |
namespace { |
class MockSocketStream : public net::SocketStream { |
@@ -260,10 +262,10 @@ |
data_ = data; |
net::MockConnect connect_data(net::SYNCHRONOUS, net::OK); |
data_->set_connect_data(connect_data); |
- session_deps_.reset(new net::SpdySessionDependencies); |
+ session_deps_.reset(new SpdySessionDependencies); |
session_deps_->socket_factory->AddSocketDataProvider(data_); |
http_session_ = |
- net::SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); |
+ SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); |
host_port_pair_.set_host("example.com"); |
host_port_pair_.set_port(80); |
host_port_proxy_pair_.first = host_port_pair_; |
@@ -302,18 +304,18 @@ |
} |
private: |
net::OrderedSocketData* data_; |
- scoped_ptr<net::SpdySessionDependencies> session_deps_; |
+ scoped_ptr<SpdySessionDependencies> session_deps_; |
scoped_refptr<net::HttpNetworkSession> http_session_; |
scoped_refptr<net::TransportSocketParams> transport_params_; |
scoped_refptr<net::SpdySession> session_; |
net::HostPortPair host_port_pair_; |
net::HostPortProxyPair host_port_proxy_pair_; |
}; |
-} |
+} // namespace |
namespace net { |
-class WebSocketJobTest : public PlatformTest { |
+class WebSocketJobSpdy2Test : public PlatformTest { |
public: |
virtual void SetUp() { |
spdy::SpdyFramer::set_enable_compression_default(false); |
@@ -473,7 +475,7 @@ |
static const size_t kDataWorldLength; |
}; |
-const char WebSocketJobTest::kHandshakeRequestWithoutCookie[] = |
+const char WebSocketJobSpdy2Test::kHandshakeRequestWithoutCookie[] = |
"GET /demo HTTP/1.1\r\n" |
"Host: example.com\r\n" |
"Connection: Upgrade\r\n" |
@@ -485,7 +487,7 @@ |
"\r\n" |
"^n:ds[4U"; |
-const char WebSocketJobTest::kHandshakeRequestWithCookie[] = |
+const char WebSocketJobSpdy2Test::kHandshakeRequestWithCookie[] = |
"GET /demo HTTP/1.1\r\n" |
"Host: example.com\r\n" |
"Connection: Upgrade\r\n" |
@@ -498,7 +500,7 @@ |
"\r\n" |
"^n:ds[4U"; |
-const char WebSocketJobTest::kHandshakeRequestWithFilteredCookie[] = |
+const char WebSocketJobSpdy2Test::kHandshakeRequestWithFilteredCookie[] = |
"GET /demo HTTP/1.1\r\n" |
"Host: example.com\r\n" |
"Connection: Upgrade\r\n" |
@@ -511,7 +513,7 @@ |
"\r\n" |
"^n:ds[4U"; |
-const char WebSocketJobTest::kHandshakeResponseWithoutCookie[] = |
+const char WebSocketJobSpdy2Test::kHandshakeResponseWithoutCookie[] = |
"HTTP/1.1 101 WebSocket Protocol Handshake\r\n" |
"Upgrade: WebSocket\r\n" |
"Connection: Upgrade\r\n" |
@@ -521,7 +523,7 @@ |
"\r\n" |
"8jKS'y:G*Co,Wxa-"; |
-const char WebSocketJobTest::kHandshakeResponseWithCookie[] = |
+const char WebSocketJobSpdy2Test::kHandshakeResponseWithCookie[] = |
"HTTP/1.1 101 WebSocket Protocol Handshake\r\n" |
"Upgrade: WebSocket\r\n" |
"Connection: Upgrade\r\n" |
@@ -532,42 +534,42 @@ |
"\r\n" |
"8jKS'y:G*Co,Wxa-"; |
-const char WebSocketJobTest::kDataHello[] = "Hello, "; |
+const char WebSocketJobSpdy2Test::kDataHello[] = "Hello, "; |
-const char WebSocketJobTest::kDataWorld[] = "World!\n"; |
+const char WebSocketJobSpdy2Test::kDataWorld[] = "World!\n"; |
// TODO(toyoshim): I should clarify which WebSocket headers for handshake must |
// be exported to SPDY SYN_STREAM and SYN_REPLY. |
// Because it depends on HyBi versions, just define it as follow for now. |
-const char* const WebSocketJobTest::kHandshakeRequestForSpdy[] = { |
+const char* const WebSocketJobSpdy2Test::kHandshakeRequestForSpdy[] = { |
"host", "example.com", |
"origin", "http://example.com", |
"sec-websocket-protocol", "sample", |
"url", "ws://example.com/demo" |
}; |
-const char* const WebSocketJobTest::kHandshakeResponseForSpdy[] = { |
+const char* const WebSocketJobSpdy2Test::kHandshakeResponseForSpdy[] = { |
"sec-websocket-origin", "http://example.com", |
"sec-websocket-location", "ws://example.com/demo", |
"sec-websocket-protocol", "sample", |
}; |
-const size_t WebSocketJobTest::kHandshakeRequestWithoutCookieLength = |
+const size_t WebSocketJobSpdy2Test::kHandshakeRequestWithoutCookieLength = |
arraysize(kHandshakeRequestWithoutCookie) - 1; |
-const size_t WebSocketJobTest::kHandshakeRequestWithCookieLength = |
+const size_t WebSocketJobSpdy2Test::kHandshakeRequestWithCookieLength = |
arraysize(kHandshakeRequestWithCookie) - 1; |
-const size_t WebSocketJobTest::kHandshakeRequestWithFilteredCookieLength = |
+const size_t WebSocketJobSpdy2Test::kHandshakeRequestWithFilteredCookieLength = |
arraysize(kHandshakeRequestWithFilteredCookie) - 1; |
-const size_t WebSocketJobTest::kHandshakeResponseWithoutCookieLength = |
+const size_t WebSocketJobSpdy2Test::kHandshakeResponseWithoutCookieLength = |
arraysize(kHandshakeResponseWithoutCookie) - 1; |
-const size_t WebSocketJobTest::kHandshakeResponseWithCookieLength = |
+const size_t WebSocketJobSpdy2Test::kHandshakeResponseWithCookieLength = |
arraysize(kHandshakeResponseWithCookie) - 1; |
-const size_t WebSocketJobTest::kDataHelloLength = |
+const size_t WebSocketJobSpdy2Test::kDataHelloLength = |
arraysize(kDataHello) - 1; |
-const size_t WebSocketJobTest::kDataWorldLength = |
+const size_t WebSocketJobSpdy2Test::kDataWorldLength = |
arraysize(kDataWorld) - 1; |
-void WebSocketJobTest::TestSimpleHandshake() { |
+void WebSocketJobSpdy2Test::TestSimpleHandshake() { |
GURL url("ws://example.com/demo"); |
MockSocketStreamDelegate delegate; |
InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET); |
@@ -590,7 +592,7 @@ |
CloseWebSocketJob(); |
} |
-void WebSocketJobTest::TestSlowHandshake() { |
+void WebSocketJobSpdy2Test::TestSlowHandshake() { |
GURL url("ws://example.com/demo"); |
MockSocketStreamDelegate delegate; |
InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET); |
@@ -628,7 +630,7 @@ |
CloseWebSocketJob(); |
} |
-TEST_F(WebSocketJobTest, DelayedCookies) { |
+TEST_F(WebSocketJobSpdy2Test, DelayedCookies) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
GURL url("ws://example.com/demo"); |
GURL cookieUrl("http://example.com/demo"); |
@@ -668,7 +670,7 @@ |
CloseWebSocketJob(); |
} |
-void WebSocketJobTest::TestHandshakeWithCookie() { |
+void WebSocketJobSpdy2Test::TestHandshakeWithCookie() { |
GURL url("ws://example.com/demo"); |
GURL cookieUrl("http://example.com/demo"); |
CookieOptions cookie_options; |
@@ -711,7 +713,7 @@ |
CloseWebSocketJob(); |
} |
-void WebSocketJobTest::TestHandshakeWithCookieButNotAllowed() { |
+void WebSocketJobSpdy2Test::TestHandshakeWithCookieButNotAllowed() { |
GURL url("ws://example.com/demo"); |
GURL cookieUrl("http://example.com/demo"); |
CookieOptions cookie_options; |
@@ -752,7 +754,7 @@ |
CloseWebSocketJob(); |
} |
-void WebSocketJobTest::TestHSTSUpgrade() { |
+void WebSocketJobSpdy2Test::TestHSTSUpgrade() { |
GURL url("ws://upgrademe.com/"); |
MockSocketStreamDelegate delegate; |
scoped_refptr<SocketStreamJob> job = |
@@ -770,7 +772,7 @@ |
job->DetachDelegate(); |
} |
-void WebSocketJobTest::TestInvalidSendData() { |
+void WebSocketJobSpdy2Test::TestInvalidSendData() { |
GURL url("ws://example.com/demo"); |
MockSocketStreamDelegate delegate; |
InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET); |
@@ -801,7 +803,8 @@ |
// packets in comparison with the MockWrite array and emulating in-coming |
// packets with MockRead array. |
-void WebSocketJobTest::TestConnectByWebSocket(ThrottlingOption throttling) { |
+void WebSocketJobSpdy2Test::TestConnectByWebSocket( |
+ ThrottlingOption throttling) { |
// This is a test for verifying cooperation between WebSocketJob and |
// SocketStream. If |throttling| was |THROTTLING_OFF|, it test basic |
// situation. If |throttling| was |THROTTLING_ON|, throttling limits the |
@@ -832,16 +835,17 @@ |
GURL url("ws://example.com/demo"); |
MockSocketStreamDelegate delegate; |
- WebSocketJobTest* test = this; |
+ WebSocketJobSpdy2Test* test = this; |
if (throttling == THROTTLING_ON) |
delegate.SetOnStartOpenConnection( |
- base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test))); |
+ base::Bind(&WebSocketJobSpdy2Test::DoSync, base::Unretained(test))); |
delegate.SetOnConnected( |
- base::Bind(&WebSocketJobTest::DoSendRequest, base::Unretained(test))); |
+ base::Bind(&WebSocketJobSpdy2Test::DoSendRequest, |
+ base::Unretained(test))); |
delegate.SetOnReceivedData( |
- base::Bind(&WebSocketJobTest::DoSendData, base::Unretained(test))); |
+ base::Bind(&WebSocketJobSpdy2Test::DoSendData, base::Unretained(test))); |
delegate.SetOnClose( |
- base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test))); |
+ base::Bind(&WebSocketJobSpdy2Test::DoSync, base::Unretained(test))); |
InitWebSocketJob(url, &delegate, STREAM_SOCKET); |
scoped_refptr<WebSocketJob> block_websocket; |
@@ -872,7 +876,7 @@ |
EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState()); |
} |
-void WebSocketJobTest::TestConnectBySpdy( |
+void WebSocketJobSpdy2Test::TestConnectBySpdy( |
SpdyOption spdy, ThrottlingOption throttling) { |
// This is a test for verifying cooperation between WebSocketJob and |
// SocketStream in the situation we have SPDY session to the server. If |
@@ -947,16 +951,17 @@ |
GURL url("ws://example.com/demo"); |
MockSocketStreamDelegate delegate; |
- WebSocketJobTest* test = this; |
+ WebSocketJobSpdy2Test* test = this; |
if (throttling == THROTTLING_ON) |
delegate.SetOnStartOpenConnection( |
- base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test))); |
+ base::Bind(&WebSocketJobSpdy2Test::DoSync, base::Unretained(test))); |
delegate.SetOnConnected( |
- base::Bind(&WebSocketJobTest::DoSendRequest, base::Unretained(test))); |
+ base::Bind(&WebSocketJobSpdy2Test::DoSendRequest, |
+ base::Unretained(test))); |
delegate.SetOnReceivedData( |
- base::Bind(&WebSocketJobTest::DoSendData, base::Unretained(test))); |
+ base::Bind(&WebSocketJobSpdy2Test::DoSendData, base::Unretained(test))); |
delegate.SetOnClose( |
- base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test))); |
+ base::Bind(&WebSocketJobSpdy2Test::DoSync, base::Unretained(test))); |
InitWebSocketJob(url, &delegate, STREAM_SPDY_WEBSOCKET); |
scoped_refptr<WebSocketJob> block_websocket; |
@@ -988,102 +993,102 @@ |
} |
// Execute tests in both spdy-disabled mode and spdy-enabled mode. |
-TEST_F(WebSocketJobTest, SimpleHandshake) { |
+TEST_F(WebSocketJobSpdy2Test, SimpleHandshake) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestSimpleHandshake(); |
} |
-TEST_F(WebSocketJobTest, SlowHandshake) { |
+TEST_F(WebSocketJobSpdy2Test, SlowHandshake) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestSlowHandshake(); |
} |
-TEST_F(WebSocketJobTest, HandshakeWithCookie) { |
+TEST_F(WebSocketJobSpdy2Test, HandshakeWithCookie) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestHandshakeWithCookie(); |
} |
-TEST_F(WebSocketJobTest, HandshakeWithCookieButNotAllowed) { |
+TEST_F(WebSocketJobSpdy2Test, HandshakeWithCookieButNotAllowed) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestHandshakeWithCookieButNotAllowed(); |
} |
-TEST_F(WebSocketJobTest, HSTSUpgrade) { |
+TEST_F(WebSocketJobSpdy2Test, HSTSUpgrade) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestHSTSUpgrade(); |
} |
-TEST_F(WebSocketJobTest, InvalidSendData) { |
+TEST_F(WebSocketJobSpdy2Test, InvalidSendData) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestInvalidSendData(); |
} |
-TEST_F(WebSocketJobTest, SimpleHandshakeSpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, SimpleHandshakeSpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestSimpleHandshake(); |
} |
-TEST_F(WebSocketJobTest, SlowHandshakeSpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, SlowHandshakeSpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestSlowHandshake(); |
} |
-TEST_F(WebSocketJobTest, HandshakeWithCookieSpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, HandshakeWithCookieSpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestHandshakeWithCookie(); |
} |
-TEST_F(WebSocketJobTest, HandshakeWithCookieButNotAllowedSpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, HandshakeWithCookieButNotAllowedSpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestHandshakeWithCookieButNotAllowed(); |
} |
-TEST_F(WebSocketJobTest, HSTSUpgradeSpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, HSTSUpgradeSpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestHSTSUpgrade(); |
} |
-TEST_F(WebSocketJobTest, InvalidSendDataSpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, InvalidSendDataSpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestInvalidSendData(); |
} |
-TEST_F(WebSocketJobTest, ConnectByWebSocket) { |
+TEST_F(WebSocketJobSpdy2Test, ConnectByWebSocket) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestConnectByWebSocket(THROTTLING_OFF); |
} |
-TEST_F(WebSocketJobTest, ConnectByWebSocketSpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, ConnectByWebSocketSpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestConnectByWebSocket(THROTTLING_OFF); |
} |
-TEST_F(WebSocketJobTest, ConnectBySpdy) { |
+TEST_F(WebSocketJobSpdy2Test, ConnectBySpdy) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestConnectBySpdy(SPDY_OFF, THROTTLING_OFF); |
} |
-TEST_F(WebSocketJobTest, ConnectBySpdySpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, ConnectBySpdySpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestConnectBySpdy(SPDY_ON, THROTTLING_OFF); |
} |
-TEST_F(WebSocketJobTest, ThrottlingWebSocket) { |
+TEST_F(WebSocketJobSpdy2Test, ThrottlingWebSocket) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestConnectByWebSocket(THROTTLING_ON); |
} |
-TEST_F(WebSocketJobTest, ThrottlingWebSocketSpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, ThrottlingWebSocketSpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestConnectByWebSocket(THROTTLING_ON); |
} |
-TEST_F(WebSocketJobTest, ThrottlingSpdy) { |
+TEST_F(WebSocketJobSpdy2Test, ThrottlingSpdy) { |
WebSocketJob::set_websocket_over_spdy_enabled(false); |
TestConnectBySpdy(SPDY_OFF, THROTTLING_ON); |
} |
-TEST_F(WebSocketJobTest, ThrottlingSpdySpdyEnabled) { |
+TEST_F(WebSocketJobSpdy2Test, ThrottlingSpdySpdyEnabled) { |
WebSocketJob::set_websocket_over_spdy_enabled(true); |
TestConnectBySpdy(SPDY_ON, THROTTLING_ON); |
} |