diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-02 22:20:02 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-02 22:20:02 +0000 |
commit | 067ce8b0ec3c50dc169de62bfefb245289ba3394 (patch) | |
tree | 15179eaa37fb3de559233e4a300ec400b9f70917 /net/websockets | |
parent | 24c9ee594694a646eec1e5028cdd088cf4d73f9d (diff) | |
download | chromium_src-067ce8b0ec3c50dc169de62bfefb245289ba3394.zip chromium_src-067ce8b0ec3c50dc169de62bfefb245289ba3394.tar.gz chromium_src-067ce8b0ec3c50dc169de62bfefb245289ba3394.tar.bz2 |
Get rid of websocket_over_spdy_enabled global.
It's now called enable_websocket_over_spdy and is a member of
HttpNetworkSession::Params.
BUG=372528
Review URL: https://codereview.chromium.org/295383007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r-- | net/websockets/websocket_job.cc | 12 | ||||
-rw-r--r-- | net/websockets/websocket_job.h | 6 | ||||
-rw-r--r-- | net/websockets/websocket_job_test.cc | 50 | ||||
-rw-r--r-- | net/websockets/websocket_throttle_test.cc | 39 |
4 files changed, 51 insertions, 56 deletions
diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc index cd8f09dd7..eb653fa 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -59,18 +59,11 @@ static base::LazyInstance<WebSocketJobInitSingleton> g_websocket_job_init = namespace net { -bool WebSocketJob::websocket_over_spdy_enabled_ = false; - // static void WebSocketJob::EnsureInit() { g_websocket_job_init.Get(); } -// static -void WebSocketJob::set_websocket_over_spdy_enabled(bool enabled) { - websocket_over_spdy_enabled_ = enabled; -} - WebSocketJob::WebSocketJob(SocketStream::Delegate* delegate) : delegate_(delegate), state_(INITIALIZED), @@ -579,16 +572,13 @@ int WebSocketJob::TrySpdyStream() { if (!socket_.get()) return ERR_FAILED; - if (!websocket_over_spdy_enabled_) - return OK; - // Check if we have a SPDY session available. HttpTransactionFactory* factory = socket_->context()->http_transaction_factory(); if (!factory) return OK; scoped_refptr<HttpNetworkSession> session = factory->GetSession(); - if (!session.get()) + if (!session.get() || !session->params().enable_websocket_over_spdy) return OK; SpdySessionPool* spdy_pool = session->spdy_session_pool(); PrivacyMode privacy_mode = socket_->privacy_mode(); diff --git a/net/websockets/websocket_job.h b/net/websockets/websocket_job.h index 119c4dc..2e90a24 100644 --- a/net/websockets/websocket_job.h +++ b/net/websockets/websocket_job.h @@ -49,10 +49,6 @@ class NET_EXPORT WebSocketJob static void EnsureInit(); - // Enable or Disable WebSocket over SPDY feature. - // This function is intended to be called before I/O thread starts. - static void set_websocket_over_spdy_enabled(bool enabled); - State state() const { return state_; } virtual void Connect() OVERRIDE; virtual bool SendData(const char* data, int len) OVERRIDE; @@ -124,8 +120,6 @@ class NET_EXPORT WebSocketJob void CloseInternal(); void SendPending(); - static bool websocket_over_spdy_enabled_; - SocketStream::Delegate* delegate_; State state_; bool waiting_; diff --git a/net/websockets/websocket_job_test.cc b/net/websockets/websocket_job_test.cc index 22fd6e7..7b87a87 100644 --- a/net/websockets/websocket_job_test.cc +++ b/net/websockets/websocket_job_test.cc @@ -274,11 +274,14 @@ class MockURLRequestContext : public URLRequestContext { class MockHttpTransactionFactory : public HttpTransactionFactory { public: - MockHttpTransactionFactory(NextProto next_proto, OrderedSocketData* data) { + MockHttpTransactionFactory(NextProto next_proto, + OrderedSocketData* data, + bool enable_websocket_over_spdy) { data_ = data; MockConnect connect_data(SYNCHRONOUS, OK); data_->set_connect_data(connect_data); session_deps_.reset(new SpdySessionDependencies(next_proto)); + session_deps_->enable_websocket_over_spdy = enable_websocket_over_spdy; session_deps_->socket_factory->AddSocketDataProvider(data_); http_session_ = SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); @@ -389,7 +392,9 @@ class DeletingSocketStreamDelegate : public SocketStream::Delegate { class WebSocketJobTest : public PlatformTest, public ::testing::WithParamInterface<NextProto> { public: - WebSocketJobTest() : spdy_util_(GetParam()) {} + WebSocketJobTest() + : spdy_util_(GetParam()), + enable_websocket_over_spdy_(false) {} virtual void SetUp() OVERRIDE { stream_type_ = STREAM_INVALID; @@ -416,6 +421,7 @@ class WebSocketJobTest : public PlatformTest, int WaitForResult() { return sync_test_callback_.WaitForResult(); } + protected: enum StreamType { STREAM_INVALID, @@ -444,8 +450,8 @@ 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(GetParam(), data_.get())); + http_factory_.reset(new MockHttpTransactionFactory( + GetParam(), data_.get(), enable_websocket_over_spdy_)); context_->set_http_transaction_factory(http_factory_.get()); } @@ -530,6 +536,9 @@ class WebSocketJobTest : public PlatformTest, scoped_ptr<MockHostResolver> host_resolver_; scoped_ptr<MockHttpTransactionFactory> http_factory_; + // Must be set before call to enable_websocket_over_spdy, defaults to false. + bool enable_websocket_over_spdy_; + static const char kHandshakeRequestWithoutCookie[]; static const char kHandshakeRequestWithCookie[]; static const char kHandshakeRequestWithFilteredCookie[]; @@ -711,7 +720,7 @@ INSTANTIATE_TEST_CASE_P( kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); TEST_P(WebSocketJobTest, DelayedCookies) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; GURL url("ws://example.com/demo"); GURL cookieUrl("http://example.com/demo"); CookieOptions cookie_options; @@ -1114,87 +1123,79 @@ void WebSocketJobTest::TestThrottlingLimit() { // Execute tests in both spdy-disabled mode and spdy-enabled mode. TEST_P(WebSocketJobTest, SimpleHandshake) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestSimpleHandshake(); } TEST_P(WebSocketJobTest, SlowHandshake) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestSlowHandshake(); } TEST_P(WebSocketJobTest, HandshakeWithCookie) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestHandshakeWithCookie(); } TEST_P(WebSocketJobTest, HandshakeWithCookieButNotAllowed) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestHandshakeWithCookieButNotAllowed(); } TEST_P(WebSocketJobTest, HSTSUpgrade) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestHSTSUpgrade(); } TEST_P(WebSocketJobTest, InvalidSendData) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestInvalidSendData(); } TEST_P(WebSocketJobTest, SimpleHandshakeSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestSimpleHandshake(); } TEST_P(WebSocketJobTest, SlowHandshakeSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestSlowHandshake(); } TEST_P(WebSocketJobTest, HandshakeWithCookieSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestHandshakeWithCookie(); } TEST_P(WebSocketJobTest, HandshakeWithCookieButNotAllowedSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestHandshakeWithCookieButNotAllowed(); } TEST_P(WebSocketJobTest, HSTSUpgradeSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestHSTSUpgrade(); } TEST_P(WebSocketJobTest, InvalidSendDataSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestInvalidSendData(); } TEST_P(WebSocketJobTest, ConnectByWebSocket) { - WebSocketJob::set_websocket_over_spdy_enabled(false); + enable_websocket_over_spdy_ = true; TestConnectByWebSocket(THROTTLING_OFF); } TEST_P(WebSocketJobTest, ConnectByWebSocketSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestConnectByWebSocket(THROTTLING_OFF); } TEST_P(WebSocketJobTest, ConnectBySpdy) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestConnectBySpdy(SPDY_OFF, THROTTLING_OFF); } TEST_P(WebSocketJobTest, ConnectBySpdySpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestConnectBySpdy(SPDY_ON, THROTTLING_OFF); } TEST_P(WebSocketJobTest, ThrottlingWebSocket) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestConnectByWebSocket(THROTTLING_ON); } @@ -1203,17 +1204,16 @@ TEST_P(WebSocketJobTest, ThrottlingMaxNumberOfThrottledJobLimit) { } TEST_P(WebSocketJobTest, ThrottlingWebSocketSpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestConnectByWebSocket(THROTTLING_ON); } TEST_P(WebSocketJobTest, ThrottlingSpdy) { - WebSocketJob::set_websocket_over_spdy_enabled(false); TestConnectBySpdy(SPDY_OFF, THROTTLING_ON); } TEST_P(WebSocketJobTest, ThrottlingSpdySpdyEnabled) { - WebSocketJob::set_websocket_over_spdy_enabled(true); + enable_websocket_over_spdy_ = true; TestConnectBySpdy(SPDY_ON, THROTTLING_ON); } diff --git a/net/websockets/websocket_throttle_test.cc b/net/websockets/websocket_throttle_test.cc index 7b33883..4d93001 100644 --- a/net/websockets/websocket_throttle_test.cc +++ b/net/websockets/websocket_throttle_test.cc @@ -16,20 +16,34 @@ #include "testing/platform_test.h" #include "url/gurl.h" -class DummySocketStreamDelegate : public net::SocketStream::Delegate { +namespace net { + +namespace { + +class DummySocketStreamDelegate : public SocketStream::Delegate { public: DummySocketStreamDelegate() {} virtual ~DummySocketStreamDelegate() {} virtual void OnConnected( - net::SocketStream* socket, int max_pending_send_allowed) OVERRIDE {} - virtual void OnSentData(net::SocketStream* socket, + SocketStream* socket, int max_pending_send_allowed) OVERRIDE {} + virtual void OnSentData(SocketStream* socket, int amount_sent) OVERRIDE {} - virtual void OnReceivedData(net::SocketStream* socket, + virtual void OnReceivedData(SocketStream* socket, const char* data, int len) OVERRIDE {} - virtual void OnClose(net::SocketStream* socket) OVERRIDE {} + virtual void OnClose(SocketStream* socket) OVERRIDE {} }; -namespace net { +class WebSocketThrottleTestContext : public TestURLRequestContext { + public: + explicit WebSocketThrottleTestContext(bool enable_websocket_over_spdy) + : TestURLRequestContext(true) { + HttpNetworkSession::Params params; + params.enable_websocket_over_spdy = enable_websocket_over_spdy; + Init(); + } +}; + +} // namespace class WebSocketThrottleTest : public PlatformTest { protected: @@ -60,11 +74,10 @@ class WebSocketThrottleTest : public PlatformTest { }; TEST_F(WebSocketThrottleTest, Throttle) { - TestURLRequestContext context; - DummySocketStreamDelegate delegate; // TODO(toyoshim): We need to consider both spdy-enabled and spdy-disabled // configuration. - WebSocketJob::set_websocket_over_spdy_enabled(true); + WebSocketThrottleTestContext context(true); + DummySocketStreamDelegate delegate; // For host1: 1.2.3.4, 1.2.3.5, 1.2.3.6 AddressList addr; @@ -273,9 +286,8 @@ TEST_F(WebSocketThrottleTest, Throttle) { } TEST_F(WebSocketThrottleTest, NoThrottleForDuplicateAddress) { - TestURLRequestContext context; + WebSocketThrottleTestContext context(true); DummySocketStreamDelegate delegate; - WebSocketJob::set_websocket_over_spdy_enabled(true); // For localhost: 127.0.0.1, 127.0.0.1 AddressList addr; @@ -302,11 +314,10 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDuplicateAddress) { // A connection should not be blocked by another connection to the same IP // with a different port. TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) { - TestURLRequestContext context; + WebSocketThrottleTestContext context(false); DummySocketStreamDelegate delegate; IPAddressNumber localhost; ParseIPLiteralToNumber("127.0.0.1", &localhost); - WebSocketJob::set_websocket_over_spdy_enabled(false); // socket1: 127.0.0.1:80 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); @@ -345,4 +356,4 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) { base::MessageLoopForIO::current()->RunUntilIdle(); } -} +} // namespace net |