diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-16 19:46:56 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-16 19:46:56 +0000 |
commit | 1f418eedde2047d92089e72265ec3e1706d97c10 (patch) | |
tree | ee444e94faae36e30fdc3ec847595e27440ffbbc /net/spdy | |
parent | 1b1a9221491b3c47b33c4380efeab04a36d98112 (diff) | |
download | chromium_src-1f418eedde2047d92089e72265ec3e1706d97c10.zip chromium_src-1f418eedde2047d92089e72265ec3e1706d97c10.tar.gz chromium_src-1f418eedde2047d92089e72265ec3e1706d97c10.tar.bz2 |
Add an off switch for SPDY:
--use-spdy=off
BUG=none
TEST=SpdyNetworkTransactionTest.SpdyOnOffToggle
Review URL: http://codereview.chromium.org/3807008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62870 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 66 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 1 |
2 files changed, 63 insertions, 4 deletions
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index e9076d3..99b50896 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -26,7 +26,7 @@ static const char kExpectedNPNString[] = "\x08http/1.1\x06spdy/2"; enum SpdyNetworkTransactionTestTypes { SPDYNPN, SPDYNOSSL, - SPDYSSL + SPDYSSL, }; class SpdyNetworkTransactionTest : public ::testing::TestWithParam<SpdyNetworkTransactionTestTypes> { @@ -69,7 +69,8 @@ class SpdyNetworkTransactionTest session_deps_.get())), log_(log), test_type_(test_type), - deterministic_(false) { + deterministic_(false), + spdy_enabled_(true) { switch (test_type_) { case SPDYNOSSL: case SPDYSSL: @@ -101,6 +102,10 @@ class SpdyNetworkTransactionTest deterministic_ = true; } + void SetSpdyDisabled() { + spdy_enabled_ = false; + } + void RunPreTestSetup() { if (!session_deps_.get()) session_deps_.reset(new SpdySessionDependencies()); @@ -154,14 +159,20 @@ class SpdyNetworkTransactionTest ASSERT_TRUE(response != NULL); ASSERT_TRUE(response->headers != NULL); EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); - EXPECT_TRUE(response->was_fetched_via_spdy); - if (test_type_ == SPDYNPN) { + EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); + if (test_type_ == SPDYNPN && spdy_enabled_) { EXPECT_TRUE(response->was_npn_negotiated); EXPECT_TRUE(response->was_alternate_protocol_available); } else { EXPECT_TRUE(!response->was_npn_negotiated); EXPECT_TRUE(!response->was_alternate_protocol_available); } + // If SPDY is not enabled, a HTTP request should not be diverted + // over a SSL session. + if (!spdy_enabled_) { + EXPECT_EQ(request_.url.SchemeIs("https"), + response->was_npn_negotiated); + } output_.status_line = response->headers->GetStatusLine(); output_.response_info = *response; // Make a copy so we can verify. output_.rv = ReadTransaction(trans_.get(), &output_.response_data); @@ -287,6 +298,7 @@ class SpdyNetworkTransactionTest SpdyNetworkTransactionTestTypes test_type_; int port_; bool deterministic_; + bool spdy_enabled_; }; void ConnectStatusHelperWithExpectedStatus(const MockRead& status, @@ -4483,4 +4495,50 @@ TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { helper.VerifyDataConsumed(); } } + +// Test that turning SPDY on and off works properly. +TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { + net::HttpStreamFactory::set_spdy_enabled(true); + scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); + MockWrite spdy_writes[] = { CreateMockWrite(*req) }; + + scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); + MockRead spdy_reads[] = { + CreateMockRead(*resp), + CreateMockRead(*body), + MockRead(true, 0, 0) // EOF + }; + + scoped_refptr<DelayedSocketData> data( + new DelayedSocketData(1, spdy_reads, arraysize(spdy_reads), + spdy_writes, arraysize(spdy_writes))); + NormalSpdyTransactionHelper helper(CreateGetRequest(), + BoundNetLog(), GetParam()); + helper.RunToCompletion(data.get()); + TransactionHelperResult out = helper.output(); + EXPECT_EQ(OK, out.rv); + EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); + EXPECT_EQ("hello!", out.response_data); + + net::HttpStreamFactory::set_spdy_enabled(false); + MockRead http_reads[] = { + MockRead("HTTP/1.1 200 OK\r\n\r\n"), + MockRead("hello from http"), + MockRead(false, OK), + }; + scoped_refptr<DelayedSocketData> data2( + new DelayedSocketData(1, http_reads, arraysize(http_reads), + NULL, 0)); + NormalSpdyTransactionHelper helper2(CreateGetRequest(), + BoundNetLog(), GetParam()); + helper2.SetSpdyDisabled(); + helper2.RunToCompletion(data2.get()); + TransactionHelperResult out2 = helper2.output(); + EXPECT_EQ(OK, out2.rv); + EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); + EXPECT_EQ("hello from http", out2.response_data); + + net::HttpStreamFactory::set_spdy_enabled(true); +} } // namespace net diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index b6e1529..f94dfd3 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -249,6 +249,7 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, initial_send_window_size_(spdy::kInitialWindowSize), initial_recv_window_size_(spdy::kInitialWindowSize), net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SPDY_SESSION)) { + DCHECK(HttpStreamFactory::spdy_enabled()); net_log_.BeginEvent( NetLog::TYPE_SPDY_SESSION, new NetLogSpdySessionParameter(host_port_proxy_pair_)); |